1/*
2 * WARNING: do not edit!
3 * Generated by Makefile from ../include/openssl/pkcs7.h.in
4 *
5 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
6 *
7 * Licensed under the Apache License 2.0 (the "License"). You may not use
8 * this file except in compliance with the License. You can obtain a copy
9 * in the file LICENSE in the source distribution or at
10 * https://www.openssl.org/source/license.html
11 */
12
13
14
15#ifndef OPENSSL_PKCS7_H
16# define OPENSSL_PKCS7_H
17# pragma once
18
19# include <openssl/macros.h>
20# ifndef OPENSSL_NO_DEPRECATED_3_0
21# define HEADER_PKCS7_H
22# endif
23
24# include <openssl/asn1.h>
25# include <openssl/bio.h>
26# include <openssl/e_os2.h>
27
28# include <openssl/symhacks.h>
29# include <openssl/types.h>
30# include <openssl/pkcs7err.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36
37/*-
38Encryption_ID DES-CBC
39Digest_ID MD5
40Digest_Encryption_ID rsaEncryption
41Key_Encryption_ID rsaEncryption
42*/
43
44typedef struct PKCS7_CTX_st {
45 OSSL_LIB_CTX *libctx;
46 char *propq;
47} PKCS7_CTX;
48
49typedef struct pkcs7_issuer_and_serial_st {
50 X509_NAME *issuer;
51 ASN1_INTEGER *serial;
52} PKCS7_ISSUER_AND_SERIAL;
53
54typedef struct pkcs7_signer_info_st {
55 ASN1_INTEGER *version; /* version 1 */
56 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
57 X509_ALGOR *digest_alg;
58 STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */
59 X509_ALGOR *digest_enc_alg;
60 ASN1_OCTET_STRING *enc_digest;
61 STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */
62 /* The private key to sign with */
63 EVP_PKEY *pkey;
64 const PKCS7_CTX *ctx;
65} PKCS7_SIGNER_INFO;
66SKM_DEFINE_STACK_OF_INTERNAL(PKCS7_SIGNER_INFO, PKCS7_SIGNER_INFO, PKCS7_SIGNER_INFO)
67#define sk_PKCS7_SIGNER_INFO_num(sk) OPENSSL_sk_num(ossl_check_const_PKCS7_SIGNER_INFO_sk_type(sk))
68#define sk_PKCS7_SIGNER_INFO_value(sk, idx) ((PKCS7_SIGNER_INFO *)OPENSSL_sk_value(ossl_check_const_PKCS7_SIGNER_INFO_sk_type(sk), (idx)))
69#define sk_PKCS7_SIGNER_INFO_new(cmp) ((STACK_OF(PKCS7_SIGNER_INFO) *)OPENSSL_sk_new(ossl_check_PKCS7_SIGNER_INFO_compfunc_type(cmp)))
70#define sk_PKCS7_SIGNER_INFO_new_null() ((STACK_OF(PKCS7_SIGNER_INFO) *)OPENSSL_sk_new_null())
71#define sk_PKCS7_SIGNER_INFO_new_reserve(cmp, n) ((STACK_OF(PKCS7_SIGNER_INFO) *)OPENSSL_sk_new_reserve(ossl_check_PKCS7_SIGNER_INFO_compfunc_type(cmp), (n)))
72#define sk_PKCS7_SIGNER_INFO_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), (n))
73#define sk_PKCS7_SIGNER_INFO_free(sk) OPENSSL_sk_free(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk))
74#define sk_PKCS7_SIGNER_INFO_zero(sk) OPENSSL_sk_zero(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk))
75#define sk_PKCS7_SIGNER_INFO_delete(sk, i) ((PKCS7_SIGNER_INFO *)OPENSSL_sk_delete(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), (i)))
76#define sk_PKCS7_SIGNER_INFO_delete_ptr(sk, ptr) ((PKCS7_SIGNER_INFO *)OPENSSL_sk_delete_ptr(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_type(ptr)))
77#define sk_PKCS7_SIGNER_INFO_push(sk, ptr) OPENSSL_sk_push(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_type(ptr))
78#define sk_PKCS7_SIGNER_INFO_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_type(ptr))
79#define sk_PKCS7_SIGNER_INFO_pop(sk) ((PKCS7_SIGNER_INFO *)OPENSSL_sk_pop(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk)))
80#define sk_PKCS7_SIGNER_INFO_shift(sk) ((PKCS7_SIGNER_INFO *)OPENSSL_sk_shift(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk)))
81#define sk_PKCS7_SIGNER_INFO_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk),ossl_check_PKCS7_SIGNER_INFO_freefunc_type(freefunc))
82#define sk_PKCS7_SIGNER_INFO_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_type(ptr), (idx))
83#define sk_PKCS7_SIGNER_INFO_set(sk, idx, ptr) ((PKCS7_SIGNER_INFO *)OPENSSL_sk_set(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), (idx), ossl_check_PKCS7_SIGNER_INFO_type(ptr)))
84#define sk_PKCS7_SIGNER_INFO_find(sk, ptr) OPENSSL_sk_find(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_type(ptr))
85#define sk_PKCS7_SIGNER_INFO_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_type(ptr))
86#define sk_PKCS7_SIGNER_INFO_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_type(ptr), pnum)
87#define sk_PKCS7_SIGNER_INFO_sort(sk) OPENSSL_sk_sort(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk))
88#define sk_PKCS7_SIGNER_INFO_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_PKCS7_SIGNER_INFO_sk_type(sk))
89#define sk_PKCS7_SIGNER_INFO_dup(sk) ((STACK_OF(PKCS7_SIGNER_INFO) *)OPENSSL_sk_dup(ossl_check_const_PKCS7_SIGNER_INFO_sk_type(sk)))
90#define sk_PKCS7_SIGNER_INFO_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(PKCS7_SIGNER_INFO) *)OPENSSL_sk_deep_copy(ossl_check_const_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_copyfunc_type(copyfunc), ossl_check_PKCS7_SIGNER_INFO_freefunc_type(freefunc)))
91#define sk_PKCS7_SIGNER_INFO_set_cmp_func(sk, cmp) ((sk_PKCS7_SIGNER_INFO_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_PKCS7_SIGNER_INFO_sk_type(sk), ossl_check_PKCS7_SIGNER_INFO_compfunc_type(cmp)))
92
93
94typedef struct pkcs7_recip_info_st {
95 ASN1_INTEGER *version; /* version 0 */
96 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
97 X509_ALGOR *key_enc_algor;
98 ASN1_OCTET_STRING *enc_key;
99 X509 *cert; /* get the pub-key from this */
100 const PKCS7_CTX *ctx;
101} PKCS7_RECIP_INFO;
102SKM_DEFINE_STACK_OF_INTERNAL(PKCS7_RECIP_INFO, PKCS7_RECIP_INFO, PKCS7_RECIP_INFO)
103#define sk_PKCS7_RECIP_INFO_num(sk) OPENSSL_sk_num(ossl_check_const_PKCS7_RECIP_INFO_sk_type(sk))
104#define sk_PKCS7_RECIP_INFO_value(sk, idx) ((PKCS7_RECIP_INFO *)OPENSSL_sk_value(ossl_check_const_PKCS7_RECIP_INFO_sk_type(sk), (idx)))
105#define sk_PKCS7_RECIP_INFO_new(cmp) ((STACK_OF(PKCS7_RECIP_INFO) *)OPENSSL_sk_new(ossl_check_PKCS7_RECIP_INFO_compfunc_type(cmp)))
106#define sk_PKCS7_RECIP_INFO_new_null() ((STACK_OF(PKCS7_RECIP_INFO) *)OPENSSL_sk_new_null())
107#define sk_PKCS7_RECIP_INFO_new_reserve(cmp, n) ((STACK_OF(PKCS7_RECIP_INFO) *)OPENSSL_sk_new_reserve(ossl_check_PKCS7_RECIP_INFO_compfunc_type(cmp), (n)))
108#define sk_PKCS7_RECIP_INFO_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), (n))
109#define sk_PKCS7_RECIP_INFO_free(sk) OPENSSL_sk_free(ossl_check_PKCS7_RECIP_INFO_sk_type(sk))
110#define sk_PKCS7_RECIP_INFO_zero(sk) OPENSSL_sk_zero(ossl_check_PKCS7_RECIP_INFO_sk_type(sk))
111#define sk_PKCS7_RECIP_INFO_delete(sk, i) ((PKCS7_RECIP_INFO *)OPENSSL_sk_delete(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), (i)))
112#define sk_PKCS7_RECIP_INFO_delete_ptr(sk, ptr) ((PKCS7_RECIP_INFO *)OPENSSL_sk_delete_ptr(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_type(ptr)))
113#define sk_PKCS7_RECIP_INFO_push(sk, ptr) OPENSSL_sk_push(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_type(ptr))
114#define sk_PKCS7_RECIP_INFO_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_type(ptr))
115#define sk_PKCS7_RECIP_INFO_pop(sk) ((PKCS7_RECIP_INFO *)OPENSSL_sk_pop(ossl_check_PKCS7_RECIP_INFO_sk_type(sk)))
116#define sk_PKCS7_RECIP_INFO_shift(sk) ((PKCS7_RECIP_INFO *)OPENSSL_sk_shift(ossl_check_PKCS7_RECIP_INFO_sk_type(sk)))
117#define sk_PKCS7_RECIP_INFO_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_PKCS7_RECIP_INFO_sk_type(sk),ossl_check_PKCS7_RECIP_INFO_freefunc_type(freefunc))
118#define sk_PKCS7_RECIP_INFO_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_type(ptr), (idx))
119#define sk_PKCS7_RECIP_INFO_set(sk, idx, ptr) ((PKCS7_RECIP_INFO *)OPENSSL_sk_set(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), (idx), ossl_check_PKCS7_RECIP_INFO_type(ptr)))
120#define sk_PKCS7_RECIP_INFO_find(sk, ptr) OPENSSL_sk_find(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_type(ptr))
121#define sk_PKCS7_RECIP_INFO_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_type(ptr))
122#define sk_PKCS7_RECIP_INFO_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_type(ptr), pnum)
123#define sk_PKCS7_RECIP_INFO_sort(sk) OPENSSL_sk_sort(ossl_check_PKCS7_RECIP_INFO_sk_type(sk))
124#define sk_PKCS7_RECIP_INFO_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_PKCS7_RECIP_INFO_sk_type(sk))
125#define sk_PKCS7_RECIP_INFO_dup(sk) ((STACK_OF(PKCS7_RECIP_INFO) *)OPENSSL_sk_dup(ossl_check_const_PKCS7_RECIP_INFO_sk_type(sk)))
126#define sk_PKCS7_RECIP_INFO_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(PKCS7_RECIP_INFO) *)OPENSSL_sk_deep_copy(ossl_check_const_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_copyfunc_type(copyfunc), ossl_check_PKCS7_RECIP_INFO_freefunc_type(freefunc)))
127#define sk_PKCS7_RECIP_INFO_set_cmp_func(sk, cmp) ((sk_PKCS7_RECIP_INFO_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_PKCS7_RECIP_INFO_sk_type(sk), ossl_check_PKCS7_RECIP_INFO_compfunc_type(cmp)))
128
129
130
131typedef struct pkcs7_signed_st {
132 ASN1_INTEGER *version; /* version 1 */
133 STACK_OF(X509_ALGOR) *md_algs; /* md used */
134 STACK_OF(X509) *cert; /* [ 0 ] */
135 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
136 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
137 struct pkcs7_st *contents;
138} PKCS7_SIGNED;
139/*
140 * The above structure is very very similar to PKCS7_SIGN_ENVELOPE. How about
141 * merging the two
142 */
143
144typedef struct pkcs7_enc_content_st {
145 ASN1_OBJECT *content_type;
146 X509_ALGOR *algorithm;
147 ASN1_OCTET_STRING *enc_data; /* [ 0 ] */
148 const EVP_CIPHER *cipher;
149 const PKCS7_CTX *ctx;
150} PKCS7_ENC_CONTENT;
151
152typedef struct pkcs7_enveloped_st {
153 ASN1_INTEGER *version; /* version 0 */
154 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
155 PKCS7_ENC_CONTENT *enc_data;
156} PKCS7_ENVELOPE;
157
158typedef struct pkcs7_signedandenveloped_st {
159 ASN1_INTEGER *version; /* version 1 */
160 STACK_OF(X509_ALGOR) *md_algs; /* md used */
161 STACK_OF(X509) *cert; /* [ 0 ] */
162 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
163 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
164 PKCS7_ENC_CONTENT *enc_data;
165 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
166} PKCS7_SIGN_ENVELOPE;
167
168typedef struct pkcs7_digest_st {
169 ASN1_INTEGER *version; /* version 0 */
170 X509_ALGOR *md; /* md used */
171 struct pkcs7_st *contents;
172 ASN1_OCTET_STRING *digest;
173} PKCS7_DIGEST;
174
175typedef struct pkcs7_encrypted_st {
176 ASN1_INTEGER *version; /* version 0 */
177 PKCS7_ENC_CONTENT *enc_data;
178} PKCS7_ENCRYPT;
179
180typedef struct pkcs7_st {
181 /*
182 * The following is non NULL if it contains ASN1 encoding of this
183 * structure
184 */
185 unsigned char *asn1;
186 long length;
187# define PKCS7_S_HEADER 0
188# define PKCS7_S_BODY 1
189# define PKCS7_S_TAIL 2
190 int state; /* used during processing */
191 int detached;
192 ASN1_OBJECT *type;
193 /* content as defined by the type */
194 /*
195 * all encryption/message digests are applied to the 'contents', leaving
196 * out the 'type' field.
197 */
198 union {
199 char *ptr;
200 /* NID_pkcs7_data */
201 ASN1_OCTET_STRING *data;
202 /* NID_pkcs7_signed */
203 PKCS7_SIGNED *sign;
204 /* NID_pkcs7_enveloped */
205 PKCS7_ENVELOPE *enveloped;
206 /* NID_pkcs7_signedAndEnveloped */
207 PKCS7_SIGN_ENVELOPE *signed_and_enveloped;
208 /* NID_pkcs7_digest */
209 PKCS7_DIGEST *digest;
210 /* NID_pkcs7_encrypted */
211 PKCS7_ENCRYPT *encrypted;
212 /* Anything else */
213 ASN1_TYPE *other;
214 } d;
215 PKCS7_CTX ctx;
216} PKCS7;
217SKM_DEFINE_STACK_OF_INTERNAL(PKCS7, PKCS7, PKCS7)
218#define sk_PKCS7_num(sk) OPENSSL_sk_num(ossl_check_const_PKCS7_sk_type(sk))
219#define sk_PKCS7_value(sk, idx) ((PKCS7 *)OPENSSL_sk_value(ossl_check_const_PKCS7_sk_type(sk), (idx)))
220#define sk_PKCS7_new(cmp) ((STACK_OF(PKCS7) *)OPENSSL_sk_new(ossl_check_PKCS7_compfunc_type(cmp)))
221#define sk_PKCS7_new_null() ((STACK_OF(PKCS7) *)OPENSSL_sk_new_null())
222#define sk_PKCS7_new_reserve(cmp, n) ((STACK_OF(PKCS7) *)OPENSSL_sk_new_reserve(ossl_check_PKCS7_compfunc_type(cmp), (n)))
223#define sk_PKCS7_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_PKCS7_sk_type(sk), (n))
224#define sk_PKCS7_free(sk) OPENSSL_sk_free(ossl_check_PKCS7_sk_type(sk))
225#define sk_PKCS7_zero(sk) OPENSSL_sk_zero(ossl_check_PKCS7_sk_type(sk))
226#define sk_PKCS7_delete(sk, i) ((PKCS7 *)OPENSSL_sk_delete(ossl_check_PKCS7_sk_type(sk), (i)))
227#define sk_PKCS7_delete_ptr(sk, ptr) ((PKCS7 *)OPENSSL_sk_delete_ptr(ossl_check_PKCS7_sk_type(sk), ossl_check_PKCS7_type(ptr)))
228#define sk_PKCS7_push(sk, ptr) OPENSSL_sk_push(ossl_check_PKCS7_sk_type(sk), ossl_check_PKCS7_type(ptr))
229#define sk_PKCS7_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_PKCS7_sk_type(sk), ossl_check_PKCS7_type(ptr))
230#define sk_PKCS7_pop(sk) ((PKCS7 *)OPENSSL_sk_pop(ossl_check_PKCS7_sk_type(sk)))
231#define sk_PKCS7_shift(sk) ((PKCS7 *)OPENSSL_sk_shift(ossl_check_PKCS7_sk_type(sk)))
232#define sk_PKCS7_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_PKCS7_sk_type(sk),ossl_check_PKCS7_freefunc_type(freefunc))
233#define sk_PKCS7_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_PKCS7_sk_type(sk), ossl_check_PKCS7_type(ptr), (idx))
234#define sk_PKCS7_set(sk, idx, ptr) ((PKCS7 *)OPENSSL_sk_set(ossl_check_PKCS7_sk_type(sk), (idx), ossl_check_PKCS7_type(ptr)))
235#define sk_PKCS7_find(sk, ptr) OPENSSL_sk_find(ossl_check_PKCS7_sk_type(sk), ossl_check_PKCS7_type(ptr))
236#define sk_PKCS7_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_PKCS7_sk_type(sk), ossl_check_PKCS7_type(ptr))
237#define sk_PKCS7_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_PKCS7_sk_type(sk), ossl_check_PKCS7_type(ptr), pnum)
238#define sk_PKCS7_sort(sk) OPENSSL_sk_sort(ossl_check_PKCS7_sk_type(sk))
239#define sk_PKCS7_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_PKCS7_sk_type(sk))
240#define sk_PKCS7_dup(sk) ((STACK_OF(PKCS7) *)OPENSSL_sk_dup(ossl_check_const_PKCS7_sk_type(sk)))
241#define sk_PKCS7_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(PKCS7) *)OPENSSL_sk_deep_copy(ossl_check_const_PKCS7_sk_type(sk), ossl_check_PKCS7_copyfunc_type(copyfunc), ossl_check_PKCS7_freefunc_type(freefunc)))
242#define sk_PKCS7_set_cmp_func(sk, cmp) ((sk_PKCS7_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_PKCS7_sk_type(sk), ossl_check_PKCS7_compfunc_type(cmp)))
243
244
245
246# define PKCS7_OP_SET_DETACHED_SIGNATURE 1
247# define PKCS7_OP_GET_DETACHED_SIGNATURE 2
248
249# define PKCS7_get_signed_attributes(si) ((si)->auth_attr)
250# define PKCS7_get_attributes(si) ((si)->unauth_attr)
251
252# define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
253# define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted)
254# define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped)
255# define PKCS7_type_is_signedAndEnveloped(a) \
256 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
257# define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
258# define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
259
260# define PKCS7_set_detached(p,v) \
261 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
262# define PKCS7_get_detached(p) \
263 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
264
265# define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7))
266
267/* S/MIME related flags */
268
269# define PKCS7_TEXT 0x1
270# define PKCS7_NOCERTS 0x2
271# define PKCS7_NOSIGS 0x4
272# define PKCS7_NOCHAIN 0x8
273# define PKCS7_NOINTERN 0x10
274# define PKCS7_NOVERIFY 0x20
275# define PKCS7_DETACHED 0x40
276# define PKCS7_BINARY 0x80
277# define PKCS7_NOATTR 0x100
278# define PKCS7_NOSMIMECAP 0x200
279# define PKCS7_NOOLDMIMETYPE 0x400
280# define PKCS7_CRLFEOL 0x800
281# define PKCS7_STREAM 0x1000
282# define PKCS7_NOCRL 0x2000
283# define PKCS7_PARTIAL 0x4000
284# define PKCS7_REUSE_DIGEST 0x8000
285# define PKCS7_NO_DUAL_CONTENT 0x10000
286
287/* Flags: for compatibility with older code */
288
289# define SMIME_TEXT PKCS7_TEXT
290# define SMIME_NOCERTS PKCS7_NOCERTS
291# define SMIME_NOSIGS PKCS7_NOSIGS
292# define SMIME_NOCHAIN PKCS7_NOCHAIN
293# define SMIME_NOINTERN PKCS7_NOINTERN
294# define SMIME_NOVERIFY PKCS7_NOVERIFY
295# define SMIME_DETACHED PKCS7_DETACHED
296# define SMIME_BINARY PKCS7_BINARY
297# define SMIME_NOATTR PKCS7_NOATTR
298
299/* CRLF ASCII canonicalisation */
300# define SMIME_ASCIICRLF 0x80000
301
302DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
303
304int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,
305 const EVP_MD *type, unsigned char *md,
306 unsigned int *len);
307# ifndef OPENSSL_NO_STDIO
308PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7);
309int i2d_PKCS7_fp(FILE *fp, const PKCS7 *p7);
310# endif
311DECLARE_ASN1_DUP_FUNCTION(PKCS7)
312PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7);
313int i2d_PKCS7_bio(BIO *bp, const PKCS7 *p7);
314int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags);
315int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *in, int flags);
316
317DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
318DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
319DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED)
320DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
321DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
322DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
323DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST)
324DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
325DECLARE_ASN1_FUNCTIONS(PKCS7)
326PKCS7 *PKCS7_new_ex(OSSL_LIB_CTX *libctx, const char *propq);
327
328DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)
329DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
330
331DECLARE_ASN1_NDEF_FUNCTION(PKCS7)
332DECLARE_ASN1_PRINT_FUNCTION(PKCS7)
333
334long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
335
336int PKCS7_type_is_other(PKCS7 *p7);
337int PKCS7_set_type(PKCS7 *p7, int type);
338int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other);
339int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
340int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
341 const EVP_MD *dgst);
342int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si);
343int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
344int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
345int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
346int PKCS7_content_new(PKCS7 *p7, int nid);
347int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
348 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
349int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
350 X509 *x509);
351
352BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
353int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);
354BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
355
356PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
357 EVP_PKEY *pkey, const EVP_MD *dgst);
358X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
359int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md);
360STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
361
362PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
363void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk,
364 X509_ALGOR **pdig, X509_ALGOR **psig);
365void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc);
366int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
367int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
368int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
369int PKCS7_stream(unsigned char ***boundary, PKCS7 *p7);
370
371PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
372ASN1_OCTET_STRING *PKCS7_get_octet_string(PKCS7 *p7);
373ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
374int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int type,
375 void *data);
376int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
377 void *value);
378ASN1_TYPE *PKCS7_get_attribute(const PKCS7_SIGNER_INFO *si, int nid);
379ASN1_TYPE *PKCS7_get_signed_attribute(const PKCS7_SIGNER_INFO *si, int nid);
380int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
381 STACK_OF(X509_ATTRIBUTE) *sk);
382int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,
383 STACK_OF(X509_ATTRIBUTE) *sk);
384
385PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
386 BIO *data, int flags);
387PKCS7 *PKCS7_sign_ex(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
388 BIO *data, int flags, OSSL_LIB_CTX *libctx,
389 const char *propq);
390
391PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7,
392 X509 *signcert, EVP_PKEY *pkey,
393 const EVP_MD *md, int flags);
394
395int PKCS7_final(PKCS7 *p7, BIO *data, int flags);
396int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
397 BIO *indata, BIO *out, int flags);
398STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs,
399 int flags);
400PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
401 int flags);
402PKCS7 *PKCS7_encrypt_ex(STACK_OF(X509) *certs, BIO *in,
403 const EVP_CIPHER *cipher, int flags,
404 OSSL_LIB_CTX *libctx, const char *propq);
405int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data,
406 int flags);
407
408int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,
409 STACK_OF(X509_ALGOR) *cap);
410STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);
411int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg);
412
413int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid);
414int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t);
415int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si,
416 const unsigned char *md, int mdlen);
417
418int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);
419PKCS7 *SMIME_read_PKCS7_ex(BIO *bio, BIO **bcont, PKCS7 **p7);
420PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);
421
422BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7);
423
424# ifdef __cplusplus
425}
426# endif
427#endif
428