summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2018-10-24 17:57:22 +0000
committerjsing <>2018-10-24 17:57:22 +0000
commit4110681dbe8efbf5d13eeff4afa956673068e8fd (patch)
treec4bde435c9466178df1c42e0747e9ccbe096ea27
parente8a59701f7438ac9a23dda80591f6a625f5d6054 (diff)
downloadopenbsd-4110681dbe8efbf5d13eeff4afa956673068e8fd.tar.gz
openbsd-4110681dbe8efbf5d13eeff4afa956673068e8fd.tar.bz2
openbsd-4110681dbe8efbf5d13eeff4afa956673068e8fd.zip
Remove a bunch of ancient and highly crufty ASN.1 related code from
libcrypto (the "new" stuff replaced this back around 2000 or so...). ok tb@
-rw-r--r--src/lib/libcrypto/Makefile6
-rw-r--r--src/lib/libcrypto/Symbols.list13
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c306
-rw-r--r--src/lib/libcrypto/asn1/a_set.c236
-rw-r--r--src/lib/libcrypto/asn1/asn1.h233
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c58
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h426
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c112
-rw-r--r--src/lib/libcrypto/stack/safestack.h265
9 files changed, 22 insertions, 1633 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile
index 8c5e46b169..7f6322ff7f 100644
--- a/src/lib/libcrypto/Makefile
+++ b/src/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.27 2018/03/17 16:20:01 beck Exp $ 1# $OpenBSD: Makefile,v 1.28 2018/10/24 17:57:22 jsing Exp $
2 2
3LIB= crypto 3LIB= crypto
4LIBREBUILD=y 4LIBREBUILD=y
@@ -55,9 +55,8 @@ SRCS+= tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c
55SRCS+= tasn_prn.c ameth_lib.c 55SRCS+= tasn_prn.c ameth_lib.c
56SRCS+= f_int.c f_string.c n_pkey.c 56SRCS+= f_int.c f_string.c n_pkey.c
57SRCS+= f_enum.c x_pkey.c a_bool.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c 57SRCS+= f_enum.c x_pkey.c a_bool.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c
58SRCS+= asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_bytes.c a_strnid.c 58SRCS+= asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_strnid.c
59SRCS+= evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c 59SRCS+= evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c
60SRCS+= a_set.c
61SRCS+= a_time_tm.c 60SRCS+= a_time_tm.c
62 61
63# bf/ 62# bf/
@@ -324,7 +323,6 @@ SRCS+= pcy_cache.c pcy_node.c pcy_data.c pcy_map.c pcy_tree.c pcy_lib.c
324HDRS=\ 323HDRS=\
325 ${LCRYPTO_SRC}/aes/aes.h \ 324 ${LCRYPTO_SRC}/aes/aes.h \
326 ${LCRYPTO_SRC}/asn1/asn1.h \ 325 ${LCRYPTO_SRC}/asn1/asn1.h \
327 ${LCRYPTO_SRC}/asn1/asn1_mac.h \
328 ${LCRYPTO_SRC}/asn1/asn1t.h \ 326 ${LCRYPTO_SRC}/asn1/asn1t.h \
329 ${LCRYPTO_SRC}/bf/blowfish.h \ 327 ${LCRYPTO_SRC}/bf/blowfish.h \
330 ${LCRYPTO_SRC}/bio/bio.h \ 328 ${LCRYPTO_SRC}/bio/bio.h \
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list
index 7851c4c3a6..4bfd84a65d 100644
--- a/src/lib/libcrypto/Symbols.list
+++ b/src/lib/libcrypto/Symbols.list
@@ -199,15 +199,12 @@ ASN1_item_verify
199ASN1_mbstring_copy 199ASN1_mbstring_copy
200ASN1_mbstring_ncopy 200ASN1_mbstring_ncopy
201ASN1_object_size 201ASN1_object_size
202ASN1_pack_string
203ASN1_parse 202ASN1_parse
204ASN1_parse_dump 203ASN1_parse_dump
205ASN1_primitive_free 204ASN1_primitive_free
206ASN1_primitive_new 205ASN1_primitive_new
207ASN1_put_eoc 206ASN1_put_eoc
208ASN1_put_object 207ASN1_put_object
209ASN1_seq_pack
210ASN1_seq_unpack
211ASN1_tag2bit 208ASN1_tag2bit
212ASN1_tag2str 209ASN1_tag2str
213ASN1_template_d2i 210ASN1_template_d2i
@@ -217,7 +214,6 @@ ASN1_template_new
217ASN1_time_parse 214ASN1_time_parse
218ASN1_time_tm_clamp_notafter 215ASN1_time_tm_clamp_notafter
219ASN1_time_tm_cmp 216ASN1_time_tm_cmp
220ASN1_unpack_string
221AUTHORITY_INFO_ACCESS_free 217AUTHORITY_INFO_ACCESS_free
222AUTHORITY_INFO_ACCESS_it 218AUTHORITY_INFO_ACCESS_it
223AUTHORITY_INFO_ACCESS_new 219AUTHORITY_INFO_ACCESS_new
@@ -3126,10 +3122,6 @@ a2i_GENERAL_NAME
3126a2i_IPADDRESS 3122a2i_IPADDRESS
3127a2i_IPADDRESS_NC 3123a2i_IPADDRESS_NC
3128a2i_ipadd 3124a2i_ipadd
3129asn1_Finish
3130asn1_GetSequence
3131asn1_add_error
3132asn1_const_Finish
3133asn1_do_adb 3125asn1_do_adb
3134asn1_do_lock 3126asn1_do_lock
3135asn1_enc_free 3127asn1_enc_free
@@ -3164,7 +3156,6 @@ d2i_ASN1_OCTET_STRING
3164d2i_ASN1_PRINTABLE 3156d2i_ASN1_PRINTABLE
3165d2i_ASN1_PRINTABLESTRING 3157d2i_ASN1_PRINTABLESTRING
3166d2i_ASN1_SEQUENCE_ANY 3158d2i_ASN1_SEQUENCE_ANY
3167d2i_ASN1_SET
3168d2i_ASN1_SET_ANY 3159d2i_ASN1_SET_ANY
3169d2i_ASN1_T61STRING 3160d2i_ASN1_T61STRING
3170d2i_ASN1_TIME 3161d2i_ASN1_TIME
@@ -3174,8 +3165,6 @@ d2i_ASN1_UNIVERSALSTRING
3174d2i_ASN1_UTCTIME 3165d2i_ASN1_UTCTIME
3175d2i_ASN1_UTF8STRING 3166d2i_ASN1_UTF8STRING
3176d2i_ASN1_VISIBLESTRING 3167d2i_ASN1_VISIBLESTRING
3177d2i_ASN1_bytes
3178d2i_ASN1_type_bytes
3179d2i_AUTHORITY_INFO_ACCESS 3168d2i_AUTHORITY_INFO_ACCESS
3180d2i_AUTHORITY_KEYID 3169d2i_AUTHORITY_KEYID
3181d2i_AutoPrivateKey 3170d2i_AutoPrivateKey
@@ -3374,7 +3363,6 @@ i2d_ASN1_OCTET_STRING
3374i2d_ASN1_PRINTABLE 3363i2d_ASN1_PRINTABLE
3375i2d_ASN1_PRINTABLESTRING 3364i2d_ASN1_PRINTABLESTRING
3376i2d_ASN1_SEQUENCE_ANY 3365i2d_ASN1_SEQUENCE_ANY
3377i2d_ASN1_SET
3378i2d_ASN1_SET_ANY 3366i2d_ASN1_SET_ANY
3379i2d_ASN1_T61STRING 3367i2d_ASN1_T61STRING
3380i2d_ASN1_TIME 3368i2d_ASN1_TIME
@@ -3384,7 +3372,6 @@ i2d_ASN1_UTCTIME
3384i2d_ASN1_UTF8STRING 3372i2d_ASN1_UTF8STRING
3385i2d_ASN1_VISIBLESTRING 3373i2d_ASN1_VISIBLESTRING
3386i2d_ASN1_bio_stream 3374i2d_ASN1_bio_stream
3387i2d_ASN1_bytes
3388i2d_AUTHORITY_INFO_ACCESS 3375i2d_AUTHORITY_INFO_ACCESS
3389i2d_AUTHORITY_KEYID 3376i2d_AUTHORITY_KEYID
3390i2d_BASIC_CONSTRAINTS 3377i2d_BASIC_CONSTRAINTS
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
deleted file mode 100644
index f3fe234851..0000000000
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ /dev/null
@@ -1,306 +0,0 @@
1/* $OpenBSD: a_bytes.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61
62#include <openssl/asn1.h>
63#include <openssl/buffer.h>
64#include <openssl/err.h>
65
66static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c);
67/* type is a 'bitmap' of acceptable string types.
68 */
69ASN1_STRING *
70d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
71 long length, int type)
72{
73 ASN1_STRING *ret = NULL;
74 const unsigned char *p;
75 unsigned char *s;
76 long len;
77 int inf, tag, xclass;
78 int i = 0;
79
80 p = *pp;
81 inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
82 if (inf & 0x80)
83 goto err;
84
85 if (tag >= 32) {
86 i = ASN1_R_TAG_VALUE_TOO_HIGH;
87 goto err;
88 }
89 if (!(ASN1_tag2bit(tag) & type)) {
90 i = ASN1_R_WRONG_TYPE;
91 goto err;
92 }
93
94 /* If a bit-string, exit early */
95 if (tag == V_ASN1_BIT_STRING)
96 return (d2i_ASN1_BIT_STRING(a, pp, length));
97
98 if ((a == NULL) || ((*a) == NULL)) {
99 if ((ret = ASN1_STRING_new()) == NULL)
100 return (NULL);
101 } else
102 ret = (*a);
103
104 if (len != 0) {
105 s = malloc(len + 1);
106 if (s == NULL) {
107 i = ERR_R_MALLOC_FAILURE;
108 goto err;
109 }
110 memcpy(s, p, len);
111 s[len]='\0';
112 p += len;
113 } else
114 s = NULL;
115
116 free(ret->data);
117 ret->length = (int)len;
118 ret->data = s;
119 ret->type = tag;
120 if (a != NULL)
121 (*a) = ret;
122 *pp = p;
123 return (ret);
124
125err:
126 ASN1error(i);
127 if (a == NULL || *a != ret)
128 ASN1_STRING_free(ret);
129 return (NULL);
130}
131
132int
133i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
134{
135 int ret, r, constructed;
136 unsigned char *p;
137
138 if (a == NULL)
139 return (0);
140
141 if (tag == V_ASN1_BIT_STRING)
142 return (i2d_ASN1_BIT_STRING(a, pp));
143
144 ret = a->length;
145 r = ASN1_object_size(0, ret, tag);
146 if (pp == NULL)
147 return (r);
148 p = *pp;
149
150 if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
151 constructed = 1;
152 else
153 constructed = 0;
154 ASN1_put_object(&p, constructed, ret, tag, xclass);
155 memcpy(p, a->data, a->length);
156 p += a->length;
157 *pp = p;
158 return (r);
159}
160
161ASN1_STRING *
162d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
163 long length, int Ptag, int Pclass)
164{
165 ASN1_STRING *ret = NULL;
166 const unsigned char *p;
167 unsigned char *s;
168 long len;
169 int inf, tag, xclass;
170 int i = 0;
171
172 if ((a == NULL) || ((*a) == NULL)) {
173 if ((ret = ASN1_STRING_new()) == NULL)
174 return (NULL);
175 } else
176 ret = (*a);
177
178 p= *pp;
179 inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
180 if (inf & 0x80) {
181 i = ASN1_R_BAD_OBJECT_HEADER;
182 goto err;
183 }
184
185 if (tag != Ptag) {
186 i = ASN1_R_WRONG_TAG;
187 goto err;
188 }
189
190 if (inf & V_ASN1_CONSTRUCTED) {
191 ASN1_const_CTX c;
192
193 c.pp = pp;
194 c.p = p;
195 c.inf = inf;
196 c.slen = len;
197 c.tag = Ptag;
198 c.xclass = Pclass;
199 c.max = (length == 0) ? 0 : (p + length);
200 if (!asn1_collate_primitive(ret, &c))
201 goto err;
202 else {
203 p = c.p;
204 }
205 } else {
206 if (len != 0) {
207 if ((ret->length < len) || (ret->data == NULL)) {
208 free(ret->data);
209 ret->data = NULL;
210 s = malloc(len + 1);
211 if (s == NULL) {
212 i = ERR_R_MALLOC_FAILURE;
213 goto err;
214 }
215 } else
216 s = ret->data;
217 memcpy(s, p, len);
218 s[len] = '\0';
219 p += len;
220 } else {
221 s = NULL;
222 free(ret->data);
223 }
224
225 ret->length = (int)len;
226 ret->data = s;
227 ret->type = Ptag;
228 }
229
230 if (a != NULL)
231 (*a) = ret;
232 *pp = p;
233 return (ret);
234
235err:
236 if (a == NULL || *a != ret)
237 ASN1_STRING_free(ret);
238 ASN1error(i);
239 return (NULL);
240}
241
242
243/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse
244 * them into the one structure that is then returned */
245/* There have been a few bug fixes for this function from
246 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
247static int
248asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c)
249{
250 ASN1_STRING *os = NULL;
251 BUF_MEM b;
252 int num;
253
254 b.length = 0;
255 b.max = 0;
256 b.data = NULL;
257
258 if (a == NULL) {
259 c->error = ERR_R_PASSED_NULL_PARAMETER;
260 goto err;
261 }
262
263 num = 0;
264 for (;;) {
265 if (c->inf & 1) {
266 c->eos = ASN1_const_check_infinite_end(&c->p,
267 (long)(c->max - c->p));
268 if (c->eos)
269 break;
270 } else {
271 if (c->slen <= 0)
272 break;
273 }
274
275 c->q = c->p;
276 if (d2i_ASN1_bytes(&os, &c->p, c->max - c->p, c->tag,
277 c->xclass) == NULL) {
278 c->error = ERR_R_ASN1_LIB;
279 goto err;
280 }
281
282 if (!BUF_MEM_grow_clean(&b, num + os->length)) {
283 c->error = ERR_R_BUF_LIB;
284 goto err;
285 }
286 memcpy(&(b.data[num]), os->data, os->length);
287 if (!(c->inf & 1))
288 c->slen -= (c->p - c->q);
289 num += os->length;
290 }
291
292 if (!asn1_const_Finish(c))
293 goto err;
294
295 a->length = num;
296 free(a->data);
297 a->data = (unsigned char *)b.data;
298 ASN1_STRING_free(os);
299 return (1);
300
301err:
302 ASN1error(c->error);
303 ASN1_STRING_free(os);
304 free(b.data);
305 return (0);
306}
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
deleted file mode 100644
index 4d5cae337b..0000000000
--- a/src/lib/libcrypto/asn1/a_set.c
+++ /dev/null
@@ -1,236 +0,0 @@
1/* $OpenBSD: a_set.c,v 1.18 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61
62#include <openssl/asn1_mac.h>
63#include <openssl/err.h>
64
65#ifndef NO_ASN1_OLD
66
67typedef struct {
68 unsigned char *pbData;
69 int cbData;
70} MYBLOB;
71
72/* SetBlobCmp
73 * This function compares two elements of SET_OF block
74 */
75static int
76SetBlobCmp(const void *elem1, const void *elem2)
77{
78 const MYBLOB *b1 = (const MYBLOB *)elem1;
79 const MYBLOB *b2 = (const MYBLOB *)elem2;
80 int r;
81
82 r = memcmp(b1->pbData, b2->pbData,
83 b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
84 if (r != 0)
85 return r;
86 return b1->cbData - b2->cbData;
87}
88
89/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
90int
91i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp, i2d_of_void *i2d,
92 int ex_tag, int ex_class, int is_set)
93{
94 int ret = 0, r;
95 int i;
96 unsigned char *p;
97 unsigned char *pStart, *pTempMem;
98 MYBLOB *rgSetBlob;
99 int totSize;
100
101 if (a == NULL)
102 return 0;
103 for (i = sk_OPENSSL_BLOCK_num(a) - 1; i >= 0; i--)
104 ret += i2d(sk_OPENSSL_BLOCK_value(a, i), NULL);
105 r = ASN1_object_size(1, ret, ex_tag);
106 if (pp == NULL)
107 return r;
108
109 p = *pp;
110 ASN1_put_object(&p, 1, ret, ex_tag, ex_class);
111
112 /* Modified by gp@nsj.co.jp */
113 /* And then again by Ben */
114 /* And again by Steve */
115
116 if (!is_set || (sk_OPENSSL_BLOCK_num(a) < 2)) {
117 for (i = 0; i < sk_OPENSSL_BLOCK_num(a); i++)
118 i2d(sk_OPENSSL_BLOCK_value(a, i), &p);
119
120 *pp = p;
121 return r;
122 }
123
124 pStart = p; /* Catch the beg of Setblobs*/
125 /* In this array we will store the SET blobs */
126 rgSetBlob = reallocarray(NULL, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB));
127 if (rgSetBlob == NULL) {
128 ASN1error(ERR_R_MALLOC_FAILURE);
129 return 0;
130 }
131
132 for (i = 0; i < sk_OPENSSL_BLOCK_num(a); i++) {
133 rgSetBlob[i].pbData = p; /* catch each set encode blob */
134 i2d(sk_OPENSSL_BLOCK_value(a, i), &p);
135 /* Length of this SetBlob */
136 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData;
137 }
138 *pp = p;
139 totSize = p - pStart; /* This is the total size of all set blobs */
140
141 /* Now we have to sort the blobs. I am using a simple algo.
142 * Sort ptrs
143 * Copy to temp-mem
144 * Copy from temp-mem to user-mem
145 */
146 qsort(rgSetBlob, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB), SetBlobCmp);
147 if ((pTempMem = malloc(totSize)) == NULL) {
148 free(rgSetBlob);
149 ASN1error(ERR_R_MALLOC_FAILURE);
150 return 0;
151 }
152
153 /* Copy to temp mem */
154 p = pTempMem;
155 for (i = 0; i < sk_OPENSSL_BLOCK_num(a); ++i) {
156 memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
157 p += rgSetBlob[i].cbData;
158 }
159
160 /* Copy back to user mem*/
161 memcpy(pStart, pTempMem, totSize);
162 free(pTempMem);
163 free(rgSetBlob);
164
165 return r;
166}
167
168STACK_OF(OPENSSL_BLOCK) *
169d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length,
170 d2i_of_void *d2i, void (*free_func)(OPENSSL_BLOCK), int ex_tag,
171 int ex_class)
172{
173 ASN1_const_CTX c;
174 STACK_OF(OPENSSL_BLOCK) *ret = NULL;
175
176 if (a == NULL || (*a) == NULL) {
177 if ((ret = sk_OPENSSL_BLOCK_new_null()) == NULL) {
178 ASN1error(ERR_R_MALLOC_FAILURE);
179 goto err;
180 }
181 } else
182 ret = *a;
183
184 c.p = *pp;
185 c.max = (length == 0) ? 0 : (c.p + length);
186
187 c.inf = ASN1_get_object(&c.p, &c.slen, &c.tag, &c.xclass, c.max - c.p);
188 if (c.inf & 0x80)
189 goto err;
190 if (ex_class != c.xclass) {
191 ASN1error(ASN1_R_BAD_CLASS);
192 goto err;
193 }
194 if (ex_tag != c.tag) {
195 ASN1error(ASN1_R_BAD_TAG);
196 goto err;
197 }
198 if (c.slen + c.p > c.max) {
199 ASN1error(ASN1_R_LENGTH_ERROR);
200 goto err;
201 }
202 /* check for infinite constructed - it can be as long
203 * as the amount of data passed to us */
204 if (c.inf == (V_ASN1_CONSTRUCTED + 1))
205 c.slen = length + *pp - c.p;
206 c.max = c.p + c.slen;
207
208 while (c.p < c.max) {
209 char *s;
210
211 if (M_ASN1_D2I_end_sequence())
212 break;
213 if ((s = d2i(NULL, &c.p, c.slen)) == NULL) {
214 ASN1error(ASN1_R_ERROR_PARSING_SET_ELEMENT);
215 asn1_add_error(*pp, (int)(c.p - *pp));
216 goto err;
217 }
218 if (!sk_OPENSSL_BLOCK_push(ret, s))
219 goto err;
220 }
221 if (a != NULL)
222 *a = ret;
223 *pp = c.p;
224 return ret;
225
226err:
227 if (a == NULL || *a != ret) {
228 if (free_func != NULL)
229 sk_OPENSSL_BLOCK_pop_free(ret, free_func);
230 else
231 sk_OPENSSL_BLOCK_free(ret);
232 }
233 return NULL;
234}
235
236#endif
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
index e3bebe45a6..7861c9cd51 100644
--- a/src/lib/libcrypto/asn1/asn1.h
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1.h,v 1.49 2018/05/19 10:46:28 tb Exp $ */ 1/* $OpenBSD: asn1.h,v 1.50 2018/10/24 17:57:22 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -125,7 +125,6 @@ extern "C" {
125#define V_ASN1_UNIVERSALSTRING 28 /**/ 125#define V_ASN1_UNIVERSALSTRING 28 /**/
126#define V_ASN1_BMPSTRING 30 126#define V_ASN1_BMPSTRING 30
127 127
128/* For use with d2i_ASN1_type_bytes() */
129#define B_ASN1_NUMERICSTRING 0x0001 128#define B_ASN1_NUMERICSTRING 0x0001
130#define B_ASN1_PRINTABLESTRING 0x0002 129#define B_ASN1_PRINTABLESTRING 0x0002
131#define B_ASN1_T61STRING 0x0004 130#define B_ASN1_T61STRING 0x0004
@@ -543,178 +542,6 @@ typedef struct BIT_STRING_BITNAME_st {
543 const char *sname; 542 const char *sname;
544} BIT_STRING_BITNAME; 543} BIT_STRING_BITNAME;
545 544
546#ifndef LIBRESSL_INTERNAL
547
548#define M_ASN1_STRING_length(x) ((x)->length)
549#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
550#define M_ASN1_STRING_type(x) ((x)->type)
551#define M_ASN1_STRING_data(x) ((x)->data)
552
553/* Macros for string operations */
554#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
555 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
556#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
557#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
558 ASN1_STRING_dup((const ASN1_STRING *)a)
559#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
560 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
561#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
562
563#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
564 ASN1_STRING_type_new(V_ASN1_INTEGER)
565#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
566#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)\
567 ASN1_STRING_dup((const ASN1_STRING *)a)
568#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
569 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
570
571#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
572 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
573#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
574#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)\
575 ASN1_STRING_dup((const ASN1_STRING *)a)
576#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
577 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
578
579#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
580 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
581#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
582#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
583 ASN1_STRING_dup((const ASN1_STRING *)a)
584#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
585 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
586#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
587#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
588#define M_i2d_ASN1_OCTET_STRING(a,pp) \
589 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
590 V_ASN1_UNIVERSAL)
591
592#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
593#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
594#define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
595 pp,a->type,V_ASN1_UNIVERSAL)
596#define M_d2i_ASN1_PRINTABLE(a,pp,l) \
597 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
598 B_ASN1_PRINTABLE)
599
600#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
601#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
602#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
603 pp,a->type,V_ASN1_UNIVERSAL)
604#define M_d2i_DIRECTORYSTRING(a,pp,l) \
605 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
606 B_ASN1_DIRECTORYSTRING)
607
608#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
609#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
610#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
611 pp,a->type,V_ASN1_UNIVERSAL)
612#define M_d2i_DISPLAYTEXT(a,pp,l) \
613 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
614 B_ASN1_DISPLAYTEXT)
615
616#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
617 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
618#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
619#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
620 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
621 V_ASN1_UNIVERSAL)
622#define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
623 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
624 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
625
626#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
627 ASN1_STRING_type_new(V_ASN1_T61STRING)
628#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
629#define M_i2d_ASN1_T61STRING(a,pp) \
630 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
631 V_ASN1_UNIVERSAL)
632#define M_d2i_ASN1_T61STRING(a,pp,l) \
633 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
634 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
635
636#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
637 ASN1_STRING_type_new(V_ASN1_IA5STRING)
638#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
639#define M_ASN1_IA5STRING_dup(a) \
640 (ASN1_IA5STRING *)ASN1_STRING_dup((const ASN1_STRING *)a)
641#define M_i2d_ASN1_IA5STRING(a,pp) \
642 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
643 V_ASN1_UNIVERSAL)
644#define M_d2i_ASN1_IA5STRING(a,pp,l) \
645 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
646 B_ASN1_IA5STRING)
647
648#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
649 ASN1_STRING_type_new(V_ASN1_UTCTIME)
650#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
651#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)\
652 ASN1_STRING_dup((const ASN1_STRING *)a)
653
654#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
655 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
656#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
657#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
658 (const ASN1_STRING *)a)
659
660#define M_ASN1_TIME_new() (ASN1_TIME *)\
661 ASN1_STRING_type_new(V_ASN1_UTCTIME)
662#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
663#define M_ASN1_TIME_dup(a) (ASN1_TIME *)\
664 ASN1_STRING_dup((const ASN1_STRING *)a)
665
666#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
667 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
668#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
669#define M_i2d_ASN1_GENERALSTRING(a,pp) \
670 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
671 V_ASN1_UNIVERSAL)
672#define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
673 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
674 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
675
676#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
677 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
678#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
679#define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
680 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
681 V_ASN1_UNIVERSAL)
682#define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
683 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
684 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
685
686#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
687 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
688#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
689#define M_i2d_ASN1_BMPSTRING(a,pp) \
690 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
691 V_ASN1_UNIVERSAL)
692#define M_d2i_ASN1_BMPSTRING(a,pp,l) \
693 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
694 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
695
696#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
697 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
698#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
699#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
700 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
701 V_ASN1_UNIVERSAL)
702#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
703 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
704 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
705
706#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
707 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
708#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
709#define M_i2d_ASN1_UTF8STRING(a,pp) \
710 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
711 V_ASN1_UNIVERSAL)
712#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
713 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
714 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
715
716#endif /* !LIBRESSL_INTERNAL */
717
718#define B_ASN1_TIME \ 545#define B_ASN1_TIME \
719 B_ASN1_UTCTIME | \ 546 B_ASN1_UTCTIME | \
720 B_ASN1_GENERALIZEDTIME 547 B_ASN1_GENERALIZEDTIME
@@ -744,9 +571,18 @@ typedef struct BIT_STRING_BITNAME_st {
744 B_ASN1_BMPSTRING|\ 571 B_ASN1_BMPSTRING|\
745 B_ASN1_UTF8STRING 572 B_ASN1_UTF8STRING
746 573
747/* for the is_set parameter to i2d_ASN1_SET */ 574#ifndef LIBRESSL_INTERNAL
748#define IS_SEQUENCE 0 575#define M_ASN1_IA5STRING_new ASN1_IA5STRING_new
749#define IS_SET 1 576
577#define M_ASN1_INTEGER_free ASN1_INTEGER_free
578#define M_ASN1_ENUMERATED_free ASN1_ENUMERATED_free
579#define M_ASN1_OCTET_STRING_free ASN1_OCTET_STRING_free
580
581#define M_ASN1_OCTET_STRING_print ASN1_STRING_print
582
583#define M_ASN1_STRING_data ASN1_STRING_data
584#define M_ASN1_STRING_length ASN1_STRING_length
585#endif
750 586
751ASN1_TYPE *ASN1_TYPE_new(void); 587ASN1_TYPE *ASN1_TYPE_new(void);
752void ASN1_TYPE_free(ASN1_TYPE *a); 588void ASN1_TYPE_free(ASN1_TYPE *a);
@@ -948,12 +784,6 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
948 ASN1_GENERALIZEDTIME **out); 784 ASN1_GENERALIZEDTIME **out);
949int ASN1_TIME_set_string(ASN1_TIME *s, const char *str); 785int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
950 786
951int i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp,
952 i2d_of_void *i2d, int ex_tag, int ex_class, int is_set);
953STACK_OF(OPENSSL_BLOCK) *d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a,
954 const unsigned char **pp, long length, d2i_of_void *d2i,
955 void (*free_func)(OPENSSL_BLOCK), int ex_tag, int ex_class);
956
957#ifndef OPENSSL_NO_BIO 787#ifndef OPENSSL_NO_BIO
958int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a); 788int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a);
959int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size); 789int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size);
@@ -983,18 +813,6 @@ BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn);
983/* given a string, return the correct type, max is the maximum length */ 813/* given a string, return the correct type, max is the maximum length */
984int ASN1_PRINTABLE_type(const unsigned char *s, int max); 814int ASN1_PRINTABLE_type(const unsigned char *s, int max);
985 815
986int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
987ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
988 long length, int Ptag, int Pclass);
989unsigned long ASN1_tag2bit(int tag);
990/* type is one or more of the B_ASN1_ values. */
991ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
992 long length, int type);
993
994/* PARSING */
995int asn1_Finish(ASN1_CTX *c);
996int asn1_const_Finish(ASN1_const_CTX *c);
997
998/* SPECIALS */ 816/* SPECIALS */
999int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, 817int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
1000 int *pclass, long omax); 818 int *pclass, long omax);
@@ -1007,29 +825,6 @@ int ASN1_object_size(int constructed, int length, int tag);
1007 825
1008void *ASN1_item_dup(const ASN1_ITEM *it, void *x); 826void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
1009 827
1010#ifndef LIBRESSL_INTERNAL
1011
1012/* Used to implement other functions */
1013void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x);
1014
1015#define ASN1_dup_of(type,i2d,d2i,x) \
1016 ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
1017 CHECKED_D2I_OF(type, d2i), \
1018 CHECKED_PTR_OF(type, x)))
1019
1020#define ASN1_dup_of_const(type,i2d,d2i,x) \
1021 ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \
1022 CHECKED_D2I_OF(type, d2i), \
1023 CHECKED_PTR_OF(const type, x)))
1024
1025/* ASN1 alloc/free macros for when a type is only used internally */
1026
1027#define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
1028#define M_ASN1_free_of(x, type) \
1029 ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
1030
1031#endif /* !LIBRESSL_INTERNAL */
1032
1033void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x); 828void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x);
1034 829
1035#define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \ 830#define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \
@@ -1090,6 +885,8 @@ int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
1090int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent); 885int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent);
1091int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump); 886int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump);
1092#endif 887#endif
888
889unsigned long ASN1_tag2bit(int tag);
1093const char *ASN1_tag2str(int tag); 890const char *ASN1_tag2str(int tag);
1094 891
1095/* Used to load and write netscape format cert */ 892/* Used to load and write netscape format cert */
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
index ffd3ad6a46..2a123d1d9a 100644
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_lib.c,v 1.41 2018/04/25 11:48:21 tb Exp $ */ 1/* $OpenBSD: asn1_lib.c,v 1.42 2018/10/24 17:57:22 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -285,62 +285,6 @@ ASN1_object_size(int constructed, int length, int tag)
285 return (ret); 285 return (ret);
286} 286}
287 287
288static int
289_asn1_Finish(ASN1_const_CTX *c)
290{
291 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) {
292 if (!ASN1_const_check_infinite_end(&c->p, c->slen)) {
293 c->error = ERR_R_MISSING_ASN1_EOS;
294 return (0);
295 }
296 }
297 if (((c->slen != 0) && !(c->inf & 1)) ||
298 ((c->slen < 0) && (c->inf & 1))) {
299 c->error = ERR_R_ASN1_LENGTH_MISMATCH;
300 return (0);
301 }
302 return (1);
303}
304
305int
306asn1_Finish(ASN1_CTX *c)
307{
308 return _asn1_Finish((ASN1_const_CTX *)c);
309}
310
311int
312asn1_const_Finish(ASN1_const_CTX *c)
313{
314 return _asn1_Finish(c);
315}
316
317int
318asn1_GetSequence(ASN1_const_CTX *c, long *length)
319{
320 const unsigned char *q;
321
322 q = c->p;
323 c->inf = ASN1_get_object(&(c->p), &(c->slen), &(c->tag), &(c->xclass),
324 *length);
325 if (c->inf & 0x80) {
326 c->error = ERR_R_BAD_GET_ASN1_OBJECT_CALL;
327 return (0);
328 }
329 if (c->tag != V_ASN1_SEQUENCE) {
330 c->error = ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
331 return (0);
332 }
333 (*length) -= (c->p - q);
334 if (c->max && (*length < 0)) {
335 c->error = ERR_R_ASN1_LENGTH_MISMATCH;
336 return (0);
337 }
338 if (c->inf == (1|V_ASN1_CONSTRUCTED))
339 c->slen= *length+ *(c->pp) - c->p;
340 c->eos = 0;
341 return (1);
342}
343
344int 288int
345ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) 289ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
346{ 290{
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
deleted file mode 100644
index fd524dc21c..0000000000
--- a/src/lib/libcrypto/asn1/asn1_mac.h
+++ /dev/null
@@ -1,426 +0,0 @@
1/* $OpenBSD: asn1_mac.h,v 1.14 2014/06/27 04:41:09 miod Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_ASN1_MAC_H
60#define HEADER_ASN1_MAC_H
61
62#include <openssl/asn1.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifndef ASN1_MAC_ERR_LIB
69#define ASN1_MAC_ERR_LIB ERR_LIB_ASN1
70#endif
71
72#define ASN1_MAC_H_err(f,r,line) \
73 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
74
75#define M_ASN1_D2I_vars(a,type,func) \
76 ASN1_const_CTX c; \
77 type ret=NULL; \
78 \
79 c.pp=(const unsigned char **)pp; \
80 c.q= *(const unsigned char **)pp; \
81 c.error=ERR_R_NESTED_ASN1_ERROR; \
82 if ((a == NULL) || ((*a) == NULL)) \
83 { if ((ret=(type)func()) == NULL) \
84 { c.line=__LINE__; goto err; } } \
85 else ret=(*a);
86
87#define M_ASN1_D2I_Init() \
88 c.p= *(const unsigned char **)pp; \
89 c.max=(length == 0)?0:(c.p+length);
90
91#define M_ASN1_D2I_Finish_2(a) \
92 if (!asn1_const_Finish(&c)) \
93 { c.line=__LINE__; goto err; } \
94 *(const unsigned char **)pp=c.p; \
95 if (a != NULL) (*a)=ret; \
96 return(ret);
97
98#define M_ASN1_D2I_Finish(a,func,e) \
99 M_ASN1_D2I_Finish_2(a); \
100err:\
101 ASN1_MAC_H_err((e),c.error,c.line); \
102 asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \
103 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
104 return(NULL)
105
106#define M_ASN1_D2I_start_sequence() \
107 if (!asn1_GetSequence(&c,&length)) \
108 { c.line=__LINE__; goto err; }
109/* Begin reading ASN1 without a surrounding sequence */
110#define M_ASN1_D2I_begin() \
111 c.slen = length;
112
113/* End reading ASN1 with no check on length */
114#define M_ASN1_D2I_Finish_nolen(a, func, e) \
115 *pp=c.p; \
116 if (a != NULL) (*a)=ret; \
117 return(ret); \
118err:\
119 ASN1_MAC_H_err((e),c.error,c.line); \
120 asn1_add_error(*pp,(int)(c.q- *pp)); \
121 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
122 return(NULL)
123
124#define M_ASN1_D2I_end_sequence() \
125 (((c.inf&1) == 0)?(c.slen <= 0): \
126 (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen)))
127
128/* Don't use this with d2i_ASN1_BOOLEAN() */
129#define M_ASN1_D2I_get(b, func) \
130 c.q=c.p; \
131 if (func(&(b),&c.p,c.slen) == NULL) \
132 {c.line=__LINE__; goto err; } \
133 c.slen-=(c.p-c.q);
134
135/* Don't use this with d2i_ASN1_BOOLEAN() */
136#define M_ASN1_D2I_get_x(type,b,func) \
137 c.q=c.p; \
138 if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \
139 {c.line=__LINE__; goto err; } \
140 c.slen-=(c.p-c.q);
141
142/* use this instead () */
143#define M_ASN1_D2I_get_int(b,func) \
144 c.q=c.p; \
145 if (func(&(b),&c.p,c.slen) < 0) \
146 {c.line=__LINE__; goto err; } \
147 c.slen-=(c.p-c.q);
148
149#define M_ASN1_D2I_get_opt(b,func,type) \
150 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
151 == (V_ASN1_UNIVERSAL|(type)))) \
152 { \
153 M_ASN1_D2I_get(b,func); \
154 }
155
156#define M_ASN1_D2I_get_int_opt(b,func,type) \
157 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \
158 == (V_ASN1_UNIVERSAL|(type)))) \
159 { \
160 M_ASN1_D2I_get_int(b,func); \
161 }
162
163#define M_ASN1_D2I_get_imp(b,func, type) \
164 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
165 c.q=c.p; \
166 if (func(&(b),&c.p,c.slen) == NULL) \
167 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
168 c.slen-=(c.p-c.q);\
169 M_ASN1_next_prev=_tmp;
170
171#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
172 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
173 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
174 { \
175 unsigned char _tmp = M_ASN1_next; \
176 M_ASN1_D2I_get_imp(b,func, type);\
177 }
178
179#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
180 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
181 V_ASN1_SET,V_ASN1_UNIVERSAL);
182
183#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
184 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
185 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
186 { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
187
188#define M_ASN1_I2D_len_SET_opt(a,f) \
189 if ((a != NULL) && (sk_num(a) != 0)) \
190 M_ASN1_I2D_len_SET(a,f);
191
192#define M_ASN1_I2D_put_SET_opt(a,f) \
193 if ((a != NULL) && (sk_num(a) != 0)) \
194 M_ASN1_I2D_put_SET(a,f);
195
196#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
197 if ((a != NULL) && (sk_num(a) != 0)) \
198 M_ASN1_I2D_put_SEQUENCE(a,f);
199
200#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
201 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
202 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
203
204#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
205 if ((c.slen != 0) && \
206 (M_ASN1_next == \
207 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
208 { \
209 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
210 tag,V_ASN1_CONTEXT_SPECIFIC); \
211 }
212
213#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
214 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
215 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
216
217#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
218 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
219 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
220 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
221
222#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
223 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
224 x,V_ASN1_CONTEXT_SPECIFIC);
225
226#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
227 c.q=c.p; \
228 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
229 free_func,a,b) == NULL) \
230 { c.line=__LINE__; goto err; } \
231 c.slen-=(c.p-c.q);
232
233#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
234 c.q=c.p; \
235 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
236 { c.line=__LINE__; goto err; } \
237 c.slen-=(c.p-c.q);
238
239#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
240 if ((c.slen != 0L) && (M_ASN1_next == \
241 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
242 { \
243 int Tinf,Ttag,Tclass; \
244 long Tlen; \
245 \
246 c.q=c.p; \
247 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
248 if (Tinf & 0x80) \
249 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
250 c.line=__LINE__; goto err; } \
251 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
252 Tlen = c.slen - (c.p - c.q) - 2; \
253 if (func(&(r),&c.p,Tlen) == NULL) \
254 { c.line=__LINE__; goto err; } \
255 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
256 Tlen = c.slen - (c.p - c.q); \
257 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \
258 { c.error=ERR_R_MISSING_ASN1_EOS; \
259 c.line=__LINE__; goto err; } \
260 }\
261 c.slen-=(c.p-c.q); \
262 }
263
264#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
265 if ((c.slen != 0) && (M_ASN1_next == \
266 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
267 { \
268 int Tinf,Ttag,Tclass; \
269 long Tlen; \
270 \
271 c.q=c.p; \
272 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
273 if (Tinf & 0x80) \
274 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
275 c.line=__LINE__; goto err; } \
276 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
277 Tlen = c.slen - (c.p - c.q) - 2; \
278 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
279 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
280 { c.line=__LINE__; goto err; } \
281 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
282 Tlen = c.slen - (c.p - c.q); \
283 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
284 { c.error=ERR_R_MISSING_ASN1_EOS; \
285 c.line=__LINE__; goto err; } \
286 }\
287 c.slen-=(c.p-c.q); \
288 }
289
290/* BIG UGLY WARNING! This is so damn ugly I wanna puke. Unfortunately,
291 some macros that use ASN1_const_CTX still insist on writing in the input
292 stream. ARGH! ARGH! ARGH! Let's get rid of this macro package.
293 Please? -- Richard Levitte */
294#define M_ASN1_next (*((unsigned char *)(c.p)))
295#define M_ASN1_next_prev (*((unsigned char *)(c.q)))
296
297/*************************************************/
298
299#define M_ASN1_I2D_vars(a) int r=0,ret=0; \
300 unsigned char *p; \
301 if (a == NULL) return(0)
302
303/* Length Macros */
304#define M_ASN1_I2D_len(a,f) ret+=f(a,NULL)
305#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
306
307#define M_ASN1_I2D_len_SET_type(type,a,f) \
308 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
309 V_ASN1_UNIVERSAL,IS_SET);
310
311#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
312 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
313 V_ASN1_UNIVERSAL,IS_SEQUENCE)
314
315#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
316 if ((a != NULL) && (sk_num(a) != 0)) \
317 M_ASN1_I2D_len_SEQUENCE(a,f);
318
319#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
320 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
321 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
322
323#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
324 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
325 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
326
327#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
328 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
329 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
330 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
331
332#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
333 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
334 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
335 V_ASN1_CONTEXT_SPECIFIC, \
336 IS_SEQUENCE);
337
338#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
339 if (a != NULL)\
340 { \
341 v=f(a,NULL); \
342 ret+=ASN1_object_size(1,v,mtag); \
343 }
344
345#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
346 if ((a != NULL) && (sk_##type##_num(a) != 0))\
347 { \
348 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
349 V_ASN1_UNIVERSAL, \
350 IS_SEQUENCE); \
351 ret+=ASN1_object_size(1,v,mtag); \
352 }
353
354/* Put Macros */
355#define M_ASN1_I2D_put(a,f) f(a,&p)
356
357#define M_ASN1_I2D_put_IMP_opt(a,f,t) \
358 if (a != NULL) \
359 { \
360 unsigned char *q=p; \
361 f(a,&p); \
362 *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\
363 }
364
365#define M_ASN1_I2D_put_SET_type(type,a,f) \
366 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
367#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
368 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
369
370#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
371 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
372 IS_SEQUENCE)
373
374#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
375 if ((a != NULL) && (sk_num(a) != 0)) \
376 M_ASN1_I2D_put_SEQUENCE(a,f);
377
378#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
379 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
380 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
381 V_ASN1_CONTEXT_SPECIFIC, \
382 IS_SET); }
383
384#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
385 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
386 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
387 V_ASN1_CONTEXT_SPECIFIC, \
388 IS_SEQUENCE); }
389
390#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
391 if (a != NULL) \
392 { \
393 ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \
394 f(a,&p); \
395 }
396
397#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
398 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
399 { \
400 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
401 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
402 IS_SEQUENCE); \
403 }
404
405#define M_ASN1_I2D_seq_total() \
406 r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \
407 if (pp == NULL) return(r); \
408 p= *pp; \
409 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
410
411#define M_ASN1_I2D_INF_seq_start(tag,ctx) \
412 *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \
413 *(p++)=0x80
414
415#define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00
416
417#define M_ASN1_I2D_finish() *pp=p; \
418 return(r);
419
420int asn1_GetSequence(ASN1_const_CTX *c, long *length);
421void asn1_add_error(const unsigned char *address, int offset);
422#ifdef __cplusplus
423}
424#endif
425
426#endif
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
index 1a5420e42b..090beff0f0 100644
--- a/src/lib/libcrypto/asn1/asn_pack.c
+++ b/src/lib/libcrypto/asn1/asn_pack.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn_pack.c,v 1.17 2018/04/25 11:48:21 tb Exp $ */ 1/* $OpenBSD: asn_pack.c,v 1.18 2018/10/24 17:57:22 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -61,112 +61,7 @@
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/err.h> 62#include <openssl/err.h>
63 63
64#ifndef NO_ASN1_OLD 64/* Pack an ASN1 object into an ASN1_STRING. */
65
66/* ASN1 packing and unpacking functions */
67
68/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
69
70STACK_OF(OPENSSL_BLOCK) *
71ASN1_seq_unpack(const unsigned char *buf, int len, d2i_of_void *d2i,
72 void (*free_func)(OPENSSL_BLOCK))
73{
74 STACK_OF(OPENSSL_BLOCK) *sk;
75 const unsigned char *pbuf;
76
77 pbuf = buf;
78 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
79 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
80 ASN1error(ASN1_R_DECODE_ERROR);
81 return sk;
82}
83
84/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
85 * OPENSSL_malloc'ed buffer
86 */
87
88unsigned char *
89ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
90 unsigned char **buf, int *len)
91{
92 int safelen;
93 unsigned char *safe, *p;
94
95 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
96 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
97 ASN1error(ASN1_R_ENCODE_ERROR);
98 return NULL;
99 }
100 if (!(safe = malloc(safelen))) {
101 ASN1error(ERR_R_MALLOC_FAILURE);
102 return NULL;
103 }
104 p = safe;
105 i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
106 IS_SEQUENCE);
107 if (len)
108 *len = safelen;
109 if (buf)
110 *buf = safe;
111 return safe;
112}
113
114/* Extract an ASN1 object from an ASN1_STRING */
115
116void *
117ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i)
118{
119 const unsigned char *p;
120 char *ret;
121
122 p = oct->data;
123 if (!(ret = d2i(NULL, &p, oct->length)))
124 ASN1error(ASN1_R_DECODE_ERROR);
125 return ret;
126}
127
128/* Pack an ASN1 object into an ASN1_STRING */
129
130ASN1_STRING *
131ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct)
132{
133 unsigned char *p;
134 ASN1_STRING *octmp;
135
136 if (!oct || !*oct) {
137 if (!(octmp = ASN1_STRING_new())) {
138 ASN1error(ERR_R_MALLOC_FAILURE);
139 return NULL;
140 }
141 } else
142 octmp = *oct;
143
144 if (!(octmp->length = i2d(obj, NULL))) {
145 ASN1error(ASN1_R_ENCODE_ERROR);
146 goto err;
147 }
148 if (!(p = malloc (octmp->length))) {
149 ASN1error(ERR_R_MALLOC_FAILURE);
150 goto err;
151 }
152 octmp->data = p;
153 i2d (obj, &p);
154 if (oct)
155 *oct = octmp;
156 return octmp;
157err:
158 if (!oct || octmp != *oct) {
159 ASN1_STRING_free(octmp);
160 if (oct)
161 *oct = NULL;
162 }
163 return NULL;
164}
165
166#endif
167
168/* ASN1_ITEM versions of the above */
169
170ASN1_STRING * 65ASN1_STRING *
171ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) 66ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
172{ 67{
@@ -200,8 +95,7 @@ err:
200 return NULL; 95 return NULL;
201} 96}
202 97
203/* Extract an ASN1 object from an ASN1_STRING */ 98/* Extract an ASN1 object from an ASN1_STRING. */
204
205void * 99void *
206ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it) 100ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it)
207{ 101{
diff --git a/src/lib/libcrypto/stack/safestack.h b/src/lib/libcrypto/stack/safestack.h
index 5d5c7873f1..ace2e95c13 100644
--- a/src/lib/libcrypto/stack/safestack.h
+++ b/src/lib/libcrypto/stack/safestack.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: safestack.h,v 1.16 2018/10/24 17:37:05 jsing Exp $ */ 1/* $OpenBSD: safestack.h,v 1.17 2018/10/24 17:57:22 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -179,35 +179,6 @@ DECLARE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
179#define SKM_sk_is_sorted(type, st) \ 179#define SKM_sk_is_sorted(type, st) \
180 sk_is_sorted(CHECKED_STACK_OF(type, st)) 180 sk_is_sorted(CHECKED_STACK_OF(type, st))
181 181
182#ifndef LIBRESSL_INTERNAL
183#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
184 (STACK_OF(type) *)d2i_ASN1_SET( \
185 (STACK_OF(OPENSSL_BLOCK) **)CHECKED_PTR_OF(STACK_OF(type)*, st), \
186 pp, length, \
187 CHECKED_D2I_OF(type, d2i_func), \
188 CHECKED_SK_FREE_FUNC(type, free_func), \
189 ex_tag, ex_class)
190
191#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \
192 i2d_ASN1_SET((STACK_OF(OPENSSL_BLOCK) *)CHECKED_STACK_OF(type, st), pp, \
193 CHECKED_I2D_OF(type, i2d_func), \
194 ex_tag, ex_class, is_set)
195
196#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \
197 ASN1_seq_pack(CHECKED_PTR_OF(STACK_OF(type), st), \
198 CHECKED_I2D_OF(type, i2d_func), buf, len)
199
200#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \
201 (STACK_OF(type) *)ASN1_seq_unpack(buf, len, CHECKED_D2I_OF(type, d2i_func), CHECKED_SK_FREE_FUNC(type, free_func))
202
203#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \
204 (STACK_OF(type) *)PKCS12_decrypt_d2i(algor, \
205 CHECKED_D2I_OF(type, d2i_func), \
206 CHECKED_SK_FREE_FUNC(type, free_func), \
207 pass, passlen, oct, seq)
208#endif
209
210/* This block of defines is updated by util/mkstack.pl, please do not touch! */
211#define sk_ACCESS_DESCRIPTION_new(cmp) SKM_sk_new(ACCESS_DESCRIPTION, (cmp)) 182#define sk_ACCESS_DESCRIPTION_new(cmp) SKM_sk_new(ACCESS_DESCRIPTION, (cmp))
212#define sk_ACCESS_DESCRIPTION_new_null() SKM_sk_new_null(ACCESS_DESCRIPTION) 183#define sk_ACCESS_DESCRIPTION_new_null() SKM_sk_new_null(ACCESS_DESCRIPTION)
213#define sk_ACCESS_DESCRIPTION_free(st) SKM_sk_free(ACCESS_DESCRIPTION, (st)) 184#define sk_ACCESS_DESCRIPTION_free(st) SKM_sk_free(ACCESS_DESCRIPTION, (st))
@@ -1864,239 +1835,6 @@ DECLARE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
1864#define sk_OPENSSL_PSTRING_sort(st) SKM_sk_sort(OPENSSL_PSTRING, (st)) 1835#define sk_OPENSSL_PSTRING_sort(st) SKM_sk_sort(OPENSSL_PSTRING, (st))
1865#define sk_OPENSSL_PSTRING_is_sorted(st) SKM_sk_is_sorted(OPENSSL_PSTRING, (st)) 1836#define sk_OPENSSL_PSTRING_is_sorted(st) SKM_sk_is_sorted(OPENSSL_PSTRING, (st))
1866 1837
1867#ifndef LIBRESSL_INTERNAL
1868#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1869 SKM_ASN1_SET_OF_d2i(ACCESS_DESCRIPTION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1870#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1871 SKM_ASN1_SET_OF_i2d(ACCESS_DESCRIPTION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1872#define ASN1_seq_pack_ACCESS_DESCRIPTION(st, i2d_func, buf, len) \
1873 SKM_ASN1_seq_pack(ACCESS_DESCRIPTION, (st), (i2d_func), (buf), (len))
1874#define ASN1_seq_unpack_ACCESS_DESCRIPTION(buf, len, d2i_func, free_func) \
1875 SKM_ASN1_seq_unpack(ACCESS_DESCRIPTION, (buf), (len), (d2i_func), (free_func))
1876
1877#define d2i_ASN1_SET_OF_ASN1_INTEGER(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1878 SKM_ASN1_SET_OF_d2i(ASN1_INTEGER, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1879#define i2d_ASN1_SET_OF_ASN1_INTEGER(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1880 SKM_ASN1_SET_OF_i2d(ASN1_INTEGER, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1881#define ASN1_seq_pack_ASN1_INTEGER(st, i2d_func, buf, len) \
1882 SKM_ASN1_seq_pack(ASN1_INTEGER, (st), (i2d_func), (buf), (len))
1883#define ASN1_seq_unpack_ASN1_INTEGER(buf, len, d2i_func, free_func) \
1884 SKM_ASN1_seq_unpack(ASN1_INTEGER, (buf), (len), (d2i_func), (free_func))
1885
1886#define d2i_ASN1_SET_OF_ASN1_OBJECT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1887 SKM_ASN1_SET_OF_d2i(ASN1_OBJECT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1888#define i2d_ASN1_SET_OF_ASN1_OBJECT(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1889 SKM_ASN1_SET_OF_i2d(ASN1_OBJECT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1890#define ASN1_seq_pack_ASN1_OBJECT(st, i2d_func, buf, len) \
1891 SKM_ASN1_seq_pack(ASN1_OBJECT, (st), (i2d_func), (buf), (len))
1892#define ASN1_seq_unpack_ASN1_OBJECT(buf, len, d2i_func, free_func) \
1893 SKM_ASN1_seq_unpack(ASN1_OBJECT, (buf), (len), (d2i_func), (free_func))
1894
1895#define d2i_ASN1_SET_OF_ASN1_TYPE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1896 SKM_ASN1_SET_OF_d2i(ASN1_TYPE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1897#define i2d_ASN1_SET_OF_ASN1_TYPE(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1898 SKM_ASN1_SET_OF_i2d(ASN1_TYPE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1899#define ASN1_seq_pack_ASN1_TYPE(st, i2d_func, buf, len) \
1900 SKM_ASN1_seq_pack(ASN1_TYPE, (st), (i2d_func), (buf), (len))
1901#define ASN1_seq_unpack_ASN1_TYPE(buf, len, d2i_func, free_func) \
1902 SKM_ASN1_seq_unpack(ASN1_TYPE, (buf), (len), (d2i_func), (free_func))
1903
1904#define d2i_ASN1_SET_OF_ASN1_UTF8STRING(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1905 SKM_ASN1_SET_OF_d2i(ASN1_UTF8STRING, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1906#define i2d_ASN1_SET_OF_ASN1_UTF8STRING(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1907 SKM_ASN1_SET_OF_i2d(ASN1_UTF8STRING, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1908#define ASN1_seq_pack_ASN1_UTF8STRING(st, i2d_func, buf, len) \
1909 SKM_ASN1_seq_pack(ASN1_UTF8STRING, (st), (i2d_func), (buf), (len))
1910#define ASN1_seq_unpack_ASN1_UTF8STRING(buf, len, d2i_func, free_func) \
1911 SKM_ASN1_seq_unpack(ASN1_UTF8STRING, (buf), (len), (d2i_func), (free_func))
1912
1913#define d2i_ASN1_SET_OF_DIST_POINT(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1914 SKM_ASN1_SET_OF_d2i(DIST_POINT, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1915#define i2d_ASN1_SET_OF_DIST_POINT(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1916 SKM_ASN1_SET_OF_i2d(DIST_POINT, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1917#define ASN1_seq_pack_DIST_POINT(st, i2d_func, buf, len) \
1918 SKM_ASN1_seq_pack(DIST_POINT, (st), (i2d_func), (buf), (len))
1919#define ASN1_seq_unpack_DIST_POINT(buf, len, d2i_func, free_func) \
1920 SKM_ASN1_seq_unpack(DIST_POINT, (buf), (len), (d2i_func), (free_func))
1921
1922#define d2i_ASN1_SET_OF_ESS_CERT_ID(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1923 SKM_ASN1_SET_OF_d2i(ESS_CERT_ID, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1924#define i2d_ASN1_SET_OF_ESS_CERT_ID(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1925 SKM_ASN1_SET_OF_i2d(ESS_CERT_ID, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1926#define ASN1_seq_pack_ESS_CERT_ID(st, i2d_func, buf, len) \
1927 SKM_ASN1_seq_pack(ESS_CERT_ID, (st), (i2d_func), (buf), (len))
1928#define ASN1_seq_unpack_ESS_CERT_ID(buf, len, d2i_func, free_func) \
1929 SKM_ASN1_seq_unpack(ESS_CERT_ID, (buf), (len), (d2i_func), (free_func))
1930
1931#define d2i_ASN1_SET_OF_EVP_MD(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1932 SKM_ASN1_SET_OF_d2i(EVP_MD, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1933#define i2d_ASN1_SET_OF_EVP_MD(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1934 SKM_ASN1_SET_OF_i2d(EVP_MD, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1935#define ASN1_seq_pack_EVP_MD(st, i2d_func, buf, len) \
1936 SKM_ASN1_seq_pack(EVP_MD, (st), (i2d_func), (buf), (len))
1937#define ASN1_seq_unpack_EVP_MD(buf, len, d2i_func, free_func) \
1938 SKM_ASN1_seq_unpack(EVP_MD, (buf), (len), (d2i_func), (free_func))
1939
1940#define d2i_ASN1_SET_OF_GENERAL_NAME(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1941 SKM_ASN1_SET_OF_d2i(GENERAL_NAME, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1942#define i2d_ASN1_SET_OF_GENERAL_NAME(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1943 SKM_ASN1_SET_OF_i2d(GENERAL_NAME, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1944#define ASN1_seq_pack_GENERAL_NAME(st, i2d_func, buf, len) \
1945 SKM_ASN1_seq_pack(GENERAL_NAME, (st), (i2d_func), (buf), (len))
1946#define ASN1_seq_unpack_GENERAL_NAME(buf, len, d2i_func, free_func) \
1947 SKM_ASN1_seq_unpack(GENERAL_NAME, (buf), (len), (d2i_func), (free_func))
1948
1949#define d2i_ASN1_SET_OF_OCSP_ONEREQ(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1950 SKM_ASN1_SET_OF_d2i(OCSP_ONEREQ, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1951#define i2d_ASN1_SET_OF_OCSP_ONEREQ(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1952 SKM_ASN1_SET_OF_i2d(OCSP_ONEREQ, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1953#define ASN1_seq_pack_OCSP_ONEREQ(st, i2d_func, buf, len) \
1954 SKM_ASN1_seq_pack(OCSP_ONEREQ, (st), (i2d_func), (buf), (len))
1955#define ASN1_seq_unpack_OCSP_ONEREQ(buf, len, d2i_func, free_func) \
1956 SKM_ASN1_seq_unpack(OCSP_ONEREQ, (buf), (len), (d2i_func), (free_func))
1957
1958#define d2i_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1959 SKM_ASN1_SET_OF_d2i(OCSP_SINGLERESP, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1960#define i2d_ASN1_SET_OF_OCSP_SINGLERESP(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1961 SKM_ASN1_SET_OF_i2d(OCSP_SINGLERESP, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1962#define ASN1_seq_pack_OCSP_SINGLERESP(st, i2d_func, buf, len) \
1963 SKM_ASN1_seq_pack(OCSP_SINGLERESP, (st), (i2d_func), (buf), (len))
1964#define ASN1_seq_unpack_OCSP_SINGLERESP(buf, len, d2i_func, free_func) \
1965 SKM_ASN1_seq_unpack(OCSP_SINGLERESP, (buf), (len), (d2i_func), (free_func))
1966
1967#define d2i_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1968 SKM_ASN1_SET_OF_d2i(PKCS12_SAFEBAG, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1969#define i2d_ASN1_SET_OF_PKCS12_SAFEBAG(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1970 SKM_ASN1_SET_OF_i2d(PKCS12_SAFEBAG, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1971#define ASN1_seq_pack_PKCS12_SAFEBAG(st, i2d_func, buf, len) \
1972 SKM_ASN1_seq_pack(PKCS12_SAFEBAG, (st), (i2d_func), (buf), (len))
1973#define ASN1_seq_unpack_PKCS12_SAFEBAG(buf, len, d2i_func, free_func) \
1974 SKM_ASN1_seq_unpack(PKCS12_SAFEBAG, (buf), (len), (d2i_func), (free_func))
1975
1976#define d2i_ASN1_SET_OF_PKCS7(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1977 SKM_ASN1_SET_OF_d2i(PKCS7, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1978#define i2d_ASN1_SET_OF_PKCS7(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1979 SKM_ASN1_SET_OF_i2d(PKCS7, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1980#define ASN1_seq_pack_PKCS7(st, i2d_func, buf, len) \
1981 SKM_ASN1_seq_pack(PKCS7, (st), (i2d_func), (buf), (len))
1982#define ASN1_seq_unpack_PKCS7(buf, len, d2i_func, free_func) \
1983 SKM_ASN1_seq_unpack(PKCS7, (buf), (len), (d2i_func), (free_func))
1984
1985#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1986 SKM_ASN1_SET_OF_d2i(PKCS7_RECIP_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1987#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1988 SKM_ASN1_SET_OF_i2d(PKCS7_RECIP_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1989#define ASN1_seq_pack_PKCS7_RECIP_INFO(st, i2d_func, buf, len) \
1990 SKM_ASN1_seq_pack(PKCS7_RECIP_INFO, (st), (i2d_func), (buf), (len))
1991#define ASN1_seq_unpack_PKCS7_RECIP_INFO(buf, len, d2i_func, free_func) \
1992 SKM_ASN1_seq_unpack(PKCS7_RECIP_INFO, (buf), (len), (d2i_func), (free_func))
1993
1994#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1995 SKM_ASN1_SET_OF_d2i(PKCS7_SIGNER_INFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1996#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
1997 SKM_ASN1_SET_OF_i2d(PKCS7_SIGNER_INFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
1998#define ASN1_seq_pack_PKCS7_SIGNER_INFO(st, i2d_func, buf, len) \
1999 SKM_ASN1_seq_pack(PKCS7_SIGNER_INFO, (st), (i2d_func), (buf), (len))
2000#define ASN1_seq_unpack_PKCS7_SIGNER_INFO(buf, len, d2i_func, free_func) \
2001 SKM_ASN1_seq_unpack(PKCS7_SIGNER_INFO, (buf), (len), (d2i_func), (free_func))
2002
2003#define d2i_ASN1_SET_OF_POLICYINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2004 SKM_ASN1_SET_OF_d2i(POLICYINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2005#define i2d_ASN1_SET_OF_POLICYINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2006 SKM_ASN1_SET_OF_i2d(POLICYINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2007#define ASN1_seq_pack_POLICYINFO(st, i2d_func, buf, len) \
2008 SKM_ASN1_seq_pack(POLICYINFO, (st), (i2d_func), (buf), (len))
2009#define ASN1_seq_unpack_POLICYINFO(buf, len, d2i_func, free_func) \
2010 SKM_ASN1_seq_unpack(POLICYINFO, (buf), (len), (d2i_func), (free_func))
2011
2012#define d2i_ASN1_SET_OF_POLICYQUALINFO(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2013 SKM_ASN1_SET_OF_d2i(POLICYQUALINFO, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2014#define i2d_ASN1_SET_OF_POLICYQUALINFO(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2015 SKM_ASN1_SET_OF_i2d(POLICYQUALINFO, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2016#define ASN1_seq_pack_POLICYQUALINFO(st, i2d_func, buf, len) \
2017 SKM_ASN1_seq_pack(POLICYQUALINFO, (st), (i2d_func), (buf), (len))
2018#define ASN1_seq_unpack_POLICYQUALINFO(buf, len, d2i_func, free_func) \
2019 SKM_ASN1_seq_unpack(POLICYQUALINFO, (buf), (len), (d2i_func), (free_func))
2020
2021#define d2i_ASN1_SET_OF_SXNETID(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2022 SKM_ASN1_SET_OF_d2i(SXNETID, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2023#define i2d_ASN1_SET_OF_SXNETID(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2024 SKM_ASN1_SET_OF_i2d(SXNETID, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2025#define ASN1_seq_pack_SXNETID(st, i2d_func, buf, len) \
2026 SKM_ASN1_seq_pack(SXNETID, (st), (i2d_func), (buf), (len))
2027#define ASN1_seq_unpack_SXNETID(buf, len, d2i_func, free_func) \
2028 SKM_ASN1_seq_unpack(SXNETID, (buf), (len), (d2i_func), (free_func))
2029
2030#define d2i_ASN1_SET_OF_X509(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2031 SKM_ASN1_SET_OF_d2i(X509, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2032#define i2d_ASN1_SET_OF_X509(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2033 SKM_ASN1_SET_OF_i2d(X509, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2034#define ASN1_seq_pack_X509(st, i2d_func, buf, len) \
2035 SKM_ASN1_seq_pack(X509, (st), (i2d_func), (buf), (len))
2036#define ASN1_seq_unpack_X509(buf, len, d2i_func, free_func) \
2037 SKM_ASN1_seq_unpack(X509, (buf), (len), (d2i_func), (free_func))
2038
2039#define d2i_ASN1_SET_OF_X509_ALGOR(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2040 SKM_ASN1_SET_OF_d2i(X509_ALGOR, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2041#define i2d_ASN1_SET_OF_X509_ALGOR(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2042 SKM_ASN1_SET_OF_i2d(X509_ALGOR, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2043#define ASN1_seq_pack_X509_ALGOR(st, i2d_func, buf, len) \
2044 SKM_ASN1_seq_pack(X509_ALGOR, (st), (i2d_func), (buf), (len))
2045#define ASN1_seq_unpack_X509_ALGOR(buf, len, d2i_func, free_func) \
2046 SKM_ASN1_seq_unpack(X509_ALGOR, (buf), (len), (d2i_func), (free_func))
2047
2048#define d2i_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2049 SKM_ASN1_SET_OF_d2i(X509_ATTRIBUTE, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2050#define i2d_ASN1_SET_OF_X509_ATTRIBUTE(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2051 SKM_ASN1_SET_OF_i2d(X509_ATTRIBUTE, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2052#define ASN1_seq_pack_X509_ATTRIBUTE(st, i2d_func, buf, len) \
2053 SKM_ASN1_seq_pack(X509_ATTRIBUTE, (st), (i2d_func), (buf), (len))
2054#define ASN1_seq_unpack_X509_ATTRIBUTE(buf, len, d2i_func, free_func) \
2055 SKM_ASN1_seq_unpack(X509_ATTRIBUTE, (buf), (len), (d2i_func), (free_func))
2056
2057#define d2i_ASN1_SET_OF_X509_CRL(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2058 SKM_ASN1_SET_OF_d2i(X509_CRL, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2059#define i2d_ASN1_SET_OF_X509_CRL(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2060 SKM_ASN1_SET_OF_i2d(X509_CRL, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2061#define ASN1_seq_pack_X509_CRL(st, i2d_func, buf, len) \
2062 SKM_ASN1_seq_pack(X509_CRL, (st), (i2d_func), (buf), (len))
2063#define ASN1_seq_unpack_X509_CRL(buf, len, d2i_func, free_func) \
2064 SKM_ASN1_seq_unpack(X509_CRL, (buf), (len), (d2i_func), (free_func))
2065
2066#define d2i_ASN1_SET_OF_X509_EXTENSION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2067 SKM_ASN1_SET_OF_d2i(X509_EXTENSION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2068#define i2d_ASN1_SET_OF_X509_EXTENSION(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2069 SKM_ASN1_SET_OF_i2d(X509_EXTENSION, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2070#define ASN1_seq_pack_X509_EXTENSION(st, i2d_func, buf, len) \
2071 SKM_ASN1_seq_pack(X509_EXTENSION, (st), (i2d_func), (buf), (len))
2072#define ASN1_seq_unpack_X509_EXTENSION(buf, len, d2i_func, free_func) \
2073 SKM_ASN1_seq_unpack(X509_EXTENSION, (buf), (len), (d2i_func), (free_func))
2074
2075#define d2i_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2076 SKM_ASN1_SET_OF_d2i(X509_NAME_ENTRY, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2077#define i2d_ASN1_SET_OF_X509_NAME_ENTRY(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2078 SKM_ASN1_SET_OF_i2d(X509_NAME_ENTRY, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2079#define ASN1_seq_pack_X509_NAME_ENTRY(st, i2d_func, buf, len) \
2080 SKM_ASN1_seq_pack(X509_NAME_ENTRY, (st), (i2d_func), (buf), (len))
2081#define ASN1_seq_unpack_X509_NAME_ENTRY(buf, len, d2i_func, free_func) \
2082 SKM_ASN1_seq_unpack(X509_NAME_ENTRY, (buf), (len), (d2i_func), (free_func))
2083
2084#define d2i_ASN1_SET_OF_X509_REVOKED(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
2085 SKM_ASN1_SET_OF_d2i(X509_REVOKED, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
2086#define i2d_ASN1_SET_OF_X509_REVOKED(st, pp, i2d_func, ex_tag, ex_class, is_set) \
2087 SKM_ASN1_SET_OF_i2d(X509_REVOKED, (st), (pp), (i2d_func), (ex_tag), (ex_class), (is_set))
2088#define ASN1_seq_pack_X509_REVOKED(st, i2d_func, buf, len) \
2089 SKM_ASN1_seq_pack(X509_REVOKED, (st), (i2d_func), (buf), (len))
2090#define ASN1_seq_unpack_X509_REVOKED(buf, len, d2i_func, free_func) \
2091 SKM_ASN1_seq_unpack(X509_REVOKED, (buf), (len), (d2i_func), (free_func))
2092
2093#define PKCS12_decrypt_d2i_PKCS12_SAFEBAG(algor, d2i_func, free_func, pass, passlen, oct, seq) \
2094 SKM_PKCS12_decrypt_d2i(PKCS12_SAFEBAG, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
2095
2096#define PKCS12_decrypt_d2i_PKCS7(algor, d2i_func, free_func, pass, passlen, oct, seq) \
2097 SKM_PKCS12_decrypt_d2i(PKCS7, (algor), (d2i_func), (free_func), (pass), (passlen), (oct), (seq))
2098#endif /* !LIBRESSL_INTERNAL */
2099
2100#define lh_ADDED_OBJ_new() LHM_lh_new(ADDED_OBJ,added_obj) 1838#define lh_ADDED_OBJ_new() LHM_lh_new(ADDED_OBJ,added_obj)
2101#define lh_ADDED_OBJ_insert(lh,inst) LHM_lh_insert(ADDED_OBJ,lh,inst) 1839#define lh_ADDED_OBJ_insert(lh,inst) LHM_lh_insert(ADDED_OBJ,lh,inst)
2102#define lh_ADDED_OBJ_retrieve(lh,inst) LHM_lh_retrieve(ADDED_OBJ,lh,inst) 1840#define lh_ADDED_OBJ_retrieve(lh,inst) LHM_lh_retrieve(ADDED_OBJ,lh,inst)
@@ -2330,6 +2068,5 @@ DECLARE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
2330#define lh_SSL_SESSION_stats_bio(lh,out) \ 2068#define lh_SSL_SESSION_stats_bio(lh,out) \
2331 LHM_lh_stats_bio(SSL_SESSION,lh,out) 2069 LHM_lh_stats_bio(SSL_SESSION,lh,out)
2332#define lh_SSL_SESSION_free(lh) LHM_lh_free(SSL_SESSION,lh) 2070#define lh_SSL_SESSION_free(lh) LHM_lh_free(SSL_SESSION,lh)
2333/* End of util/mkstack.pl block, you may now edit :-) */
2334 2071
2335#endif /* !defined HEADER_SAFESTACK_H */ 2072#endif /* !defined HEADER_SAFESTACK_H */