]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/cms/cms_lcl.h
Remove /* foo.c */ comments
[thirdparty/openssl.git] / crypto / cms / cms_lcl.h
CommitLineData
0f113f3e
MC
1/*
2 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
8931b30d
DSH
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
0f113f3e 13 * notice, this list of conditions and the following disclaimer.
8931b30d
DSH
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
0f113f3e 55# define HEADER_CMS_LCL_H
8931b30d
DSH
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
0f113f3e 61# include <openssl/x509.h>
8931b30d 62
0f113f3e
MC
63/*
64 * Cryptographic message syntax (CMS) structures: taken from RFC3852
8931b30d
DSH
65 */
66
67/* Forward references */
68
69typedef struct CMS_IssuerAndSerialNumber_st CMS_IssuerAndSerialNumber;
70typedef struct CMS_EncapsulatedContentInfo_st CMS_EncapsulatedContentInfo;
71typedef struct CMS_SignerIdentifier_st CMS_SignerIdentifier;
72typedef struct CMS_SignedData_st CMS_SignedData;
73typedef struct CMS_OtherRevocationInfoFormat_st CMS_OtherRevocationInfoFormat;
74typedef struct CMS_OriginatorInfo_st CMS_OriginatorInfo;
75typedef struct CMS_EncryptedContentInfo_st CMS_EncryptedContentInfo;
76typedef struct CMS_EnvelopedData_st CMS_EnvelopedData;
77typedef struct CMS_DigestedData_st CMS_DigestedData;
78typedef struct CMS_EncryptedData_st CMS_EncryptedData;
79typedef struct CMS_AuthenticatedData_st CMS_AuthenticatedData;
80typedef struct CMS_CompressedData_st CMS_CompressedData;
81typedef struct CMS_OtherCertificateFormat_st CMS_OtherCertificateFormat;
82typedef struct CMS_KeyTransRecipientInfo_st CMS_KeyTransRecipientInfo;
83typedef struct CMS_OriginatorPublicKey_st CMS_OriginatorPublicKey;
84typedef struct CMS_OriginatorIdentifierOrKey_st CMS_OriginatorIdentifierOrKey;
85typedef struct CMS_KeyAgreeRecipientInfo_st CMS_KeyAgreeRecipientInfo;
8931b30d 86typedef struct CMS_RecipientKeyIdentifier_st CMS_RecipientKeyIdentifier;
0f113f3e
MC
87typedef struct CMS_KeyAgreeRecipientIdentifier_st
88 CMS_KeyAgreeRecipientIdentifier;
8931b30d
DSH
89typedef struct CMS_KEKIdentifier_st CMS_KEKIdentifier;
90typedef struct CMS_KEKRecipientInfo_st CMS_KEKRecipientInfo;
91typedef struct CMS_PasswordRecipientInfo_st CMS_PasswordRecipientInfo;
92typedef struct CMS_OtherRecipientInfo_st CMS_OtherRecipientInfo;
be86c7fc 93typedef struct CMS_ReceiptsFrom_st CMS_ReceiptsFrom;
8931b30d 94
0f113f3e
MC
95struct CMS_ContentInfo_st {
96 ASN1_OBJECT *contentType;
97 union {
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;
105 ASN1_TYPE *other;
106 /* Other types ... */
107 void *otherData;
108 } d;
109};
110
85885715 111DEFINE_STACK_OF(CMS_CertificateChoices)
4a640fb6 112
0f113f3e
MC
113struct CMS_SignedData_st {
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
122struct CMS_EncapsulatedContentInfo_st {
123 ASN1_OBJECT *eContentType;
124 ASN1_OCTET_STRING *eContent;
125 /* Set to 1 if incomplete structure only part set up */
126 int partial;
127};
128
129struct CMS_SignerInfo_st {
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 /* Digest and public key context for alternative parameters */
6e59a892 141 EVP_MD_CTX *mctx;
0f113f3e
MC
142 EVP_PKEY_CTX *pctx;
143};
144
145struct CMS_SignerIdentifier_st {
146 int type;
147 union {
148 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
149 ASN1_OCTET_STRING *subjectKeyIdentifier;
150 } d;
151};
152
153struct CMS_EnvelopedData_st {
154 long version;
155 CMS_OriginatorInfo *originatorInfo;
156 STACK_OF(CMS_RecipientInfo) *recipientInfos;
157 CMS_EncryptedContentInfo *encryptedContentInfo;
158 STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
159};
160
161struct CMS_OriginatorInfo_st {
162 STACK_OF(CMS_CertificateChoices) *certificates;
163 STACK_OF(CMS_RevocationInfoChoice) *crls;
164};
165
166struct CMS_EncryptedContentInfo_st {
167 ASN1_OBJECT *contentType;
168 X509_ALGOR *contentEncryptionAlgorithm;
169 ASN1_OCTET_STRING *encryptedContent;
170 /* Content encryption algorithm and key */
171 const EVP_CIPHER *cipher;
172 unsigned char *key;
173 size_t keylen;
174 /* Set to 1 if we are debugging decrypt and don't fake keys for MMA */
175 int debug;
176};
177
178struct CMS_RecipientInfo_st {
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};
8931b30d 188
8931b30d
DSH
189typedef CMS_SignerIdentifier CMS_RecipientIdentifier;
190
0f113f3e
MC
191struct CMS_KeyTransRecipientInfo_st {
192 long version;
193 CMS_RecipientIdentifier *rid;
194 X509_ALGOR *keyEncryptionAlgorithm;
195 ASN1_OCTET_STRING *encryptedKey;
196 /* Recipient Key and cert */
197 X509 *recip;
198 EVP_PKEY *pkey;
199 /* Public key context for this operation */
200 EVP_PKEY_CTX *pctx;
201};
202
203struct CMS_KeyAgreeRecipientInfo_st {
204 long version;
205 CMS_OriginatorIdentifierOrKey *originator;
206 ASN1_OCTET_STRING *ukm;
207 X509_ALGOR *keyEncryptionAlgorithm;
208 STACK_OF(CMS_RecipientEncryptedKey) *recipientEncryptedKeys;
209 /* Public key context associated with current operation */
210 EVP_PKEY_CTX *pctx;
211 /* Cipher context for CEK wrapping */
846ec07d 212 EVP_CIPHER_CTX *ctx;
0f113f3e
MC
213};
214
215struct CMS_OriginatorIdentifierOrKey_st {
216 int type;
217 union {
218 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
219 ASN1_OCTET_STRING *subjectKeyIdentifier;
220 CMS_OriginatorPublicKey *originatorKey;
221 } d;
222};
223
224struct CMS_OriginatorPublicKey_st {
225 X509_ALGOR *algorithm;
226 ASN1_BIT_STRING *publicKey;
227};
228
229struct CMS_RecipientEncryptedKey_st {
230 CMS_KeyAgreeRecipientIdentifier *rid;
231 ASN1_OCTET_STRING *encryptedKey;
232 /* Public key associated with this recipient */
233 EVP_PKEY *pkey;
234};
235
236struct CMS_KeyAgreeRecipientIdentifier_st {
237 int type;
238 union {
239 CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
240 CMS_RecipientKeyIdentifier *rKeyId;
241 } d;
242};
243
244struct CMS_RecipientKeyIdentifier_st {
245 ASN1_OCTET_STRING *subjectKeyIdentifier;
246 ASN1_GENERALIZEDTIME *date;
247 CMS_OtherKeyAttribute *other;
248};
249
250struct CMS_KEKRecipientInfo_st {
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
260struct CMS_KEKIdentifier_st {
261 ASN1_OCTET_STRING *keyIdentifier;
262 ASN1_GENERALIZEDTIME *date;
263 CMS_OtherKeyAttribute *other;
264};
265
266struct CMS_PasswordRecipientInfo_st {
267 long version;
268 X509_ALGOR *keyDerivationAlgorithm;
269 X509_ALGOR *keyEncryptionAlgorithm;
270 ASN1_OCTET_STRING *encryptedKey;
271 /* Extra info: password to use */
272 unsigned char *pass;
273 size_t passlen;
274};
275
276struct CMS_OtherRecipientInfo_st {
277 ASN1_OBJECT *oriType;
278 ASN1_TYPE *oriValue;
279};
280
281struct CMS_DigestedData_st {
282 long version;
283 X509_ALGOR *digestAlgorithm;
284 CMS_EncapsulatedContentInfo *encapContentInfo;
285 ASN1_OCTET_STRING *digest;
286};
287
288struct CMS_EncryptedData_st {
289 long version;
290 CMS_EncryptedContentInfo *encryptedContentInfo;
291 STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
292};
293
294struct CMS_AuthenticatedData_st {
295 long version;
296 CMS_OriginatorInfo *originatorInfo;
297 STACK_OF(CMS_RecipientInfo) *recipientInfos;
298 X509_ALGOR *macAlgorithm;
299 X509_ALGOR *digestAlgorithm;
300 CMS_EncapsulatedContentInfo *encapContentInfo;
301 STACK_OF(X509_ATTRIBUTE) *authAttrs;
302 ASN1_OCTET_STRING *mac;
303 STACK_OF(X509_ATTRIBUTE) *unauthAttrs;
304};
305
306struct CMS_CompressedData_st {
307 long version;
308 X509_ALGOR *compressionAlgorithm;
309 STACK_OF(CMS_RecipientInfo) *recipientInfos;
310 CMS_EncapsulatedContentInfo *encapContentInfo;
311};
312
313struct CMS_RevocationInfoChoice_st {
314 int type;
315 union {
316 X509_CRL *crl;
317 CMS_OtherRevocationInfoFormat *other;
318 } d;
319};
320
321# define CMS_REVCHOICE_CRL 0
322# define CMS_REVCHOICE_OTHER 1
323
324struct CMS_OtherRevocationInfoFormat_st {
325 ASN1_OBJECT *otherRevInfoFormat;
326 ASN1_TYPE *otherRevInfo;
327};
328
329struct CMS_CertificateChoices {
330 int type;
331 union {
332 X509 *certificate;
333 ASN1_STRING *extendedCertificate; /* Obsolete */
334 ASN1_STRING *v1AttrCert; /* Left encoded for now */
335 ASN1_STRING *v2AttrCert; /* Left encoded for now */
336 CMS_OtherCertificateFormat *other;
337 } d;
338};
339
340# define CMS_CERTCHOICE_CERT 0
341# define CMS_CERTCHOICE_EXCERT 1
342# define CMS_CERTCHOICE_V1ACERT 2
343# define CMS_CERTCHOICE_V2ACERT 3
344# define CMS_CERTCHOICE_OTHER 4
345
346struct CMS_OtherCertificateFormat_st {
347 ASN1_OBJECT *otherCertFormat;
348 ASN1_TYPE *otherCert;
349};
350
351/*
352 * This is also defined in pkcs7.h but we duplicate it to allow the CMS code
353 * to be independent of PKCS#7
8931b30d
DSH
354 */
355
0f113f3e
MC
356struct CMS_IssuerAndSerialNumber_st {
357 X509_NAME *issuer;
358 ASN1_INTEGER *serialNumber;
359};
8931b30d 360
0f113f3e
MC
361struct CMS_OtherKeyAttribute_st {
362 ASN1_OBJECT *keyAttrId;
363 ASN1_TYPE *keyAttr;
364};
8931b30d 365
be86c7fc
DSH
366/* ESS structures */
367
0f113f3e
MC
368# ifdef HEADER_X509V3_H
369
370struct CMS_ReceiptRequest_st {
371 ASN1_OCTET_STRING *signedContentIdentifier;
372 CMS_ReceiptsFrom *receiptsFrom;
373 STACK_OF(GENERAL_NAMES) *receiptsTo;
374};
375
376struct CMS_ReceiptsFrom_st {
377 int type;
378 union {
379 long allOrFirstTier;
380 STACK_OF(GENERAL_NAMES) *receiptList;
381 } d;
382};
383# endif
384
385struct CMS_Receipt_st {
386 long version;
387 ASN1_OBJECT *contentType;
388 ASN1_OCTET_STRING *signedContentIdentifier;
389 ASN1_OCTET_STRING *originatorSignatureValue;
390};
be86c7fc 391
8931b30d
DSH
392DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo)
393DECLARE_ASN1_ITEM(CMS_SignerInfo)
394DECLARE_ASN1_ITEM(CMS_IssuerAndSerialNumber)
395DECLARE_ASN1_ITEM(CMS_Attributes_Sign)
396DECLARE_ASN1_ITEM(CMS_Attributes_Verify)
d2a53c22
DSH
397DECLARE_ASN1_ITEM(CMS_RecipientInfo)
398DECLARE_ASN1_ITEM(CMS_PasswordRecipientInfo)
8931b30d
DSH
399DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_IssuerAndSerialNumber)
400
0f113f3e
MC
401# define CMS_SIGNERINFO_ISSUER_SERIAL 0
402# define CMS_SIGNERINFO_KEYIDENTIFIER 1
8931b30d 403
0f113f3e
MC
404# define CMS_RECIPINFO_ISSUER_SERIAL 0
405# define CMS_RECIPINFO_KEYIDENTIFIER 1
8931b30d 406
0f113f3e
MC
407# define CMS_REK_ISSUER_SERIAL 0
408# define CMS_REK_KEYIDENTIFIER 1
17c2764d 409
0f113f3e
MC
410# define CMS_OIK_ISSUER_SERIAL 0
411# define CMS_OIK_KEYIDENTIFIER 1
412# define CMS_OIK_PUBKEY 2
17c2764d 413
8931b30d
DSH
414BIO *cms_content_bio(CMS_ContentInfo *cms);
415
416CMS_ContentInfo *cms_Data_create(void);
417
418CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md);
419BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms);
420int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify);
421
422BIO *cms_SignedData_init_bio(CMS_ContentInfo *cms);
423int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain);
0f113f3e
MC
424int cms_set1_SignerIdentifier(CMS_SignerIdentifier *sid, X509 *cert,
425 int type);
8931b30d 426int cms_SignerIdentifier_get0_signer_id(CMS_SignerIdentifier *sid,
0f113f3e
MC
427 ASN1_OCTET_STRING **keyid,
428 X509_NAME **issuer,
429 ASN1_INTEGER **sno);
8931b30d
DSH
430int cms_SignerIdentifier_cert_cmp(CMS_SignerIdentifier *sid, X509 *cert);
431
432CMS_ContentInfo *cms_CompressedData_create(int comp_nid);
433BIO *cms_CompressedData_init_bio(CMS_ContentInfo *cms);
434
8931b30d
DSH
435BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm);
436int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
0f113f3e 437 X509_ALGOR *mdalg);
b820455c 438
17c2764d
DSH
439int cms_ias_cert_cmp(CMS_IssuerAndSerialNumber *ias, X509 *cert);
440int cms_keyid_cert_cmp(ASN1_OCTET_STRING *keyid, X509 *cert);
441int cms_set1_ias(CMS_IssuerAndSerialNumber **pias, X509 *cert);
442int cms_set1_keyid(ASN1_OCTET_STRING **pkeyid, X509 *cert);
443
4f1aa191 444BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec);
320bfc1b 445BIO *cms_EncryptedData_init_bio(CMS_ContentInfo *cms);
0f113f3e
MC
446int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
447 const EVP_CIPHER *cipher,
448 const unsigned char *key, size_t keylen);
4f1aa191 449
eb9d8d8c 450int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms);
36309aa2
DSH
451int cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src);
452ASN1_OCTET_STRING *cms_encode_Receipt(CMS_SignerInfo *si);
eb9d8d8c 453
4f1aa191 454BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms);
d2a53c22 455CMS_EnvelopedData *cms_get0_enveloped(CMS_ContentInfo *cms);
17c2764d
DSH
456int cms_env_asn1_ctrl(CMS_RecipientInfo *ri, int cmd);
457int cms_pkey_get_ri_type(EVP_PKEY *pk);
458/* KARI routines */
459int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip,
0f113f3e
MC
460 EVP_PKEY *pk, unsigned int flags);
461int cms_RecipientInfo_kari_encrypt(CMS_ContentInfo *cms,
462 CMS_RecipientInfo *ri);
d2a53c22
DSH
463
464/* PWRI routines */
465int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
0f113f3e
MC
466 int en_de);
467
df2ee0e2
BL
468DECLARE_ASN1_ITEM(CMS_CertificateChoices)
469DECLARE_ASN1_ITEM(CMS_DigestedData)
470DECLARE_ASN1_ITEM(CMS_EncryptedData)
471DECLARE_ASN1_ITEM(CMS_EnvelopedData)
472DECLARE_ASN1_ITEM(CMS_KEKRecipientInfo)
473DECLARE_ASN1_ITEM(CMS_KeyAgreeRecipientInfo)
474DECLARE_ASN1_ITEM(CMS_KeyTransRecipientInfo)
475DECLARE_ASN1_ITEM(CMS_OriginatorPublicKey)
476DECLARE_ASN1_ITEM(CMS_OtherKeyAttribute)
477DECLARE_ASN1_ITEM(CMS_Receipt)
478DECLARE_ASN1_ITEM(CMS_ReceiptRequest)
479DECLARE_ASN1_ITEM(CMS_RecipientEncryptedKey)
480DECLARE_ASN1_ITEM(CMS_RecipientKeyIdentifier)
481DECLARE_ASN1_ITEM(CMS_RevocationInfoChoice)
482DECLARE_ASN1_ITEM(CMS_SignedData)
bc2a15cd 483DECLARE_ASN1_ITEM(CMS_CompressedData)
df2ee0e2 484
8931b30d
DSH
485#ifdef __cplusplus
486}
487#endif
488#endif