xref: /openbsd/lib/libcrypto/pkcs7/pk7_asn1.c (revision 589ce5b7)
1 /* $OpenBSD: pk7_asn1.c,v 1.18 2024/07/08 16:23:27 beck Exp $ */
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3  * project 2000.
4  */
5 /* ====================================================================
6  * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. All advertising materials mentioning features or use of this
21  *    software must display the following acknowledgment:
22  *    "This product includes software developed by the OpenSSL Project
23  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24  *
25  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26  *    endorse or promote products derived from this software without
27  *    prior written permission. For written permission, please contact
28  *    licensing@OpenSSL.org.
29  *
30  * 5. Products derived from this software may not be called "OpenSSL"
31  *    nor may "OpenSSL" appear in their names without prior written
32  *    permission of the OpenSSL Project.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  *    acknowledgment:
36  *    "This product includes software developed by the OpenSSL Project
37  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50  * OF THE POSSIBILITY OF SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This product includes cryptographic software written by Eric Young
54  * (eay@cryptsoft.com).  This product includes software written by Tim
55  * Hudson (tjh@cryptsoft.com).
56  *
57  */
58 
59 #include <stdio.h>
60 
61 #include <openssl/asn1t.h>
62 #include <openssl/pkcs7.h>
63 #include <openssl/x509.h>
64 
65 /* PKCS#7 ASN1 module */
66 
67 /* This is the ANY DEFINED BY table for the top level PKCS#7 structure */
68 
69 static const ASN1_TEMPLATE p7default_tt = {
70 	.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL,
71 	.tag = 0,
72 	.offset = offsetof(PKCS7, d.other),
73 	.field_name = "d.other",
74 	.item = &ASN1_ANY_it,
75 };
76 
77 static const ASN1_ADB_TABLE PKCS7_adbtbl[] = {
78 	{
79 		.value = NID_pkcs7_data,
80 		.tt = {
81 			.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL | ASN1_TFLG_NDEF,
82 			.tag = 0,
83 			.offset = offsetof(PKCS7, d.data),
84 			.field_name = "d.data",
85 			.item = &ASN1_OCTET_STRING_NDEF_it,
86 		},
87 
88 	},
89 	{
90 		.value = NID_pkcs7_signed,
91 		.tt = {
92 			.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL | ASN1_TFLG_NDEF,
93 			.tag = 0,
94 			.offset = offsetof(PKCS7, d.sign),
95 			.field_name = "d.sign",
96 			.item = &PKCS7_SIGNED_it,
97 		},
98 
99 	},
100 	{
101 		.value = NID_pkcs7_enveloped,
102 		.tt = {
103 			.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL | ASN1_TFLG_NDEF,
104 			.tag = 0,
105 			.offset = offsetof(PKCS7, d.enveloped),
106 			.field_name = "d.enveloped",
107 			.item = &PKCS7_ENVELOPE_it,
108 		},
109 
110 	},
111 	{
112 		.value = NID_pkcs7_signedAndEnveloped,
113 		.tt = {
114 			.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL | ASN1_TFLG_NDEF,
115 			.tag = 0,
116 			.offset = offsetof(PKCS7, d.signed_and_enveloped),
117 			.field_name = "d.signed_and_enveloped",
118 			.item = &PKCS7_SIGN_ENVELOPE_it,
119 		},
120 
121 	},
122 	{
123 		.value = NID_pkcs7_digest,
124 		.tt = {
125 			.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL | ASN1_TFLG_NDEF,
126 			.tag = 0,
127 			.offset = offsetof(PKCS7, d.digest),
128 			.field_name = "d.digest",
129 			.item = &PKCS7_DIGEST_it,
130 		},
131 
132 	},
133 	{
134 		.value = NID_pkcs7_encrypted,
135 		.tt = {
136 			.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL | ASN1_TFLG_NDEF,
137 			.tag = 0,
138 			.offset = offsetof(PKCS7, d.encrypted),
139 			.field_name = "d.encrypted",
140 			.item = &PKCS7_ENCRYPT_it,
141 		},
142 
143 	},
144 };
145 
146 static const ASN1_ADB PKCS7_adb = {
147 	.flags = 0,
148 	.offset = offsetof(PKCS7, type),
149 	.tbl = PKCS7_adbtbl,
150 	.tblcount = sizeof(PKCS7_adbtbl) / sizeof(ASN1_ADB_TABLE),
151 	.default_tt = &p7default_tt,
152 	.null_tt = NULL,
153 };
154 
155 /* PKCS#7 streaming support */
156 static int
pk7_cb(int operation,ASN1_VALUE ** pval,const ASN1_ITEM * it,void * exarg)157 pk7_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
158 {
159 	ASN1_STREAM_ARG *sarg = exarg;
160 	PKCS7 **pp7 = (PKCS7 **)pval;
161 
162 	switch (operation) {
163 	case ASN1_OP_STREAM_PRE:
164 		if (PKCS7_stream(&sarg->boundary, *pp7) <= 0)
165 			return 0;
166 		/* FALLTHROUGH */
167 
168 	case ASN1_OP_DETACHED_PRE:
169 		sarg->ndef_bio = PKCS7_dataInit(*pp7, sarg->out);
170 		if (!sarg->ndef_bio)
171 			return 0;
172 		break;
173 
174 	case ASN1_OP_STREAM_POST:
175 	case ASN1_OP_DETACHED_POST:
176 		if (PKCS7_dataFinal(*pp7, sarg->ndef_bio) <= 0)
177 			return 0;
178 		break;
179 	}
180 	return 1;
181 }
182 
183 static const ASN1_AUX PKCS7_aux = {
184 	.app_data = NULL,
185 	.flags = 0,
186 	.ref_offset = 0,
187 	.ref_lock = 0,
188 	.asn1_cb = pk7_cb,
189 	.enc_offset = 0,
190 };
191 static const ASN1_TEMPLATE PKCS7_seq_tt[] = {
192 	{
193 		.flags = 0,
194 		.tag = 0,
195 		.offset = offsetof(PKCS7, type),
196 		.field_name = "type",
197 		.item = &ASN1_OBJECT_it,
198 	},
199 	{
200 		.flags = ASN1_TFLG_ADB_OID,
201 		.tag = -1,
202 		.offset = 0,
203 		.field_name = "PKCS7",
204 		.item = (const ASN1_ITEM *)&PKCS7_adb,
205 	},
206 };
207 
208 const ASN1_ITEM PKCS7_it = {
209 	.itype = ASN1_ITYPE_NDEF_SEQUENCE,
210 	.utype = V_ASN1_SEQUENCE,
211 	.templates = PKCS7_seq_tt,
212 	.tcount = sizeof(PKCS7_seq_tt) / sizeof(ASN1_TEMPLATE),
213 	.funcs = &PKCS7_aux,
214 	.size = sizeof(PKCS7),
215 	.sname = "PKCS7",
216 };
217 LCRYPTO_ALIAS(PKCS7_it);
218 
219 
220 PKCS7 *
d2i_PKCS7(PKCS7 ** a,const unsigned char ** in,long len)221 d2i_PKCS7(PKCS7 **a, const unsigned char **in, long len)
222 {
223 	return (PKCS7 *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
224 	    &PKCS7_it);
225 }
226 LCRYPTO_ALIAS(d2i_PKCS7);
227 
228 int
i2d_PKCS7(PKCS7 * a,unsigned char ** out)229 i2d_PKCS7(PKCS7 *a, unsigned char **out)
230 {
231 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_it);
232 }
233 LCRYPTO_ALIAS(i2d_PKCS7);
234 
235 PKCS7 *
PKCS7_new(void)236 PKCS7_new(void)
237 {
238 	return (PKCS7 *)ASN1_item_new(&PKCS7_it);
239 }
240 LCRYPTO_ALIAS(PKCS7_new);
241 
242 void
PKCS7_free(PKCS7 * a)243 PKCS7_free(PKCS7 *a)
244 {
245 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_it);
246 }
247 LCRYPTO_ALIAS(PKCS7_free);
248 
249 PKCS7 *
PKCS7_dup(PKCS7 * x)250 PKCS7_dup(PKCS7 *x)
251 {
252 	return ASN1_item_dup(&PKCS7_it, x);
253 }
254 LCRYPTO_ALIAS(PKCS7_dup);
255 
256 static const ASN1_TEMPLATE PKCS7_SIGNED_seq_tt[] = {
257 	{
258 		.flags = 0,
259 		.tag = 0,
260 		.offset = offsetof(PKCS7_SIGNED, version),
261 		.field_name = "version",
262 		.item = &ASN1_INTEGER_it,
263 	},
264 	{
265 		.flags = ASN1_TFLG_SET_OF,
266 		.tag = 0,
267 		.offset = offsetof(PKCS7_SIGNED, md_algs),
268 		.field_name = "md_algs",
269 		.item = &X509_ALGOR_it,
270 	},
271 	{
272 		.flags = 0,
273 		.tag = 0,
274 		.offset = offsetof(PKCS7_SIGNED, contents),
275 		.field_name = "contents",
276 		.item = &PKCS7_it,
277 	},
278 	{
279 		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
280 		.tag = 0,
281 		.offset = offsetof(PKCS7_SIGNED, cert),
282 		.field_name = "cert",
283 		.item = &X509_it,
284 	},
285 	{
286 		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL,
287 		.tag = 1,
288 		.offset = offsetof(PKCS7_SIGNED, crl),
289 		.field_name = "crl",
290 		.item = &X509_CRL_it,
291 	},
292 	{
293 		.flags = ASN1_TFLG_SET_OF,
294 		.tag = 0,
295 		.offset = offsetof(PKCS7_SIGNED, signer_info),
296 		.field_name = "signer_info",
297 		.item = &PKCS7_SIGNER_INFO_it,
298 	},
299 };
300 
301 const ASN1_ITEM PKCS7_SIGNED_it = {
302 	.itype = ASN1_ITYPE_NDEF_SEQUENCE,
303 	.utype = V_ASN1_SEQUENCE,
304 	.templates = PKCS7_SIGNED_seq_tt,
305 	.tcount = sizeof(PKCS7_SIGNED_seq_tt) / sizeof(ASN1_TEMPLATE),
306 	.funcs = NULL,
307 	.size = sizeof(PKCS7_SIGNED),
308 	.sname = "PKCS7_SIGNED",
309 };
310 LCRYPTO_ALIAS(PKCS7_SIGNED_it);
311 
312 
313 PKCS7_SIGNED *
d2i_PKCS7_SIGNED(PKCS7_SIGNED ** a,const unsigned char ** in,long len)314 d2i_PKCS7_SIGNED(PKCS7_SIGNED **a, const unsigned char **in, long len)
315 {
316 	return (PKCS7_SIGNED *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
317 	    &PKCS7_SIGNED_it);
318 }
319 LCRYPTO_ALIAS(d2i_PKCS7_SIGNED);
320 
321 int
i2d_PKCS7_SIGNED(PKCS7_SIGNED * a,unsigned char ** out)322 i2d_PKCS7_SIGNED(PKCS7_SIGNED *a, unsigned char **out)
323 {
324 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_SIGNED_it);
325 }
326 LCRYPTO_ALIAS(i2d_PKCS7_SIGNED);
327 
328 PKCS7_SIGNED *
PKCS7_SIGNED_new(void)329 PKCS7_SIGNED_new(void)
330 {
331 	return (PKCS7_SIGNED *)ASN1_item_new(&PKCS7_SIGNED_it);
332 }
333 LCRYPTO_ALIAS(PKCS7_SIGNED_new);
334 
335 void
PKCS7_SIGNED_free(PKCS7_SIGNED * a)336 PKCS7_SIGNED_free(PKCS7_SIGNED *a)
337 {
338 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_SIGNED_it);
339 }
340 LCRYPTO_ALIAS(PKCS7_SIGNED_free);
341 
342 /* Minor tweak to operation: free up EVP_PKEY */
343 static int
si_cb(int operation,ASN1_VALUE ** pval,const ASN1_ITEM * it,void * exarg)344 si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
345 {
346 	if (operation == ASN1_OP_FREE_POST) {
347 		PKCS7_SIGNER_INFO *si = (PKCS7_SIGNER_INFO *)*pval;
348 		EVP_PKEY_free(si->pkey);
349 	}
350 	return 1;
351 }
352 
353 static const ASN1_AUX PKCS7_SIGNER_INFO_aux = {
354 	.app_data = NULL,
355 	.flags = 0,
356 	.ref_offset = 0,
357 	.ref_lock = 0,
358 	.asn1_cb = si_cb,
359 	.enc_offset = 0,
360 };
361 static const ASN1_TEMPLATE PKCS7_SIGNER_INFO_seq_tt[] = {
362 	{
363 		.flags = 0,
364 		.tag = 0,
365 		.offset = offsetof(PKCS7_SIGNER_INFO, version),
366 		.field_name = "version",
367 		.item = &ASN1_INTEGER_it,
368 	},
369 	{
370 		.flags = 0,
371 		.tag = 0,
372 		.offset = offsetof(PKCS7_SIGNER_INFO, issuer_and_serial),
373 		.field_name = "issuer_and_serial",
374 		.item = &PKCS7_ISSUER_AND_SERIAL_it,
375 	},
376 	{
377 		.flags = 0,
378 		.tag = 0,
379 		.offset = offsetof(PKCS7_SIGNER_INFO, digest_alg),
380 		.field_name = "digest_alg",
381 		.item = &X509_ALGOR_it,
382 	},
383 	/* NB this should be a SET OF but we use a SEQUENCE OF so the
384 	 * original order * is retained when the structure is reencoded.
385 	 * Since the attributes are implicitly tagged this will not affect
386 	 * the encoding.
387 	 */
388 	{
389 		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
390 		.tag = 0,
391 		.offset = offsetof(PKCS7_SIGNER_INFO, auth_attr),
392 		.field_name = "auth_attr",
393 		.item = &X509_ATTRIBUTE_it,
394 	},
395 	{
396 		.flags = 0,
397 		.tag = 0,
398 		.offset = offsetof(PKCS7_SIGNER_INFO, digest_enc_alg),
399 		.field_name = "digest_enc_alg",
400 		.item = &X509_ALGOR_it,
401 	},
402 	{
403 		.flags = 0,
404 		.tag = 0,
405 		.offset = offsetof(PKCS7_SIGNER_INFO, enc_digest),
406 		.field_name = "enc_digest",
407 		.item = &ASN1_OCTET_STRING_it,
408 	},
409 	{
410 		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL,
411 		.tag = 1,
412 		.offset = offsetof(PKCS7_SIGNER_INFO, unauth_attr),
413 		.field_name = "unauth_attr",
414 		.item = &X509_ATTRIBUTE_it,
415 	},
416 };
417 
418 const ASN1_ITEM PKCS7_SIGNER_INFO_it = {
419 	.itype = ASN1_ITYPE_SEQUENCE,
420 	.utype = V_ASN1_SEQUENCE,
421 	.templates = PKCS7_SIGNER_INFO_seq_tt,
422 	.tcount = sizeof(PKCS7_SIGNER_INFO_seq_tt) / sizeof(ASN1_TEMPLATE),
423 	.funcs = &PKCS7_SIGNER_INFO_aux,
424 	.size = sizeof(PKCS7_SIGNER_INFO),
425 	.sname = "PKCS7_SIGNER_INFO",
426 };
427 LCRYPTO_ALIAS(PKCS7_SIGNER_INFO_it);
428 
429 
430 PKCS7_SIGNER_INFO *
d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO ** a,const unsigned char ** in,long len)431 d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a, const unsigned char **in, long len)
432 {
433 	return (PKCS7_SIGNER_INFO *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
434 	    &PKCS7_SIGNER_INFO_it);
435 }
436 LCRYPTO_ALIAS(d2i_PKCS7_SIGNER_INFO);
437 
438 int
i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO * a,unsigned char ** out)439 i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a, unsigned char **out)
440 {
441 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_SIGNER_INFO_it);
442 }
443 LCRYPTO_ALIAS(i2d_PKCS7_SIGNER_INFO);
444 
445 PKCS7_SIGNER_INFO *
PKCS7_SIGNER_INFO_new(void)446 PKCS7_SIGNER_INFO_new(void)
447 {
448 	return (PKCS7_SIGNER_INFO *)ASN1_item_new(&PKCS7_SIGNER_INFO_it);
449 }
450 LCRYPTO_ALIAS(PKCS7_SIGNER_INFO_new);
451 
452 void
PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO * a)453 PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a)
454 {
455 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_SIGNER_INFO_it);
456 }
457 LCRYPTO_ALIAS(PKCS7_SIGNER_INFO_free);
458 
459 static const ASN1_TEMPLATE PKCS7_ISSUER_AND_SERIAL_seq_tt[] = {
460 	{
461 		.flags = 0,
462 		.tag = 0,
463 		.offset = offsetof(PKCS7_ISSUER_AND_SERIAL, issuer),
464 		.field_name = "issuer",
465 		.item = &X509_NAME_it,
466 	},
467 	{
468 		.flags = 0,
469 		.tag = 0,
470 		.offset = offsetof(PKCS7_ISSUER_AND_SERIAL, serial),
471 		.field_name = "serial",
472 		.item = &ASN1_INTEGER_it,
473 	},
474 };
475 
476 const ASN1_ITEM PKCS7_ISSUER_AND_SERIAL_it = {
477 	.itype = ASN1_ITYPE_SEQUENCE,
478 	.utype = V_ASN1_SEQUENCE,
479 	.templates = PKCS7_ISSUER_AND_SERIAL_seq_tt,
480 	.tcount = sizeof(PKCS7_ISSUER_AND_SERIAL_seq_tt) / sizeof(ASN1_TEMPLATE),
481 	.funcs = NULL,
482 	.size = sizeof(PKCS7_ISSUER_AND_SERIAL),
483 	.sname = "PKCS7_ISSUER_AND_SERIAL",
484 };
485 LCRYPTO_ALIAS(PKCS7_ISSUER_AND_SERIAL_it);
486 
487 
488 PKCS7_ISSUER_AND_SERIAL *
d2i_PKCS7_ISSUER_AND_SERIAL(PKCS7_ISSUER_AND_SERIAL ** a,const unsigned char ** in,long len)489 d2i_PKCS7_ISSUER_AND_SERIAL(PKCS7_ISSUER_AND_SERIAL **a, const unsigned char **in, long len)
490 {
491 	return (PKCS7_ISSUER_AND_SERIAL *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
492 	    &PKCS7_ISSUER_AND_SERIAL_it);
493 }
494 LCRYPTO_ALIAS(d2i_PKCS7_ISSUER_AND_SERIAL);
495 
496 int
i2d_PKCS7_ISSUER_AND_SERIAL(PKCS7_ISSUER_AND_SERIAL * a,unsigned char ** out)497 i2d_PKCS7_ISSUER_AND_SERIAL(PKCS7_ISSUER_AND_SERIAL *a, unsigned char **out)
498 {
499 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_ISSUER_AND_SERIAL_it);
500 }
501 LCRYPTO_ALIAS(i2d_PKCS7_ISSUER_AND_SERIAL);
502 
503 PKCS7_ISSUER_AND_SERIAL *
PKCS7_ISSUER_AND_SERIAL_new(void)504 PKCS7_ISSUER_AND_SERIAL_new(void)
505 {
506 	return (PKCS7_ISSUER_AND_SERIAL *)ASN1_item_new(&PKCS7_ISSUER_AND_SERIAL_it);
507 }
508 LCRYPTO_ALIAS(PKCS7_ISSUER_AND_SERIAL_new);
509 
510 void
PKCS7_ISSUER_AND_SERIAL_free(PKCS7_ISSUER_AND_SERIAL * a)511 PKCS7_ISSUER_AND_SERIAL_free(PKCS7_ISSUER_AND_SERIAL *a)
512 {
513 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_ISSUER_AND_SERIAL_it);
514 }
515 LCRYPTO_ALIAS(PKCS7_ISSUER_AND_SERIAL_free);
516 
517 static const ASN1_TEMPLATE PKCS7_ENVELOPE_seq_tt[] = {
518 	{
519 		.flags = 0,
520 		.tag = 0,
521 		.offset = offsetof(PKCS7_ENVELOPE, version),
522 		.field_name = "version",
523 		.item = &ASN1_INTEGER_it,
524 	},
525 	{
526 		.flags = ASN1_TFLG_SET_OF,
527 		.tag = 0,
528 		.offset = offsetof(PKCS7_ENVELOPE, recipientinfo),
529 		.field_name = "recipientinfo",
530 		.item = &PKCS7_RECIP_INFO_it,
531 	},
532 	{
533 		.flags = 0,
534 		.tag = 0,
535 		.offset = offsetof(PKCS7_ENVELOPE, enc_data),
536 		.field_name = "enc_data",
537 		.item = &PKCS7_ENC_CONTENT_it,
538 	},
539 };
540 
541 const ASN1_ITEM PKCS7_ENVELOPE_it = {
542 	.itype = ASN1_ITYPE_NDEF_SEQUENCE,
543 	.utype = V_ASN1_SEQUENCE,
544 	.templates = PKCS7_ENVELOPE_seq_tt,
545 	.tcount = sizeof(PKCS7_ENVELOPE_seq_tt) / sizeof(ASN1_TEMPLATE),
546 	.funcs = NULL,
547 	.size = sizeof(PKCS7_ENVELOPE),
548 	.sname = "PKCS7_ENVELOPE",
549 };
550 LCRYPTO_ALIAS(PKCS7_ENVELOPE_it);
551 
552 
553 PKCS7_ENVELOPE *
d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE ** a,const unsigned char ** in,long len)554 d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE **a, const unsigned char **in, long len)
555 {
556 	return (PKCS7_ENVELOPE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
557 	    &PKCS7_ENVELOPE_it);
558 }
559 LCRYPTO_ALIAS(d2i_PKCS7_ENVELOPE);
560 
561 int
i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE * a,unsigned char ** out)562 i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE *a, unsigned char **out)
563 {
564 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_ENVELOPE_it);
565 }
566 LCRYPTO_ALIAS(i2d_PKCS7_ENVELOPE);
567 
568 PKCS7_ENVELOPE *
PKCS7_ENVELOPE_new(void)569 PKCS7_ENVELOPE_new(void)
570 {
571 	return (PKCS7_ENVELOPE *)ASN1_item_new(&PKCS7_ENVELOPE_it);
572 }
573 LCRYPTO_ALIAS(PKCS7_ENVELOPE_new);
574 
575 void
PKCS7_ENVELOPE_free(PKCS7_ENVELOPE * a)576 PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a)
577 {
578 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_ENVELOPE_it);
579 }
580 LCRYPTO_ALIAS(PKCS7_ENVELOPE_free);
581 
582 /* Minor tweak to operation: free up X509 */
583 static int
ri_cb(int operation,ASN1_VALUE ** pval,const ASN1_ITEM * it,void * exarg)584 ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
585 {
586 	if (operation == ASN1_OP_FREE_POST) {
587 		PKCS7_RECIP_INFO *ri = (PKCS7_RECIP_INFO *)*pval;
588 		X509_free(ri->cert);
589 	}
590 	return 1;
591 }
592 
593 static const ASN1_AUX PKCS7_RECIP_INFO_aux = {
594 	.app_data = NULL,
595 	.flags = 0,
596 	.ref_offset = 0,
597 	.ref_lock = 0,
598 	.asn1_cb = ri_cb,
599 	.enc_offset = 0,
600 };
601 static const ASN1_TEMPLATE PKCS7_RECIP_INFO_seq_tt[] = {
602 	{
603 		.flags = 0,
604 		.tag = 0,
605 		.offset = offsetof(PKCS7_RECIP_INFO, version),
606 		.field_name = "version",
607 		.item = &ASN1_INTEGER_it,
608 	},
609 	{
610 		.flags = 0,
611 		.tag = 0,
612 		.offset = offsetof(PKCS7_RECIP_INFO, issuer_and_serial),
613 		.field_name = "issuer_and_serial",
614 		.item = &PKCS7_ISSUER_AND_SERIAL_it,
615 	},
616 	{
617 		.flags = 0,
618 		.tag = 0,
619 		.offset = offsetof(PKCS7_RECIP_INFO, key_enc_algor),
620 		.field_name = "key_enc_algor",
621 		.item = &X509_ALGOR_it,
622 	},
623 	{
624 		.flags = 0,
625 		.tag = 0,
626 		.offset = offsetof(PKCS7_RECIP_INFO, enc_key),
627 		.field_name = "enc_key",
628 		.item = &ASN1_OCTET_STRING_it,
629 	},
630 };
631 
632 const ASN1_ITEM PKCS7_RECIP_INFO_it = {
633 	.itype = ASN1_ITYPE_SEQUENCE,
634 	.utype = V_ASN1_SEQUENCE,
635 	.templates = PKCS7_RECIP_INFO_seq_tt,
636 	.tcount = sizeof(PKCS7_RECIP_INFO_seq_tt) / sizeof(ASN1_TEMPLATE),
637 	.funcs = &PKCS7_RECIP_INFO_aux,
638 	.size = sizeof(PKCS7_RECIP_INFO),
639 	.sname = "PKCS7_RECIP_INFO",
640 };
641 LCRYPTO_ALIAS(PKCS7_RECIP_INFO_it);
642 
643 
644 PKCS7_RECIP_INFO *
d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO ** a,const unsigned char ** in,long len)645 d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO **a, const unsigned char **in, long len)
646 {
647 	return (PKCS7_RECIP_INFO *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
648 	    &PKCS7_RECIP_INFO_it);
649 }
650 LCRYPTO_ALIAS(d2i_PKCS7_RECIP_INFO);
651 
652 int
i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO * a,unsigned char ** out)653 i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO *a, unsigned char **out)
654 {
655 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_RECIP_INFO_it);
656 }
657 LCRYPTO_ALIAS(i2d_PKCS7_RECIP_INFO);
658 
659 PKCS7_RECIP_INFO *
PKCS7_RECIP_INFO_new(void)660 PKCS7_RECIP_INFO_new(void)
661 {
662 	return (PKCS7_RECIP_INFO *)ASN1_item_new(&PKCS7_RECIP_INFO_it);
663 }
664 LCRYPTO_ALIAS(PKCS7_RECIP_INFO_new);
665 
666 void
PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO * a)667 PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a)
668 {
669 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_RECIP_INFO_it);
670 }
671 LCRYPTO_ALIAS(PKCS7_RECIP_INFO_free);
672 
673 static const ASN1_TEMPLATE PKCS7_ENC_CONTENT_seq_tt[] = {
674 	{
675 		.flags = 0,
676 		.tag = 0,
677 		.offset = offsetof(PKCS7_ENC_CONTENT, content_type),
678 		.field_name = "content_type",
679 		.item = &ASN1_OBJECT_it,
680 	},
681 	{
682 		.flags = 0,
683 		.tag = 0,
684 		.offset = offsetof(PKCS7_ENC_CONTENT, algorithm),
685 		.field_name = "algorithm",
686 		.item = &X509_ALGOR_it,
687 	},
688 	{
689 		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL,
690 		.tag = 0,
691 		.offset = offsetof(PKCS7_ENC_CONTENT, enc_data),
692 		.field_name = "enc_data",
693 		.item = &ASN1_OCTET_STRING_NDEF_it,
694 	},
695 };
696 
697 const ASN1_ITEM PKCS7_ENC_CONTENT_it = {
698 	.itype = ASN1_ITYPE_NDEF_SEQUENCE,
699 	.utype = V_ASN1_SEQUENCE,
700 	.templates = PKCS7_ENC_CONTENT_seq_tt,
701 	.tcount = sizeof(PKCS7_ENC_CONTENT_seq_tt) / sizeof(ASN1_TEMPLATE),
702 	.funcs = NULL,
703 	.size = sizeof(PKCS7_ENC_CONTENT),
704 	.sname = "PKCS7_ENC_CONTENT",
705 };
706 LCRYPTO_ALIAS(PKCS7_ENC_CONTENT_it);
707 
708 
709 PKCS7_ENC_CONTENT *
d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT ** a,const unsigned char ** in,long len)710 d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT **a, const unsigned char **in, long len)
711 {
712 	return (PKCS7_ENC_CONTENT *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
713 	    &PKCS7_ENC_CONTENT_it);
714 }
715 LCRYPTO_ALIAS(d2i_PKCS7_ENC_CONTENT);
716 
717 int
i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT * a,unsigned char ** out)718 i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT *a, unsigned char **out)
719 {
720 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_ENC_CONTENT_it);
721 }
722 LCRYPTO_ALIAS(i2d_PKCS7_ENC_CONTENT);
723 
724 PKCS7_ENC_CONTENT *
PKCS7_ENC_CONTENT_new(void)725 PKCS7_ENC_CONTENT_new(void)
726 {
727 	return (PKCS7_ENC_CONTENT *)ASN1_item_new(&PKCS7_ENC_CONTENT_it);
728 }
729 LCRYPTO_ALIAS(PKCS7_ENC_CONTENT_new);
730 
731 void
PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT * a)732 PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT *a)
733 {
734 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_ENC_CONTENT_it);
735 }
736 LCRYPTO_ALIAS(PKCS7_ENC_CONTENT_free);
737 
738 static const ASN1_TEMPLATE PKCS7_SIGN_ENVELOPE_seq_tt[] = {
739 	{
740 		.flags = 0,
741 		.tag = 0,
742 		.offset = offsetof(PKCS7_SIGN_ENVELOPE, version),
743 		.field_name = "version",
744 		.item = &ASN1_INTEGER_it,
745 	},
746 	{
747 		.flags = ASN1_TFLG_SET_OF,
748 		.tag = 0,
749 		.offset = offsetof(PKCS7_SIGN_ENVELOPE, recipientinfo),
750 		.field_name = "recipientinfo",
751 		.item = &PKCS7_RECIP_INFO_it,
752 	},
753 	{
754 		.flags = ASN1_TFLG_SET_OF,
755 		.tag = 0,
756 		.offset = offsetof(PKCS7_SIGN_ENVELOPE, md_algs),
757 		.field_name = "md_algs",
758 		.item = &X509_ALGOR_it,
759 	},
760 	{
761 		.flags = 0,
762 		.tag = 0,
763 		.offset = offsetof(PKCS7_SIGN_ENVELOPE, enc_data),
764 		.field_name = "enc_data",
765 		.item = &PKCS7_ENC_CONTENT_it,
766 	},
767 	{
768 		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL,
769 		.tag = 0,
770 		.offset = offsetof(PKCS7_SIGN_ENVELOPE, cert),
771 		.field_name = "cert",
772 		.item = &X509_it,
773 	},
774 	{
775 		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SET_OF | ASN1_TFLG_OPTIONAL,
776 		.tag = 1,
777 		.offset = offsetof(PKCS7_SIGN_ENVELOPE, crl),
778 		.field_name = "crl",
779 		.item = &X509_CRL_it,
780 	},
781 	{
782 		.flags = ASN1_TFLG_SET_OF,
783 		.tag = 0,
784 		.offset = offsetof(PKCS7_SIGN_ENVELOPE, signer_info),
785 		.field_name = "signer_info",
786 		.item = &PKCS7_SIGNER_INFO_it,
787 	},
788 };
789 
790 const ASN1_ITEM PKCS7_SIGN_ENVELOPE_it = {
791 	.itype = ASN1_ITYPE_NDEF_SEQUENCE,
792 	.utype = V_ASN1_SEQUENCE,
793 	.templates = PKCS7_SIGN_ENVELOPE_seq_tt,
794 	.tcount = sizeof(PKCS7_SIGN_ENVELOPE_seq_tt) / sizeof(ASN1_TEMPLATE),
795 	.funcs = NULL,
796 	.size = sizeof(PKCS7_SIGN_ENVELOPE),
797 	.sname = "PKCS7_SIGN_ENVELOPE",
798 };
799 LCRYPTO_ALIAS(PKCS7_SIGN_ENVELOPE_it);
800 
801 
802 PKCS7_SIGN_ENVELOPE *
d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE ** a,const unsigned char ** in,long len)803 d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE **a, const unsigned char **in, long len)
804 {
805 	return (PKCS7_SIGN_ENVELOPE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
806 	    &PKCS7_SIGN_ENVELOPE_it);
807 }
808 LCRYPTO_ALIAS(d2i_PKCS7_SIGN_ENVELOPE);
809 
810 int
i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE * a,unsigned char ** out)811 i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE *a, unsigned char **out)
812 {
813 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_SIGN_ENVELOPE_it);
814 }
815 LCRYPTO_ALIAS(i2d_PKCS7_SIGN_ENVELOPE);
816 
817 PKCS7_SIGN_ENVELOPE *
PKCS7_SIGN_ENVELOPE_new(void)818 PKCS7_SIGN_ENVELOPE_new(void)
819 {
820 	return (PKCS7_SIGN_ENVELOPE *)ASN1_item_new(&PKCS7_SIGN_ENVELOPE_it);
821 }
822 LCRYPTO_ALIAS(PKCS7_SIGN_ENVELOPE_new);
823 
824 void
PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE * a)825 PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a)
826 {
827 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_SIGN_ENVELOPE_it);
828 }
829 LCRYPTO_ALIAS(PKCS7_SIGN_ENVELOPE_free);
830 
831 static const ASN1_TEMPLATE PKCS7_ENCRYPT_seq_tt[] = {
832 	{
833 		.flags = 0,
834 		.tag = 0,
835 		.offset = offsetof(PKCS7_ENCRYPT, version),
836 		.field_name = "version",
837 		.item = &ASN1_INTEGER_it,
838 	},
839 	{
840 		.flags = 0,
841 		.tag = 0,
842 		.offset = offsetof(PKCS7_ENCRYPT, enc_data),
843 		.field_name = "enc_data",
844 		.item = &PKCS7_ENC_CONTENT_it,
845 	},
846 };
847 
848 const ASN1_ITEM PKCS7_ENCRYPT_it = {
849 	.itype = ASN1_ITYPE_NDEF_SEQUENCE,
850 	.utype = V_ASN1_SEQUENCE,
851 	.templates = PKCS7_ENCRYPT_seq_tt,
852 	.tcount = sizeof(PKCS7_ENCRYPT_seq_tt) / sizeof(ASN1_TEMPLATE),
853 	.funcs = NULL,
854 	.size = sizeof(PKCS7_ENCRYPT),
855 	.sname = "PKCS7_ENCRYPT",
856 };
857 LCRYPTO_ALIAS(PKCS7_ENCRYPT_it);
858 
859 
860 PKCS7_ENCRYPT *
d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT ** a,const unsigned char ** in,long len)861 d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT **a, const unsigned char **in, long len)
862 {
863 	return (PKCS7_ENCRYPT *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
864 	    &PKCS7_ENCRYPT_it);
865 }
866 LCRYPTO_ALIAS(d2i_PKCS7_ENCRYPT);
867 
868 int
i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT * a,unsigned char ** out)869 i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT *a, unsigned char **out)
870 {
871 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_ENCRYPT_it);
872 }
873 LCRYPTO_ALIAS(i2d_PKCS7_ENCRYPT);
874 
875 PKCS7_ENCRYPT *
PKCS7_ENCRYPT_new(void)876 PKCS7_ENCRYPT_new(void)
877 {
878 	return (PKCS7_ENCRYPT *)ASN1_item_new(&PKCS7_ENCRYPT_it);
879 }
880 LCRYPTO_ALIAS(PKCS7_ENCRYPT_new);
881 
882 void
PKCS7_ENCRYPT_free(PKCS7_ENCRYPT * a)883 PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a)
884 {
885 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_ENCRYPT_it);
886 }
887 LCRYPTO_ALIAS(PKCS7_ENCRYPT_free);
888 
889 static const ASN1_TEMPLATE PKCS7_DIGEST_seq_tt[] = {
890 	{
891 		.flags = 0,
892 		.tag = 0,
893 		.offset = offsetof(PKCS7_DIGEST, version),
894 		.field_name = "version",
895 		.item = &ASN1_INTEGER_it,
896 	},
897 	{
898 		.flags = 0,
899 		.tag = 0,
900 		.offset = offsetof(PKCS7_DIGEST, md),
901 		.field_name = "md",
902 		.item = &X509_ALGOR_it,
903 	},
904 	{
905 		.flags = 0,
906 		.tag = 0,
907 		.offset = offsetof(PKCS7_DIGEST, contents),
908 		.field_name = "contents",
909 		.item = &PKCS7_it,
910 	},
911 	{
912 		.flags = 0,
913 		.tag = 0,
914 		.offset = offsetof(PKCS7_DIGEST, digest),
915 		.field_name = "digest",
916 		.item = &ASN1_OCTET_STRING_it,
917 	},
918 };
919 
920 const ASN1_ITEM PKCS7_DIGEST_it = {
921 	.itype = ASN1_ITYPE_NDEF_SEQUENCE,
922 	.utype = V_ASN1_SEQUENCE,
923 	.templates = PKCS7_DIGEST_seq_tt,
924 	.tcount = sizeof(PKCS7_DIGEST_seq_tt) / sizeof(ASN1_TEMPLATE),
925 	.funcs = NULL,
926 	.size = sizeof(PKCS7_DIGEST),
927 	.sname = "PKCS7_DIGEST",
928 };
929 LCRYPTO_ALIAS(PKCS7_DIGEST_it);
930 
931 
932 PKCS7_DIGEST *
d2i_PKCS7_DIGEST(PKCS7_DIGEST ** a,const unsigned char ** in,long len)933 d2i_PKCS7_DIGEST(PKCS7_DIGEST **a, const unsigned char **in, long len)
934 {
935 	return (PKCS7_DIGEST *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
936 	    &PKCS7_DIGEST_it);
937 }
938 LCRYPTO_ALIAS(d2i_PKCS7_DIGEST);
939 
940 int
i2d_PKCS7_DIGEST(PKCS7_DIGEST * a,unsigned char ** out)941 i2d_PKCS7_DIGEST(PKCS7_DIGEST *a, unsigned char **out)
942 {
943 	return ASN1_item_i2d((ASN1_VALUE *)a, out, &PKCS7_DIGEST_it);
944 }
945 LCRYPTO_ALIAS(i2d_PKCS7_DIGEST);
946 
947 PKCS7_DIGEST *
PKCS7_DIGEST_new(void)948 PKCS7_DIGEST_new(void)
949 {
950 	return (PKCS7_DIGEST *)ASN1_item_new(&PKCS7_DIGEST_it);
951 }
952 LCRYPTO_ALIAS(PKCS7_DIGEST_new);
953 
954 void
PKCS7_DIGEST_free(PKCS7_DIGEST * a)955 PKCS7_DIGEST_free(PKCS7_DIGEST *a)
956 {
957 	ASN1_item_free((ASN1_VALUE *)a, &PKCS7_DIGEST_it);
958 }
959 LCRYPTO_ALIAS(PKCS7_DIGEST_free);
960 
961 /* Specials for authenticated attributes */
962 
963 /* When signing attributes we want to reorder them to match the sorted
964  * encoding.
965  */
966 
967 static const ASN1_TEMPLATE PKCS7_ATTR_SIGN_item_tt = {
968 	.flags = ASN1_TFLG_SET_ORDER,
969 	.tag = 0,
970 	.offset = 0,
971 	.field_name = "PKCS7_ATTRIBUTES",
972 	.item = &X509_ATTRIBUTE_it,
973 };
974 
975 const ASN1_ITEM PKCS7_ATTR_SIGN_it = {
976 	.itype = ASN1_ITYPE_PRIMITIVE,
977 	.utype = -1,
978 	.templates = &PKCS7_ATTR_SIGN_item_tt,
979 	.tcount = 0,
980 	.funcs = NULL,
981 	.size = 0,
982 	.sname = "PKCS7_ATTR_SIGN",
983 };
984 LCRYPTO_ALIAS(PKCS7_ATTR_SIGN_it);
985 
986 /* When verifying attributes we need to use the received order. So
987  * we use SEQUENCE OF and tag it to SET OF
988  */
989 
990 static const ASN1_TEMPLATE PKCS7_ATTR_VERIFY_item_tt = {
991 	.flags = ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_IMPTAG | ASN1_TFLG_UNIVERSAL,
992 	.tag = V_ASN1_SET,
993 	.offset = 0,
994 	.field_name = "PKCS7_ATTRIBUTES",
995 	.item = &X509_ATTRIBUTE_it,
996 };
997 
998 const ASN1_ITEM PKCS7_ATTR_VERIFY_it = {
999 	.itype = ASN1_ITYPE_PRIMITIVE,
1000 	.utype = -1,
1001 	.templates = &PKCS7_ATTR_VERIFY_item_tt,
1002 	.tcount = 0,
1003 	.funcs = NULL,
1004 	.size = 0,
1005 	.sname = "PKCS7_ATTR_VERIFY",
1006 };
1007 LCRYPTO_ALIAS(PKCS7_ATTR_VERIFY_it);
1008 
1009 
1010 int
PKCS7_print_ctx(BIO * out,PKCS7 * x,int indent,const ASN1_PCTX * pctx)1011 PKCS7_print_ctx(BIO *out, PKCS7 *x, int indent, const ASN1_PCTX *pctx)
1012 {
1013 	return ASN1_item_print(out, (ASN1_VALUE *)x, indent,
1014 	    &PKCS7_it, pctx);
1015 }
1016 LCRYPTO_ALIAS(PKCS7_print_ctx);
1017 
1018 PKCS7 *
d2i_PKCS7_bio(BIO * bp,PKCS7 ** p7)1019 d2i_PKCS7_bio(BIO *bp, PKCS7 **p7)
1020 {
1021 	return ASN1_item_d2i_bio(&PKCS7_it, bp, p7);
1022 }
1023 LCRYPTO_ALIAS(d2i_PKCS7_bio);
1024 
1025 int
i2d_PKCS7_bio(BIO * bp,PKCS7 * p7)1026 i2d_PKCS7_bio(BIO *bp, PKCS7 *p7)
1027 {
1028 	return ASN1_item_i2d_bio(&PKCS7_it, bp, p7);
1029 }
1030 LCRYPTO_ALIAS(i2d_PKCS7_bio);
1031 
1032 PKCS7 *
d2i_PKCS7_fp(FILE * fp,PKCS7 ** p7)1033 d2i_PKCS7_fp(FILE *fp, PKCS7 **p7)
1034 {
1035 	return ASN1_item_d2i_fp(&PKCS7_it, fp, p7);
1036 }
1037 LCRYPTO_ALIAS(d2i_PKCS7_fp);
1038 
1039 int
i2d_PKCS7_fp(FILE * fp,PKCS7 * p7)1040 i2d_PKCS7_fp(FILE *fp, PKCS7 *p7)
1041 {
1042 	return ASN1_item_i2d_fp(&PKCS7_it, fp, p7);
1043 }
1044 LCRYPTO_ALIAS(i2d_PKCS7_fp);
1045 
1046 int
PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL * data,const EVP_MD * type,unsigned char * md,unsigned int * len)1047 PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,
1048     const EVP_MD *type, unsigned char *md, unsigned int *len)
1049 {
1050 	return(ASN1_item_digest(&PKCS7_ISSUER_AND_SERIAL_it, type,
1051 	    (char *)data, md, len));
1052 }
1053 LCRYPTO_ALIAS(PKCS7_ISSUER_AND_SERIAL_digest);
1054