1 /* crypto/cms/cms_lcl.h */
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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/)"
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.
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.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
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 * ====================================================================
54 #ifndef HEADER_CMS_LCL_H
55 #define HEADER_CMS_LCL_H
61 #include <openssl/x509.h>
63 /* Cryptographic message syntax (CMS) structures: taken
67 /* Forward references */
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;
95 struct CMS_ContentInfo_st
97 ASN1_OBJECT *contentType;
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;
107 /* Other types ... */
112 struct CMS_SignedData_st
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;
122 struct CMS_EncapsulatedContentInfo_st
124 ASN1_OBJECT *eContentType;
125 ASN1_OCTET_STRING *eContent;
126 /* Set to 1 if incomplete structure only part set up */
130 struct CMS_SignerInfo_st
133 CMS_SignerIdentifier *sid;
134 X509_ALGOR *digestAlgorithm;
135 STACK_OF(X509_ATTRIBUTE) *signedAttrs;
136 X509_ALGOR *signatureAlgorithm;
137 ASN1_OCTET_STRING *signature;
138 STACK_OF(X509_ATTRIBUTE) *unsignedAttrs;
139 /* Signing certificate and key */
144 struct CMS_SignerIdentifier_st
148 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
149 ASN1_OCTET_STRING *subjectKeyIdentifier;
153 struct CMS_EnvelopedData_st
156 CMS_OriginatorInfo *originatorInfo;
157 STACK_OF(CMS_RecipientInfo) *recipientInfos;
158 CMS_EncryptedContentInfo *encryptedContentInfo;
159 STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
162 struct CMS_OriginatorInfo_st
164 STACK_OF(CMS_CertificateChoices) *certificates;
165 STACK_OF(CMS_RevocationInfoChoice) *crls;
168 struct CMS_EncryptedContentInfo_st
170 ASN1_OBJECT *contentType;
171 X509_ALGOR *contentEncryptionAlgorithm;
172 ASN1_OCTET_STRING *encryptedContent;
173 /* Content encryption algorithm and key */
174 const EVP_CIPHER *cipher;
179 struct CMS_RecipientInfo_st
183 CMS_KeyTransRecipientInfo *ktri;
184 CMS_KeyAgreeRecipientInfo *kari;
185 CMS_KEKRecipientInfo *kekri;
186 CMS_PasswordRecipientInfo *pwri;
187 CMS_OtherRecipientInfo *ori;
191 typedef CMS_SignerIdentifier CMS_RecipientIdentifier;
193 struct CMS_KeyTransRecipientInfo_st
196 CMS_RecipientIdentifier *rid;
197 X509_ALGOR *keyEncryptionAlgorithm;
198 ASN1_OCTET_STRING *encryptedKey;
199 /* Recipient Key and cert */
204 struct CMS_KeyAgreeRecipientInfo_st
207 CMS_OriginatorIdentifierOrKey *originator;
208 ASN1_OCTET_STRING *ukm;
209 X509_ALGOR *keyEncryptionAlgorithm;
210 STACK_OF(CMS_RecipientEncryptedKey) *recipientEncryptedKeys;
213 struct CMS_OriginatorIdentifierOrKey_st
217 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
218 ASN1_OCTET_STRING *subjectKeyIdentifier;
219 CMS_OriginatorPublicKey *originatorKey;
223 struct CMS_OriginatorPublicKey_st
225 X509_ALGOR *algorithm;
226 ASN1_BIT_STRING *publicKey;
229 struct CMS_RecipientEncryptedKey_st
231 CMS_KeyAgreeRecipientIdentifier *rid;
232 ASN1_OCTET_STRING *encryptedKey;
235 struct CMS_KeyAgreeRecipientIdentifier_st
239 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
240 CMS_RecipientKeyIdentifier *rKeyId;
244 struct CMS_RecipientKeyIdentifier_st
246 ASN1_OCTET_STRING *subjectKeyIdentifier;
247 ASN1_GENERALIZEDTIME *date;
248 CMS_OtherKeyAttribute *other;
251 struct CMS_KEKRecipientInfo_st
254 CMS_KEKIdentifier *kekid;
255 X509_ALGOR *keyEncryptionAlgorithm;
256 ASN1_OCTET_STRING *encryptedKey;
257 /* Extra info: symmetric key to use */
262 struct CMS_KEKIdentifier_st
264 ASN1_OCTET_STRING *keyIdentifier;
265 ASN1_GENERALIZEDTIME *date;
266 CMS_OtherKeyAttribute *other;
269 struct CMS_PasswordRecipientInfo_st
272 X509_ALGOR *keyDerivationAlgorithm;
273 X509_ALGOR *keyEncryptionAlgorithm;
274 ASN1_OCTET_STRING *encryptedKey;
277 struct CMS_OtherRecipientInfo_st
279 ASN1_OBJECT *oriType;
283 struct CMS_DigestedData_st
286 X509_ALGOR *digestAlgorithm;
287 CMS_EncapsulatedContentInfo *encapContentInfo;
288 ASN1_OCTET_STRING *digest;
291 struct CMS_EncryptedData_st
294 CMS_EncryptedContentInfo *encryptedContentInfo;
295 STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
298 struct CMS_AuthenticatedData_st
301 CMS_OriginatorInfo *originatorInfo;
302 STACK_OF(CMS_RecipientInfo) *recipientInfos;
303 X509_ALGOR *macAlgorithm;
304 X509_ALGOR *digestAlgorithm;
305 CMS_EncapsulatedContentInfo *encapContentInfo;
306 STACK_OF(X509_ATTRIBUTE) *authAttrs;
307 ASN1_OCTET_STRING *mac;
308 STACK_OF(X509_ATTRIBUTE) *unauthAttrs;
311 struct CMS_CompressedData_st
314 X509_ALGOR *compressionAlgorithm;
315 STACK_OF(CMS_RecipientInfo) *recipientInfos;
316 CMS_EncapsulatedContentInfo *encapContentInfo;
319 struct CMS_RevocationInfoChoice_st
324 CMS_OtherRevocationInfoFormat *other;
328 #define CMS_REVCHOICE_CRL 0
329 #define CMS_REVCHOICE_OTHER 1
331 struct CMS_OtherRevocationInfoFormat_st
333 ASN1_OBJECT *otherRevInfoFormat;
334 ASN1_TYPE *otherRevInfo;
337 struct CMS_CertificateChoices
342 ASN1_STRING *extendedCertificate; /* Obsolete */
343 ASN1_STRING *v1AttrCert; /* Left encoded for now */
344 ASN1_STRING *v2AttrCert; /* Left encoded for now */
345 CMS_OtherCertificateFormat *other;
349 #define CMS_CERTCHOICE_CERT 0
350 #define CMS_CERTCHOICE_EXCERT 1
351 #define CMS_CERTCHOICE_V1ACERT 2
352 #define CMS_CERTCHOICE_V2ACERT 3
353 #define CMS_CERTCHOICE_OTHER 4
355 struct CMS_OtherCertificateFormat_st
357 ASN1_OBJECT *otherCertFormat;
358 ASN1_TYPE *otherCert;
361 /* This is also defined in pkcs7.h but we duplicate it
362 * to allow the CMS code to be independent of PKCS#7
365 struct CMS_IssuerAndSerialNumber_st
368 ASN1_INTEGER *serialNumber;
371 struct CMS_OtherKeyAttribute_st
373 ASN1_OBJECT *keyAttrId;
377 DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo)
378 DECLARE_ASN1_ITEM(CMS_SignerInfo)
379 DECLARE_ASN1_ITEM(CMS_IssuerAndSerialNumber)
380 DECLARE_ASN1_ITEM(CMS_Attributes_Sign)
381 DECLARE_ASN1_ITEM(CMS_Attributes_Verify)
382 DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_IssuerAndSerialNumber)
384 #define CMS_SIGNERINFO_ISSUER_SERIAL 0
385 #define CMS_SIGNERINFO_KEYIDENTIFIER 1
387 #define CMS_RECIPINFO_ISSUER_SERIAL 0
388 #define CMS_RECIPINFO_KEYIDENTIFIER 1
390 BIO *cms_content_bio(CMS_ContentInfo *cms);
392 CMS_ContentInfo *cms_Data_create(void);
394 CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md);
395 BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms);
396 int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify);
398 BIO *cms_SignedData_init_bio(CMS_ContentInfo *cms);
399 int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain);
400 int cms_set1_SignerIdentifier(CMS_SignerIdentifier *sid, X509 *cert, int type);
401 int cms_SignerIdentifier_get0_signer_id(CMS_SignerIdentifier *sid,
402 ASN1_OCTET_STRING **keyid,
403 X509_NAME **issuer, ASN1_INTEGER **sno);
404 int cms_SignerIdentifier_cert_cmp(CMS_SignerIdentifier *sid, X509 *cert);
406 CMS_ContentInfo *cms_CompressedData_create(int comp_nid);
407 BIO *cms_CompressedData_init_bio(CMS_ContentInfo *cms);
409 void cms_DigestAlgorithm_set(X509_ALGOR *alg, const EVP_MD *md);
410 BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm);
411 int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
414 BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec);
415 BIO *cms_EncryptedData_init_bio(CMS_ContentInfo *cms);
416 int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
417 const EVP_CIPHER *cipher,
418 const unsigned char *key, size_t keylen);
420 BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms);