Files
node/test/parallel/test-webcrypto-fips-refresh.js
T
Filip Skokan 38187f81eb crypto: use backend cSHAKE and KMAC
Require cSHAKE and KMAC output lengths and KMAC key lengths to be
multiples of 8 bits. KMAC keys must be at least 32 bits. Share these
restrictions between operations and supports.

Use OpenSSL's KMAC provider for all supported inputs and its cSHAKE
implementation for non-empty function names or customization strings.
Keep using SHAKE when both cSHAKE parameters are empty. Remove the
custom Keccak framing, partial-bit handling, and short-key fallback.

Document the OpenSSL 4.0 requirement for non-empty cSHAKE parameters and
reject customization strings containing null bytes. Keep the documented
512-byte customization limit and let backend failures reach callers.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66237
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
2026-09-25 13:23:26 +00:00

38 lines
1.3 KiB
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { getFips, getHashes, setFips } = require('crypto');
const { internalBinding } = require('internal/test/binding');
const { getOptionValue } = require('internal/options');
if (!internalBinding('crypto').testFipsCrypto())
common.skip('requires an active FIPS provider');
if (getOptionValue('--force-fips'))
common.skip('FIPS mode cannot be changed when forced');
const initial = getFips();
try {
for (const fips of [false, true, false]) {
setFips(fips);
assert.strictEqual(SubtleCrypto.supports('digest', {
name: 'TurboSHAKE128', outputLength: 128,
}), !fips);
assert.strictEqual(SubtleCrypto.supports('digest', {
name: 'KT128', outputLength: 128,
}), !fips);
assert.strictEqual(SubtleCrypto.supports('digest', {
name: 'cSHAKE128', outputLength: 128, customization: new Uint8Array([1]),
}), getHashes().includes('cshake128'));
assert.strictEqual(SubtleCrypto.supports('generateKey', {
name: 'RSA-PSS', hash: 'SHA-256', modulusLength: 1024,
publicExponent: new Uint8Array([1, 0, 1]),
}), !fips);
}
} finally {
setFips(initial);
}