@@ -1356,9 +1356,9 @@ password always creates the same key. The low iteration count and
1356
1356
non-cryptographically secure hash algorithm allow passwords to be tested very
1357
1357
rapidly.
1358
1358
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
1360
1360
[ ` 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() ` ] [ ]
1362
1362
to create the ` Cipher ` object. Users should not use ciphers with counter mode
1363
1363
(e.g. CTR, GCM, or CCM) in ` crypto.createCipher() ` . A warning is emitted when
1364
1364
they 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
1458
1458
non-cryptographically secure hash algorithm allow passwords to be tested very
1459
1459
rapidly.
1460
1460
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
1462
1462
[ ` 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() ` ] [ ]
1464
1464
to create the ` Decipher ` object.
1465
1465
1466
1466
### crypto.createDecipheriv(algorithm, key, iv[ , options] )
@@ -1796,9 +1796,8 @@ The `iterations` argument must be a number set as high as possible. The
1796
1796
higher the number of iterations, the more secure the derived key will be,
1797
1797
but will take a longer amount of time to complete.
1798
1798
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.
1802
1801
1803
1802
Example:
1804
1803
@@ -1862,9 +1861,8 @@ The `iterations` argument must be a number set as high as possible. The
1862
1861
higher the number of iterations, the more secure the derived key will be,
1863
1862
but will take a longer amount of time to complete.
1864
1863
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.
1868
1866
1869
1867
Example:
1870
1868
@@ -2138,6 +2136,91 @@ threadpool request. To minimize threadpool task length variation, partition
2138
2136
large ` randomFill ` requests when doing so as part of fulfilling a client
2139
2137
request.
2140
2138
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
+
2141
2224
### crypto.setEngine(engine[ , flags] )
2142
2225
<!-- YAML
2143
2226
added: v0.11.11
@@ -2645,9 +2728,9 @@ the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL.
2645
2728
[ `crypto.createVerify()` ] : #crypto_crypto_createverify_algorithm_options
2646
2729
[ `crypto.getCurves()` ] : #crypto_crypto_getcurves
2647
2730
[ `crypto.getHashes()` ] : #crypto_crypto_gethashes
2648
- [ `crypto.pbkdf2()` ] : #crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
2649
2731
[ `crypto.randomBytes()` ] : #crypto_crypto_randombytes_size_callback
2650
2732
[ `crypto.randomFill()` ] : #crypto_crypto_randomfill_buffer_offset_size_callback
2733
+ [ `crypto.scrypt()` ] : #crypto_crypto_scrypt_password_salt_keylen_options_callback
2651
2734
[ `decipher.final()` ] : #crypto_decipher_final_outputencoding
2652
2735
[ `decipher.update()` ] : #crypto_decipher_update_data_inputencoding_outputencoding
2653
2736
[ `diffieHellman.setPublicKey()` ] : #crypto_diffiehellman_setpublickey_publickey_encoding
@@ -2681,5 +2764,6 @@ the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL.
2681
2764
[ RFC 3610 ] : https://www.rfc-editor.org/rfc/rfc3610.txt
2682
2765
[ RFC 4055 ] : https://www.rfc-editor.org/rfc/rfc4055.txt
2683
2766
[ initialization vector ] : https://en.wikipedia.org/wiki/Initialization_vector
2767
+ [ scrypt ] : https://en.wikipedia.org/wiki/Scrypt
2684
2768
[ stream-writable-write ] : stream.html#stream_writable_write_chunk_encoding_callback
2685
2769
[ stream ] : stream.html
0 commit comments