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