Skip to content

Commit

Permalink
test: make test-crypto-hash compatible with OpenSSL > 3.4.0
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.

openssl/openssl@b911fef
  • Loading branch information
jelly committed Dec 6, 2024
1 parent 4211ab5 commit 93eabf6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
4 changes: 4 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,10 @@ const common = {
return hasOpenSSL(3, 2);
},

get hasOpenSSL34() {
return hasOpenSSL(3, 4);
},

get inFreeBSDJail() {
if (inFreeBSDJail !== null) return inFreeBSDJail;

Expand Down
29 changes: 16 additions & 13 deletions test/parallel/test-crypto-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const assert = require('assert');
const crypto = require('crypto');
const fs = require('fs');

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

let cryptoType;
Expand Down Expand Up @@ -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 (!hasOpenSSL34) {
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 })
Expand Down

0 comments on commit 93eabf6

Please sign in to comment.