@@ -2958,6 +2958,171 @@ Does not perform any other validation checks on the certificate.
29582958
29592959## ` node:crypto ` module methods and properties
29602960
2961+ ### ` crypto.argon2(algorithm, parameters, callback) `
2962+
2963+ <!-- YAML
2964+ added: REPLACEME
2965+ -->
2966+
2967+ > Stability: 1.2 - Release candidate
2968+
2969+ * ` algorithm ` {string} Variant of Argon2, one of ` "argon2d" ` , ` "argon2i" ` or ` "argon2id" ` .
2970+ * ` parameters ` {Object}
2971+ * ` message ` {string|ArrayBuffer|Buffer|TypedArray|DataView} REQUIRED, this is the password for password
2972+ hashing applications of Argon2.
2973+ * ` nonce ` {string|ArrayBuffer|Buffer|TypedArray|DataView} REQUIRED, must be at
2974+ least 8 bytes long. This is the salt for password hashing applications of Argon2.
2975+ * ` parallelism ` {number} REQUIRED, degree of parallelism determines how many computational chains (lanes)
2976+ can be run. Must be greater than 1 and less than ` 2**24-1 ` .
2977+ * ` tagLength ` {number} REQUIRED, the length of the key to generate. Must be greater than 4 and
2978+ less than ` 2**32-1 ` .
2979+ * ` memory ` {number} REQUIRED, memory cost in 1KiB blocks. Must be greater than
2980+ ` 8 * parallelism ` and less than ` 2**32-1 ` . The actual number of blocks is rounded
2981+ down to the nearest multiple of ` 4 * parallelism ` .
2982+ * ` passes ` {number} REQUIRED, number of passes (iterations). Must be greater than 1 and less
2983+ than ` 2**32-1 ` .
2984+ * ` secret ` {string|ArrayBuffer|Buffer|TypedArray|DataView|undefined} OPTIONAL, Random additional input,
2985+ similar to the salt, that should ** NOT** be stored with the derived key. This is known as pepper in
2986+ password hashing applications. If used, must have a length not greater than ` 2**32-1 ` bytes.
2987+ * ` associatedData ` {string|ArrayBuffer|Buffer|TypedArray|DataView|undefined} OPTIONAL, Additional data to
2988+ be added to the hash, functionally equivalent to salt or secret, but meant for
2989+ non-random data. If used, must have a length not greater than ` 2**32-1 ` bytes.
2990+ * ` callback ` {Function}
2991+ * ` err ` {Error}
2992+ * ` derivedKey ` {Buffer}
2993+
2994+ Provides an asynchronous [ Argon2] [ ] implementation. Argon2 is a password-based
2995+ key derivation function that is designed to be expensive computationally and
2996+ memory-wise in order to make brute-force attacks unrewarding.
2997+
2998+ The ` nonce ` should be as unique as possible. It is recommended that a nonce is
2999+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ] for details.
3000+
3001+ When passing strings for ` message ` , ` nonce ` , ` secret ` or ` associatedData ` , please
3002+ consider [ caveats when using strings as inputs to cryptographic APIs] [ ] .
3003+
3004+ The ` callback ` function is called with two arguments: ` err ` and ` derivedKey ` .
3005+ ` err ` is an exception object when key derivation fails, otherwise ` err ` is
3006+ ` null ` . ` derivedKey ` is passed to the callback as a [ ` Buffer ` ] [ ] .
3007+
3008+ An exception is thrown when any of the input arguments specify invalid values
3009+ or types.
3010+
3011+ ``` mjs
3012+ const { argon2 , randomBytes } = await import (' node:crypto' );
3013+
3014+ const parameters = {
3015+ message: ' password' ,
3016+ nonce: randomBytes (16 ),
3017+ parallelism: 4 ,
3018+ tagLength: 64 ,
3019+ memory: 65536 ,
3020+ passes: 3 ,
3021+ };
3022+
3023+ argon2 (' argon2id' , parameters, (err , derivedKey ) => {
3024+ if (err) throw err;
3025+ console .log (derivedKey .toString (' hex' )); // 'af91dad...9520f15'
3026+ });
3027+ ```
3028+
3029+ ``` cjs
3030+ const { argon2 , randomBytes } = require (' node:crypto' );
3031+
3032+ const parameters = {
3033+ message: ' password' ,
3034+ nonce: randomBytes (16 ),
3035+ parallelism: 4 ,
3036+ tagLength: 64 ,
3037+ memory: 65536 ,
3038+ passes: 3 ,
3039+ };
3040+
3041+ argon2 (' argon2id' , parameters, (err , derivedKey ) => {
3042+ if (err) throw err;
3043+ console .log (derivedKey .toString (' hex' )); // 'af91dad...9520f15'
3044+ });
3045+ ```
3046+
3047+ ### ` crypto.argon2Sync(algorithm, parameters) `
3048+
3049+ <!-- YAML
3050+ added: REPLACEME
3051+ -->
3052+
3053+ > Stability: 1.2 - Release candidate
3054+
3055+ * ` algorithm ` {string} Variant of Argon2, one of ` "argon2d" ` , ` "argon2i" ` or ` "argon2id" ` .
3056+ * ` parameters ` {Object}
3057+ * ` message ` {string|ArrayBuffer|Buffer|TypedArray|DataView} REQUIRED, this is the password for password
3058+ hashing applications of Argon2.
3059+ * ` nonce ` {string|ArrayBuffer|Buffer|TypedArray|DataView} REQUIRED, must be at
3060+ least 8 bytes long. This is the salt for password hashing applications of Argon2.
3061+ * ` parallelism ` {number} REQUIRED, degree of parallelism determines how many computational chains (lanes)
3062+ can be run. Must be greater than 1 and less than ` 2**24-1 ` .
3063+ * ` tagLength ` {number} REQUIRED, the length of the key to generate. Must be greater than 4 and
3064+ less than ` 2**32-1 ` .
3065+ * ` memory ` {number} REQUIRED, memory cost in 1KiB blocks. Must be greater than
3066+ ` 8 * parallelism ` and less than ` 2**32-1 ` . The actual number of blocks is rounded
3067+ down to the nearest multiple of ` 4 * parallelism ` .
3068+ * ` passes ` {number} REQUIRED, number of passes (iterations). Must be greater than 1 and less
3069+ than ` 2**32-1 ` .
3070+ * ` secret ` {string|ArrayBuffer|Buffer|TypedArray|DataView|undefined} OPTIONAL, Random additional input,
3071+ similar to the salt, that should ** NOT** be stored with the derived key. This is known as pepper in
3072+ password hashing applications. If used, must have a length not greater than ` 2**32-1 ` bytes.
3073+ * ` associatedData ` {string|ArrayBuffer|Buffer|TypedArray|DataView|undefined} OPTIONAL, Additional data to
3074+ be added to the hash, functionally equivalent to salt or secret, but meant for
3075+ non-random data. If used, must have a length not greater than ` 2**32-1 ` bytes.
3076+ * Returns: {Buffer}
3077+
3078+ Provides a synchronous [ Argon2] [ ] implementation. Argon2 is a password-based
3079+ key derivation function that is designed to be expensive computationally and
3080+ memory-wise in order to make brute-force attacks unrewarding.
3081+
3082+ The ` nonce ` should be as unique as possible. It is recommended that a nonce is
3083+ random and at least 16 bytes long. See [ NIST SP 800-132] [ ] for details.
3084+
3085+ When passing strings for ` message ` , ` nonce ` , ` secret ` or ` associatedData ` , please
3086+ consider [ caveats when using strings as inputs to cryptographic APIs] [ ] .
3087+
3088+ An exception is thrown when key derivation fails, otherwise the derived key is
3089+ returned as a [ ` Buffer ` ] [ ] .
3090+
3091+ An exception is thrown when any of the input arguments specify invalid values
3092+ or types.
3093+
3094+ ``` mjs
3095+ const { argon2Sync , randomBytes } = await import (' node:crypto' );
3096+
3097+ const parameters = {
3098+ message: ' password' ,
3099+ nonce: randomBytes (16 ),
3100+ parallelism: 4 ,
3101+ tagLength: 64 ,
3102+ memory: 65536 ,
3103+ passes: 3 ,
3104+ };
3105+
3106+ const derivedKey = argon2Sync (' argon2id' , parameters);
3107+ console .log (derivedKey .toString (' hex' )); // 'af91dad...9520f15'
3108+ ```
3109+
3110+ ``` cjs
3111+ const { argon2Sync , randomBytes } = require (' node:crypto' );
3112+
3113+ const parameters = {
3114+ message: ' password' ,
3115+ nonce: randomBytes (16 ),
3116+ parallelism: 4 ,
3117+ tagLength: 64 ,
3118+ memory: 65536 ,
3119+ passes: 3 ,
3120+ };
3121+
3122+ const derivedKey = argon2Sync (' argon2id' , parameters);
3123+ console .log (derivedKey .toString (' hex' )); // 'af91dad...9520f15'
3124+ ```
3125+
29613126### ` crypto.checkPrime(candidate[, options], callback) `
29623127
29633128<!-- YAML
@@ -6268,6 +6433,7 @@ See the [list of SSL OP Flags][] for details.
62686433[ `verify.verify()` ] : #verifyverifyobject-signature-signatureencoding
62696434[ `x509.fingerprint256` ] : #x509fingerprint256
62706435[ `x509.verify(publicKey)` ] : #x509verifypublickey
6436+ [ argon2 ] : https://www.rfc-editor.org/rfc/rfc9106.html
62716437[ caveats when using strings as inputs to cryptographic APIs ] : #using-strings-as-inputs-to-cryptographic-apis
62726438[ certificate object ] : tls.md#certificate-object
62736439[ encoding ] : buffer.md#buffers-and-character-encodings
0 commit comments