Constants for new GOST TLS 1.2 ciphersuites
[openssl.git] / include / openssl / cms.h
1 /*
2  * Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef OPENSSL_CMS_H
11 # define OPENSSL_CMS_H
12 # pragma once
13
14 # include <openssl/macros.h>
15 # ifndef OPENSSL_NO_DEPRECATED_3_0
16 #  define HEADER_CMS_H
17 # endif
18
19 # include <openssl/opensslconf.h>
20
21 # ifndef OPENSSL_NO_CMS
22 # include <openssl/x509.h>
23 # include <openssl/x509v3.h>
24 # include <openssl/cmserr.h>
25 # ifdef __cplusplus
26 extern "C" {
27 # endif
28
29 typedef struct CMS_ContentInfo_st CMS_ContentInfo;
30 typedef struct CMS_SignerInfo_st CMS_SignerInfo;
31 typedef struct CMS_CertificateChoices CMS_CertificateChoices;
32 typedef struct CMS_RevocationInfoChoice_st CMS_RevocationInfoChoice;
33 typedef struct CMS_RecipientInfo_st CMS_RecipientInfo;
34 typedef struct CMS_ReceiptRequest_st CMS_ReceiptRequest;
35 typedef struct CMS_Receipt_st CMS_Receipt;
36 typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey;
37 typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute;
38
39 DEFINE_OR_DECLARE_STACK_OF(CMS_SignerInfo)
40 DEFINE_OR_DECLARE_STACK_OF(CMS_RecipientEncryptedKey)
41 DEFINE_OR_DECLARE_STACK_OF(CMS_RecipientInfo)
42 DEFINE_OR_DECLARE_STACK_OF(CMS_RevocationInfoChoice)
43
44 DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo)
45 DECLARE_ASN1_FUNCTIONS(CMS_ReceiptRequest)
46 DECLARE_ASN1_PRINT_FUNCTION(CMS_ContentInfo)
47
48 # define CMS_SIGNERINFO_ISSUER_SERIAL    0
49 # define CMS_SIGNERINFO_KEYIDENTIFIER    1
50
51 # define CMS_RECIPINFO_NONE              -1
52 # define CMS_RECIPINFO_TRANS             0
53 # define CMS_RECIPINFO_AGREE             1
54 # define CMS_RECIPINFO_KEK               2
55 # define CMS_RECIPINFO_PASS              3
56 # define CMS_RECIPINFO_OTHER             4
57
58 /* S/MIME related flags */
59
60 # define CMS_TEXT                        0x1
61 # define CMS_NOCERTS                     0x2
62 # define CMS_NO_CONTENT_VERIFY           0x4
63 # define CMS_NO_ATTR_VERIFY              0x8
64 # define CMS_NOSIGS                      \
65                         (CMS_NO_CONTENT_VERIFY|CMS_NO_ATTR_VERIFY)
66 # define CMS_NOINTERN                    0x10
67 # define CMS_NO_SIGNER_CERT_VERIFY       0x20
68 # define CMS_NOVERIFY                    0x20
69 # define CMS_DETACHED                    0x40
70 # define CMS_BINARY                      0x80
71 # define CMS_NOATTR                      0x100
72 # define CMS_NOSMIMECAP                  0x200
73 # define CMS_NOOLDMIMETYPE               0x400
74 # define CMS_CRLFEOL                     0x800
75 # define CMS_STREAM                      0x1000
76 # define CMS_NOCRL                       0x2000
77 # define CMS_PARTIAL                     0x4000
78 # define CMS_REUSE_DIGEST                0x8000
79 # define CMS_USE_KEYID                   0x10000
80 # define CMS_DEBUG_DECRYPT               0x20000
81 # define CMS_KEY_PARAM                   0x40000
82 # define CMS_ASCIICRLF                   0x80000
83 # define CMS_CADES                       0x100000
84 # define CMS_USE_ORIGINATOR_KEYID        0x200000
85
86 const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms);
87
88 BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont);
89 int CMS_dataFinal(CMS_ContentInfo *cms, BIO *bio);
90
91 ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms);
92 int CMS_is_detached(CMS_ContentInfo *cms);
93 int CMS_set_detached(CMS_ContentInfo *cms, int detached);
94
95 # ifdef OPENSSL_PEM_H
96 DECLARE_PEM_rw(CMS, CMS_ContentInfo)
97 # endif
98 int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms);
99 CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms);
100 int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms);
101
102 BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms);
103 int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags);
104 int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in,
105                              int flags);
106 CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont);
107 int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags);
108
109 int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont,
110               unsigned int flags);
111
112 CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey,
113                           STACK_OF(X509) *certs, BIO *data,
114                           unsigned int flags);
115
116 CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
117                                   X509 *signcert, EVP_PKEY *pkey,
118                                   STACK_OF(X509) *certs, unsigned int flags);
119
120 int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags);
121 CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags);
122
123 int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
124                       unsigned int flags);
125 CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md,
126                                    unsigned int flags);
127
128 int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms,
129                               const unsigned char *key, size_t keylen,
130                               BIO *dcont, BIO *out, unsigned int flags);
131
132 CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
133                                            const unsigned char *key,
134                                            size_t keylen, unsigned int flags);
135
136 int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph,
137                                const unsigned char *key, size_t keylen);
138
139 int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
140                X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags);
141
142 int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms,
143                        STACK_OF(X509) *certs,
144                        X509_STORE *store, unsigned int flags);
145
146 STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);
147
148 CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in,
149                              const EVP_CIPHER *cipher, unsigned int flags);
150
151 int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert,
152                 BIO *dcont, BIO *out, unsigned int flags);
153
154 int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert);
155 int CMS_decrypt_set1_pkey_and_peer(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert, X509 *peer);
156 int CMS_decrypt_set1_key(CMS_ContentInfo *cms,
157                          unsigned char *key, size_t keylen,
158                          const unsigned char *id, size_t idlen);
159 int CMS_decrypt_set1_password(CMS_ContentInfo *cms,
160                               unsigned char *pass, ossl_ssize_t passlen);
161
162 STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms);
163 int CMS_RecipientInfo_type(CMS_RecipientInfo *ri);
164 EVP_PKEY_CTX *CMS_RecipientInfo_get0_pkey_ctx(CMS_RecipientInfo *ri);
165 CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher);
166 CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
167                                            X509 *recip, unsigned int flags);
168 CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip,
169      EVP_PKEY *originatorPrivKey, X509 * originator, unsigned int flags);
170 int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey);
171 int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert);
172 int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri,
173                                      EVP_PKEY **pk, X509 **recip,
174                                      X509_ALGOR **palg);
175 int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri,
176                                           ASN1_OCTET_STRING **keyid,
177                                           X509_NAME **issuer,
178                                           ASN1_INTEGER **sno);
179
180 CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
181                                           unsigned char *key, size_t keylen,
182                                           unsigned char *id, size_t idlen,
183                                           ASN1_GENERALIZEDTIME *date,
184                                           ASN1_OBJECT *otherTypeId,
185                                           ASN1_TYPE *otherType);
186
187 int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri,
188                                     X509_ALGOR **palg,
189                                     ASN1_OCTET_STRING **pid,
190                                     ASN1_GENERALIZEDTIME **pdate,
191                                     ASN1_OBJECT **potherid,
192                                     ASN1_TYPE **pothertype);
193
194 int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri,
195                                unsigned char *key, size_t keylen);
196
197 int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri,
198                                    const unsigned char *id, size_t idlen);
199
200 int CMS_RecipientInfo_set0_password(CMS_RecipientInfo *ri,
201                                     unsigned char *pass,
202                                     ossl_ssize_t passlen);
203
204 CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
205                                                int iter, int wrap_nid,
206                                                int pbe_nid,
207                                                unsigned char *pass,
208                                                ossl_ssize_t passlen,
209                                                const EVP_CIPHER *kekciph);
210
211 int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
212 int CMS_RecipientInfo_encrypt(const CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
213
214 int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
215                    unsigned int flags);
216 CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags);
217
218 int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid);
219 const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms);
220
221 CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms);
222 int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert);
223 int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert);
224 STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms);
225
226 CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms);
227 int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl);
228 int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl);
229 STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms);
230
231 int CMS_SignedData_init(CMS_ContentInfo *cms);
232 CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
233                                 X509 *signer, EVP_PKEY *pk, const EVP_MD *md,
234                                 unsigned int flags);
235 EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si);
236 EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si);
237 STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms);
238
239 void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer);
240 int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si,
241                                   ASN1_OCTET_STRING **keyid,
242                                   X509_NAME **issuer, ASN1_INTEGER **sno);
243 int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert);
244 int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
245                            unsigned int flags);
246 void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk,
247                               X509 **signer, X509_ALGOR **pdig,
248                               X509_ALGOR **psig);
249 ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si);
250 int CMS_SignerInfo_sign(CMS_SignerInfo *si);
251 int CMS_SignerInfo_verify(CMS_SignerInfo *si);
252 int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain);
253
254 int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs);
255 int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs,
256                             int algnid, int keysize);
257 int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap);
258
259 int CMS_signed_get_attr_count(const CMS_SignerInfo *si);
260 int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
261                                int lastpos);
262 int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj,
263                                int lastpos);
264 X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc);
265 X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc);
266 int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
267 int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
268                                 const ASN1_OBJECT *obj, int type,
269                                 const void *bytes, int len);
270 int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
271                                 int nid, int type,
272                                 const void *bytes, int len);
273 int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
274                                 const char *attrname, int type,
275                                 const void *bytes, int len);
276 void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *oid,
277                                   int lastpos, int type);
278
279 int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si);
280 int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
281                                  int lastpos);
282 int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si,
283                                  const ASN1_OBJECT *obj, int lastpos);
284 X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc);
285 X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc);
286 int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
287 int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
288                                   const ASN1_OBJECT *obj, int type,
289                                   const void *bytes, int len);
290 int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
291                                   int nid, int type,
292                                   const void *bytes, int len);
293 int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
294                                   const char *attrname, int type,
295                                   const void *bytes, int len);
296 void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
297                                     int lastpos, int type);
298
299 int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr);
300 CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen,
301                                                int allorfirst,
302                                                STACK_OF(GENERAL_NAMES)
303                                                *receiptList, STACK_OF(GENERAL_NAMES)
304                                                *receiptsTo);
305 int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr);
306 void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr,
307                                     ASN1_STRING **pcid,
308                                     int *pallorfirst,
309                                     STACK_OF(GENERAL_NAMES) **plist,
310                                     STACK_OF(GENERAL_NAMES) **prto);
311 int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri,
312                                     X509_ALGOR **palg,
313                                     ASN1_OCTET_STRING **pukm);
314 STACK_OF(CMS_RecipientEncryptedKey)
315 *CMS_RecipientInfo_kari_get0_reks(CMS_RecipientInfo *ri);
316
317 int CMS_RecipientInfo_kari_get0_orig_id(CMS_RecipientInfo *ri,
318                                         X509_ALGOR **pubalg,
319                                         ASN1_BIT_STRING **pubkey,
320                                         ASN1_OCTET_STRING **keyid,
321                                         X509_NAME **issuer,
322                                         ASN1_INTEGER **sno);
323
324 int CMS_RecipientInfo_kari_orig_id_cmp(CMS_RecipientInfo *ri, X509 *cert);
325
326 int CMS_RecipientEncryptedKey_get0_id(CMS_RecipientEncryptedKey *rek,
327                                       ASN1_OCTET_STRING **keyid,
328                                       ASN1_GENERALIZEDTIME **tm,
329                                       CMS_OtherKeyAttribute **other,
330                                       X509_NAME **issuer, ASN1_INTEGER **sno);
331 int CMS_RecipientEncryptedKey_cert_cmp(CMS_RecipientEncryptedKey *rek,
332                                        X509 *cert);
333 int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk);
334 int CMS_RecipientInfo_kari_set0_pkey_and_peer(CMS_RecipientInfo *ri, EVP_PKEY *pk, X509 *peer);
335 EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri);
336 int CMS_RecipientInfo_kari_decrypt(CMS_ContentInfo *cms,
337                                    CMS_RecipientInfo *ri,
338                                    CMS_RecipientEncryptedKey *rek);
339
340 int CMS_SharedInfo_encode(unsigned char **pder, X509_ALGOR *kekalg,
341                           ASN1_OCTET_STRING *ukm, int keylen);
342
343 /* Backward compatibility for spelling errors. */
344 # define CMS_R_UNKNOWN_DIGEST_ALGORITM CMS_R_UNKNOWN_DIGEST_ALGORITHM
345 # define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE \
346     CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE
347
348 #  ifdef  __cplusplus
349 }
350 #  endif
351 # endif
352 #endif