Skip to content

Commit b8c7948

Browse files
committed
test,benchmark: use OpenSSL feature helpers
Add isBoringSSL() to the test crypto helpers and use it in tests and benchmarks. Replace hasOpenSSL3 call sites with hasOpenSSL(3). Assisted-by: Codex Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent 095fdd3 commit b8c7948

159 files changed

Lines changed: 616 additions & 514 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmark/crypto/create-keyobject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const common = require('../common.js');
4-
const { hasOpenSSL } = require('../../test/common/crypto.js');
4+
const { hasOpenSSL, isBoringSSL } = require('../../test/common/crypto.js');
55
const crypto = require('crypto');
66
const fs = require('fs');
77
const path = require('path');
@@ -26,7 +26,7 @@ const keyFixtures = {
2626

2727
if (hasOpenSSL(3, 5)) {
2828
keyFixtures['ml-dsa-44'] = readKeyPair('ml_dsa_44_public', 'ml_dsa_44_private');
29-
} else if (process.features.openssl_is_boringssl) {
29+
} else if (isBoringSSL()) {
3030
keyFixtures['ml-dsa-44'] = readKeyPair('ml_dsa_44_public', 'ml_dsa_44_private_seed_only');
3131
}
3232

benchmark/crypto/kem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const common = require('../common.js');
4-
const { hasOpenSSL } = require('../../test/common/crypto.js');
4+
const { hasOpenSSL, isBoringSSL } = require('../../test/common/crypto.js');
55
const crypto = require('crypto');
66
const fs = require('fs');
77
const path = require('path');
@@ -24,7 +24,7 @@ if (hasOpenSSL(3, 5)) {
2424
keyFixtures['ml-kem-512'] = readKeyPair('ml_kem_512_public', 'ml_kem_512_private');
2525
keyFixtures['ml-kem-768'] = readKeyPair('ml_kem_768_public', 'ml_kem_768_private');
2626
keyFixtures['ml-kem-1024'] = readKeyPair('ml_kem_1024_public', 'ml_kem_1024_private');
27-
} else if (process.features.openssl_is_boringssl) {
27+
} else if (isBoringSSL()) {
2828
keyFixtures['ml-kem-768'] = readKeyPair('ml_kem_768_public', 'ml_kem_768_private_seed_only');
2929
keyFixtures['ml-kem-1024'] = readKeyPair('ml_kem_1024_public', 'ml_kem_1024_private_seed_only');
3030
}

benchmark/crypto/mac.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const common = require('../common.js');
4-
const { hasOpenSSL } = require('../../test/common/crypto.js');
4+
const { hasOpenSSL, isBoringSSL } = require('../../test/common/crypto.js');
55
const assert = require('node:assert');
66
const {
77
createHmac,
@@ -10,7 +10,7 @@ const {
1010
} = require('node:crypto');
1111

1212
if (!hasOpenSSL(3) ||
13-
process.features.openssl_is_boringssl ||
13+
isBoringSSL() ||
1414
typeof createMac !== 'function' ||
1515
typeof getMacs !== 'function') {
1616
console.log('Skipping: generic MAC API requires OpenSSL >= 3');

benchmark/crypto/oneshot-sign.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const common = require('../common.js');
4-
const { hasOpenSSL } = require('../../test/common/crypto.js');
4+
const { hasOpenSSL, isBoringSSL } = require('../../test/common/crypto.js');
55
const crypto = require('crypto');
66
const fs = require('fs');
77
const path = require('path');
@@ -19,7 +19,7 @@ const keyFixtures = {
1919

2020
if (hasOpenSSL(3, 5)) {
2121
keyFixtures['ml-dsa-44'] = readKey('ml_dsa_44_private');
22-
} else if (process.features.openssl_is_boringssl) {
22+
} else if (isBoringSSL()) {
2323
keyFixtures['ml-dsa-44'] = readKey('ml_dsa_44_private_seed_only');
2424
}
2525

benchmark/crypto/oneshot-verify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const common = require('../common.js');
4-
const { hasOpenSSL } = require('../../test/common/crypto.js');
4+
const { hasOpenSSL, isBoringSSL } = require('../../test/common/crypto.js');
55
const crypto = require('crypto');
66
const fs = require('fs');
77
const path = require('path');
@@ -26,7 +26,7 @@ const keyFixtures = {
2626

2727
if (hasOpenSSL(3, 5)) {
2828
keyFixtures['ml-dsa-44'] = readKeyPair('ml_dsa_44_public', 'ml_dsa_44_private');
29-
} else if (process.features.openssl_is_boringssl) {
29+
} else if (isBoringSSL()) {
3030
keyFixtures['ml-dsa-44'] = readKeyPair('ml_dsa_44_public', 'ml_dsa_44_private_seed_only');
3131
}
3232

test/addons/openssl-providers/providers.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const common = require('../../common');
44
if (!common.hasCrypto) {
55
common.skip('missing crypto');
66
}
7-
const { hasOpenSSL3 } = require('../../common/crypto');
7+
const { hasOpenSSL } = require('../../common/crypto');
88

9-
if (!hasOpenSSL3) {
9+
if (!hasOpenSSL(3)) {
1010
common.skip('this test requires OpenSSL 3.x');
1111
}
1212
const assert = require('node:assert');

test/common/crypto.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ const hasOpenSSL = (major = 0, minor = 0, patch = 0) => {
123123
return OPENSSL_VERSION_NUMBER >= opensslVersionNumber(major, minor, patch);
124124
};
125125

126+
const isBoringSSL = () => process.features.openssl_is_boringssl;
127+
126128
const hasFIPS = (major = 0, minor = 0, patch = 0) => {
127129
return crypto.getFips() === 1 && hasOpenSSL(major, minor, patch);
128130
};
@@ -144,6 +146,7 @@ module.exports = {
144146
sec1EncExp,
145147
hasOpenSSL,
146148
hasFIPS,
149+
isBoringSSL,
147150
get hasOpenSSL3() {
148151
return hasOpenSSL(3);
149152
},

test/fixtures/crypto/ecdsa.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { isBoringSSL } = require('../../common/crypto');
4+
35
module.exports = function() {
46
const pkcs8 = {
57
'P-256': Buffer.from(
@@ -72,7 +74,7 @@ module.exports = function() {
7274
'b6a0a14d7e4bc6dd2eda82c9234f174b670b60c8f7d101f68fdf5889e02373b025' +
7375
'dcbc4c82f2929b8e06c68535da98e38fe399c53a814b097935581ef21535eb',
7476
'hex'),
75-
...(!process.features.openssl_is_boringssl ? {
77+
...(!isBoringSSL() ? {
7678
'SHA3-256': Buffer.from(
7779
'f6a48eb5557f484ed0c3e4b5c78a3cf497cbd346db06a4165d429248aa2cc51a69' +
7880
'747d09f57af145469a8b607a9b8b9709629d74e8f5ca337c6ddc581b6f6103',
@@ -104,7 +106,7 @@ module.exports = function() {
104106
'72fbdb369fd34c1c54264d07f4facd69b02e4206f8a8bb259b882a305c56fde2d3' +
105107
'5107e493c53cd6b4af0b31306f4d03fd43cfc762a1030e17a3d775453a1212b142' +
106108
'9f7b3d93066a5f42a10b138cd177dc09616e827d598822d78d4627b754e6', 'hex'),
107-
...(!process.features.openssl_is_boringssl ? {
109+
...(!isBoringSSL() ? {
108110
'SHA3-256': Buffer.from(
109111
'0b07c078be30fa5925a307d6fc559c5f398e63fb5d007d6b24a834847f2d3d18d5' +
110112
'b5e840711c52a7bc6626c3ced93301e873c013a706f6b297c12cc6d47a71e0529e' +
@@ -144,7 +146,7 @@ module.exports = function() {
144146
'01f0071e6a32867fa70f695cd39c4e87e142b9e4134d38740bd6fee354a575167e' +
145147
'13524e94832637910fe11e53a85fb21b91adb81bb1779c4e2b8bc87c717dc35084',
146148
'hex'),
147-
...(!process.features.openssl_is_boringssl ? {
149+
...(!isBoringSSL() ? {
148150
'SHA3-256': Buffer.from(
149151
'00463679f47a4c705e03447360dcf34d1743e0d4b2591cc66832a6bc80d92e538c' +
150152
'169a1fd330f98e7235ca7fec7e16ac44fb13095b8edf2c76b75c4845177d59e425' +
@@ -170,7 +172,7 @@ module.exports = function() {
170172
const curves = ['P-256', 'P-384', 'P-521'];
171173
const hashes = ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512'];
172174

173-
if (!process.features.openssl_is_boringssl) {
175+
if (!isBoringSSL()) {
174176
hashes.push('SHA3-256', 'SHA3-384', 'SHA3-512');
175177
}
176178

test/fixtures/crypto/eddsa.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { isBoringSSL } = require('../../common/crypto');
4+
35
const common = require('../../common');
46

57
module.exports = function() {
@@ -46,7 +48,7 @@ module.exports = function() {
4648
const algorithms = ['Ed25519'];
4749
const contexts = [new Uint8Array(0), new Uint8Array(32), new Uint8Array(255)];
4850

49-
if (!process.features.openssl_is_boringssl) {
51+
if (!isBoringSSL()) {
5052
algorithms.push('Ed448')
5153
} else {
5254
common.printSkipMessage(`Skipping unsupported Ed448 test cases`);

test/fixtures/crypto/hmac.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { isBoringSSL } = require('../../common/crypto');
4+
35
module.exports = function () {
46
const plaintext = Buffer.from(
57
'5f4dba4f320c0ce876725afce5fbd25bf83e5a7125a08cafe73c3ebac421779df9d55d' +
@@ -22,7 +24,7 @@ module.exports = function () {
2224
'5dcc359443aaf652fa1375d6b3e61fdcf29bb4a28bd5d3dcfa40f82f906bb280' +
2325
'0455db03b5d31fb972a15a6d0103a24e56d156a119c0e5a1e92a44c3c5657cf9',
2426
'hex'),
25-
...(!process.features.openssl_is_boringssl ? {
27+
...(!isBoringSSL() ? {
2628
'SHA3-256': Buffer.from(
2729
'e588ec0811463d767241df1074b47ae4071b51f2ce36537ba69ccdc3fdc2b7a8',
2830
'hex'),
@@ -48,7 +50,7 @@ module.exports = function () {
4850
'61fb278c3ffb0cce2bf1cf723ddfd8ef1f931c0c618c25907324605939e3f9a2' +
4951
'c6f4af690bda3407dc2f5770f6a0a44b954d64a332e3ee0821abf82b7f3e99c1',
5052
'hex'),
51-
...(!process.features.openssl_is_boringssl ? {
53+
...(!isBoringSSL() ? {
5254
'SHA3-256': Buffer.from(
5355
'c1ac5e11fcd50c48bf567f6e296632f5801c4eb07a8a47579b41dee971a3099b',
5456
'hex'),

0 commit comments

Comments
 (0)