Remove deleted function from header file, update mkfiles.pl
[openssl.git] / crypto / cms / cms_lcl.h
1 /* crypto/cms/cms_lcl.h */
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3  * project.
4  */
5 /* ====================================================================
6  * Copyright (c) 2008 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
54 #ifndef HEADER_CMS_LCL_H
55 #define HEADER_CMS_LCL_H
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61 #include <openssl/x509.h>
62
63 /* Cryptographic message syntax (CMS) structures: taken
64  * from RFC3852
65  */
66
67 /* Forward references */
68
69 typedef struct CMS_IssuerAndSerialNumber_st CMS_IssuerAndSerialNumber;
70 typedef struct CMS_EncapsulatedContentInfo_st CMS_EncapsulatedContentInfo;
71 typedef struct CMS_SignerIdentifier_st CMS_SignerIdentifier;
72 typedef struct CMS_SignedData_st CMS_SignedData;
73 typedef struct CMS_OtherRevocationInfoFormat_st CMS_OtherRevocationInfoFormat;
74 typedef struct CMS_OriginatorInfo_st CMS_OriginatorInfo;
75 typedef struct CMS_EncryptedContentInfo_st CMS_EncryptedContentInfo;
76 typedef struct CMS_EnvelopedData_st CMS_EnvelopedData;
77 typedef struct CMS_DigestedData_st CMS_DigestedData;
78 typedef struct CMS_EncryptedData_st CMS_EncryptedData;
79 typedef struct CMS_AuthenticatedData_st CMS_AuthenticatedData;
80 typedef struct CMS_CompressedData_st CMS_CompressedData;
81 typedef struct CMS_OtherCertificateFormat_st CMS_OtherCertificateFormat;
82 typedef struct CMS_KeyTransRecipientInfo_st CMS_KeyTransRecipientInfo;
83 typedef struct CMS_OriginatorPublicKey_st CMS_OriginatorPublicKey;
84 typedef struct CMS_OriginatorIdentifierOrKey_st CMS_OriginatorIdentifierOrKey;
85 typedef struct CMS_KeyAgreeRecipientInfo_st CMS_KeyAgreeRecipientInfo;
86 typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute;
87 typedef struct CMS_RecipientKeyIdentifier_st CMS_RecipientKeyIdentifier;
88 typedef struct CMS_KeyAgreeRecipientIdentifier_st CMS_KeyAgreeRecipientIdentifier;
89 typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey;
90 typedef struct CMS_KEKIdentifier_st CMS_KEKIdentifier;
91 typedef struct CMS_KEKRecipientInfo_st CMS_KEKRecipientInfo;
92 typedef struct CMS_PasswordRecipientInfo_st CMS_PasswordRecipientInfo;
93 typedef struct CMS_OtherRecipientInfo_st CMS_OtherRecipientInfo;
94
95 struct CMS_ContentInfo_st
96         {
97         ASN1_OBJECT *contentType;
98         union   {
99                 ASN1_OCTET_STRING *data;
100                 CMS_SignedData *signedData;
101                 CMS_EnvelopedData *envelopedData;
102                 CMS_DigestedData *digestedData;
103                 CMS_EncryptedData *encryptedData;
104                 CMS_AuthenticatedData *authenticatedData;
105                 CMS_CompressedData *compressedData;
106                 ASN1_TYPE *other;
107                 /* Other types ... */
108                 void *otherData;
109                 } d;
110         };
111
112 struct CMS_SignedData_st
113         {
114         long version;
115         STACK_OF(X509_ALGOR) *digestAlgorithms;
116         CMS_EncapsulatedContentInfo *encapContentInfo;
117         STACK_OF(CMS_CertificateChoices) *certificates;
118         STACK_OF(CMS_RevocationInfoChoice) *crls;
119         STACK_OF(CMS_SignerInfo) *signerInfos;
120         };
121  
122 struct CMS_EncapsulatedContentInfo_st
123         {
124         ASN1_OBJECT *eContentType;
125         ASN1_OCTET_STRING *eContent;
126         };
127
128 struct CMS_SignerInfo_st
129         {
130         long version;
131         CMS_SignerIdentifier *sid;
132         X509_ALGOR *digestAlgorithm;
133         STACK_OF(X509_ATTRIBUTE) *signedAttrs;
134         X509_ALGOR *signatureAlgorithm;
135         ASN1_OCTET_STRING *signature;
136         STACK_OF(X509_ATTRIBUTE) *unsignedAttrs;
137         /* Signing certificate and key */
138         X509 *signer;
139         EVP_PKEY *pkey;
140         };
141
142 struct CMS_SignerIdentifier_st
143         {
144         int type;
145         union   {
146                 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
147                 ASN1_OCTET_STRING *subjectKeyIdentifier;
148                 } d;
149         };
150
151 struct CMS_EnvelopedData_st
152         {
153         long version;
154         CMS_OriginatorInfo *originatorInfo;
155         STACK_OF(CMS_RecipientInfo) *recipientInfos;
156         CMS_EncryptedContentInfo *encryptedContentInfo;
157         STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
158         };
159
160 struct CMS_OriginatorInfo_st
161         {
162         STACK_OF(CMS_CertificateChoices) *certificates;
163         STACK_OF(CMS_RevocationInfoChoice) *crls;
164         };
165
166 struct CMS_EncryptedContentInfo_st
167         {
168         ASN1_OBJECT *contentType;
169         X509_ALGOR *contentEncryptionAlgorithm;
170         ASN1_OCTET_STRING *encryptedContent;
171         /* Content encryption algorithm and key */
172         const EVP_CIPHER *cipher;
173         unsigned char *key;
174         size_t keylen;
175         };
176
177 struct CMS_RecipientInfo_st
178         {
179         int type;
180         union   {
181                 CMS_KeyTransRecipientInfo *ktri;
182                 CMS_KeyAgreeRecipientInfo *kari;
183                 CMS_KEKRecipientInfo *kekri;
184                 CMS_PasswordRecipientInfo *pwri;
185                 CMS_OtherRecipientInfo *ori;
186                 } d;
187         };
188
189 typedef CMS_SignerIdentifier CMS_RecipientIdentifier;
190
191 struct CMS_KeyTransRecipientInfo_st
192         {
193         long version;
194         CMS_RecipientIdentifier *rid;
195         X509_ALGOR *keyEncryptionAlgorithm;
196         ASN1_OCTET_STRING *encryptedKey;
197         /* Recipient Key and cert */
198         X509 *recip;
199         EVP_PKEY *pkey;
200         };
201
202 struct CMS_KeyAgreeRecipientInfo_st
203         {
204         long version;
205         CMS_OriginatorIdentifierOrKey *originator;
206         ASN1_OCTET_STRING *ukm;
207         X509_ALGOR *keyEncryptionAlgorithm;
208         STACK_OF(CMS_RecipientEncryptedKey) *recipientEncryptedKeys;
209         };
210
211 struct CMS_OriginatorIdentifierOrKey_st
212         {
213         int type;
214         union   {
215                 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
216                 ASN1_OCTET_STRING *subjectKeyIdentifier;
217                 CMS_OriginatorPublicKey *originatorKey;
218                 } d;
219         };
220
221 struct CMS_OriginatorPublicKey_st
222         {
223         X509_ALGOR *algorithm;
224         ASN1_BIT_STRING *publicKey;
225         };
226
227 struct CMS_RecipientEncryptedKey_st
228         {
229         CMS_KeyAgreeRecipientIdentifier *rid;
230         ASN1_OCTET_STRING *encryptedKey;
231         };
232
233 struct CMS_KeyAgreeRecipientIdentifier_st
234         {
235         int type;
236         union   {
237                 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
238                 CMS_RecipientKeyIdentifier *rKeyId;
239                 } d;
240         };
241
242 struct CMS_RecipientKeyIdentifier_st
243         {
244         ASN1_OCTET_STRING *subjectKeyIdentifier;
245         ASN1_GENERALIZEDTIME *date;
246         CMS_OtherKeyAttribute *other;
247         };
248
249 struct CMS_KEKRecipientInfo_st
250         {
251         long version;
252         CMS_KEKIdentifier *kekid;
253         X509_ALGOR *keyEncryptionAlgorithm;
254         ASN1_OCTET_STRING *encryptedKey;
255         /* Extra info: symmetric key to use */
256         unsigned char *key;
257         size_t keylen;
258         };
259
260 struct CMS_KEKIdentifier_st
261         {
262         ASN1_OCTET_STRING *keyIdentifier;
263         ASN1_GENERALIZEDTIME *date;
264         CMS_OtherKeyAttribute *other;
265         };
266
267 struct CMS_PasswordRecipientInfo_st
268         {
269         long version;
270         X509_ALGOR *keyDerivationAlgorithm;
271         X509_ALGOR *keyEncryptionAlgorithm;
272         ASN1_OCTET_STRING *encryptedKey;
273         };
274
275 struct CMS_OtherRecipientInfo_st
276         {
277         ASN1_OBJECT *oriType;
278         ASN1_TYPE *oriValue;
279         };
280
281 struct CMS_DigestedData_st
282         {
283         long version;
284         X509_ALGOR *digestAlgorithm;
285         CMS_EncapsulatedContentInfo *encapContentInfo;
286         ASN1_OCTET_STRING *digest;
287         };
288
289 struct CMS_EncryptedData_st
290         {
291         long version;
292         CMS_EncryptedContentInfo *encryptedContentInfo;
293         STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
294         };
295
296 struct CMS_AuthenticatedData_st
297         {
298         long version;
299         CMS_OriginatorInfo *originatorInfo;
300         STACK_OF(CMS_RecipientInfo) *recipientInfos;
301         X509_ALGOR *macAlgorithm;
302         X509_ALGOR *digestAlgorithm;
303         CMS_EncapsulatedContentInfo *encapContentInfo;
304         STACK_OF(X509_ATTRIBUTE) *authAttrs;
305         ASN1_OCTET_STRING *mac;
306         STACK_OF(X509_ATTRIBUTE) *unauthAttrs;
307         };
308
309 struct CMS_CompressedData_st
310         {
311         long version;
312         X509_ALGOR *compressionAlgorithm;
313         STACK_OF(CMS_RecipientInfo) *recipientInfos;
314         CMS_EncapsulatedContentInfo *encapContentInfo;
315         };
316
317 struct CMS_RevocationInfoChoice_st
318         {
319         int type;
320         union   {
321                 X509_CRL *crl;
322                 CMS_OtherRevocationInfoFormat *other;
323                 } d;
324         };
325
326 #define CMS_REVCHOICE_CRL               0
327 #define CMS_REVCHOICE_OTHER             1
328
329 struct CMS_OtherRevocationInfoFormat_st
330         {
331         ASN1_OBJECT *otherRevInfoFormat;
332         ASN1_TYPE *otherRevInfo;
333         };
334
335 struct CMS_CertificateChoices
336         {
337         int type;
338                 union {
339                 X509 *certificate;
340                 ASN1_STRING *extendedCertificate;       /* Obsolete */
341                 ASN1_STRING *v1AttrCert;        /* Left encoded for now */
342                 ASN1_STRING *v2AttrCert;        /* Left encoded for now */
343                 CMS_OtherCertificateFormat *other;
344                 } d;
345         };
346
347 #define CMS_CERTCHOICE_CERT             0
348 #define CMS_CERTCHOICE_EXCERT           1
349 #define CMS_CERTCHOICE_V1ACERT          2
350 #define CMS_CERTCHOICE_V2ACERT          3
351 #define CMS_CERTCHOICE_OTHER            4
352
353 struct CMS_OtherCertificateFormat_st
354         {
355         ASN1_OBJECT *otherCertFormat;
356         ASN1_TYPE *otherCert;
357         };
358
359 /* This is also defined in pkcs7.h but we duplicate it
360  * to allow the CMS code to be independent of PKCS#7
361  */
362
363 struct CMS_IssuerAndSerialNumber_st
364         {
365         X509_NAME *issuer;
366         ASN1_INTEGER *serialNumber;
367         };
368
369 struct CMS_OtherKeyAttribute_st
370         {
371         ASN1_OBJECT *keyAttrId;
372         ASN1_TYPE *keyAttr;
373         };
374
375 DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo)
376 DECLARE_ASN1_ITEM(CMS_SignerInfo)
377 DECLARE_ASN1_ITEM(CMS_IssuerAndSerialNumber)
378 DECLARE_ASN1_ITEM(CMS_Attributes_Sign)
379 DECLARE_ASN1_ITEM(CMS_Attributes_Verify)
380 DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_IssuerAndSerialNumber)
381
382 #define CMS_SIGNERINFO_ISSUER_SERIAL    0
383 #define CMS_SIGNERINFO_KEYIDENTIFIER    1
384
385 #define CMS_RECIPINFO_ISSUER_SERIAL     0
386 #define CMS_RECIPINFO_KEYIDENTIFIER     1
387
388 BIO *cms_content_bio(CMS_ContentInfo *cms);
389
390 CMS_ContentInfo *cms_Data_create(void);
391
392 CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md);
393 BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms);
394 int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify);
395
396 BIO *cms_SignedData_init_bio(CMS_ContentInfo *cms);
397 int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain);
398 int cms_set1_SignerIdentifier(CMS_SignerIdentifier *sid, X509 *cert, int type);
399 int cms_SignerIdentifier_get0_signer_id(CMS_SignerIdentifier *sid,
400                                         ASN1_OCTET_STRING **keyid,
401                                         X509_NAME **issuer, ASN1_INTEGER **sno);
402 int cms_SignerIdentifier_cert_cmp(CMS_SignerIdentifier *sid, X509 *cert);
403
404 CMS_ContentInfo *cms_CompressedData_create(int comp_nid);
405 BIO *cms_CompressedData_init_bio(CMS_ContentInfo *cms);
406
407 void cms_DigestAlgorithm_set(X509_ALGOR *alg, const EVP_MD *md);
408 BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm);
409 int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
410                                         X509_ALGOR *mdalg);
411
412 BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec);
413 BIO *cms_EncryptedData_init_bio(CMS_ContentInfo *cms);
414
415 BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms);
416         
417 #ifdef  __cplusplus
418 }
419 #endif
420 #endif