xref: /netbsd-src/crypto/external/bsd/openssl/dist/doc/man3/CMS_encrypt.pod (revision b0d1725196a7921d003d2c66a14f186abda4176b)
113d40330Schristos=pod
213d40330Schristos
313d40330Schristos=head1 NAME
413d40330Schristos
5*b0d17251SchristosCMS_encrypt_ex, CMS_encrypt - create a CMS envelopedData structure
613d40330Schristos
713d40330Schristos=head1 SYNOPSIS
813d40330Schristos
913d40330Schristos #include <openssl/cms.h>
1013d40330Schristos
11*b0d17251Schristos CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *in,
12*b0d17251Schristos                                 const EVP_CIPHER *cipher, unsigned int flags,
13*b0d17251Schristos                                 OSSL_LIB_CTX *libctx, const char *propq);
1413d40330Schristos CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in,
1513d40330Schristos                              const EVP_CIPHER *cipher, unsigned int flags);
1613d40330Schristos
1713d40330Schristos=head1 DESCRIPTION
1813d40330Schristos
19*b0d17251SchristosCMS_encrypt_ex() creates and returns a CMS EnvelopedData or
20*b0d17251SchristosAuthEnvelopedData structure. I<certs> is a list of recipient certificates.
21*b0d17251SchristosI<in> is the content to be encrypted. I<cipher> is the symmetric cipher to use.
22*b0d17251SchristosI<flags> is an optional set of flags. The library context I<libctx> and the
23*b0d17251Schristosproperty query I<propq> are used internally when retrieving algorithms from
24*b0d17251Schristosproviders.
2513d40330Schristos
2613d40330SchristosOnly certificates carrying RSA, Diffie-Hellman or EC keys are supported by this
2713d40330Schristosfunction.
2813d40330Schristos
2913d40330SchristosEVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use
3013d40330Schristosbecause most clients will support it.
3113d40330Schristos
3213d40330SchristosThe algorithm passed in the B<cipher> parameter must support ASN1 encoding of
33*b0d17251Schristosits parameters. If the cipher mode is GCM, then an AuthEnvelopedData structure
34*b0d17251Schristoscontaining MAC is used. Otherwise an EnvelopedData structure is used. Currently
35*b0d17251Schristosthe AES variants with GCM mode are the only supported AEAD algorithms.
3613d40330Schristos
3713d40330SchristosMany browsers implement a "sign and encrypt" option which is simply an S/MIME
3813d40330SchristosenvelopedData containing an S/MIME signed message. This can be readily produced
3913d40330Schristosby storing the S/MIME signed message in a memory BIO and passing it to
4013d40330SchristosCMS_encrypt().
4113d40330Schristos
4213d40330SchristosThe following flags can be passed in the B<flags> parameter.
4313d40330Schristos
4413d40330SchristosIf the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are
4513d40330Schristosprepended to the data.
4613d40330Schristos
4713d40330SchristosNormally the supplied content is translated into MIME canonical format (as
4813d40330Schristosrequired by the S/MIME specifications) if B<CMS_BINARY> is set no translation
4913d40330Schristosoccurs. This option should be used if the supplied data is in binary format
5013d40330Schristosotherwise the translation will corrupt it. If B<CMS_BINARY> is set then
5113d40330SchristosB<CMS_TEXT> is ignored.
5213d40330Schristos
5313d40330SchristosOpenSSL will by default identify recipient certificates using issuer name
5413d40330Schristosand serial number. If B<CMS_USE_KEYID> is set it will use the subject key
5513d40330Schristosidentifier value instead. An error occurs if all recipient certificates do not
5613d40330Schristoshave a subject key identifier extension.
5713d40330Schristos
5813d40330SchristosIf the B<CMS_STREAM> flag is set a partial B<CMS_ContentInfo> structure is
5913d40330Schristosreturned suitable for streaming I/O: no data is read from the BIO B<in>.
6013d40330Schristos
6113d40330SchristosIf the B<CMS_PARTIAL> flag is set a partial B<CMS_ContentInfo> structure is
6213d40330Schristosreturned to which additional recipients and attributes can be added before
6313d40330Schristosfinalization.
6413d40330Schristos
6513d40330SchristosThe data being encrypted is included in the CMS_ContentInfo structure, unless
6613d40330SchristosB<CMS_DETACHED> is set in which case it is omitted. This is rarely used in
6713d40330Schristospractice and is not supported by SMIME_write_CMS().
6813d40330Schristos
6913d40330SchristosIf the flag B<CMS_STREAM> is set the returned B<CMS_ContentInfo> structure is
7013d40330SchristosB<not> complete and outputting its contents via a function that does not
7113d40330Schristosproperly finalize the B<CMS_ContentInfo> structure will give unpredictable
7213d40330Schristosresults.
7313d40330Schristos
7413d40330SchristosSeveral functions including SMIME_write_CMS(), i2d_CMS_bio_stream(),
7513d40330SchristosPEM_write_bio_CMS_stream() finalize the structure. Alternatively finalization
7613d40330Schristoscan be performed by obtaining the streaming ASN1 B<BIO> directly using
7713d40330SchristosBIO_new_CMS().
7813d40330Schristos
7913d40330SchristosThe recipients specified in B<certs> use a CMS KeyTransRecipientInfo info
8013d40330Schristosstructure. KEKRecipientInfo is also supported using the flag B<CMS_PARTIAL>
8113d40330Schristosand CMS_add0_recipient_key().
8213d40330Schristos
8313d40330SchristosThe parameter B<certs> may be NULL if B<CMS_PARTIAL> is set and recipients
8413d40330Schristosadded later using CMS_add1_recipient_cert() or CMS_add0_recipient_key().
8513d40330Schristos
86*b0d17251SchristosCMS_encrypt() is similar to CMS_encrypt_ex() but uses default values
87*b0d17251Schristosof NULL for the library context I<libctx> and the property query I<propq>.
88*b0d17251Schristos
8913d40330Schristos=head1 RETURN VALUES
9013d40330Schristos
91*b0d17251SchristosCMS_encrypt_ex() and CMS_encrypt() return either a CMS_ContentInfo
92*b0d17251Schristosstructure or NULL if an error occurred. The error can be obtained from
93*b0d17251SchristosERR_get_error(3).
9413d40330Schristos
9513d40330Schristos=head1 SEE ALSO
9613d40330Schristos
9713d40330SchristosL<ERR_get_error(3)>, L<CMS_decrypt(3)>
9813d40330Schristos
9913d40330Schristos=head1 HISTORY
10013d40330Schristos
101*b0d17251SchristosThe function CMS_encrypt_ex() was added in OpenSSL 3.0.
102*b0d17251Schristos
10313d40330SchristosThe B<CMS_STREAM> flag was first supported in OpenSSL 1.0.0.
10413d40330Schristos
10513d40330Schristos=head1 COPYRIGHT
10613d40330Schristos
107*b0d17251SchristosCopyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved.
10813d40330Schristos
109*b0d17251SchristosLicensed under the Apache License 2.0 (the "License").  You may not use
11013d40330Schristosthis file except in compliance with the License.  You can obtain a copy
11113d40330Schristosin the file LICENSE in the source distribution or at
11213d40330SchristosL<https://www.openssl.org/source/license.html>.
11313d40330Schristos
11413d40330Schristos=cut
115