1EVP_KDF-HKDF(7ossl) OpenSSL EVP_KDF-HKDF(7ossl)
2
3
4
6 EVP_KDF-HKDF - The HKDF EVP_KDF implementation
7
9 Support for computing the HKDF KDF through the EVP_KDF API.
10
11 The EVP_KDF-HKDF algorithm implements the HKDF key derivation function.
12 HKDF follows the "extract-then-expand" paradigm, where the KDF
13 logically consists of two modules. The first stage takes the input
14 keying material and "extracts" from it a fixed-length pseudorandom key
15 K. The second stage "expands" the key K into several additional
16 pseudorandom keys (the output of the KDF).
17
18 Identity
19 "HKDF" is the name for this implementation; it can be used with the
20 EVP_KDF_fetch() function.
21
22 Supported parameters
23 The supported parameters are:
24
25 "properties" (OSSL_KDF_PARAM_PROPERTIES) <UTF8 string>
26 "digest" (OSSL_KDF_PARAM_DIGEST) <UTF8 string>
27 "key" (OSSL_KDF_PARAM_KEY) <octet string>
28 "salt" (OSSL_KDF_PARAM_SALT) <octet string>
29 These parameters work as described in "PARAMETERS" in EVP_KDF(3).
30
31 "info" (OSSL_KDF_PARAM_INFO) <octet string>
32 This parameter sets the info value. The length of the context info
33 buffer cannot exceed 1024 bytes; this should be more than enough
34 for any normal use of HKDF.
35
36 "mode" (OSSL_KDF_PARAM_MODE) <UTF8 string> or <integer>
37 This parameter sets the mode for the HKDF operation. There are
38 three modes that are currently defined:
39
40 "EXTRACT_AND_EXPAND" or EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND
41 This is the default mode. Calling EVP_KDF_derive(3) on an
42 EVP_KDF_CTX set up for HKDF will perform an extract followed by
43 an expand operation in one go. The derived key returned will
44 be the result after the expand operation. The intermediate
45 fixed-length pseudorandom key K is not returned.
46
47 In this mode the digest, key, salt and info values must be set
48 before a key is derived otherwise an error will occur.
49
50 "EXTRACT_ONLY" or EVP_KDF_HKDF_MODE_EXTRACT_ONLY
51 In this mode calling EVP_KDF_derive(3) will just perform the
52 extract operation. The value returned will be the intermediate
53 fixed-length pseudorandom key K. The keylen parameter must
54 match the size of K, which can be looked up by calling
55 EVP_KDF_CTX_get_kdf_size() after setting the mode and digest.
56
57 The digest, key and salt values must be set before a key is
58 derived otherwise an error will occur.
59
60 "EXPAND_ONLY" or EVP_KDF_HKDF_MODE_EXPAND_ONLY
61 In this mode calling EVP_KDF_derive(3) will just perform the
62 expand operation. The input key should be set to the
63 intermediate fixed-length pseudorandom key K returned from a
64 previous extract operation.
65
66 The digest, key and info values must be set before a key is
67 derived otherwise an error will occur.
68
70 A context for HKDF can be obtained by calling:
71
72 EVP_KDF *kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
73 EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
74
75 The output length of an HKDF expand operation is specified via the
76 keylen parameter to the EVP_KDF_derive(3) function. When using
77 EVP_KDF_HKDF_MODE_EXTRACT_ONLY the keylen parameter must equal the size
78 of the intermediate fixed-length pseudorandom key otherwise an error
79 will occur. For that mode, the fixed output size can be looked up by
80 calling EVP_KDF_CTX_get_kdf_size() after setting the mode and digest on
81 the EVP_KDF_CTX.
82
84 This example derives 10 bytes using SHA-256 with the secret key
85 "secret", salt value "salt" and info value "label":
86
87 EVP_KDF *kdf;
88 EVP_KDF_CTX *kctx;
89 unsigned char out[10];
90 OSSL_PARAM params[5], *p = params;
91
92 kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
93 kctx = EVP_KDF_CTX_new(kdf);
94 EVP_KDF_free(kdf);
95
96 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
97 SN_sha256, strlen(SN_sha256));
98 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
99 "secret", (size_t)6);
100 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
101 "label", (size_t)5);
102 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
103 "salt", (size_t)4);
104 *p = OSSL_PARAM_construct_end();
105 if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
106 error("EVP_KDF_derive");
107 }
108
109 EVP_KDF_CTX_free(kctx);
110
112 RFC 5869
113
115 EVP_KDF(3), EVP_KDF_CTX_new(3), EVP_KDF_CTX_free(3),
116 EVP_KDF_CTX_get_kdf_size(3), EVP_KDF_CTX_set_params(3),
117 EVP_KDF_derive(3), "PARAMETERS" in EVP_KDF(3), EVP_KDF-TLS13_KDF(7)
118
120 Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
121
122 Licensed under the Apache License 2.0 (the "License"). You may not use
123 this file except in compliance with the License. You can obtain a copy
124 in the file LICENSE in the source distribution or at
125 <https://www.openssl.org/source/license.html>.
126
127
128
1293.0.5 2022-11-01 EVP_KDF-HKDF(7ossl)