Debian Codegraph @

upstream/debian-unstable/man7/EVP_KDF-HKDF.7ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "EVP_KDF-HKDF 7SSL"
58 .TH EVP_KDF-HKDF 7SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 EVP_KDF\-HKDF \- The HKDF EVP_KDF implementations
65 .SH DESCRIPTION
66 .IX Header "DESCRIPTION"
67 Support for computing the \fBHKDF\fR KDF through the \fBEVP_KDF\fR API.
68 .PP
69 The EVP_KDF\-HKDF algorithm implements the HKDF key derivation function.
70 HKDF follows the "extract-then-expand" paradigm, where the KDF logically
71 consists of two modules. The first stage takes the input keying material
72 and "extracts" from it a fixed-length pseudorandom key K. The second stage
73 "expands" the key K into several additional pseudorandom keys (the output
74 of the KDF).
75 .PP
76 The output is considered to be keying material.
77 .SS Identity
78 .IX Subsection "Identity"
79 The following algorithms are available for this implementation; they
80 can be used with the \fBEVP_KDF_fetch()\fR function.
81 .PP
82 In this list, names are grouped together to signify that they are the same
83 algorithm having multiple names. This also includes the OID in canonical
84 decimal form (which means that they are possible to fetch if the caller has a
85 mere OID which came out in this form after a call to \fBOBJ_obj2txt\fR\|(3)).
86 .IP """HKDF""" 4
87 .IX Item """HKDF"""
88 The \fBOSSL_KDF_PARAM_DIGEST\fR parameter must be set for \fBHKDF\fR before it can
89 be used.
90 .IP """HKDF\-SHA256"", ""id\-alg\-hkdf\-with\-sha256"", ""1.2.840.113549.1.9.16.3.28""" 4
91 .IX Item """HKDF-SHA256"", ""id-alg-hkdf-with-sha256"", ""1.2.840.113549.1.9.16.3.28"""
92 .PD 0
93 .IP """HKDF\-SHA384"", ""id\-alg\-hkdf\-with\-sha384"", ""1.2.840.113549.1.9.16.3.29""" 4
94 .IX Item """HKDF-SHA384"", ""id-alg-hkdf-with-sha384"", ""1.2.840.113549.1.9.16.3.29"""
95 .IP """HKDF\-SHA512"", ""id\-alg\-hkdf\-with\-sha512"", ""1.2.840.113549.1.9.16.3.30""" 4
96 .IX Item """HKDF-SHA512"", ""id-alg-hkdf-with-sha512"", ""1.2.840.113549.1.9.16.3.30"""
97 .PD
98 \&\fBHKDF\-SHA256\fR, \fBHKDF\-SHA384\fR and \fBHKDF\-SHA512\fR are fixed-digest versions
99 of \fBHKDF\fR with the appropriate digest already configured.
100 \&\fBEVP_KDF_CTX_reset\fR\|(3) will not reset the context's digest for fixed-digest
101 versions.
102 .SS "Supported parameters"
103 .IX Subsection "Supported parameters"
104 The supported parameters are:
105 .IP """properties"" (\fBOSSL_KDF_PARAM_PROPERTIES\fR) <UTF8 string>" 4
106 .IX Item """properties"" (OSSL_KDF_PARAM_PROPERTIES) <UTF8 string>"
107 .PD 0
108 .IP """digest"" (\fBOSSL_KDF_PARAM_DIGEST\fR) <UTF8 string>" 4
109 .IX Item """digest"" (OSSL_KDF_PARAM_DIGEST) <UTF8 string>"
110 .PD
111 Attempting to set the digest on a fixed-digest \fBHKDF\fR will result in an error.
112 .IP """key"" (\fBOSSL_KDF_PARAM_KEY\fR) <octet string>" 4
113 .IX Item """key"" (OSSL_KDF_PARAM_KEY) <octet string>"
114 .PD 0
115 .IP """salt"" (\fBOSSL_KDF_PARAM_SALT\fR) <octet string>" 4
116 .IX Item """salt"" (OSSL_KDF_PARAM_SALT) <octet string>"
117 .PD
118 These parameters work as described in "PARAMETERS" in \fBEVP_KDF\fR\|(3).
119 .IP """info"" (\fBOSSL_KDF_PARAM_INFO\fR) <octet string>" 4
120 .IX Item """info"" (OSSL_KDF_PARAM_INFO) <octet string>"
121 This parameter sets the info value.
122 The length of the context info buffer cannot exceed 1024 bytes;
123 this should be more than enough for any normal use of HKDF.
124 .IP """mode"" (\fBOSSL_KDF_PARAM_MODE\fR) <UTF8 string> or <integer>" 4
125 .IX Item """mode"" (OSSL_KDF_PARAM_MODE) <UTF8 string> or <integer>"
126 This parameter sets the mode for the HKDF operation.
127 There are three modes that are currently defined:
128 .RS 4
129 .IP """EXTRACT_AND_EXPAND"" or \fBEVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND\fR" 4
130 .IX Item """EXTRACT_AND_EXPAND"" or EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND"
131 This is the default mode. Calling \fBEVP_KDF_derive\fR\|(3) on an EVP_KDF_CTX set
132 up for HKDF will perform an extract followed by an expand operation in one go.
133 The derived key returned will be the result after the expand operation. The
134 intermediate fixed-length pseudorandom key K is not returned.
135 .Sp
136 In this mode the key, salt and info values must be set before a key is
137 derived otherwise an error will occur. For non-fixed mode (\fBHKDF\fR) the digest
138 must also be set.
139 .IP """EXTRACT_ONLY"" or \fBEVP_KDF_HKDF_MODE_EXTRACT_ONLY\fR" 4
140 .IX Item """EXTRACT_ONLY"" or EVP_KDF_HKDF_MODE_EXTRACT_ONLY"
141 In this mode calling \fBEVP_KDF_derive\fR\|(3) will just perform the extract
142 operation. The value returned will be the intermediate fixed-length pseudorandom
143 key K. The \fIkeylen\fR parameter must match the size of K, which can be looked
144 up by calling \fBEVP_KDF_CTX_get_kdf_size()\fR after setting the mode and digest.
145 .Sp
146 The key and salt values must be set before a key is derived otherwise
147 an error will occur. For non-fixed mode (\fBHKDF\fR) the digest
148 must also be set.
149 .IP """EXPAND_ONLY"" or \fBEVP_KDF_HKDF_MODE_EXPAND_ONLY\fR" 4
150 .IX Item """EXPAND_ONLY"" or EVP_KDF_HKDF_MODE_EXPAND_ONLY"
151 In this mode calling \fBEVP_KDF_derive\fR\|(3) will just perform the expand
152 operation. The input key should be set to the intermediate fixed-length
153 pseudorandom key K returned from a previous extract operation.
154 .Sp
155 The key and info values must be set before a key is derived otherwise
156 an error will occur. For non-fixed mode (\fBHKDF\fR) the digest
157 must also be set.
158 .RE
159 .RS 4
160 .RE
161 .PP
162 The OpenSSL FIPS provider also supports the following parameters:
163 .IP """fips-indicator"" (\fBOSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR\fR) <integer>" 4
164 .IX Item """fips-indicator"" (OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR) <integer>"
165 A getter that returns 1 if the operation is FIPS approved, or 0 otherwise.
166 This may be used after calling EVP_KDF_derive. It returns 0 if "key-check"
167 is set to 0 and the check fails.
168 .IP """key-check"" (\fBOSSL_KDF_PARAM_FIPS_KEY_CHECK\fR) <integer>" 4
169 .IX Item """key-check"" (OSSL_KDF_PARAM_FIPS_KEY_CHECK) <integer>"
170 The default value of 1 causes an error during \fBEVP_KDF_CTX_set_params()\fR if the
171 length of used key-derivation key (\fBOSSL_KDF_PARAM_KEY\fR) is shorter than 112
172 bits.
173 Setting this to zero will ignore the error and set the approved
174 "fips-indicator" to 0.
175 This option breaks FIPS compliance if it causes the approved "fips-indicator"
176 to return 0.
177 .SH NOTES
178 .IX Header "NOTES"
179 A context for HKDF can be obtained by calling:
180 .PP
181 .Vb 2
182 \& EVP_KDF *kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
183 \& EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
184 .Ve
185 .PP
186 The output length of an HKDF expand operation is specified via the \fIkeylen\fR
187 parameter to the \fBEVP_KDF_derive\fR\|(3) function. When using
188 EVP_KDF_HKDF_MODE_EXTRACT_ONLY the \fIkeylen\fR parameter must equal the size of
189 the intermediate fixed-length pseudorandom key otherwise an error will occur.
190 For that mode, the fixed output size can be looked up by calling \fBEVP_KDF_CTX_get_kdf_size()\fR
191 after setting the mode and digest on the \fBEVP_KDF_CTX\fR.
192 .SH EXAMPLES
193 .IX Header "EXAMPLES"
194 .SS "HKDF Algorithm"
195 .IX Subsection "HKDF Algorithm"
196 This example derives 10 bytes using SHA\-256 with the secret key "secret",
197 salt value "salt" and info value "label":
198 .PP
199 .Vb 4
200 \& EVP_KDF *kdf;
201 \& EVP_KDF_CTX *kctx;
202 \& unsigned char out[10];
203 \& OSSL_PARAM params[5], *p = params;
204 \&
205 \& kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
206 \& kctx = EVP_KDF_CTX_new(kdf);
207 \& EVP_KDF_free(kdf);
208 \&
209 \& *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
210 \& SN_sha256, strlen(SN_sha256));
211 \& *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
212 \& "secret", (size_t)6);
213 \& *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
214 \& "label", (size_t)5);
215 \& *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
216 \& "salt", (size_t)4);
217 \& *p = OSSL_PARAM_construct_end();
218 \& if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
219 \& error("EVP_KDF_derive");
220 \& }
221 \&
222 \& EVP_KDF_CTX_free(kctx);
223 .Ve
224 .SS "HKDF\-SHA256 Algorithm"
225 .IX Subsection "HKDF-SHA256 Algorithm"
226 This example derives 10 bytes using HKDF\-SHA256 with the secret key "secret",
227 salt value "salt" and info value "label":
228 .PP
229 .Vb 4
230 \& EVP_KDF *kdf;
231 \& EVP_KDF_CTX *kctx;
232 \& unsigned char out[10];
233 \& OSSL_PARAM params[4], *p = params;
234 \&
235 \& kdf = EVP_KDF_fetch(NULL, "HKDF\-SHA256", NULL);
236 \& kctx = EVP_KDF_CTX_new(kdf);
237 \& EVP_KDF_free(kdf);
238 \&
239 \& *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
240 \& "secret", (size_t)6);
241 \& *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
242 \& "label", (size_t)5);
243 \& *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
244 \& "salt", (size_t)4);
245 \& *p = OSSL_PARAM_construct_end();
246 \& if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
247 \& error("EVP_KDF_derive");
248 \& }
249 \&
250 \& EVP_KDF_CTX_free(kctx);
251 .Ve
252 .SH "CONFORMING TO"
253 .IX Header "CONFORMING TO"
254 RFC 5869 and RFC 8619
255 .SH "SEE ALSO"
256 .IX Header "SEE ALSO"
257 \&\fBEVP_KDF\fR\|(3),
258 \&\fBEVP_KDF_CTX_new\fR\|(3),
259 \&\fBEVP_KDF_CTX_free\fR\|(3),
260 \&\fBEVP_KDF_CTX_get_kdf_size\fR\|(3),
261 \&\fBEVP_KDF_CTX_set_params\fR\|(3),
262 \&\fBEVP_KDF_derive\fR\|(3),
263 "PARAMETERS" in \fBEVP_KDF\fR\|(3),
264 \&\fBEVP_KDF\-TLS13_KDF\fR\|(7)
265 .SH HISTORY
266 .IX Header "HISTORY"
267 HKDF\-SHA256, HKDF\-SHA384 and HKDF\-SHA512 were added in OpenSSL 3.6.
268 .PP
269 All other functionality was added in OpenSSL 3.0.
270 .SH COPYRIGHT
271 .IX Header "COPYRIGHT"
272 Copyright 2016\-2025 The OpenSSL Project Authors. All Rights Reserved.
273 .PP
274 Licensed under the Apache License 2.0 (the "License"). You may not use
275 this file except in compliance with the License. You can obtain a copy
276 in the file LICENSE in the source distribution or at
277 <https://www.openssl.org/source/license.html>.