diff options
Diffstat (limited to 'src/lib/libcrypto/man')
| -rw-r--r-- | src/lib/libcrypto/man/EVP_PKEY_CTX_set_hkdf_md.3 | 251 |
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 | ||
| 93 | The EVP_PKEY_HKDF algorithm implements the HKDF key derivation function. | ||
| 94 | HKDF follows the "extract-then-expand" paradigm, where the KDF logically | ||
| 95 | consists of two modules. | ||
| 96 | The first stage takes the input keying material and "extracts" from it a | ||
| 97 | fixed-length pseudorandom key K. | ||
| 98 | The second stage "expands" the key K | ||
| 99 | into several additional pseudorandom keys (the output of the KDF). | ||
| 100 | .Pp | ||
| 101 | .Fn EVP_PKEY_CTX_hkdf_mode | ||
| 102 | sets the mode for the HKDF operation. | ||
| 103 | There are three modes that are currently defined: | ||
| 104 | .Bl -tag -width Ds | ||
| 105 | .It Dv EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND | ||
| 106 | This is the default mode. | ||
| 107 | Calling | ||
| 108 | .Xr EVP_PKEY_derive 3 | ||
| 109 | on an EVP_PKEY_CTX set up for HKDF will perform an extract followed by | ||
| 110 | an expand operation in one go. | ||
| 111 | The derived key returned will be the result after the expand operation. | ||
| 112 | The intermediate fixed-length pseudorandom key K is not returned. | ||
| 113 | .Pp | ||
| 114 | In this mode the digest, key, salt and info values must be set before a | ||
| 115 | key is derived or an error occurs. | ||
| 116 | .It Dv EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY | ||
| 117 | In this mode calling | ||
| 118 | .Xr EVP_PKEY_derive 3 | ||
| 119 | will just perform the extract operation. | ||
| 120 | The value returned will be the intermediate fixed-length pseudorandom | ||
| 121 | key K. | ||
| 122 | .Pp | ||
| 123 | The digest, key and salt values must be set before a key is derived or | ||
| 124 | an error occurs. | ||
| 125 | .It Dv EVP_PKEY_HKDEF_MODE_EXPAND_ONLY | ||
| 126 | In this mode calling | ||
| 127 | .Xr EVP_PKEY_derive 3 | ||
| 128 | will just perform the expand operation. | ||
| 129 | The input key should be set to the intermediate fixed-length | ||
| 130 | pseudorandom key K returned from a previous extract operation. | ||
| 131 | .Pp | ||
| 132 | The digest, key and info values must be set before a key is derived or | ||
| 133 | an error occurs. | ||
| 134 | .El | ||
| 135 | .Pp | ||
| 136 | .Fn EVP_PKEY_CTX_set_hkdf_md | ||
| 137 | sets the message digest associated with the HKDF. | ||
| 138 | .Pp | ||
| 139 | .Fn EVP_PKEY_CTX_set1_hkdf_salt | ||
| 140 | sets the salt to | ||
| 141 | .Fa saltlen | ||
| 142 | bytes of the buffer | ||
| 143 | .Fa salt . | ||
| 144 | Any existing value is replaced. | ||
| 145 | .Pp | ||
| 146 | .Fn EVP_PKEY_CTX_set1_hkdf_key | ||
| 147 | sets the key to | ||
| 148 | .Fa keylen | ||
| 149 | bytes of the buffer | ||
| 150 | .Fa key . | ||
| 151 | Any existing value is replaced. | ||
| 152 | .Pp | ||
| 153 | .Fn EVP_PKEY_CTX_add1_hkdf_info | ||
| 154 | sets the info value to | ||
| 155 | .Fa infolen | ||
| 156 | bytes of the buffer | ||
| 157 | .Fa info . | ||
| 158 | If a value is already set, it is appended to the existing value. | ||
| 159 | .Sh STRING CTRLS | ||
| 160 | HKDF also supports string based control operations via | ||
| 161 | .Xr EVP_PKEY_CTX_ctrl_str 3 . | ||
| 162 | The | ||
| 163 | .Fa type | ||
| 164 | parameter "md" uses the supplied | ||
| 165 | .Fa value | ||
| 166 | as the name of the digest algorithm to use. | ||
| 167 | The | ||
| 168 | .Fa type | ||
| 169 | parameter "mode" accepts "EXTRACT_AND_EXPAND", "EXTRACT_ONLY" | ||
| 170 | and "EXPAND_ONLY" as | ||
| 171 | .Fa value | ||
| 172 | to determine the mode to use. | ||
| 173 | The | ||
| 174 | .Fa type | ||
| 175 | parameters "salt", "key" and "info" use the supplied | ||
| 176 | .Fa value | ||
| 177 | parameter as a | ||
| 178 | seed, key, or info. | ||
| 179 | The names "hexsalt", "hexkey" and "hexinfo" are similar except they take | ||
| 180 | a hex string which is converted to binary. | ||
| 181 | .Sh NOTES | ||
| 182 | All these functions are implemented as macros. | ||
| 183 | .Pp | ||
| 184 | A 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 | ||
| 189 | The total length of the info buffer cannot exceed 1024 bytes in length: | ||
| 190 | this should be more than enough for any normal use of HKDF. | ||
| 191 | .Pp | ||
| 192 | The output length of an HKDF expand operation is specified via the | ||
| 193 | length parameter to the | ||
| 194 | .Xr EVP_PKEY_derive 3 | ||
| 195 | function. | ||
| 196 | Since the HKDF output length is variable, passing a | ||
| 197 | .Dv NULL | ||
| 198 | buffer as a means to obtain the requisite length is not meaningful with | ||
| 199 | HKDF in any mode that performs an expand operation. | ||
| 200 | Instead, the caller must allocate a buffer of the desired length, and | ||
| 201 | pass that buffer to | ||
| 202 | .Xr EVP_PKEY_derive 3 | ||
| 203 | along with (a pointer initialized to) the desired length. | ||
| 204 | Passing a | ||
| 205 | .Dv NULL | ||
| 206 | buffer to obtain the length is allowed when using | ||
| 207 | .Dv EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY . | ||
| 208 | .Sh RETURN VALUES | ||
| 209 | All these functions return 1 for success and 0 or a negative value for | ||
| 210 | failure. | ||
| 211 | In particular a return value of -2 indicates the operation is not | ||
| 212 | supported by the public key algorithm. | ||
| 213 | .Sh EXAMPLES | ||
| 214 | This example derives 10 bytes using SHA-256 with the secret key | ||
| 215 | "secret", salt value "salt" and info value "label": | ||
| 216 | .Bd -literal | ||
| 217 | EVP_PKEY_CTX *pctx; | ||
| 218 | unsigned char out[10]; | ||
| 219 | size_t outlen = sizeof(out); | ||
| 220 | pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL); | ||
| 221 | |||
| 222 | if (EVP_PKEY_derive_init(pctx) <= 0) | ||
| 223 | /* Error */ | ||
| 224 | if (EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()) <= 0) | ||
| 225 | /* Error */ | ||
| 226 | if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, "salt", 4) <= 0) | ||
| 227 | /* Error */ | ||
| 228 | if (EVP_PKEY_CTX_set1_hkdf_key(pctx, "secret", 6) <= 0) | ||
| 229 | /* Error */ | ||
| 230 | if (EVP_PKEY_CTX_add1_hkdf_info(pctx, "label", 5) <= 0) | ||
| 231 | /* Error */ | ||
| 232 | if (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 | ||
| 240 | RFC 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 , | ||
| 245 | and | ||
| 246 | .Fn EVP_PKEY_CTX_add1_hkdf_info | ||
| 247 | first appeared in OpenSSL 1.1.0 and | ||
| 248 | .Fn EVP_PKEY_CTX_hkdf_mode | ||
| 249 | in OpenSSL 1.1.1. | ||
| 250 | These functions have been available since | ||
| 251 | .Ox 7.2 . | ||
