1 /* crypto/pkcs7/pkcs7.h */
2 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
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.
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).
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.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
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)"
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
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.]
59 #ifndef HEADER_PKCS7_H
60 #define HEADER_PKCS7_H
72 Digest_Encryption_ID rsaEncryption
73 Key_Encryption_ID rsaEncryption
76 typedef struct pkcs7_issuer_and_serial_st
80 } PKCS7_ISSUER_AND_SERIAL
;
82 typedef struct pkcs7_signer_info_st
84 ASN1_INTEGER
*version
; /* version 1 */
85 PKCS7_ISSUER_AND_SERIAL
*issuer_and_serial
;
86 X509_ALGOR
*digest_alg
;
87 STACK
/* X509_ATTRIBUTE */ *auth_attr
; /* [ 0 ] */
88 X509_ALGOR
*digest_enc_alg
;
89 ASN1_OCTET_STRING
*enc_digest
;
90 STACK
/* X509_ATTRIBUTE */ *unauth_attr
; /* [ 1 ] */
92 /* The private key to sign with */
96 typedef struct pkcs7_recip_info_st
98 ASN1_INTEGER
*version
; /* version 0 */
99 PKCS7_ISSUER_AND_SERIAL
*issuer_and_serial
;
100 X509_ALGOR
*key_enc_algor
;
101 ASN1_OCTET_STRING
*enc_key
;
104 typedef struct pkcs7_signed_st
106 ASN1_INTEGER
*version
; /* version 1 */
107 STACK
/* X509_ALGOR's */ *md_algs
; /* md used */
108 struct pkcs7_st
*contents
;
109 STACK
/* X509 */ *cert
; /* [ 0 ] */
110 STACK
/* X509_CRL */ *crl
; /* [ 1 ] */
111 STACK
/* PKCS7_SIGNER_INFO */ *signer_info
;
113 /* The above structure is very very similar to PKCS7_SIGN_ENVELOPE.
114 * How about merging the two */
116 typedef struct pkcs7_enc_content_st
118 ASN1_OBJECT
*content_type
;
119 X509_ALGOR
*algorithm
;
120 ASN1_OCTET_STRING
*enc_data
; /* [ 0 ] */
123 typedef struct pkcs7_enveloped_st
125 ASN1_INTEGER
*version
; /* version 0 */
126 STACK
/* PKCS7_RECIP_INFO */ *recipientinfo
;
127 PKCS7_ENC_CONTENT
*enc_data
;
130 typedef struct pkcs7_signedandenveloped_st
132 ASN1_INTEGER
*version
; /* version 1 */
133 STACK
/* PKCS7_RECIP_INFO */ *recipientinfo
;
134 STACK
/* X509_ALGOR's */ *md_algs
; /* md used */
135 PKCS7_ENC_CONTENT
*enc_data
;
136 STACK
/* X509 */ *cert
; /* [ 0 ] */
137 STACK
/* X509_CRL */ *crl
; /* [ 1 ] */
138 STACK
/* PKCS7_SIGNER_INFO */ *signer_info
;
139 } PKCS7_SIGN_ENVELOPE
;
141 typedef struct pkcs7_digest_st
143 ASN1_INTEGER
*version
; /* version 0 */
144 X509_ALGOR
*md
; /* md used */
145 struct pkcs7_st
*contents
;
146 ASN1_OCTET_STRING
*digest
;
149 typedef struct pkcs7_encrypted_st
151 ASN1_INTEGER
*version
; /* version 0 */
152 PKCS7_ENC_CONTENT
*enc_data
;
155 typedef struct pkcs7_st
157 /* The following is non NULL if it contains ASN1 encoding of
162 #define PKCS7_S_HEADER 0
163 #define PKCS7_S_BODY 1
164 #define PKCS7_S_TAIL 2
165 int state
; /* used during processing */
170 /* content as defined by the type */
171 /* all encryption/message digests are applied to the 'contents',
172 * leaving out the 'type' field. */
177 ASN1_OCTET_STRING
*data
;
179 /* NID_pkcs7_signed */
182 /* NID_pkcs7_enveloped */
183 PKCS7_ENVELOPE
*enveloped
;
185 /* NID_pkcs7_signedAndEnveloped */
186 PKCS7_SIGN_ENVELOPE
*signed_and_enveloped
;
188 /* NID_pkcs7_digest */
189 PKCS7_DIGEST
*digest
;
191 /* NID_pkcs7_encrypted */
192 PKCS7_ENCRYPT
*encrypted
;
196 #define PKCS7_OP_SET_DETACHED_SIGNATURE 1
197 #define PKCS7_OP_GET_DETACHED_SIGNATURE 2
199 #define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
200 #define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
202 #define PKCS7_set_detached(p,v) \
203 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
204 #define PKCS7_get_detached(p) \
205 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
208 PKCS7_ISSUER_AND_SERIAL
*PKCS7_ISSUER_AND_SERIAL_new(void );
209 void PKCS7_ISSUER_AND_SERIAL_free(
210 PKCS7_ISSUER_AND_SERIAL
*a
);
211 int i2d_PKCS7_ISSUER_AND_SERIAL(
212 PKCS7_ISSUER_AND_SERIAL
*a
,unsigned char **pp
);
213 PKCS7_ISSUER_AND_SERIAL
*d2i_PKCS7_ISSUER_AND_SERIAL(
214 PKCS7_ISSUER_AND_SERIAL
**a
,
215 unsigned char **pp
, long length
);
217 int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL
*data
,EVP_MD
*type
,
218 unsigned char *md
,unsigned int *len
);
220 PKCS7_SIGNER_INFO
*PKCS7_SIGNER_INFO_new(void);
221 void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO
*a
);
222 int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO
*a
,
224 PKCS7_SIGNER_INFO
*d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO
**a
,
225 unsigned char **pp
,long length
);
227 PKCS7_RECIP_INFO
*PKCS7_RECIP_INFO_new(void);
228 void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO
*a
);
229 int i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO
*a
,
231 PKCS7_RECIP_INFO
*d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO
**a
,
232 unsigned char **pp
,long length
);
234 PKCS7_SIGNED
*PKCS7_SIGNED_new(void);
235 void PKCS7_SIGNED_free(PKCS7_SIGNED
*a
);
236 int i2d_PKCS7_SIGNED(PKCS7_SIGNED
*a
,
238 PKCS7_SIGNED
*d2i_PKCS7_SIGNED(PKCS7_SIGNED
**a
,
239 unsigned char **pp
,long length
);
241 PKCS7_ENC_CONTENT
*PKCS7_ENC_CONTENT_new(void);
242 void PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT
*a
);
243 int i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT
*a
,
245 PKCS7_ENC_CONTENT
*d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT
**a
,
246 unsigned char **pp
,long length
);
248 PKCS7_ENVELOPE
*PKCS7_ENVELOPE_new(void);
249 void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE
*a
);
250 int i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE
*a
,
252 PKCS7_ENVELOPE
*d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE
**a
,
253 unsigned char **pp
,long length
);
255 PKCS7_SIGN_ENVELOPE
*PKCS7_SIGN_ENVELOPE_new(void);
256 void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE
*a
);
257 int i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE
*a
,
259 PKCS7_SIGN_ENVELOPE
*d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE
**a
,
260 unsigned char **pp
,long length
);
262 PKCS7_DIGEST
*PKCS7_DIGEST_new(void);
263 void PKCS7_DIGEST_free(PKCS7_DIGEST
*a
);
264 int i2d_PKCS7_DIGEST(PKCS7_DIGEST
*a
,
266 PKCS7_DIGEST
*d2i_PKCS7_DIGEST(PKCS7_DIGEST
**a
,
267 unsigned char **pp
,long length
);
269 PKCS7_ENCRYPT
*PKCS7_ENCRYPT_new(void);
270 void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT
*a
);
271 int i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT
*a
,
273 PKCS7_ENCRYPT
*d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT
**a
,
274 unsigned char **pp
,long length
);
276 PKCS7
*PKCS7_new(void);
277 void PKCS7_free(PKCS7
*a
);
278 void PKCS7_content_free(PKCS7
*a
);
279 int i2d_PKCS7(PKCS7
*a
,
281 PKCS7
*d2i_PKCS7(PKCS7
**a
,
282 unsigned char **pp
,long length
);
284 void ERR_load_PKCS7_strings(void);
287 PKCS7
*d2i_PKCS7_fp(FILE *fp
,PKCS7
*p7
);
288 int i2d_PKCS7_fp(FILE *fp
,PKCS7
*p7
);
290 PKCS7
*PKCS7_dup(PKCS7
*p7
);
291 PKCS7
*d2i_PKCS7_bio(BIO
*bp
,PKCS7
*p7
);
292 int i2d_PKCS7_bio(BIO
*bp
,PKCS7
*p7
);
294 long PKCS7_ctrl(PKCS7
*p7
, int cmd
, long larg
, char *parg
);
296 int PKCS7_set_type(PKCS7
*p7
, int type
);
297 int PKCS7_set_content(PKCS7
*p7
, PKCS7
*p7_data
);
298 int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO
*p7i
, X509
*x509
, EVP_PKEY
*pkey
,
300 int PKCS7_add_signer(PKCS7
*p7
, PKCS7_SIGNER_INFO
*p7i
);
301 int PKCS7_add_certificate(PKCS7
*p7
, X509
*x509
);
302 int PKCS7_add_crl(PKCS7
*p7
, X509_CRL
*x509
);
303 int PKCS7_content_new(PKCS7
*p7
, int nid
);
304 int PKCS7_dataSign(PKCS7
*p7
, BIO
*bio
);
305 int PKCS7_dataVerify(X509_STORE
*cert_store
, X509_STORE_CTX
*ctx
,
306 BIO
*bio
, PKCS7
*p7
, PKCS7_SIGNER_INFO
*si
);
308 BIO
*PKCS7_dataInit(PKCS7
*p7
, BIO
*bio
);
309 /*int PKCS7_DataFinal(PKCS7 *p7, BIO *bio); */
311 PKCS7_SIGNER_INFO
*PKCS7_add_signature(PKCS7
*p7
, X509
*x509
,
312 EVP_PKEY
*pkey
, EVP_MD
*dgst
);
313 X509
*PKCS7_cert_from_signer_info(PKCS7
*p7
, PKCS7_SIGNER_INFO
*si
);
314 STACK
*PKCS7_get_signer_info(PKCS7
*p7
);
318 PKCS7_ISSUER_AND_SERIAL
*PKCS7_ISSUER_AND_SERIAL_new();
319 void PKCS7_ISSUER_AND_SERIAL_free();
320 int i2d_PKCS7_ISSUER_AND_SERIAL();
321 PKCS7_ISSUER_AND_SERIAL
*d2i_PKCS7_ISSUER_AND_SERIAL();
323 int PKCS7_ISSUER_AND_SERIAL_digest();
325 PKCS7_SIGNER_INFO
*PKCS7_SIGNER_INFO_new();
326 void PKCS7_SIGNER_INFO_free();
327 int i2d_PKCS7_SIGNER_INFO();
328 PKCS7_SIGNER_INFO
*d2i_PKCS7_SIGNER_INFO();
329 PKCS7_RECIP_INFO
*PKCS7_RECIP_INFO_new();
330 void PKCS7_RECIP_INFO_free();
331 int i2d_PKCS7_RECIP_INFO();
332 PKCS7_RECIP_INFO
*d2i_PKCS7_RECIP_INFO();
333 PKCS7_SIGNED
*PKCS7_SIGNED_new();
334 void PKCS7_SIGNED_free();
335 int i2d_PKCS7_SIGNED();
336 PKCS7_SIGNED
*d2i_PKCS7_SIGNED();
337 PKCS7_ENC_CONTENT
*PKCS7_ENC_CONTENT_new();
338 void PKCS7_ENC_CONTENT_free();
339 int i2d_PKCS7_ENC_CONTENT();
340 PKCS7_ENC_CONTENT
*d2i_PKCS7_ENC_CONTENT();
341 PKCS7_ENVELOPE
*PKCS7_ENVELOPE_new();
342 void PKCS7_ENVELOPE_free();
343 int i2d_PKCS7_ENVELOPE();
344 PKCS7_ENVELOPE
*d2i_PKCS7_ENVELOPE();
345 PKCS7_SIGN_ENVELOPE
*PKCS7_SIGN_ENVELOPE_new();
346 void PKCS7_SIGN_ENVELOPE_free();
347 int i2d_PKCS7_SIGN_ENVELOPE();
348 PKCS7_SIGN_ENVELOPE
*d2i_PKCS7_SIGN_ENVELOPE();
349 PKCS7_DIGEST
*PKCS7_DIGEST_new();
350 void PKCS7_DIGEST_free();
351 int i2d_PKCS7_DIGEST();
352 PKCS7_DIGEST
*d2i_PKCS7_DIGEST();
353 PKCS7_ENCRYPT
*PKCS7_ENCRYPT_new();
354 void PKCS7_ENCRYPT_free();
355 int i2d_PKCS7_ENCRYPT();
356 PKCS7_ENCRYPT
*d2i_PKCS7_ENCRYPT();
359 void PKCS7_content_free();
363 void ERR_load_PKCS7_strings();
366 PKCS7
*d2i_PKCS7_fp();
370 PKCS7
*d2i_PKCS7_bio();
373 int PKCS7_set_type();
374 int PKCS7_set_content();
375 int PKCS7_SIGNER_INFO_set();
376 int PKCS7_add_signer();
377 int PKCS7_add_certificate();
379 int PKCS7_content_new();
380 int PKCS7_dataSign();
381 int PKCS7_dataVerify();
382 BIO
*PKCS7_dataInit();
383 PKCS7_SIGNER_INFO
*PKCS7_add_signature();
384 X509
*PKCS7_cert_from_signer_info();
385 STACK
*PKCS7_get_signer_info();
389 /* BEGIN ERROR CODES */
390 /* Error codes for the PKCS7 functions. */
392 /* Function codes. */
393 #define PKCS7_F_PKCS7_ADD_SIGNER 100
394 #define PKCS7_F_PKCS7_CTRL 101
395 #define PKCS7_F_PKCS7_DATAFINAL 102
396 #define PKCS7_F_PKCS7_DATAINIT 103
397 #define PKCS7_F_PKCS7_DATAVERIFY 104
398 #define PKCS7_F_PKCS7_SET_CONTENT 105
399 #define PKCS7_F_PKCS7_SET_TYPE 106
402 #define PKCS7_R_INTERNAL_ERROR 100
403 #define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 101
404 #define PKCS7_R_SIGNATURE_FAILURE 102
405 #define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 103
406 #define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 104
407 #define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 105
408 #define PKCS7_R_UNKNOWN_DIGEST_TYPE 106
409 #define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 107
410 #define PKCS7_R_WRONG_CONTENT_TYPE 108