From 247d01750159908eeebbee4ffba799eaa115aaa8 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 4 Mar 2025 15:34:25 +0100 Subject: [PATCH] crypto: add SHAKE Web Cryptography digest algorithms PR-URL: https://github.com/nodejs/node/pull/59365 Reviewed-By: James M Snell Reviewed-By: Ethan Arrowood Reviewed-By: Yagiz Nizipli Reviewed-By: Joyee Cheung --- doc/api/webcrypto.md | 62 ++++++++++++++- lib/internal/crypto/hash.js | 7 +- lib/internal/crypto/hashnames.js | 8 ++ lib/internal/crypto/mac.js | 2 +- lib/internal/crypto/rsa.js | 2 +- lib/internal/crypto/util.js | 6 ++ lib/internal/crypto/webidl.js | 44 +++++++++++ .../test-webcrypto-derivebits-hkdf.js | 11 +-- test/parallel/test-webcrypto-digest.js | 77 +++++++++++++++---- test/parallel/test-webcrypto-keygen.js | 11 +-- .../test-webcrypto-derivebits-pbkdf2.js | 12 +-- tools/doc/type-parser.mjs | 1 + 12 files changed, 197 insertions(+), 46 deletions(-) diff --git a/doc/api/webcrypto.md b/doc/api/webcrypto.md index c16140b17f6..0219c01e02c 100644 --- a/doc/api/webcrypto.md +++ b/doc/api/webcrypto.md @@ -2,6 +2,9 @@ -* `algorithm` {string|Algorithm} +* `algorithm` {string|Algorithm|CShakeParams} * `data` {ArrayBuffer|TypedArray|DataView|Buffer} * Returns: {Promise} Fulfills with an {ArrayBuffer} upon success. @@ -812,6 +823,8 @@ with an {ArrayBuffer} containing the computed digest. If `algorithm` is provided as a {string}, it must be one of: +* `'cSHAKE128'`[^modern-algos] +* `'cSHAKE256'`[^modern-algos] * `'SHA-1'` * `'SHA-256'` * `'SHA-384'` @@ -1423,6 +1436,53 @@ the message. The Node.js Web Crypto API implementation only supports zero-length context which is equivalent to not providing context at all. +### Class: `CShakeParams` + + + +#### `cShakeParams.customization` + + + +* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined} + +The `customization` member represents the customization string. +The Node.js Web Crypto API implementation only supports zero-length customization +which is equivalent to not providing customization at all. + +#### `cShakeParams.functionName` + + + +* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined} + +The `functionName` member represents represents the function name, used by NIST to define +functions based on cSHAKE. +The Node.js Web Crypto API implementation only supports zero-length functionName +which is equivalent to not providing functionName at all. + +#### `cShakeParams.length` + + + +* Type: {number} represents the requested output length in bits. + +#### `cShakeParams.name` + + + +* Type: {string} Must be `'cSHAKE128'`[^modern-algos] or `'cSHAKE256'`[^modern-algos] + ### Class: `EcdhKeyDeriveParams`