1=pod
2
3=head1 NAME
4
5PKCS12_key_gen_asc, PKCS12_key_gen_asc_ex,
6PKCS12_key_gen_uni, PKCS12_key_gen_uni_ex,
7PKCS12_key_gen_utf8, PKCS12_key_gen_utf8_ex - PKCS#12 Password based key derivation
8
9=head1 SYNOPSIS
10
11 #include <openssl/pkcs12.h>
12
13 int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
14                        int saltlen, int id, int iter, int n,
15                        unsigned char *out, const EVP_MD *md_type);
16 int PKCS12_key_gen_asc_ex(const char *pass, int passlen, unsigned char *salt,
17                           int saltlen, int id, int iter, int n,
18                           unsigned char *out, const EVP_MD *md_type,
19                           OSSL_LIB_CTX *ctx, const char *propq);
20 int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
21                        int saltlen, int id, int iter, int n,
22                        unsigned char *out, const EVP_MD *md_type);
23 int PKCS12_key_gen_uni_ex(unsigned char *pass, int passlen, unsigned char *salt,
24                           int saltlen, int id, int iter, int n,
25                           unsigned char *out, const EVP_MD *md_type,
26                           OSSL_LIB_CTX *ctx, const char *propq);
27 int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt,
28                         int saltlen, int id, int iter, int n,
29                         unsigned char *out, const EVP_MD *md_type);
30 int PKCS12_key_gen_utf8_ex(const char *pass, int passlen, unsigned char *salt,
31                            int saltlen, int id, int iter, int n,
32                            unsigned char *out, const EVP_MD *md_type,
33                            OSSL_LIB_CTX *ctx, const char *propq);
34
35=head1 DESCRIPTION
36
37These methods perform a key derivation according to PKCS#12 (RFC7292)
38with an input password I<pass> of length I<passlen>, a salt I<salt> of length
39I<saltlen>, an iteration count I<iter> and a digest algorithm I<md_type>.
40The ID byte I<id> determines how the resulting key is intended to be used:
41
42=over 4
43
44=item *
45
46If ID=1, then the pseudorandom bits being produced are to be used
47as key material for performing encryption or decryption.
48
49=item *
50
51If ID=2, then the pseudorandom bits being produced are to be used
52as an IV (Initial Value) for encryption or decryption.
53
54=item *
55
56If ID=3, then the pseudorandom bits being produced are to be used
57as an integrity key for MACing.
58
59=back
60
61The intended format of the supplied password is determined by the method chosen:
62
63=over 4
64
65=item *
66
67PKCS12_key_gen_asc() and PKCS12_key_gen_asc_ex() expect an ASCII-formatted password.
68
69=item *
70
71PKCS12_key_gen_uni() and PKCS12_key_gen_uni_ex() expect a Unicode-formatted password.
72
73=item *
74
75PKCS12_key_gen_utf8() and PKCS12_key_gen_utf8_ex() expect a UTF-8 encoded password.
76
77=back
78
79I<pass> is the password used in the derivation of length I<passlen>. I<pass>
80is an optional parameter and can be NULL. If I<passlen> is -1, then the
81function will calculate the length of I<pass> using strlen().
82
83I<salt> is the salt used in the derivation of length I<saltlen>. If the
84I<salt> is NULL, then I<saltlen> must be 0. The function will not
85attempt to calculate the length of the I<salt> because it is not assumed to
86be NULL terminated.
87
88I<iter> is the iteration count and its value should be greater than or
89equal to 1. RFC 2898 suggests an iteration count of at least 1000. Any
90I<iter> less than 1 is treated as a single iteration.
91
92I<digest> is the message digest function used in the derivation.
93
94The derived key will be written to I<out>. The size of the I<out> buffer
95is specified via I<n>.
96
97Functions ending in _ex() allow for a library context I<ctx> and property query
98I<propq> to be used to select algorithm implementations.
99
100=head1 NOTES
101
102A typical application of this function is to derive keying material for an
103encryption algorithm from a password in the I<pass>, a salt in I<salt>,
104and an iteration count.
105
106Increasing the I<iter> parameter slows down the algorithm which makes it
107harder for an attacker to perform a brute force attack using a large number
108of candidate passwords.
109
110=head1 RETURN VALUES
111
112Returns 1 on success or 0 on error.
113
114=head1 CONFORMING TO
115
116IETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>)
117
118=head1 SEE ALSO
119
120L<PKCS12_create_ex(3)>,
121L<PKCS12_pbe_crypt_ex(3)>,
122L<passphrase-encoding(7)>
123
124=head1 HISTORY
125
126PKCS12_key_gen_asc_ex(), PKCS12_key_gen_uni_ex() and PKCS12_key_gen_utf8_ex()
127were added in OpenSSL 3.0.
128
129=head1 COPYRIGHT
130
131Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
132
133Licensed under the Apache License 2.0 (the "License").  You may not use
134this file except in compliance with the License.  You can obtain a copy
135in the file LICENSE in the source distribution or at
136L<https://www.openssl.org/source/license.html>.
137
138=cut
139