From b1d28785b2a4333cbeb709e4ad82bb2d87d062ab Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 26 Aug 2025 18:05:56 +0200 Subject: [PATCH] crypto: add Argon2 Web Cryptography algorithms PR-URL: https://github.com/nodejs/node/pull/59544 Reviewed-By: James M Snell Reviewed-By: Ethan Arrowood --- doc/api/webcrypto.md | 124 +++++++++++++++++- lib/internal/crypto/argon2.js | 59 ++++++++- lib/internal/crypto/keys.js | 7 + lib/internal/crypto/util.js | 27 ++++ lib/internal/crypto/webcrypto.js | 40 ++++++ lib/internal/crypto/webidl.js | 62 +++++++++ .../webcrypto/supports-modern-algorithms.mjs | 45 +++++++ .../test-webcrypto-derivebits-argon2.js | 92 +++++++++++++ tools/doc/type-parser.mjs | 1 + 9 files changed, 452 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-webcrypto-derivebits-argon2.js diff --git a/doc/api/webcrypto.md b/doc/api/webcrypto.md index b567c89785d..5e24f9da78d 100644 --- a/doc/api/webcrypto.md +++ b/doc/api/webcrypto.md @@ -2,6 +2,9 @@ -* `algorithm` {EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params} +* `algorithm` {EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params|Argon2Params} * `baseKey` {CryptoKey} * `length` {number|null} **Default:** `null` * Returns: {Promise} Fulfills with an {ArrayBuffer} upon success. @@ -899,6 +917,9 @@ containing the generated data. The algorithms currently supported include: +* `'Argon2d'`[^modern-algos] +* `'Argon2i'`[^modern-algos] +* `'Argon2id'`[^modern-algos] * `'ECDH'` * `'HKDF'` * `'PBKDF2'` @@ -910,6 +931,9 @@ The algorithms currently supported include: -* `algorithm` {EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params} +* `algorithm` {EcdhKeyDeriveParams|HkdfParams|Pbkdf2Params|Argon2Params} * `baseKey` {CryptoKey} * `derivedKeyAlgorithm` {string|Algorithm|HmacImportParams|AesDerivedKeyParams} * `extractable` {boolean} @@ -939,6 +963,9 @@ generate raw keying material, then passing the result into the The algorithms currently supported include: +* `'Argon2d'`[^modern-algos] +* `'Argon2i'`[^modern-algos] +* `'Argon2id'`[^modern-algos] * `'ECDH'` * `'HKDF'` * `'PBKDF2'` @@ -1234,7 +1261,7 @@ as the given `format` to create a {CryptoKey} instance using the provided `algorithm`, `extractable`, and `keyUsages` arguments. If the import is successful, the returned promise will be resolved with the created {CryptoKey}. -If importing a `'PBKDF2'` key, `extractable` must be `false`. +If importing KDF algorithm keys, `extractable` must be `false`. The algorithms currently supported include: @@ -1245,6 +1272,9 @@ The algorithms currently supported include: | `'AES-GCM'` | | | ✔ | ✔ | ✔ | | | | `'AES-KW'` | | | ✔ | ✔ | ✔ | | | | `'AES-OCB'`[^modern-algos] | | | ✔ | | ✔ | | | +| `'Argon2d'`[^modern-algos] | | | | | ✔ | | | +| `'Argon2i'`[^modern-algos] | | | | | ✔ | | | +| `'Argon2id'`[^modern-algos] | | | | | ✔ | | | | `'ChaCha20-Poly1305'`[^modern-algos] | | | ✔ | | ✔ | | | | `'ECDH'` | ✔ | ✔ | ✔ | ✔ | | ✔ | | | `'ECDSA'` | ✔ | ✔ | ✔ | ✔ | | ✔ | | @@ -1665,6 +1695,90 @@ added: v15.0.0 * Type: {string} Must be one of `'AES-CBC'`, `'AES-CTR'`, `'AES-GCM'`, or `'AES-KW'` +### Class: `Argon2Params` + + + +#### `argon2Params.associatedData` + + + +* Type: {ArrayBuffer|TypedArray|DataView|Buffer} + +Represents the optional associated data. + +#### `argon2Params.memory` + + + +* Type: {number} + +Represents the memory size in kibibytes. It must be at least 8 times the degree of parallelism. + +#### `argon2Params.name` + + + +* Type: {string} Must be one of `'Argon2d'`, `'Argon2i'`, or `'Argon2id'`. + +#### `argon2Params.nonce` + + + +* Type: {ArrayBuffer|TypedArray|DataView|Buffer} + +Represents the nonce, which is a salt for password hashing applications. + +#### `argon2Params.parallelism` + + + +* Type: {number} + +Represents the degree of parallelism. + +#### `argon2Params.passes` + + + +* Type: {number} + +Represents the number of passes. + +#### `argon2Params.secretValue` + + + +* Type: {ArrayBuffer|TypedArray|DataView|Buffer} + +Represents the optional secret value. + +#### `argon2Params.version` + + + +* Type: {number} + +Represents the Argon2 version number. The default and currently only defined version is `19` (`0x13`). + ### Class: `ContextParams`