@@ -1361,9 +1361,9 @@ password always creates the same key. The low iteration count and
13611361non-cryptographically secure hash algorithm allow passwords to be tested very
13621362rapidly.
13631363
1364- In line with OpenSSL's recommendation to use PBKDF2 instead of
1364+ In line with OpenSSL's recommendation to use a more modern algorithm instead of
13651365[ ` EVP_BytesToKey ` ] [ ] it is recommended that developers derive a key and IV on
1366- their own using [ ` crypto.pbkdf2 () ` ] [ ] and to use [ ` crypto.createCipheriv() ` ] [ ]
1366+ their own using [ ` crypto.scrypt () ` ] [ ] and to use [ ` crypto.createCipheriv() ` ] [ ]
13671367to create the ` Cipher ` object. Users should not use ciphers with counter mode
13681368(e.g. CTR, GCM, or CCM) in ` crypto.createCipher() ` . A warning is emitted when
13691369they are used in order to avoid the risk of IV reuse that causes
@@ -1463,9 +1463,9 @@ password always creates the same key. The low iteration count and
14631463non-cryptographically secure hash algorithm allow passwords to be tested very
14641464rapidly.
14651465
1466- In line with OpenSSL's recommendation to use PBKDF2 instead of
1466+ In line with OpenSSL's recommendation to use a more modern algorithm instead of
14671467[ ` EVP_BytesToKey ` ] [ ] it is recommended that developers derive a key and IV on
1468- their own using [ ` crypto.pbkdf2 () ` ] [ ] and to use [ ` crypto.createDecipheriv() ` ] [ ]
1468+ their own using [ ` crypto.scrypt () ` ] [ ] and to use [ ` crypto.createDecipheriv() ` ] [ ]
14691469to create the ` Decipher ` object.
14701470
14711471### crypto.createDecipheriv(algorithm, key, iv[ , options] )
@@ -1801,9 +1801,8 @@ The `iterations` argument must be a number set as high as possible. The
18011801higher the number of iterations, the more secure the derived key will be,
18021802but will take a longer amount of time to complete.
18031803
1804- The ` salt ` should also be as unique as possible. It is recommended that the
1805- salts are random and their lengths are at least 16 bytes. See
1806- [ NIST SP 800-132] [ ] for details.
1804+ The ` salt ` should be as unique as possible. It is recommended that a salt is
1805+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ] for details.
18071806
18081807Example:
18091808
@@ -1867,9 +1866,8 @@ The `iterations` argument must be a number set as high as possible. The
18671866higher the number of iterations, the more secure the derived key will be,
18681867but will take a longer amount of time to complete.
18691868
1870- The ` salt ` should also be as unique as possible. It is recommended that the
1871- salts are random and their lengths are at least 16 bytes. See
1872- [ NIST SP 800-132] [ ] for details.
1869+ The ` salt ` should be as unique as possible. It is recommended that a salt is
1870+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ] for details.
18731871
18741872Example:
18751873
@@ -2143,6 +2141,91 @@ threadpool request. To minimize threadpool task length variation, partition
21432141large ` randomFill ` requests when doing so as part of fulfilling a client
21442142request.
21452143
2144+ ### crypto.scrypt(password, salt, keylen[ , options] , callback)
2145+ <!-- YAML
2146+ added: REPLACEME
2147+ -->
2148+ - ` password ` {string|Buffer|TypedArray}
2149+ - ` salt ` {string|Buffer|TypedArray}
2150+ - ` keylen ` {number}
2151+ - ` options ` {Object}
2152+ - ` N ` {number} CPU/memory cost parameter. Must be a power of two greater
2153+ than one. ** Default:** ` 16384 ` .
2154+ - ` r ` {number} Block size parameter. ** Default:** ` 8 ` .
2155+ - ` p ` {number} Parallelization parameter. ** Default:** ` 1 ` .
2156+ - ` maxmem ` {number} Memory upper bound. It is an error when (approximately)
2157+ ` 128*N*r > maxmem ` ** Default:** ` 32 * 1024 * 1024 ` .
2158+ - ` callback ` {Function}
2159+ - ` err ` {Error}
2160+ - ` derivedKey ` {Buffer}
2161+
2162+ Provides an asynchronous [ scrypt] [ ] implementation. Scrypt is a password-based
2163+ key derivation function that is designed to be expensive computationally and
2164+ memory-wise in order to make brute-force attacks unrewarding.
2165+
2166+ The ` salt ` should be as unique as possible. It is recommended that a salt is
2167+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ] for details.
2168+
2169+ The ` callback ` function is called with two arguments: ` err ` and ` derivedKey ` .
2170+ ` err ` is an exception object when key derivation fails, otherwise ` err ` is
2171+ ` null ` . ` derivedKey ` is passed to the callback as a [ ` Buffer ` ] [ ] .
2172+
2173+ An exception is thrown when any of the input arguments specify invalid values
2174+ or types.
2175+
2176+ ``` js
2177+ const crypto = require (' crypto' );
2178+ // Using the factory defaults.
2179+ crypto .scrypt (' secret' , ' salt' , 64 , (err , derivedKey ) => {
2180+ if (err) throw err;
2181+ console .log (derivedKey .toString (' hex' )); // '3745e48...08d59ae'
2182+ });
2183+ // Using a custom N parameter. Must be a power of two.
2184+ crypto .scrypt (' secret' , ' salt' , 64 , { N : 1024 }, (err , derivedKey ) => {
2185+ if (err) throw err;
2186+ console .log (derivedKey .toString (' hex' )); // '3745e48...aa39b34'
2187+ });
2188+ ```
2189+
2190+ ### crypto.scryptSync(password, salt, keylen[ , options] )
2191+ <!-- YAML
2192+ added: REPLACEME
2193+ -->
2194+ - ` password ` {string|Buffer|TypedArray}
2195+ - ` salt ` {string|Buffer|TypedArray}
2196+ - ` keylen ` {number}
2197+ - ` options ` {Object}
2198+ - ` N ` {number} CPU/memory cost parameter. Must be a power of two greater
2199+ than one. ** Default:** ` 16384 ` .
2200+ - ` r ` {number} Block size parameter. ** Default:** ` 8 ` .
2201+ - ` p ` {number} Parallelization parameter. ** Default:** ` 1 ` .
2202+ - ` maxmem ` {number} Memory upper bound. It is an error when (approximately)
2203+ ` 128*N*r > maxmem ` ** Default:** ` 32 * 1024 * 1024 ` .
2204+ - Returns: {Buffer}
2205+
2206+ Provides a synchronous [ scrypt] [ ] implementation. Scrypt is a password-based
2207+ key derivation function that is designed to be expensive computationally and
2208+ memory-wise in order to make brute-force attacks unrewarding.
2209+
2210+ The ` salt ` should be as unique as possible. It is recommended that a salt is
2211+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ] for details.
2212+
2213+ An exception is thrown when key derivation fails, otherwise the derived key is
2214+ returned as a [ ` Buffer ` ] [ ] .
2215+
2216+ An exception is thrown when any of the input arguments specify invalid values
2217+ or types.
2218+
2219+ ``` js
2220+ const crypto = require (' crypto' );
2221+ // Using the factory defaults.
2222+ const key1 = crypto .scryptSync (' secret' , ' salt' , 64 );
2223+ console .log (key1 .toString (' hex' )); // '3745e48...08d59ae'
2224+ // Using a custom N parameter. Must be a power of two.
2225+ const key2 = crypto .scryptSync (' secret' , ' salt' , 64 , { N : 1024 });
2226+ console .log (key2 .toString (' hex' )); // '3745e48...aa39b34'
2227+ ```
2228+
21462229### crypto.setEngine(engine[ , flags] )
21472230<!-- YAML
21482231added: v0.11.11
@@ -2650,9 +2733,9 @@ the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL.
26502733[ `crypto.createVerify()` ] : #crypto_crypto_createverify_algorithm_options
26512734[ `crypto.getCurves()` ] : #crypto_crypto_getcurves
26522735[ `crypto.getHashes()` ] : #crypto_crypto_gethashes
2653- [ `crypto.pbkdf2()` ] : #crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
26542736[ `crypto.randomBytes()` ] : #crypto_crypto_randombytes_size_callback
26552737[ `crypto.randomFill()` ] : #crypto_crypto_randomfill_buffer_offset_size_callback
2738+ [ `crypto.scrypt()` ] : #crypto_crypto_scrypt_password_salt_keylen_options_callback
26562739[ `decipher.final()` ] : #crypto_decipher_final_outputencoding
26572740[ `decipher.update()` ] : #crypto_decipher_update_data_inputencoding_outputencoding
26582741[ `diffieHellman.setPublicKey()` ] : #crypto_diffiehellman_setpublickey_publickey_encoding
@@ -2686,5 +2769,6 @@ the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL.
26862769[ RFC 3610 ] : https://www.rfc-editor.org/rfc/rfc3610.txt
26872770[ RFC 4055 ] : https://www.rfc-editor.org/rfc/rfc4055.txt
26882771[ initialization vector ] : https://en.wikipedia.org/wiki/Initialization_vector
2772+ [ scrypt ] : https://en.wikipedia.org/wiki/Scrypt
26892773[ stream-writable-write ] : stream.html#stream_writable_write_chunk_encoding_callback
26902774[ stream ] : stream.html
0 commit comments