{"id":4008,"date":"2022-12-20T17:28:41","date_gmt":"2022-12-20T20:28:41","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/evp_kdf_hkdf-man7\/"},"modified":"2022-12-20T17:28:41","modified_gmt":"2022-12-20T20:28:41","slug":"evp_kdf_hkdf-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/evp_kdf_hkdf-man7\/","title":{"rendered":"EVP_KDF_HKDF (man7)"},"content":{"rendered":"<h1 align=\"center\">EVP_KDF_HKDF<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#EXAMPLE\">EXAMPLE<\/a><br \/> <a href=\"#CONFORMING TO\">CONFORMING TO<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">EVP_KDF_HKDF \u2212 The HKDF EVP_KDF implementation<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Support for computing the <b><small>HKDF<\/small><\/b> <small>KDF<\/small> through the <b><small>EVP_KDF<\/small><\/b> <small>API.<\/small><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <small>EVP_KDF_HKDF<\/small> algorithm implements the <small>HKDF<\/small> key derivation function. <small>HKDF<\/small> follows the &#8220;extract-then-expand&#8221; paradigm, where the <small>KDF<\/small> logically consists of two modules. The first stage takes the input keying material and &#8220;extracts&#8221; from it a fixed-length pseudorandom key K. The second stage &#8220;expands&#8221; the key K into several additional pseudorandom keys (the output of the <small>KDF<\/small> ).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Numeric identity <small><br \/> EVP_KDF_HKDF<\/small><\/b> is the numeric identity for this implementation; it can be used with the <b>EVP_KDF_CTX_new_id()<\/b> function.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Supported controls<\/b> <br \/> The supported controls are: <b><small><br \/> EVP_KDF_CTRL_SET_SALT <br \/> EVP_KDF_CTRL_SET_MD <br \/> EVP_KDF_CTRL_SET_KEY<\/small><\/b><\/p>\n<p style=\"margin-left:17%;\">These controls work as described in &#8221; <small>CONTROLS&#8221;<\/small> in <b><small>EVP_KDF_CTX<\/small><\/b> (3).<\/p>\n<p style=\"margin-left:11%;\"><b><small>EVP_KDF_CTRL_RESET_HKDF_INFO<\/small><\/b><\/p>\n<p style=\"margin-left:17%;\">This control does not expect any arguments.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Resets the context info buffer to zero length.<\/p>\n<p style=\"margin-left:11%;\"><b><small>EVP_KDF_CTRL_ADD_HKDF_INFO<\/small><\/b><\/p>\n<p style=\"margin-left:17%;\">This control expects two arguments: &#8220;unsigned char *info&#8221;, &#8220;size_t infolen&#8221;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Sets the info value to the first <b>infolen<\/b> bytes of the buffer <b>info<\/b>. If a value is already set, the contents of the buffer are appended to the existing value.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">The total length of the context info buffer cannot exceed 1024 bytes; this should be more than enough for any normal use of <small>HKDF.<\/small><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>EVP_KDF_ctrl_str()<\/b> takes two type strings for this control: <br \/> &#8220;info&#8221;<\/p>\n<p style=\"margin-left:23%;\">The value string is used as is.<\/p>\n<p style=\"margin-left:17%;\">&#8220;hexinfo&#8221;<\/p>\n<p style=\"margin-left:23%;\">The value string is expected to be a hexadecimal number, which will be decoded before being passed on as the control value.<\/p>\n<p style=\"margin-left:11%;\"><b><small>EVP_KDF_CTRL_SET_HKDF_MODE<\/small><\/b><\/p>\n<p style=\"margin-left:17%;\">This control expects one argument: &#8220;int mode&#8221;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Sets the mode for the <small>HKDF<\/small> operation. There are three modes that are currently defined: <small><br \/> EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND<\/small><\/p>\n<p style=\"margin-left:23%;\">This is the default mode. Calling <b>EVP_KDF_derive<\/b>(3) on an <small>EVP_KDF_CTX<\/small> set up for <small>HKDF<\/small> will perform an extract followed by an expand operation in one go. The derived key returned will be the result after the expand operation. The intermediate fixed-length pseudorandom key K is not returned.<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\">In this mode the digest, key, salt and info values must be set before a key is derived otherwise an error will occur.<\/p>\n<p style=\"margin-left:17%;\"><small>EVP_KDF_HKDF_MODE_EXTRACT_ONLY<\/small><\/p>\n<p style=\"margin-left:23%;\">In this mode calling <b>EVP_KDF_derive<\/b>(3) will just perform the extract operation. The value returned will be the intermediate fixed-length pseudorandom key K. The &#8220;keylen&#8221; parameter must match the size of K, which can be looked up by calling <b>EVP_KDF_size()<\/b> after setting the mode and digest.<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\">The digest, key and salt values must be set before a key is derived otherwise an error will occur.<\/p>\n<p style=\"margin-left:17%;\"><small>EVP_KDF_HKDF_MODE_EXPAND_ONLY<\/small><\/p>\n<p style=\"margin-left:23%;\">In this mode calling <b>EVP_KDF_derive<\/b>(3) will just perform the expand operation. The input key should be set to the intermediate fixed-length pseudorandom key K returned from a previous extract operation.<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\">The digest, key and info values must be set before a key is derived otherwise an error will occur.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>EVP_KDF_ctrl_str()<\/b> type string: &#8220;mode&#8221;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">The value string is expected to be one of: &#8221; <small>EXTRACT_AND_EXPAND&#8221;, &#8220;EXTRACT_ONLY&#8221;<\/small> or &#8221; <small>EXPAND_ONLY&#8221;.<\/small><\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">A context for <small>HKDF<\/small> can be obtained by calling:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_HKDF);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The output length of an <small>HKDF<\/small> expand operation is specified via the &#8220;keylen&#8221; parameter to the <b>EVP_KDF_derive<\/b>(3) function. When using <small>EVP_KDF_HKDF_MODE_EXTRACT_ONLY<\/small> the &#8220;keylen&#8221; parameter must equal the size of the intermediate fixed-length pseudorandom key otherwise an error will occur. For that mode, the fixed output size can be looked up by calling <b>EVP_KDF_size()<\/b> after setting the mode and digest on the &#8220;EVP_KDF_CTX&#8221;.<\/p>\n<h2>EXAMPLE <a name=\"EXAMPLE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This example derives 10 bytes using <small>SHA\u2212256<\/small> with the secret key &#8220;secret&#8221;, salt value &#8220;salt&#8221; and info value &#8220;label&#8221;:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">EVP_KDF_CTX *kctx; <br \/> unsigned char out[10]; <br \/> kctx = EVP_KDF_CTX_new_id(EVP_KDF_HKDF); <br \/> if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) { <br \/> error(&#8220;EVP_KDF_CTRL_SET_MD&#8221;); <br \/> } <br \/> if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, &#8220;salt&#8221;, (size_t)4) <= 0) { <br \/> error(&#8220;EVP_KDF_CTRL_SET_SALT&#8221;); <br \/> } <br \/> if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, &#8220;secret&#8221;, (size_t)6) <= 0) { <br \/> error(&#8220;EVP_KDF_CTRL_SET_KEY&#8221;); <br \/> } <br \/> if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_HKDF_INFO, &#8220;label&#8221;, (size_t)5) <= 0) { <br \/> error(&#8220;EVP_KDF_CTRL_ADD_HKDF_INFO&#8221;); <br \/> } <br \/> if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) { <br \/> error(&#8220;EVP_KDF_derive&#8221;); <br \/> } <br \/> EVP_KDF_CTX_free(kctx);<\/p>\n<h2>CONFORMING TO <a name=\"CONFORMING TO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><small>RFC 5869<\/small><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><small>EVP_KDF_CTX<\/small> , <b>EVP_KDF_CTX_new_id<\/b>(3), <b>EVP_KDF_CTX_free<\/b>(3), <b>EVP_KDF_ctrl<\/b>(3), <b>EVP_KDF_size<\/b>(3), <b>EVP_KDF_derive<\/b>(3), &#8221; <small>CONTROLS&#8221;<\/small> in <b><small>EVP_KDF_CTX<\/small><\/b> (3)<\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Copyright 2016\u22122018 The OpenSSL Project Authors. All Rights Reserved.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Licensed under the Apache License 2.0 (the &#8220;License&#8221;). You may not use this file except in compliance with the License. You can obtain a copy in the file <small>LICENSE<\/small> in the source distribution or at <https:\/\/www.openssl.org\/source\/license.html>.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  EVP_KDF_HKDF \u2212 The HKDF EVP_KDF implementation <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[971],"tags":[973,1096,972],"class_list":["post-4008","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-evp_kdf_hkdf","tag-man7"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4008","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4008"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4008\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}