summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2022-05-06 07:36:54 +0000
committertb <>2022-05-06 07:36:54 +0000
commit98d636d9b5f23ac037cb013e2b03affc206b4c2f (patch)
tree7c3393e2fc060f02914a5e8968e9f45a0a58e80e /src/lib
parentb484578b1e35d9f8da653e5431c8f7a042dc3aea (diff)
downloadopenbsd-98d636d9b5f23ac037cb013e2b03affc206b4c2f.tar.gz
openbsd-98d636d9b5f23ac037cb013e2b03affc206b4c2f.tar.bz2
openbsd-98d636d9b5f23ac037cb013e2b03affc206b4c2f.zip
Document the EVP HKDF API
Manual from OpenSSL 1.1.1o with minimal tweaks. input/ok schwarze
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/man/EVP_PKEY_CTX_set_hkdf_md.3251
1 files changed, 251 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/EVP_PKEY_CTX_set_hkdf_md.3 b/src/lib/libcrypto/man/EVP_PKEY_CTX_set_hkdf_md.3
new file mode 100644
index 0000000000..36e34f3c27
--- /dev/null
+++ b/src/lib/libcrypto/man/EVP_PKEY_CTX_set_hkdf_md.3
@@ -0,0 +1,251 @@
1.\" $OpenBSD: EVP_PKEY_CTX_set_hkdf_md.3,v 1.1 2022/05/06 07:36:54 tb Exp $
2.\" full merge up to: OpenSSL 1cb7eff4 Sep 10 13:56:40 2019 +0100
3.\"
4.\" This file was written by Alessandro Ghedini <alessandro@ghedini.me>,
5.\" Matt Caswell <matt@openssl.org>, and Viktor Dukhovni <viktor@dukhovni.org>.
6.\" Copyright (c) 2016 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: May 6 2022 $
53.Dt EVP_PKEY_CTX_SET_HKDF_MD 3
54.Os
55.Sh NAME
56.Nm EVP_PKEY_CTX_set_hkdf_md ,
57.Nm EVP_PKEY_CTX_set1_hkdf_salt ,
58.Nm EVP_PKEY_CTX_set1_hkdf_key ,
59.Nm EVP_PKEY_CTX_add1_hkdf_info ,
60.Nm EVP_PKEY_CTX_hkdf_mode
61.Nd HMAC-based Extract-and-Expand key derivation algorithm
62.Sh SYNOPSIS
63.In openssl/kdf.h
64.Ft int
65.Fo EVP_PKEY_CTX_hkdf_mode
66.Fa "EVP_PKEY_CTX *pctx"
67.Fa "int mode"
68.Fc
69.Ft int
70.Fo EVP_PKEY_CTX_set_hkdf_md
71.Fa "EVP_PKEY_CTX *pctx"
72.Fa "const EVP_MD *md"
73.Fc
74.Ft int
75.Fo EVP_PKEY_CTX_set1_hkdf_salt
76.Fa "EVP_PKEY_CTX *pctx"
77.Fa "unsigned char *salt"
78.Fa "int saltlen"
79.Fc
80.Ft int
81.Fo EVP_PKEY_CTX_set1_hkdf_key
82.Fa "EVP_PKEY_CTX *pctx"
83.Fa "unsigned char *key"
84.Fa "int keylen"
85.Fc
86.Ft int
87.Fo EVP_PKEY_CTX_add1_hkdf_info
88.Fa "EVP_PKEY_CTX *pctx"
89.Fa "unsigned char *info"
90.Fa "int infolen"
91.Fc
92.Sh DESCRIPTION
93The EVP_PKEY_HKDF algorithm implements the HKDF key derivation function.
94HKDF follows the "extract-then-expand" paradigm, where the KDF logically
95consists of two modules.
96The first stage takes the input keying material and "extracts" from it a
97fixed-length pseudorandom key K.
98The second stage "expands" the key K
99into several additional pseudorandom keys (the output of the KDF).
100.Pp
101.Fn EVP_PKEY_CTX_hkdf_mode
102sets the mode for the HKDF operation.
103There are three modes that are currently defined:
104.Bl -tag -width Ds
105.It Dv EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND
106This is the default mode.
107Calling
108.Xr EVP_PKEY_derive 3
109on an EVP_PKEY_CTX set up for HKDF will perform an extract followed by
110an expand operation in one go.
111The derived key returned will be the result after the expand operation.
112The intermediate fixed-length pseudorandom key K is not returned.
113.Pp
114In this mode the digest, key, salt and info values must be set before a
115key is derived or an error occurs.
116.It Dv EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY
117In this mode calling
118.Xr EVP_PKEY_derive 3
119will just perform the extract operation.
120The value returned will be the intermediate fixed-length pseudorandom
121key K.
122.Pp
123The digest, key and salt values must be set before a key is derived or
124an error occurs.
125.It Dv EVP_PKEY_HKDEF_MODE_EXPAND_ONLY
126In this mode calling
127.Xr EVP_PKEY_derive 3
128will just perform the expand operation.
129The input key should be set to the intermediate fixed-length
130pseudorandom key K returned from a previous extract operation.
131.Pp
132The digest, key and info values must be set before a key is derived or
133an error occurs.
134.El
135.Pp
136.Fn EVP_PKEY_CTX_set_hkdf_md
137sets the message digest associated with the HKDF.
138.Pp
139.Fn EVP_PKEY_CTX_set1_hkdf_salt
140sets the salt to
141.Fa saltlen
142bytes of the buffer
143.Fa salt .
144Any existing value is replaced.
145.Pp
146.Fn EVP_PKEY_CTX_set1_hkdf_key
147sets the key to
148.Fa keylen
149bytes of the buffer
150.Fa key .
151Any existing value is replaced.
152.Pp
153.Fn EVP_PKEY_CTX_add1_hkdf_info
154sets the info value to
155.Fa infolen
156bytes of the buffer
157.Fa info .
158If a value is already set, it is appended to the existing value.
159.Sh STRING CTRLS
160HKDF also supports string based control operations via
161.Xr EVP_PKEY_CTX_ctrl_str 3 .
162The
163.Fa type
164parameter "md" uses the supplied
165.Fa value
166as the name of the digest algorithm to use.
167The
168.Fa type
169parameter "mode" accepts "EXTRACT_AND_EXPAND", "EXTRACT_ONLY"
170and "EXPAND_ONLY" as
171.Fa value
172to determine the mode to use.
173The
174.Fa type
175parameters "salt", "key" and "info" use the supplied
176.Fa value
177parameter as a
178seed, key, or info.
179The names "hexsalt", "hexkey" and "hexinfo" are similar except they take
180a hex string which is converted to binary.
181.Sh NOTES
182All these functions are implemented as macros.
183.Pp
184A context for HKDF can be obtained by calling:
185.Bd -literal
186 EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
187.Ed
188.Pp
189The total length of the info buffer cannot exceed 1024 bytes in length:
190this should be more than enough for any normal use of HKDF.
191.Pp
192The output length of an HKDF expand operation is specified via the
193length parameter to the
194.Xr EVP_PKEY_derive 3
195function.
196Since the HKDF output length is variable, passing a
197.Dv NULL
198buffer as a means to obtain the requisite length is not meaningful with
199HKDF in any mode that performs an expand operation.
200Instead, the caller must allocate a buffer of the desired length, and
201pass that buffer to
202.Xr EVP_PKEY_derive 3
203along with (a pointer initialized to) the desired length.
204Passing a
205.Dv NULL
206buffer to obtain the length is allowed when using
207.Dv EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY .
208.Sh RETURN VALUES
209All these functions return 1 for success and 0 or a negative value for
210failure.
211In particular a return value of -2 indicates the operation is not
212supported by the public key algorithm.
213.Sh EXAMPLES
214This example derives 10 bytes using SHA-256 with the secret key
215"secret", salt value "salt" and info value "label":
216.Bd -literal
217EVP_PKEY_CTX *pctx;
218unsigned char out[10];
219size_t outlen = sizeof(out);
220pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
221
222if (EVP_PKEY_derive_init(pctx) <= 0)
223 /* Error */
224if (EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()) <= 0)
225 /* Error */
226if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, "salt", 4) <= 0)
227 /* Error */
228if (EVP_PKEY_CTX_set1_hkdf_key(pctx, "secret", 6) <= 0)
229 /* Error */
230if (EVP_PKEY_CTX_add1_hkdf_info(pctx, "label", 5) <= 0)
231 /* Error */
232if (EVP_PKEY_derive(pctx, out, &outlen) <= 0)
233 /* Error */
234.Ed
235.Sh SEE ALSO
236.Xr EVP_PKEY_CTX_ctrl_str 3 ,
237.Xr EVP_PKEY_CTX_new 3 ,
238.Xr EVP_PKEY_derive 3
239.Sh STANDARDS
240RFC 5869: HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
241.Sh HISTORY
242.Fn EVP_PKEY_CTX_set_hkdf_md ,
243.Fn EVP_PKEY_CTX_set1_hkdf_salt ,
244.Fn EVP_PKEY_CTX_set1_hkdf_key ,
245and
246.Fn EVP_PKEY_CTX_add1_hkdf_info
247first appeared in OpenSSL 1.1.0 and
248.Fn EVP_PKEY_CTX_hkdf_mode
249in OpenSSL 1.1.1.
250These functions have been available since
251.Ox 7.2 .