@@ -2949,39 +2949,40 @@ Does not perform any other validation checks on the certificate.
29492949
29502950## ` node:crypto ` module methods and properties
29512951
2952- ### ` crypto.argon2(options , callback) `
2952+ ### ` crypto.argon2(algorithm, parameters , callback) `
29532953
29542954<!-- YAML
29552955added: REPLACEME
29562956-->
29572957
29582958> Stability: 1.2 - Release candidate
29592959
2960- * ` options ` {Object}
2961- * ` message ` {string|ArrayBuffer|Buffer|TypedArray|DataView}
2962- * ` nonce ` {string|ArrayBuffer|Buffer|TypedArray|DataView} The salt value. Must be at
2963- least 8 bytes long.
2964- * ` parallelism ` {number} Parallelization parameter (number of lanes and threads).
2965- Must be greater than 1 and less than ` 2**24-1 ` .
2966- * ` tagLength ` {number} The length of the key to generate. Must be greater than 4 and
2960+ * ` algorithm ` {string} Variant of Argon2, one of ` "argon2d" ` , ` "argon2i" ` or ` "argon2id" ` .
2961+ * ` parameters ` {Object}
2962+ * ` message ` {string|ArrayBuffer|Buffer|TypedArray|DataView} REQUIRED, this is the password for password
2963+ hashing applications of Argon2.
2964+ * ` nonce ` {string|ArrayBuffer|Buffer|TypedArray|DataView} REQUIRED, must be at
2965+ least 8 bytes long. This is the salt for password hashing applications of Argon2.
2966+ * ` parallelism ` {number} REQUIRED, degree of parallelism determines how many computational chains (lanes)
2967+ can be run. Must be greater than 1 and less than ` 2**24-1 ` .
2968+ * ` tagLength ` {number} REQUIRED, the length of the key to generate. Must be greater than 4 and
29672969 less than ` 2**32-1 ` .
2968- * ` memory ` {number} Memory cost in 1KiB blocks. Must be greater than
2970+ * ` memory ` {number} REQUIRED, memory cost in 1KiB blocks. Must be greater than
29692971 ` 8 * parallelism ` and less than ` 2**32-1 ` . The actual number of blocks is rounded
29702972 down to the nearest multiple of ` 4 * parallelism ` .
2971- * ` passes ` {number} Number of passes (iterations). Must be greater than 1 and less
2973+ * ` passes ` {number} REQUIRED, number of passes (iterations). Must be greater than 1 and less
29722974 than ` 2**32-1 ` .
2973- * ` secret ` {string|ArrayBuffer|Buffer|TypedArray|DataView} Random additional input,
2974- similar to the salt, that should ** NOT** be stored with the derived key. Also known
2975- as a pepper . If used, must have a length not greater than ` 2**32-1 ` bytes.
2976- * ` associatedData ` {string|ArrayBuffer|Buffer|TypedArray|DataView} Additional data to
2975+ * ` secret ` {string|ArrayBuffer|Buffer|TypedArray|DataView|undefined} OPTIONAL, Random additional input,
2976+ similar to the salt, that should ** NOT** be stored with the derived key. This is known as pepper in
2977+ password hashing applications . If used, must have a length not greater than ` 2**32-1 ` bytes.
2978+ * ` associatedData ` {string|ArrayBuffer|Buffer|TypedArray|DataView|undefined} OPTIONAL, Additional data to
29772979 be added to the hash, functionally equivalent to salt or secret, but meant for
29782980 non-random data. If used, must have a length not greater than ` 2**32-1 ` bytes.
2979- * ` type ` {string} Variant of Argon2, one of ` "argon2d" ` , ` "argon2i" ` or ` "argon2id" ` .
29802981* ` callback ` {Function}
29812982 * ` err ` {Error}
29822983 * ` derivedKey ` {Buffer}
29832984
2984- Provides an asynchronous [ argon2 ] [ ] implementation. Argon2 is a password-based
2985+ Provides an asynchronous [ Argon2 ] [ ] implementation. Argon2 is a password-based
29852986key derivation function that is designed to be expensive computationally and
29862987memory-wise in order to make brute-force attacks unrewarding.
29872988
@@ -2999,64 +3000,73 @@ An exception is thrown when any of the input arguments specify invalid values
29993000or types.
30003001
30013002``` mjs
3002- const {
3003- argon2 ,
3004- randomBytes ,
3005- } = await import (' node:crypto' );
3006-
3007- const nonce = randomBytes (16 );
3008- argon2 ({ message: ' password' , nonce, parallelism: 4 , tagLength: 64 , memory: 65536 , passes: 3 }, (err , derivedKey ) => {
3003+ const { argon2 , randomBytes } = await import (' node:crypto' );
3004+
3005+ const parameters = {
3006+ message: ' password' ,
3007+ nonce: randomBytes (16 ),
3008+ parallelism: 4 ,
3009+ tagLength: 64 ,
3010+ memory: 65536 ,
3011+ passes: 3 ,
3012+ };
3013+
3014+ argon2 (' argon2id' , parameters, (err , derivedKey ) => {
30093015 if (err) throw err;
3010- console .log (derivedKey .toString (' hex' )); // '0de3036 ...22afcc5 '
3016+ console .log (derivedKey .toString (' hex' )); // 'af91dad ...9520f15 '
30113017});
30123018```
30133019
30143020``` cjs
3015- const {
3016- argon2 ,
3017- randomBytes ,
3018- } = require (' node:crypto' );
3019-
3020- randomBytes (16 , (err , nonce ) => {
3021+ const { argon2 , randomBytes } = require (' node:crypto' );
3022+
3023+ const parameters = {
3024+ message: ' password' ,
3025+ nonce: randomBytes (16 ),
3026+ parallelism: 4 ,
3027+ tagLength: 64 ,
3028+ memory: 65536 ,
3029+ passes: 3 ,
3030+ };
3031+
3032+ argon2 (' argon2id' , parameters, (err , derivedKey ) => {
30213033 if (err) throw err;
3022- argon2 ({ message: ' password' , nonce, parallelism: 4 , tagLength: 64 , memory: 65536 , passes: 3 }, (err , derivedKey ) => {
3023- if (err) throw err;
3024- console .log (derivedKey .toString (' hex' )); // '0de3036...22afcc5'
3025- });
3034+ console .log (derivedKey .toString (' hex' )); // 'af91dad...9520f15'
30263035});
30273036```
30283037
3029- ### ` crypto.argon2Sync(password, salt, keylen, options ) `
3038+ ### ` crypto.argon2Sync(algorithm, parameters ) `
30303039
30313040<!-- YAML
30323041added: REPLACEME
30333042-->
30343043
30353044> Stability: 1.2 - Release candidate
30363045
3037- * ` options ` {Object}
3038- * ` message ` {string|ArrayBuffer|Buffer|TypedArray|DataView}
3039- * ` nonce ` {string|ArrayBuffer|Buffer|TypedArray|DataView} The salt value. Must be at
3040- least 8 bytes long.
3041- * ` parallelism ` {number} Parallelization parameter (number of lanes and threads).
3042- Must be greater than 1 and less than ` 2**24-1 ` .
3043- * ` tagLength ` {number} The length of the key to generate. Must be greater than 4 and
3046+ * ` algorithm ` {string} Variant of Argon2, one of ` "argon2d" ` , ` "argon2i" ` or ` "argon2id" ` .
3047+ * ` parameters ` {Object}
3048+ * ` message ` {string|ArrayBuffer|Buffer|TypedArray|DataView} REQUIRED, this is the password for password
3049+ hashing applications of Argon2.
3050+ * ` nonce ` {string|ArrayBuffer|Buffer|TypedArray|DataView} REQUIRED, must be at
3051+ least 8 bytes long. This is the salt for password hashing applications of Argon2.
3052+ * ` parallelism ` {number} REQUIRED, degree of parallelism determines how many computational chains (lanes)
3053+ can be run. Must be greater than 1 and less than ` 2**24-1 ` .
3054+ * ` tagLength ` {number} REQUIRED, the length of the key to generate. Must be greater than 4 and
30443055 less than ` 2**32-1 ` .
3045- * ` memory ` {number} Memory cost in 1KiB blocks. Must be greater than
3056+ * ` memory ` {number} REQUIRED, memory cost in 1KiB blocks. Must be greater than
30463057 ` 8 * parallelism ` and less than ` 2**32-1 ` . The actual number of blocks is rounded
30473058 down to the nearest multiple of ` 4 * parallelism ` .
3048- * ` passes ` {number} Number of passes (iterations). Must be greater than 1 and less
3059+ * ` passes ` {number} REQUIRED, number of passes (iterations). Must be greater than 1 and less
30493060 than ` 2**32-1 ` .
3050- * ` secret ` {string|ArrayBuffer|Buffer|TypedArray|DataView} Random additional input,
3051- similar to the salt, that should ** NOT** be stored with the derived key. Also known
3052- as a pepper . If used, must have a length not greater than ` 2**32-1 ` bytes.
3053- * ` associatedData ` {string|ArrayBuffer|Buffer|TypedArray|DataView} Additional data to
3061+ * ` secret ` {string|ArrayBuffer|Buffer|TypedArray|DataView|undefined} OPTIONAL, Random additional input,
3062+ similar to the salt, that should ** NOT** be stored with the derived key. This is known as pepper in
3063+ password hashing applications . If used, must have a length not greater than ` 2**32-1 ` bytes.
3064+ * ` associatedData ` {string|ArrayBuffer|Buffer|TypedArray|DataView|undefined} OPTIONAL, Additional data to
30543065 be added to the hash, functionally equivalent to salt or secret, but meant for
30553066 non-random data. If used, must have a length not greater than ` 2**32-1 ` bytes.
3056- * ` type ` {string} Variant of Argon2, one of ` "argon2d" ` , ` "argon2i" ` or ` "argon2id" ` .
30573067* Returns: {Buffer}
30583068
3059- Provides a synchronous [ argon2 ] [ ] implementation. Argon2 is a password-based
3069+ Provides a synchronous [ Argon2 ] [ ] implementation. Argon2 is a password-based
30603070key derivation function that is designed to be expensive computationally and
30613071memory-wise in order to make brute-force attacks unrewarding.
30623072
@@ -3073,25 +3083,35 @@ An exception is thrown when any of the input arguments specify invalid values
30733083or types.
30743084
30753085``` mjs
3076- const {
3077- argon2Sync ,
3078- randomBytes ,
3079- } = await import (' node:crypto' );
3080-
3081- const nonce = randomBytes (16 );
3082- const key = argon2Sync ({ message: ' password' , nonce, parallelism: 4 , tagLength: 64 , memory: 65536 , passes: 3 });
3083- console .log (key .toString (' hex' )); // '3745e48...08d59ae'
3086+ const { argon2Sync , randomBytes } = await import (' node:crypto' );
3087+
3088+ const parameters = {
3089+ message: ' password' ,
3090+ nonce: randomBytes (16 ),
3091+ parallelism: 4 ,
3092+ tagLength: 64 ,
3093+ memory: 65536 ,
3094+ passes: 3 ,
3095+ };
3096+
3097+ const derivedKey = argon2Sync (' argon2id' , parameters);
3098+ console .log (derivedKey .toString (' hex' )); // 'af91dad...9520f15'
30843099```
30853100
30863101``` cjs
3087- const {
3088- argon2Sync ,
3089- randomBytes ,
3090- } = require (' node:crypto' );
3091-
3092- const nonce = randomBytes (16 );
3093- const key = argon2Sync ({ message: ' password' , nonce, parallelism: 4 , tagLength: 64 , memory: 65536 , passes: 3 });
3094- console .log (key .toString (' hex' )); // '3745e48...08d59ae'
3102+ const { argon2Sync , randomBytes } = require (' node:crypto' );
3103+
3104+ const parameters = {
3105+ message: ' password' ,
3106+ nonce: randomBytes (16 ),
3107+ parallelism: 4 ,
3108+ tagLength: 64 ,
3109+ memory: 65536 ,
3110+ passes: 3 ,
3111+ };
3112+
3113+ const derivedKey = argon2Sync (' argon2id' , parameters);
3114+ console .log (derivedKey .toString (' hex' )); // 'af91dad...9520f15'
30953115```
30963116
30973117### ` crypto.checkPrime(candidate[, options], callback) `
0 commit comments