xref: /freebsd/crypto/openssl/doc/man3/PKCS12_PBE_keyivgen.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1*b077aed3SPierre Pronchery=pod
2*b077aed3SPierre Pronchery
3*b077aed3SPierre Pronchery=head1 NAME
4*b077aed3SPierre Pronchery
5*b077aed3SPierre ProncheryPKCS12_PBE_keyivgen, PKCS12_PBE_keyivgen_ex,
6*b077aed3SPierre ProncheryPKCS12_pbe_crypt, PKCS12_pbe_crypt_ex - PKCS#12 Password based encryption
7*b077aed3SPierre Pronchery
8*b077aed3SPierre Pronchery=head1 SYNOPSIS
9*b077aed3SPierre Pronchery
10*b077aed3SPierre Pronchery #include <openssl/evp.h>
11*b077aed3SPierre Pronchery
12*b077aed3SPierre Pronchery int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
13*b077aed3SPierre Pronchery                         ASN1_TYPE *param, const EVP_CIPHER *cipher,
14*b077aed3SPierre Pronchery                         const EVP_MD *md_type, int en_de);
15*b077aed3SPierre Pronchery int PKCS12_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
16*b077aed3SPierre Pronchery                            ASN1_TYPE *param, const EVP_CIPHER *cipher,
17*b077aed3SPierre Pronchery                            const EVP_MD *md_type, int en_de,
18*b077aed3SPierre Pronchery                            OSSL_LIB_CTX *libctx, const char *propq);
19*b077aed3SPierre Pronchery unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor,
20*b077aed3SPierre Pronchery                                 const char *pass, int passlen,
21*b077aed3SPierre Pronchery                                 const unsigned char *in, int inlen,
22*b077aed3SPierre Pronchery                                 unsigned char **data, int *datalen,
23*b077aed3SPierre Pronchery                                 int en_de);
24*b077aed3SPierre Pronchery unsigned char *PKCS12_pbe_crypt_ex(const X509_ALGOR *algor,
25*b077aed3SPierre Pronchery                                    const char *pass, int passlen,
26*b077aed3SPierre Pronchery                                    const unsigned char *in, int inlen,
27*b077aed3SPierre Pronchery                                    unsigned char **data, int *datalen,
28*b077aed3SPierre Pronchery                                    int en_de, OSSL_LIB_CTX *libctx,
29*b077aed3SPierre Pronchery                                    const char *propq);
30*b077aed3SPierre Pronchery
31*b077aed3SPierre Pronchery=head1 DESCRIPTION
32*b077aed3SPierre Pronchery
33*b077aed3SPierre ProncheryPKCS12_PBE_keyivgen() and PKCS12_PBE_keyivgen_ex() take a password I<pass> of
34*b077aed3SPierre Proncherylength I<passlen>, parameters I<param> and a message digest function I<md_type>
35*b077aed3SPierre Proncheryand perform a key derivation according to PKCS#12. The resulting key is
36*b077aed3SPierre Proncherythen used to initialise the cipher context I<ctx> with a cipher I<cipher> for
37*b077aed3SPierre Proncheryencryption (I<en_de>=1) or decryption (I<en_de>=0).
38*b077aed3SPierre Pronchery
39*b077aed3SPierre ProncheryPKCS12_PBE_keyivgen_ex() also allows the application to specify a library context
40*b077aed3SPierre ProncheryI<libctx> and property query I<propq> to select appropriate algorithm
41*b077aed3SPierre Proncheryimplementations.
42*b077aed3SPierre Pronchery
43*b077aed3SPierre ProncheryPKCS12_pbe_crypt() and PKCS12_pbe_crypt_ex() will encrypt or decrypt a buffer
44*b077aed3SPierre Proncherybased on the algorithm in I<algor> and password I<pass> of length I<passlen>.
45*b077aed3SPierre ProncheryThe input is from I<in> of length I<inlen> and output is into a malloc'd buffer
46*b077aed3SPierre Proncheryreturned in I<*data> of length I<datalen>. The operation is determined by I<en_de>,
47*b077aed3SPierre Proncheryencryption (I<en_de>=1) or decryption (I<en_de>=0).
48*b077aed3SPierre Pronchery
49*b077aed3SPierre ProncheryPKCS12_pbe_crypt_ex() allows the application to specify a library context
50*b077aed3SPierre ProncheryI<libctx> and property query I<propq> to select appropriate algorithm
51*b077aed3SPierre Proncheryimplementations.
52*b077aed3SPierre Pronchery
53*b077aed3SPierre ProncheryI<pass> is the password used in the derivation of length I<passlen>. I<pass>
54*b077aed3SPierre Proncheryis an optional parameter and can be NULL. If I<passlen> is -1, then the
55*b077aed3SPierre Proncheryfunction will calculate the length of I<pass> using strlen().
56*b077aed3SPierre Pronchery
57*b077aed3SPierre ProncheryI<salt> is the salt used in the derivation of length I<saltlen>. If the
58*b077aed3SPierre ProncheryI<salt> is NULL, then I<saltlen> must be 0. The function will not
59*b077aed3SPierre Proncheryattempt to calculate the length of the I<salt> because it is not assumed to
60*b077aed3SPierre Proncherybe NULL terminated.
61*b077aed3SPierre Pronchery
62*b077aed3SPierre ProncheryI<iter> is the iteration count and its value should be greater than or
63*b077aed3SPierre Proncheryequal to 1. RFC 2898 suggests an iteration count of at least 1000. Any
64*b077aed3SPierre ProncheryI<iter> less than 1 is treated as a single iteration.
65*b077aed3SPierre Pronchery
66*b077aed3SPierre ProncheryI<digest> is the message digest function used in the derivation.
67*b077aed3SPierre Pronchery
68*b077aed3SPierre ProncheryFunctions ending in _ex() take optional parameters I<libctx> and I<propq> which
69*b077aed3SPierre Proncheryare used to select appropriate algorithm implementations.
70*b077aed3SPierre Pronchery
71*b077aed3SPierre Pronchery=head1 NOTES
72*b077aed3SPierre Pronchery
73*b077aed3SPierre ProncheryThe functions are typically used in PKCS#12 to encrypt objects.
74*b077aed3SPierre Pronchery
75*b077aed3SPierre ProncheryThese functions make no assumption regarding the given password.
76*b077aed3SPierre ProncheryIt will simply be treated as a byte sequence.
77*b077aed3SPierre Pronchery
78*b077aed3SPierre Pronchery=head1 RETURN VALUES
79*b077aed3SPierre Pronchery
80*b077aed3SPierre ProncheryPKCS12_PBE_keyivgen(), PKCS12_PBE_keyivgen_ex() return 1 on success or 0 on error.
81*b077aed3SPierre Pronchery
82*b077aed3SPierre ProncheryPKCS12_pbe_crypt() and PKCS12_pbe_crypt_ex() return a buffer containing the
83*b077aed3SPierre Proncheryoutput or NULL if an error occurred.
84*b077aed3SPierre Pronchery
85*b077aed3SPierre Pronchery=head1 CONFORMING TO
86*b077aed3SPierre Pronchery
87*b077aed3SPierre ProncheryIETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>)
88*b077aed3SPierre Pronchery
89*b077aed3SPierre Pronchery=head1 SEE ALSO
90*b077aed3SPierre Pronchery
91*b077aed3SPierre ProncheryL<EVP_PBE_CipherInit_ex(3)>,
92*b077aed3SPierre ProncheryL<PKCS8_encrypt_ex(3)>,
93*b077aed3SPierre ProncheryL<passphrase-encoding(7)>
94*b077aed3SPierre Pronchery
95*b077aed3SPierre Pronchery=head1 HISTORY
96*b077aed3SPierre Pronchery
97*b077aed3SPierre ProncheryPKCS12_PBE_keyivgen_ex() and PKCS12_pbe_crypt_ex() were added in OpenSSL 3.0.
98*b077aed3SPierre Pronchery
99*b077aed3SPierre Pronchery=head1 COPYRIGHT
100*b077aed3SPierre Pronchery
101*b077aed3SPierre ProncheryCopyright 2014-2021 The OpenSSL Project Authors. All Rights Reserved.
102*b077aed3SPierre Pronchery
103*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
104*b077aed3SPierre Proncherythis file except in compliance with the License.  You can obtain a copy
105*b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at
106*b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>.
107*b077aed3SPierre Pronchery
108*b077aed3SPierre Pronchery=cut
109