@@ -1356,9 +1356,9 @@ password always creates the same key. The low iteration count and
13561356non-cryptographically secure hash algorithm allow passwords to be tested very
13571357rapidly.
13581358
1359- In line with OpenSSL's recommendation to use PBKDF2  instead of
1359+ In line with OpenSSL's recommendation to use a more modern algorithm  instead of
13601360[ ` EVP_BytesToKey ` ] [ ]  it is recommended that developers derive a key and IV on
1361- their own using [ ` crypto.pbkdf2 () ` ] [ ]  and to use [ ` crypto.createCipheriv() ` ] [ ] 
1361+ their own using [ ` crypto.scrypt () ` ] [ ]  and to use [ ` crypto.createCipheriv() ` ] [ ] 
13621362to create the ` Cipher `  object. Users should not use ciphers with counter mode
13631363(e.g. CTR, GCM, or CCM) in ` crypto.createCipher() ` . A warning is emitted when
13641364they are used in order to avoid the risk of IV reuse that causes
@@ -1458,9 +1458,9 @@ password always creates the same key. The low iteration count and
14581458non-cryptographically secure hash algorithm allow passwords to be tested very
14591459rapidly.
14601460
1461- In line with OpenSSL's recommendation to use PBKDF2  instead of
1461+ In line with OpenSSL's recommendation to use a more modern algorithm  instead of
14621462[ ` EVP_BytesToKey ` ] [ ]  it is recommended that developers derive a key and IV on
1463- their own using [ ` crypto.pbkdf2 () ` ] [ ]  and to use [ ` crypto.createDecipheriv() ` ] [ ] 
1463+ their own using [ ` crypto.scrypt () ` ] [ ]  and to use [ ` crypto.createDecipheriv() ` ] [ ] 
14641464to create the ` Decipher `  object.
14651465
14661466### crypto.createDecipheriv(algorithm, key, iv[ , options] )  
@@ -1796,9 +1796,8 @@ The `iterations` argument must be a number set as high as possible. The
17961796higher the number of iterations, the more secure the derived key will be,
17971797but will take a longer amount of time to complete.
17981798
1799- The ` salt `  should also be as unique as possible. It is recommended that the
1800- salts are random and their lengths are at least 16 bytes. See
1801- [ NIST SP 800-132] [ ]  for details.
1799+ The ` salt `  should be as unique as possible. It is recommended that a salt is
1800+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ]  for details.
18021801
18031802Example:
18041803
@@ -1862,9 +1861,8 @@ The `iterations` argument must be a number set as high as possible. The
18621861higher the number of iterations, the more secure the derived key will be,
18631862but will take a longer amount of time to complete.
18641863
1865- The ` salt `  should also be as unique as possible. It is recommended that the
1866- salts are random and their lengths are at least 16 bytes. See
1867- [ NIST SP 800-132] [ ]  for details.
1864+ The ` salt `  should be as unique as possible. It is recommended that a salt is
1865+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ]  for details.
18681866
18691867Example:
18701868
@@ -2138,6 +2136,91 @@ threadpool request. To minimize threadpool task length variation, partition
21382136large ` randomFill `  requests when doing so as part of fulfilling a client
21392137request.
21402138
2139+ ### crypto.scrypt(password, salt, keylen[ , options] , callback)  
2140+ <!--  YAML
2141+ added: REPLACEME 
2142+ --> 
2143+ -  ` password `  {string|Buffer|TypedArray}
2144+ -  ` salt `  {string|Buffer|TypedArray}
2145+ -  ` keylen `  {number}
2146+ -  ` options `  {Object}
2147+   -  ` N `  {number} CPU/memory cost parameter. Must be a power of two greater
2148+                  than one. ** Default:**  ` 16384 ` .
2149+   -  ` r `  {number} Block size parameter. ** Default:**  ` 8 ` .
2150+   -  ` p `  {number} Parallelization parameter. ** Default:**  ` 1 ` .
2151+   -  ` maxmem `  {number} Memory upper bound. It is an error when (approximately)
2152+                       ` 128*N*r > maxmem `  ** Default:**  ` 32 * 1024 * 1024 ` .
2153+ -  ` callback `  {Function}
2154+   -  ` err `  {Error}
2155+   -  ` derivedKey `  {Buffer}
2156+ 
2157+ Provides an asynchronous [ scrypt] [ ]  implementation. Scrypt is a password-based
2158+ key derivation function that is designed to be expensive computationally and
2159+ memory-wise in order to make brute-force attacks unrewarding.
2160+ 
2161+ The ` salt `  should be as unique as possible. It is recommended that a salt is
2162+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ]  for details.
2163+ 
2164+ The ` callback `  function is called with two arguments: ` err `  and ` derivedKey ` .
2165+ ` err `  is an exception object when key derivation fails, otherwise ` err `  is
2166+ ` null ` . ` derivedKey `  is passed to the callback as a [ ` Buffer ` ] [ ] .
2167+ 
2168+ An exception is thrown when any of the input arguments specify invalid values
2169+ or types.
2170+ 
2171+ ``` js 
2172+ const  crypto  =  require (' crypto' 
2173+ //  Using the factory defaults.
2174+ crypto .scrypt (' secret' ' salt' 64 , (err , derivedKey ) =>  {
2175+   if  (err) throw  err;
2176+   console .log (derivedKey .toString (' hex' //  '3745e48...08d59ae'
2177+ });
2178+ //  Using a custom N parameter. Must be a power of two.
2179+ crypto .scrypt (' secret' ' salt' 64 , { N :  1024  }, (err , derivedKey ) =>  {
2180+   if  (err) throw  err;
2181+   console .log (derivedKey .toString (' hex' //  '3745e48...aa39b34'
2182+ });
2183+ ``` 
2184+ 
2185+ ### crypto.scryptSync(password, salt, keylen[ , options] )  
2186+ <!--  YAML
2187+ added: REPLACEME 
2188+ --> 
2189+ -  ` password `  {string|Buffer|TypedArray}
2190+ -  ` salt `  {string|Buffer|TypedArray}
2191+ -  ` keylen `  {number}
2192+ -  ` options `  {Object}
2193+   -  ` N `  {number} CPU/memory cost parameter. Must be a power of two greater
2194+                  than one. ** Default:**  ` 16384 ` .
2195+   -  ` r `  {number} Block size parameter. ** Default:**  ` 8 ` .
2196+   -  ` p `  {number} Parallelization parameter. ** Default:**  ` 1 ` .
2197+   -  ` maxmem `  {number} Memory upper bound. It is an error when (approximately)
2198+                       ` 128*N*r > maxmem `  ** Default:**  ` 32 * 1024 * 1024 ` .
2199+ -  Returns: {Buffer}
2200+ 
2201+ Provides a synchronous [ scrypt] [ ]  implementation. Scrypt is a password-based
2202+ key derivation function that is designed to be expensive computationally and
2203+ memory-wise in order to make brute-force attacks unrewarding.
2204+ 
2205+ The ` salt `  should be as unique as possible. It is recommended that a salt is
2206+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ]  for details.
2207+ 
2208+ An exception is thrown when key derivation fails, otherwise the derived key is
2209+ returned as a [ ` Buffer ` ] [ ] .
2210+ 
2211+ An exception is thrown when any of the input arguments specify invalid values
2212+ or types.
2213+ 
2214+ ``` js 
2215+ const  crypto  =  require (' crypto' 
2216+ //  Using the factory defaults.
2217+ const  key1  =  crypto .scryptSync (' secret' ' salt' 64 );
2218+ console .log (key1 .toString (' hex' //  '3745e48...08d59ae'
2219+ //  Using a custom N parameter. Must be a power of two.
2220+ const  key2  =  crypto .scryptSync (' secret' ' salt' 64 , { N :  1024  });
2221+ console .log (key2 .toString (' hex' //  '3745e48...aa39b34'
2222+ ``` 
2223+ 
21412224### crypto.setEngine(engine[ , flags] )  
21422225<!--  YAML
21432226added: v0.11.11 
@@ -2645,9 +2728,9 @@ the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL.
26452728[ `crypto.createVerify()` ] : #crypto_crypto_createverify_algorithm_options 
26462729[ `crypto.getCurves()` ] : #crypto_crypto_getcurves 
26472730[ `crypto.getHashes()` ] : #crypto_crypto_gethashes 
2648- [ `crypto.pbkdf2()` ] : #crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback 
26492731[ `crypto.randomBytes()` ] : #crypto_crypto_randombytes_size_callback 
26502732[ `crypto.randomFill()` ] : #crypto_crypto_randomfill_buffer_offset_size_callback 
2733+ [ `crypto.scrypt()` ] : #crypto_crypto_scrypt_password_salt_keylen_options_callback 
26512734[ `decipher.final()` ] : #crypto_decipher_final_outputencoding 
26522735[ `decipher.update()` ] : #crypto_decipher_update_data_inputencoding_outputencoding 
26532736[ `diffieHellman.setPublicKey()` ] : #crypto_diffiehellman_setpublickey_publickey_encoding 
@@ -2681,5 +2764,6 @@ the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL.
26812764[ RFC 3610 ] : https://www.rfc-editor.org/rfc/rfc3610.txt 
26822765[ RFC 4055 ] : https://www.rfc-editor.org/rfc/rfc4055.txt 
26832766[ initialization vector ] : https://en.wikipedia.org/wiki/Initialization_vector 
2767+ [ scrypt ] : https://en.wikipedia.org/wiki/Scrypt 
26842768[ stream-writable-write ] : stream.html#stream_writable_write_chunk_encoding_callback 
26852769[ stream ] : stream.html 
0 commit comments