1EVP_KDF_HKDF(7)                     OpenSSL                    EVP_KDF_HKDF(7)
2
3
4

NAME

6       EVP_KDF_HKDF - The HKDF EVP_KDF implementation
7

DESCRIPTION

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   Numeric identity
19       EVP_KDF_HKDF is the numeric identity for this implementation; it can be
20       used with the EVP_KDF_CTX_new_id() function.
21
22   Supported controls
23       The supported controls are:
24
25       EVP_KDF_CTRL_SET_SALT
26       EVP_KDF_CTRL_SET_MD
27       EVP_KDF_CTRL_SET_KEY
28           These controls work as described in "CONTROLS" in EVP_KDF_CTX(3).
29
30       EVP_KDF_CTRL_RESET_HKDF_INFO
31           This control does not expect any arguments.
32
33           Resets the context info buffer to zero length.
34
35       EVP_KDF_CTRL_ADD_HKDF_INFO
36           This control expects two arguments: "unsigned char *info", "size_t
37           infolen"
38
39           Sets the info value to the first infolen bytes of the buffer info.
40           If a value is already set, the contents of the buffer are appended
41           to the existing value.
42
43           The total length of the context info buffer cannot exceed 1024
44           bytes; this should be more than enough for any normal use of HKDF.
45
46           EVP_KDF_ctrl_str() takes two type strings for this control:
47
48           "info"
49               The value string is used as is.
50
51           "hexinfo"
52               The value string is expected to be a hexadecimal number, which
53               will be decoded before being passed on as the control value.
54
55       EVP_KDF_CTRL_SET_HKDF_MODE
56           This control expects one argument: "int mode"
57
58           Sets the mode for the HKDF operation. There are three modes that
59           are currently defined:
60
61           EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND
62               This is the default mode.  Calling EVP_KDF_derive(3) on an
63               EVP_KDF_CTX set up for HKDF will perform an extract followed by
64               an expand operation in one go.  The derived key returned will
65               be the result after the expand operation. The intermediate
66               fixed-length pseudorandom key K is not returned.
67
68               In this mode the digest, key, salt and info values must be set
69               before a key is derived otherwise an error will occur.
70
71           EVP_KDF_HKDF_MODE_EXTRACT_ONLY
72               In this mode calling EVP_KDF_derive(3) will just perform the
73               extract operation. The value returned will be the intermediate
74               fixed-length pseudorandom key K.  The "keylen" parameter must
75               match the size of K, which can be looked up by calling
76               EVP_KDF_size() after setting the mode and digest.
77
78               The digest, key and salt values must be set before a key is
79               derived otherwise an error will occur.
80
81           EVP_KDF_HKDF_MODE_EXPAND_ONLY
82               In this mode calling EVP_KDF_derive(3) will just perform the
83               expand operation. The input key should be set to the
84               intermediate fixed-length pseudorandom key K returned from a
85               previous extract operation.
86
87               The digest, key and info values must be set before a key is
88               derived otherwise an error will occur.
89
90           EVP_KDF_ctrl_str() type string: "mode"
91
92           The value string is expected to be one of: "EXTRACT_AND_EXPAND",
93           "EXTRACT_ONLY" or "EXPAND_ONLY".
94

NOTES

96       A context for HKDF can be obtained by calling:
97
98        EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_HKDF);
99
100       The output length of an HKDF expand operation is specified via the
101       "keylen" parameter to the EVP_KDF_derive(3) function.  When using
102       EVP_KDF_HKDF_MODE_EXTRACT_ONLY the "keylen" parameter must equal the
103       size of the intermediate fixed-length pseudorandom key otherwise an
104       error will occur.  For that mode, the fixed output size can be looked
105       up by calling EVP_KDF_size() after setting the mode and digest on the
106       "EVP_KDF_CTX".
107

EXAMPLE

109       This example derives 10 bytes using SHA-256 with the secret key
110       "secret", salt value "salt" and info value "label":
111
112        EVP_KDF_CTX *kctx;
113        unsigned char out[10];
114
115        kctx = EVP_KDF_CTX_new_id(EVP_KDF_HKDF);
116
117        if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) {
118            error("EVP_KDF_CTRL_SET_MD");
119        }
120        if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) {
121            error("EVP_KDF_CTRL_SET_SALT");
122        }
123        if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) {
124            error("EVP_KDF_CTRL_SET_KEY");
125        }
126        if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_HKDF_INFO, "label", (size_t)5) <= 0) {
127            error("EVP_KDF_CTRL_ADD_HKDF_INFO");
128        }
129        if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) {
130            error("EVP_KDF_derive");
131        }
132
133        EVP_KDF_CTX_free(kctx);
134

CONFORMING TO

136       RFC 5869
137

SEE ALSO

139       EVP_KDF_CTX, EVP_KDF_CTX_new_id(3), EVP_KDF_CTX_free(3),
140       EVP_KDF_ctrl(3), EVP_KDF_size(3), EVP_KDF_derive(3), "CONTROLS" in
141       EVP_KDF_CTX(3)
142
144       Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
145
146       Licensed under the Apache License 2.0 (the "License").  You may not use
147       this file except in compliance with the License.  You can obtain a copy
148       in the file LICENSE in the source distribution or at
149       <https://www.openssl.org/source/license.html>.
150
151
152
1531.1.1k                            2021-03-26                   EVP_KDF_HKDF(7)
Impressum