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_RecipientKeyIdentifier_st CMS_RecipientKeyIdentifier;
87 typedef struct CMS_KeyAgreeRecipientIdentifier_st CMS_KeyAgreeRecipientIdentifier;
88 typedef struct CMS_KEKIdentifier_st CMS_KEKIdentifier;
89 typedef struct CMS_KEKRecipientInfo_st CMS_KEKRecipientInfo;
90 typedef struct CMS_PasswordRecipientInfo_st CMS_PasswordRecipientInfo;
91 typedef struct CMS_OtherRecipientInfo_st CMS_OtherRecipientInfo;
92 typedef struct CMS_ReceiptsFrom_st CMS_ReceiptsFrom;
94 struct CMS_ContentInfo_st
96 ASN1_OBJECT *contentType;
98 ASN1_OCTET_STRING *data;
99 CMS_SignedData *signedData;
100 CMS_EnvelopedData *envelopedData;
101 CMS_DigestedData *digestedData;
102 CMS_EncryptedData *encryptedData;
103 CMS_AuthenticatedData *authenticatedData;
104 CMS_CompressedData *compressedData;
106 /* Other types ... */
111 struct CMS_SignedData_st
114 STACK_OF(X509_ALGOR) *digestAlgorithms;
115 CMS_EncapsulatedContentInfo *encapContentInfo;
116 STACK_OF(CMS_CertificateChoices) *certificates;
117 STACK_OF(CMS_RevocationInfoChoice) *crls;
118 STACK_OF(CMS_SignerInfo) *signerInfos;
121 struct CMS_EncapsulatedContentInfo_st
123 ASN1_OBJECT *eContentType;
124 ASN1_OCTET_STRING *eContent;
125 /* Set to 1 if incomplete structure only part set up */
129 struct CMS_SignerInfo_st
132 CMS_SignerIdentifier *sid;
133 X509_ALGOR *digestAlgorithm;
134 STACK_OF(X509_ATTRIBUTE) *signedAttrs;
135 X509_ALGOR *signatureAlgorithm;
136 ASN1_OCTET_STRING *signature;
137 STACK_OF(X509_ATTRIBUTE) *unsignedAttrs;
138 /* Signing certificate and key */
141 /* Digest and public key context for alternative parameters */
146 struct CMS_SignerIdentifier_st
150 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
151 ASN1_OCTET_STRING *subjectKeyIdentifier;
155 struct CMS_EnvelopedData_st
158 CMS_OriginatorInfo *originatorInfo;
159 STACK_OF(CMS_RecipientInfo) *recipientInfos;
160 CMS_EncryptedContentInfo *encryptedContentInfo;
161 STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
164 struct CMS_OriginatorInfo_st
166 STACK_OF(CMS_CertificateChoices) *certificates;
167 STACK_OF(CMS_RevocationInfoChoice) *crls;
170 struct CMS_EncryptedContentInfo_st
172 ASN1_OBJECT *contentType;
173 X509_ALGOR *contentEncryptionAlgorithm;
174 ASN1_OCTET_STRING *encryptedContent;
175 /* Content encryption algorithm and key */
176 const EVP_CIPHER *cipher;
179 /* Set to 1 if we are debugging decrypt and don't fake keys for MMA */
183 struct CMS_RecipientInfo_st
187 CMS_KeyTransRecipientInfo *ktri;
188 CMS_KeyAgreeRecipientInfo *kari;
189 CMS_KEKRecipientInfo *kekri;
190 CMS_PasswordRecipientInfo *pwri;
191 CMS_OtherRecipientInfo *ori;
195 typedef CMS_SignerIdentifier CMS_RecipientIdentifier;
197 struct CMS_KeyTransRecipientInfo_st
200 CMS_RecipientIdentifier *rid;
201 X509_ALGOR *keyEncryptionAlgorithm;
202 ASN1_OCTET_STRING *encryptedKey;
203 /* Recipient Key and cert */
206 /* Public key context for this operation */
210 struct CMS_KeyAgreeRecipientInfo_st
213 CMS_OriginatorIdentifierOrKey *originator;
214 ASN1_OCTET_STRING *ukm;
215 X509_ALGOR *keyEncryptionAlgorithm;
216 STACK_OF(CMS_RecipientEncryptedKey) *recipientEncryptedKeys;
217 /* Public key context associated with current operation */
219 /* Cipher context for CEK wrapping */
223 struct CMS_OriginatorIdentifierOrKey_st
227 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
228 ASN1_OCTET_STRING *subjectKeyIdentifier;
229 CMS_OriginatorPublicKey *originatorKey;
233 struct CMS_OriginatorPublicKey_st
235 X509_ALGOR *algorithm;
236 ASN1_BIT_STRING *publicKey;
239 struct CMS_RecipientEncryptedKey_st
241 CMS_KeyAgreeRecipientIdentifier *rid;
242 ASN1_OCTET_STRING *encryptedKey;
243 /* Public key associated with this recipient */
247 struct CMS_KeyAgreeRecipientIdentifier_st
251 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
252 CMS_RecipientKeyIdentifier *rKeyId;
256 struct CMS_RecipientKeyIdentifier_st
258 ASN1_OCTET_STRING *subjectKeyIdentifier;
259 ASN1_GENERALIZEDTIME *date;
260 CMS_OtherKeyAttribute *other;
263 struct CMS_KEKRecipientInfo_st
266 CMS_KEKIdentifier *kekid;
267 X509_ALGOR *keyEncryptionAlgorithm;
268 ASN1_OCTET_STRING *encryptedKey;
269 /* Extra info: symmetric key to use */
274 struct CMS_KEKIdentifier_st
276 ASN1_OCTET_STRING *keyIdentifier;
277 ASN1_GENERALIZEDTIME *date;
278 CMS_OtherKeyAttribute *other;
281 struct CMS_PasswordRecipientInfo_st
284 X509_ALGOR *keyDerivationAlgorithm;
285 X509_ALGOR *keyEncryptionAlgorithm;
286 ASN1_OCTET_STRING *encryptedKey;
287 /* Extra info: password to use */
292 struct CMS_OtherRecipientInfo_st
294 ASN1_OBJECT *oriType;
298 struct CMS_DigestedData_st
301 X509_ALGOR *digestAlgorithm;
302 CMS_EncapsulatedContentInfo *encapContentInfo;
303 ASN1_OCTET_STRING *digest;
306 struct CMS_EncryptedData_st
309 CMS_EncryptedContentInfo *encryptedContentInfo;
310 STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
313 struct CMS_AuthenticatedData_st
316 CMS_OriginatorInfo *originatorInfo;
317 STACK_OF(CMS_RecipientInfo) *recipientInfos;
318 X509_ALGOR *macAlgorithm;
319 X509_ALGOR *digestAlgorithm;
320 CMS_EncapsulatedContentInfo *encapContentInfo;
321 STACK_OF(X509_ATTRIBUTE) *authAttrs;
322 ASN1_OCTET_STRING *mac;
323 STACK_OF(X509_ATTRIBUTE) *unauthAttrs;
326 struct CMS_CompressedData_st
329 X509_ALGOR *compressionAlgorithm;
330 STACK_OF(CMS_RecipientInfo) *recipientInfos;
331 CMS_EncapsulatedContentInfo *encapContentInfo;
334 struct CMS_RevocationInfoChoice_st
339 CMS_OtherRevocationInfoFormat *other;
343 #define CMS_REVCHOICE_CRL 0
344 #define CMS_REVCHOICE_OTHER 1
346 struct CMS_OtherRevocationInfoFormat_st
348 ASN1_OBJECT *otherRevInfoFormat;
349 ASN1_TYPE *otherRevInfo;
352 struct CMS_CertificateChoices
357 ASN1_STRING *extendedCertificate; /* Obsolete */
358 ASN1_STRING *v1AttrCert; /* Left encoded for now */
359 ASN1_STRING *v2AttrCert; /* Left encoded for now */
360 CMS_OtherCertificateFormat *other;
364 #define CMS_CERTCHOICE_CERT 0
365 #define CMS_CERTCHOICE_EXCERT 1
366 #define CMS_CERTCHOICE_V1ACERT 2
367 #define CMS_CERTCHOICE_V2ACERT 3
368 #define CMS_CERTCHOICE_OTHER 4
370 struct CMS_OtherCertificateFormat_st
372 ASN1_OBJECT *otherCertFormat;
373 ASN1_TYPE *otherCert;
376 /* This is also defined in pkcs7.h but we duplicate it
377 * to allow the CMS code to be independent of PKCS#7
380 struct CMS_IssuerAndSerialNumber_st
383 ASN1_INTEGER *serialNumber;
386 struct CMS_OtherKeyAttribute_st
388 ASN1_OBJECT *keyAttrId;
394 #ifdef HEADER_X509V3_H
396 struct CMS_ReceiptRequest_st
398 ASN1_OCTET_STRING *signedContentIdentifier;
399 CMS_ReceiptsFrom *receiptsFrom;
400 STACK_OF(GENERAL_NAMES) *receiptsTo;
404 struct CMS_ReceiptsFrom_st
410 STACK_OF(GENERAL_NAMES) *receiptList;
415 struct CMS_Receipt_st
418 ASN1_OBJECT *contentType;
419 ASN1_OCTET_STRING *signedContentIdentifier;
420 ASN1_OCTET_STRING *originatorSignatureValue;
423 DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo)
424 DECLARE_ASN1_ITEM(CMS_SignerInfo)
425 DECLARE_ASN1_ITEM(CMS_IssuerAndSerialNumber)
426 DECLARE_ASN1_ITEM(CMS_Attributes_Sign)
427 DECLARE_ASN1_ITEM(CMS_Attributes_Verify)
428 DECLARE_ASN1_ITEM(CMS_RecipientInfo)
429 DECLARE_ASN1_ITEM(CMS_PasswordRecipientInfo)
430 DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_IssuerAndSerialNumber)
432 #define CMS_SIGNERINFO_ISSUER_SERIAL 0
433 #define CMS_SIGNERINFO_KEYIDENTIFIER 1
435 #define CMS_RECIPINFO_ISSUER_SERIAL 0
436 #define CMS_RECIPINFO_KEYIDENTIFIER 1
438 #define CMS_REK_ISSUER_SERIAL 0
439 #define CMS_REK_KEYIDENTIFIER 1
441 #define CMS_OIK_ISSUER_SERIAL 0
442 #define CMS_OIK_KEYIDENTIFIER 1
443 #define CMS_OIK_PUBKEY 2
445 BIO *cms_content_bio(CMS_ContentInfo *cms);
447 CMS_ContentInfo *cms_Data_create(void);
449 CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md);
450 BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms);
451 int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify);
453 BIO *cms_SignedData_init_bio(CMS_ContentInfo *cms);
454 int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain);
455 int cms_set1_SignerIdentifier(CMS_SignerIdentifier *sid, X509 *cert, int type);
456 int cms_SignerIdentifier_get0_signer_id(CMS_SignerIdentifier *sid,
457 ASN1_OCTET_STRING **keyid,
458 X509_NAME **issuer, ASN1_INTEGER **sno);
459 int cms_SignerIdentifier_cert_cmp(CMS_SignerIdentifier *sid, X509 *cert);
461 CMS_ContentInfo *cms_CompressedData_create(int comp_nid);
462 BIO *cms_CompressedData_init_bio(CMS_ContentInfo *cms);
464 void cms_DigestAlgorithm_set(X509_ALGOR *alg, const EVP_MD *md);
465 BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm);
466 int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
469 int cms_ias_cert_cmp(CMS_IssuerAndSerialNumber *ias, X509 *cert);
470 int cms_keyid_cert_cmp(ASN1_OCTET_STRING *keyid, X509 *cert);
471 int cms_set1_ias(CMS_IssuerAndSerialNumber **pias, X509 *cert);
472 int cms_set1_keyid(ASN1_OCTET_STRING **pkeyid, X509 *cert);
474 BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec);
475 BIO *cms_EncryptedData_init_bio(CMS_ContentInfo *cms);
476 int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
477 const EVP_CIPHER *cipher,
478 const unsigned char *key, size_t keylen);
480 int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms);
481 int cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src);
482 ASN1_OCTET_STRING *cms_encode_Receipt(CMS_SignerInfo *si);
484 BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms);
485 CMS_EnvelopedData *cms_get0_enveloped(CMS_ContentInfo *cms);
486 int cms_env_asn1_ctrl(CMS_RecipientInfo *ri, int cmd);
487 int cms_pkey_get_ri_type(EVP_PKEY *pk);
489 int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip,
490 EVP_PKEY *pk, unsigned int flags);
491 int cms_RecipientInfo_kari_encrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
494 int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,