Skip to content

Commit

Permalink
test: skip sha128/256 createHash()/hash() on openssl 3.4.
Browse files Browse the repository at this point in the history
OpenSSL 3.4 has intentionally broken EVP_DigestFinal for SHAKE128 and
SHAKE256 when OSSL_DIGEST_PARAM_XOFLEN is not set because a) the default
length used weakened them from their maximum strength and b) a static
length does not fully make sense for XOFs (which SHAKE* are).

Unfortunately, while crypto.createHash accepts an option argument that can
be something like `{ outputLength: 128 }`, crypto.hash doesn't offer a
similar API. Therefore there is little choice but to skip the test
completely for shake128 and shake256 on openssl >= 3.4.

Refs: nodejs#56159
Refs: openssl/openssl@b911fef
Refs: openssl/openssl@ad3f28c
  • Loading branch information
adrien-n committed Dec 17, 2024
1 parent 6012a4e commit 16e8ce2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/parallel/test-crypto-oneshot-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ const input = fs.readFileSync(fixtures.path('utf8_test_text.txt'));

for (const method of methods) {
for (const outputEncoding of ['buffer', 'hex', 'base64', undefined]) {
const oldDigest = crypto.createHash(method).update(input).digest(outputEncoding || 'hex');
const digestFromBuffer = crypto.hash(method, input, outputEncoding);
assert.deepStrictEqual(digestFromBuffer, oldDigest,
`different result from ${method} with encoding ${outputEncoding}`);
const digestFromString = crypto.hash(method, input.toString(), outputEncoding);
assert.deepStrictEqual(digestFromString, oldDigest,
`different result from ${method} with encoding ${outputEncoding}`);
if (method !== 'shake128' && method !== 'shake256' || !common.hasOpenSSL(3, 4)) {
const oldDigest = crypto.createHash(method).update(input).digest(outputEncoding || 'hex');
const digestFromBuffer = crypto.hash(method, input, outputEncoding);
assert.deepStrictEqual(digestFromBuffer, oldDigest,
`different result from ${method} with encoding ${outputEncoding}`);
const digestFromString = crypto.hash(method, input.toString(), outputEncoding);
assert.deepStrictEqual(digestFromString, oldDigest,
`different result from ${method} with encoding ${outputEncoding}`);
}
}
}

0 comments on commit 16e8ce2

Please sign in to comment.