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
11 #include <openssl/pkcs12.h>
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);
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:
46 If ID=1, then the pseudorandom bits being produced are to be used
47 as key material for performing encryption or decryption.
51 If ID=2, then the pseudorandom bits being produced are to be used
52 as an IV (Initial Value) for encryption or decryption.
56 If ID=3, then the pseudorandom bits being produced are to be used
57 as an integrity key for MACing.
61 The intended format of the supplied password is determined by the method chosen:
67 PKCS12_key_gen_asc() and PKCS12_key_gen_asc_ex() expect an ASCII-formatted password.
71 PKCS12_key_gen_uni() and PKCS12_key_gen_uni_ex() expect a Unicode-formatted password.
75 PKCS12_key_gen_utf8() and PKCS12_key_gen_utf8_ex() expect a UTF-8 encoded password.
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().
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
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.
92 I<digest> is the message digest function used in the derivation.
94 The derived key will be written to I<out>. The size of the I<out> buffer
95 is specified via I<n>.
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.
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.
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.
112 Returns 1 on success or 0 on error.
116 IETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>)
120 L<PKCS12_create_ex(3)>,
121 L<PKCS12_pbe_crypt_ex(3)>,
122 L<passphrase-encoding(7)>
126 PKCS12_key_gen_asc_ex(), PKCS12_key_gen_uni_ex() and PKCS12_key_gen_utf8_ex()
127 were added in OpenSSL 3.0.
131 Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
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>.