Skip to content

Commit

Permalink
test: make test-crypto-hash compatible with OpenSSL 3.4+
Browse files Browse the repository at this point in the history
OpenSSL 3.4 has a breaking change where the outputLength is now
mandatory for shake* hash algorithms.

Refs: openssl/openssl@b911fef
  • Loading branch information
jelly authored and aduh95 committed Dec 17, 2024
1 parent 6012a4e commit 4f8bc73
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions test/parallel/test-crypto-hash.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ const assert = require('assert');
const crypto = require('crypto');
const fs = require('fs');

const { hasOpenSSL } = common;
const fixtures = require('../common/fixtures');

let cryptoType;
@@ -182,19 +183,21 @@ assert.throws(

// Test XOF hash functions and the outputLength option.
{
// Default outputLengths.
assert.strictEqual(crypto.createHash('shake128').digest('hex'),
'7f9c2ba4e88f827d616045507605853e');
assert.strictEqual(crypto.createHash('shake128', null).digest('hex'),
'7f9c2ba4e88f827d616045507605853e');
assert.strictEqual(crypto.createHash('shake256').digest('hex'),
'46b9dd2b0ba88d13233b3feb743eeb24' +
'3fcd52ea62b81b82b50c27646ed5762f');
assert.strictEqual(crypto.createHash('shake256', { outputLength: 0 })
.copy() // Default outputLength.
.digest('hex'),
'46b9dd2b0ba88d13233b3feb743eeb24' +
'3fcd52ea62b81b82b50c27646ed5762f');
// Default outputLengths. Since OpenSSL 3.4 an outputLength is mandatory
if (!hasOpenSSL(3, 4)) {
assert.strictEqual(crypto.createHash('shake128').digest('hex'),
'7f9c2ba4e88f827d616045507605853e');
assert.strictEqual(crypto.createHash('shake128', null).digest('hex'),
'7f9c2ba4e88f827d616045507605853e');
assert.strictEqual(crypto.createHash('shake256').digest('hex'),
'46b9dd2b0ba88d13233b3feb743eeb24' +
'3fcd52ea62b81b82b50c27646ed5762f');
assert.strictEqual(crypto.createHash('shake256', { outputLength: 0 })
.copy() // Default outputLength.
.digest('hex'),
'46b9dd2b0ba88d13233b3feb743eeb24' +
'3fcd52ea62b81b82b50c27646ed5762f');
}

// Short outputLengths.
assert.strictEqual(crypto.createHash('shake128', { outputLength: 0 })

0 comments on commit 4f8bc73

Please sign in to comment.