@@ -1361,9 +1361,9 @@ password always creates the same key. The low iteration count and
1361
1361
non-cryptographically secure hash algorithm allow passwords to be tested very
1362
1362
rapidly.
1363
1363
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
1365
1365
[ ` 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() ` ] [ ]
1367
1367
to create the ` Cipher ` object. Users should not use ciphers with counter mode
1368
1368
(e.g. CTR, GCM, or CCM) in ` crypto.createCipher() ` . A warning is emitted when
1369
1369
they 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
1463
1463
non-cryptographically secure hash algorithm allow passwords to be tested very
1464
1464
rapidly.
1465
1465
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
1467
1467
[ ` 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() ` ] [ ]
1469
1469
to create the ` Decipher ` object.
1470
1470
1471
1471
### crypto.createDecipheriv(algorithm, key, iv[ , options] )
@@ -1801,9 +1801,8 @@ The `iterations` argument must be a number set as high as possible. The
1801
1801
higher the number of iterations, the more secure the derived key will be,
1802
1802
but will take a longer amount of time to complete.
1803
1803
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.
1807
1806
1808
1807
Example:
1809
1808
@@ -1867,9 +1866,8 @@ The `iterations` argument must be a number set as high as possible. The
1867
1866
higher the number of iterations, the more secure the derived key will be,
1868
1867
but will take a longer amount of time to complete.
1869
1868
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.
1873
1871
1874
1872
Example:
1875
1873
@@ -2143,6 +2141,91 @@ threadpool request. To minimize threadpool task length variation, partition
2143
2141
large ` randomFill ` requests when doing so as part of fulfilling a client
2144
2142
request.
2145
2143
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
+
2146
2229
### crypto.setEngine(engine[ , flags] )
2147
2230
<!-- YAML
2148
2231
added: v0.11.11
@@ -2650,9 +2733,9 @@ the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL.
2650
2733
[ `crypto.createVerify()` ] : #crypto_crypto_createverify_algorithm_options
2651
2734
[ `crypto.getCurves()` ] : #crypto_crypto_getcurves
2652
2735
[ `crypto.getHashes()` ] : #crypto_crypto_gethashes
2653
- [ `crypto.pbkdf2()` ] : #crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback
2654
2736
[ `crypto.randomBytes()` ] : #crypto_crypto_randombytes_size_callback
2655
2737
[ `crypto.randomFill()` ] : #crypto_crypto_randomfill_buffer_offset_size_callback
2738
+ [ `crypto.scrypt()` ] : #crypto_crypto_scrypt_password_salt_keylen_options_callback
2656
2739
[ `decipher.final()` ] : #crypto_decipher_final_outputencoding
2657
2740
[ `decipher.update()` ] : #crypto_decipher_update_data_inputencoding_outputencoding
2658
2741
[ `diffieHellman.setPublicKey()` ] : #crypto_diffiehellman_setpublickey_publickey_encoding
@@ -2686,5 +2769,6 @@ the `crypto`, `tls`, and `https` modules and are generally specific to OpenSSL.
2686
2769
[ RFC 3610 ] : https://www.rfc-editor.org/rfc/rfc3610.txt
2687
2770
[ RFC 4055 ] : https://www.rfc-editor.org/rfc/rfc4055.txt
2688
2771
[ initialization vector ] : https://en.wikipedia.org/wiki/Initialization_vector
2772
+ [ scrypt ] : https://en.wikipedia.org/wiki/Scrypt
2689
2773
[ stream-writable-write ] : stream.html#stream_writable_write_chunk_encoding_callback
2690
2774
[ stream ] : stream.html
0 commit comments