Debian Codegraph @

upstream/debian-unstable/man3/EVP_PKEY_CTX_set_hkdf_md.3ssl

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_PKEY_CTX_SET_HKDF_MD 3SSL"
58 .TH EVP_PKEY_CTX_SET_HKDF_MD 3SSL 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_PKEY_CTX_set_hkdf_md, EVP_PKEY_CTX_set1_hkdf_salt,
65 EVP_PKEY_CTX_set1_hkdf_key, EVP_PKEY_CTX_add1_hkdf_info,
66 EVP_PKEY_CTX_set_hkdf_mode \-
67 HMAC\-based Extract\-and\-Expand key derivation algorithm
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& #include <openssl/kdf.h>
72 \&
73 \& int EVP_PKEY_CTX_set_hkdf_mode(EVP_PKEY_CTX *pctx, int mode);
74 \&
75 \& int EVP_PKEY_CTX_set_hkdf_md(EVP_PKEY_CTX *pctx, const EVP_MD *md);
76 \&
77 \& int EVP_PKEY_CTX_set1_hkdf_salt(EVP_PKEY_CTX *pctx, unsigned char *salt,
78 \& int saltlen);
79 \&
80 \& int EVP_PKEY_CTX_set1_hkdf_key(EVP_PKEY_CTX *pctx, unsigned char *key,
81 \& int keylen);
82 \&
83 \& int EVP_PKEY_CTX_add1_hkdf_info(EVP_PKEY_CTX *pctx, unsigned char *info,
84 \& int infolen);
85 .Ve
86 .SH DESCRIPTION
87 .IX Header "DESCRIPTION"
88 The EVP_PKEY_HKDF algorithm implements the HKDF key derivation function.
89 HKDF follows the "extract-then-expand" paradigm, where the KDF logically
90 consists of two modules. The first stage takes the input keying material
91 and "extracts" from it a fixed-length pseudorandom key K. The second stage
92 "expands" the key K into several additional pseudorandom keys (the output
93 of the KDF).
94 .PP
95 \&\fBEVP_PKEY_CTX_set_hkdf_mode()\fR sets the mode for the HKDF operation. There
96 are three modes that are currently defined:
97 .IP EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND 4
98 .IX Item "EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND"
99 This is the default mode. Calling \fBEVP_PKEY_derive\fR\|(3) on an EVP_PKEY_CTX set
100 up for HKDF will perform an extract followed by an expand operation in one go.
101 The derived key returned will be the result after the expand operation. The
102 intermediate fixed-length pseudorandom key K is not returned.
103 .Sp
104 In this mode the digest, key, salt and info values must be set before a key is
105 derived or an error occurs.
106 .IP EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY 4
107 .IX Item "EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY"
108 In this mode calling \fBEVP_PKEY_derive\fR\|(3) will just perform the extract
109 operation. The value returned will be the intermediate fixed-length pseudorandom
110 key K.
111 .Sp
112 The digest, key and salt values must be set before a key is derived or an
113 error occurs.
114 .IP EVP_PKEY_HKDEF_MODE_EXPAND_ONLY 4
115 .IX Item "EVP_PKEY_HKDEF_MODE_EXPAND_ONLY"
116 In this mode calling \fBEVP_PKEY_derive\fR\|(3) will just perform the expand
117 operation. The input key should be set to the intermediate fixed-length
118 pseudorandom key K returned from a previous extract operation.
119 .Sp
120 The digest, key and info values must be set before a key is derived or an
121 error occurs.
122 .PP
123 \&\fBEVP_PKEY_CTX_set_hkdf_md()\fR sets the message digest associated with the HKDF.
124 .PP
125 \&\fBEVP_PKEY_CTX_set1_hkdf_salt()\fR sets the salt to \fBsaltlen\fR bytes of the
126 buffer \fBsalt\fR. Any existing value is replaced.
127 .PP
128 \&\fBEVP_PKEY_CTX_set1_hkdf_key()\fR sets the key to \fBkeylen\fR bytes of the buffer
129 \&\fBkey\fR. Any existing value is replaced.
130 .PP
131 \&\fBEVP_PKEY_CTX_add1_hkdf_info()\fR sets the info value to \fBinfolen\fR bytes of the
132 buffer \fBinfo\fR. If a value is already set, it is appended to the existing
133 value.
134 .SH "STRING CTRLS"
135 .IX Header "STRING CTRLS"
136 HKDF also supports string based control operations via
137 \&\fBEVP_PKEY_CTX_ctrl_str\fR\|(3).
138 The \fBtype\fR parameter "md" uses the supplied \fBvalue\fR as the name of the digest
139 algorithm to use.
140 The \fBtype\fR parameter "mode" uses the values "EXTRACT_AND_EXPAND",
141 "EXTRACT_ONLY" and "EXPAND_ONLY" to determine the mode to use.
142 The \fBtype\fR parameters "salt", "key" and "info" use the supplied \fBvalue\fR
143 parameter as a \fBseed\fR, \fBkey\fR or \fBinfo\fR value.
144 The names "hexsalt", "hexkey" and "hexinfo" are similar except they take a hex
145 string which is converted to binary.
146 .SH NOTES
147 .IX Header "NOTES"
148 A context for HKDF can be obtained by calling:
149 .PP
150 .Vb 1
151 \& EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
152 .Ve
153 .PP
154 The total length of the info buffer cannot exceed 2048 bytes in length: this
155 should be more than enough for any normal use of HKDF.
156 .PP
157 The output length of an HKDF expand operation is specified via the length
158 parameter to the \fBEVP_PKEY_derive\fR\|(3) function.
159 Since the HKDF output length is variable, passing a \fBNULL\fR buffer as a means
160 to obtain the requisite length is not meaningful with HKDF in any mode that
161 performs an expand operation. Instead, the caller must allocate a buffer of the
162 desired length, and pass that buffer to \fBEVP_PKEY_derive\fR\|(3) along with (a
163 pointer initialized to) the desired length. Passing a \fBNULL\fR buffer to obtain
164 the length is allowed when using EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY.
165 .PP
166 Optimised versions of HKDF can be implemented in an ENGINE.
167 .SH "RETURN VALUES"
168 .IX Header "RETURN VALUES"
169 All these functions return 1 for success and 0 or a negative value for failure.
170 In particular a return value of \-2 indicates the operation is not supported by
171 the public key algorithm.
172 .SH EXAMPLES
173 .IX Header "EXAMPLES"
174 This example derives 10 bytes using SHA\-256 with the secret key "secret",
175 salt value "salt" and info value "label":
176 .PP
177 .Vb 4
178 \& EVP_PKEY_CTX *pctx;
179 \& unsigned char out[10];
180 \& size_t outlen = sizeof(out);
181 \& pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
182 \&
183 \& if (EVP_PKEY_derive_init(pctx) <= 0)
184 \& /* Error */
185 \& if (EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()) <= 0)
186 \& /* Error */
187 \& if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, "salt", 4) <= 0)
188 \& /* Error */
189 \& if (EVP_PKEY_CTX_set1_hkdf_key(pctx, "secret", 6) <= 0)
190 \& /* Error */
191 \& if (EVP_PKEY_CTX_add1_hkdf_info(pctx, "label", 5) <= 0)
192 \& /* Error */
193 \& if (EVP_PKEY_derive(pctx, out, &outlen) <= 0)
194 \& /* Error */
195 .Ve
196 .SH "CONFORMING TO"
197 .IX Header "CONFORMING TO"
198 RFC 5869
199 .SH "SEE ALSO"
200 .IX Header "SEE ALSO"
201 \&\fBEVP_PKEY_CTX_new\fR\|(3),
202 \&\fBEVP_PKEY_CTX_ctrl_str\fR\|(3),
203 \&\fBEVP_PKEY_derive\fR\|(3)
204 .SH HISTORY
205 .IX Header "HISTORY"
206 All of the functions described here were converted from macros to functions in
207 OpenSSL 3.0.
208 .SH COPYRIGHT
209 .IX Header "COPYRIGHT"
210 Copyright 2016\-2021 The OpenSSL Project Authors. All Rights Reserved.
211 .PP
212 Licensed under the Apache License 2.0 (the "License"). You may not use
213 this file except in compliance with the License. You can obtain a copy
214 in the file LICENSE in the source distribution or at
215 <https://www.openssl.org/source/license.html>.