{"id":4078,"date":"2022-12-20T17:39:20","date_gmt":"2022-12-20T20:39:20","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/evp_kdf_scrypt-man7\/"},"modified":"2022-12-20T17:39:20","modified_gmt":"2022-12-20T20:39:20","slug":"evp_kdf_scrypt-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/evp_kdf_scrypt-man7\/","title":{"rendered":"EVP_KDF_SCRYPT (man7)"},"content":{"rendered":"<h1 align=\"center\">EVP_KDF_SCRYPT<\/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_SCRYPT \u2212 The scrypt 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>scrypt<\/b> password-based <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_SCRYPT<\/small> algorithm implements the scrypt password-based key derivation function, as described in <small>RFC 7914.<\/small> It is memory-hard in the sense that it deliberately requires a significant amount of <small>RAM<\/small> for efficient computation. The intention of this is to render brute forcing of passwords on systems that lack large amounts of main memory (such as GPUs or ASICs) computationally infeasible.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">scrypt provides three work factors that can be customized: N, r and p. N, which has to be a positive power of two, is the general work factor and scales <small>CPU<\/small> time in an approximately linear fashion. r is the block size of the internally used hash function and p is the parallelization factor. Both r and p need to be greater than zero. The amount of <small>RAM<\/small> that scrypt requires for its computation is roughly (128 bodies manpages.csv script_extrae_body.sh script.sh usr N bodies manpages.csv script_extrae_body.sh script.sh usr r bodies manpages.csv script_extrae_body.sh script.sh usr p) bytes.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In the original paper of Colin Percival (&#8220;Stronger Key Derivation via Sequential Memory-Hard Functions&#8221;, 2009), the suggested values that give a computation time of less than 5 seconds on a 2.5 GHz Intel Core 2 Duo are N = 2^20 = 1048576, r = 8, p = 1. Consequently, the required amount of memory for this computation is roughly 1 GiB. On a more recent <small>CPU<\/small> (Intel i7\u22125930K at 3.5 GHz), this computation takes about 3 seconds. When N, r or p are not specified, they default to 1048576, 8, and 1, respectively. The maximum amount of <small>RAM<\/small> that may be used by scrypt defaults to 1025 MiB.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Numeric identity <small><br \/> EVP_KDF_SCRYPT<\/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_PASS <br \/> EVP_KDF_CTRL_SET_SALT<\/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_SET_SCRYPT_N <br \/> EVP_KDF_CTRL_SET_SCRYPT_R <br \/> EVP_KDF_CTRL_SET_SCRYPT_P<\/small><\/b><\/p>\n<p style=\"margin-left:17%;\"><b><small>EVP_KDF_CTRL_SET_SCRYPT_N<\/small><\/b> expects one argument: &#8220;uint64_t N&#8221;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b><small>EVP_KDF_CTRL_SET_SCRYPT_R<\/small><\/b> expects one argument: &#8220;uint32_t r&#8221;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b><small>EVP_KDF_CTRL_SET_SCRYPT_P<\/small><\/b> expects one argument: &#8220;uint32_t p&#8221;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">These controls configure the scrypt work factors N, r and p.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>EVP_KDF_ctrl_str()<\/b> type strings: &#8220;N&#8221;, &#8220;r&#8221; and &#8220;p&#8221;, respectively.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">The corresponding value strings are expected to be decimal numbers.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">A context for scrypt 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_SCRYPT);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The output length of an scrypt key derivation is specified via the <b>keylen<\/b> parameter to the <b>EVP_KDF_derive<\/b>(3) function.<\/p>\n<h2>EXAMPLE <a name=\"EXAMPLE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This example derives a 64\u2212byte long test vector using scrypt with the password &#8220;password&#8221;, salt &#8220;NaCl&#8221; and N = 1024, r = 8, p = 16.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">EVP_KDF_CTX *kctx; <br \/> unsigned char out[64]; <br \/> kctx = EVP_KDF_CTX_new_id(EVP_KDF_SCRYPT); <br \/> if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_PASS, &#8220;password&#8221;, (size_t)8) <= 0) { <br \/> error(&#8220;EVP_KDF_CTRL_SET_PASS&#8221;); <br \/> } <br \/> if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, &#8220;NaCl&#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_SCRYPT_N, (uint64_t)1024) <= 0) { <br \/> error(&#8220;EVP_KDF_CTRL_SET_SCRYPT_N&#8221;); <br \/> } <br \/> if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SCRYPT_R, (uint32_t)8) <= 0) { <br \/> error(&#8220;EVP_KDF_CTRL_SET_SCRYPT_R&#8221;); <br \/> } <br \/> if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SCRYPT_P, (uint32_t)16) <= 0) { <br \/> error(&#8220;EVP_KDF_CTRL_SET_SCRYPT_P&#8221;); <br \/> } <br \/> if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) { <br \/> error(&#8220;EVP_KDF_derive&#8221;); <br \/> } <br \/> { <br \/> const unsigned char expected[sizeof(out)] = { <br \/> 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00, <br \/> 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe, <br \/> 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30, <br \/> 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62, <br \/> 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88, <br \/> 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda, <br \/> 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d, <br \/> 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40 <br \/> }; <br \/> assert(!memcmp(out, expected, sizeof(out))); <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 7914<\/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_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 2017\u22122018 The OpenSSL Project Authors. All Rights Reserved.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Licensed under the OpenSSL license (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_SCRYPT \u2212 The scrypt 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,1158,972],"class_list":["post-4078","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-evp_kdf_scrypt","tag-man7"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4078","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=4078"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4078\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}