GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto: wire up SLH-DSA with BoringSSL · nodejs/node@89aba56

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • deps/ncrypto
    • ncrypto.cc
  • test
    • parallel
      • test-crypto-pqc-key-objects-slh-dsa.js
      • test-crypto-pqc-keygen-slh-dsa.js
    • pummel
      • test-crypto-pqc-sign-verify-slh-dsa.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎deps/ncrypto/ncrypto.cc‎

Copy file name to clipboardExpand all lines: deps/ncrypto/ncrypto.cc
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,6 +3607,8 @@ const BoringSSLKeyAlgorithm kBoringSSLKeyAlgorithms[] = {
36073607
{KeyAlgorithm::ML_DSA_87.name(), EVP_PKEY_ML_DSA_87, EVP_pkey_ml_dsa_87},
36083608
{KeyAlgorithm::ML_KEM_768.name(), EVP_PKEY_ML_KEM_768, EVP_pkey_ml_kem_768},
36093609
{KeyAlgorithm::ML_KEM_1024.name(), EVP_PKEY_ML_KEM_1024, EVP_pkey_ml_kem_1024},
3610+
{KeyAlgorithm::SLH_DSA_SHA2_128S.name(), EVP_PKEY_SLH_DSA_SHA2_128S, EVP_pkey_slh_dsa_sha2_128s},
3611+
{KeyAlgorithm::SLH_DSA_SHAKE_256F.name(), EVP_PKEY_SLH_DSA_SHAKE_256F, EVP_pkey_slh_dsa_shake_256f},
36103612
};
36113613
// NOLINTEND(whitespace/line_length)
36123614
// clang-format on
Collapse file

‎test/parallel/test-crypto-pqc-key-objects-slh-dsa.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-pqc-key-objects-slh-dsa.js
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,21 @@ for (const asymmetricKeyType of [
107107
assert.throws(() => createPrivateKey(keys.private), {
108108
code: isBoringSSL ? 'ERR_OSSL_EVP_UNSUPPORTED_ALGORITHM' : 'ERR_OSSL_UNSUPPORTED',
109109
});
110-
} else {
111-
const publicKey = createPublicKey(keys.public);
110+
}
111+
112+
const supported = hasOpenSSL(3, 5) ||
113+
(isBoringSSL && (asymmetricKeyType === 'slh-dsa-sha2-128s' ||
114+
asymmetricKeyType === 'slh-dsa-shake-256f'));
115+
if (supported) {
116+
const publicKey = createPublicKey(isBoringSSL ?
117+
{ format: 'jwk', key: keys.jwk } : keys.public);
118+
const privateKey = createPrivateKey(isBoringSSL ?
119+
{ format: 'jwk', key: keys.jwk } : keys.private);
112120
assertPublicKey(publicKey);
113121

114-
const pubFromPriv = createPublicKey(keys.private);
122+
const pubFromPriv = createPublicKey(isBoringSSL ? privateKey : keys.private);
115123
assertPublicKey(pubFromPriv);
116-
assertPrivateKey(createPrivateKey(keys.private));
124+
assertPrivateKey(privateKey);
117125
assert.strictEqual(pubFromPriv.equals(publicKey), true);
118126

119127
// JWK import error tests
Collapse file

‎test/parallel/test-crypto-pqc-keygen-slh-dsa.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-pqc-keygen-slh-dsa.js
+11-15Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,27 @@ const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
66

7-
const { hasOpenSSL } = require('../common/crypto');
7+
const { hasOpenSSL, isBoringSSL } = require('../common/crypto');
88

99
const assert = require('assert');
1010
const {
1111
generateKeyPair,
1212
} = require('crypto');
1313

14-
if (!hasOpenSSL(3, 5)) {
15-
for (const asymmetricKeyType of [
16-
'slh-dsa-sha2-128f', 'slh-dsa-sha2-128s', 'slh-dsa-sha2-192f', 'slh-dsa-sha2-192s',
17-
'slh-dsa-sha2-256f', 'slh-dsa-sha2-256s', 'slh-dsa-shake-128f', 'slh-dsa-shake-128s',
18-
'slh-dsa-shake-192f', 'slh-dsa-shake-192s', 'slh-dsa-shake-256f', 'slh-dsa-shake-256s',
19-
]) {
14+
for (const asymmetricKeyType of [
15+
'slh-dsa-sha2-128f', 'slh-dsa-sha2-128s', 'slh-dsa-sha2-192f', 'slh-dsa-sha2-192s',
16+
'slh-dsa-sha2-256f', 'slh-dsa-sha2-256s', 'slh-dsa-shake-128f', 'slh-dsa-shake-128s',
17+
'slh-dsa-shake-192f', 'slh-dsa-shake-192s', 'slh-dsa-shake-256f', 'slh-dsa-shake-256s',
18+
]) {
19+
const supported = hasOpenSSL(3, 5) ||
20+
(isBoringSSL && (asymmetricKeyType === 'slh-dsa-sha2-128s' ||
21+
asymmetricKeyType === 'slh-dsa-shake-256f'));
22+
if (!supported) {
2023
assert.throws(() => generateKeyPair(asymmetricKeyType, common.mustNotCall()), {
2124
code: 'ERR_INVALID_ARG_VALUE',
2225
message: /The argument 'type' must be a supported key type/
2326
});
24-
}
25-
} else {
26-
for (const asymmetricKeyType of [
27-
'slh-dsa-sha2-128f', 'slh-dsa-sha2-128s', 'slh-dsa-sha2-192f', 'slh-dsa-sha2-192s',
28-
'slh-dsa-sha2-256f', 'slh-dsa-sha2-256s', 'slh-dsa-shake-128f', 'slh-dsa-shake-128s',
29-
'slh-dsa-shake-192f', 'slh-dsa-shake-192s', 'slh-dsa-shake-256f', 'slh-dsa-shake-256s',
30-
]) {
31-
27+
} else {
3228
function assertJwk(jwk) {
3329
assert.strictEqual(jwk.kty, 'AKP');
3430
// SLH-DSA algorithm names keep the last character (f/s) lowercase.
Collapse file

‎test/pummel/test-crypto-pqc-sign-verify-slh-dsa.mjs‎

Copy file name to clipboardExpand all lines: test/pummel/test-crypto-pqc-sign-verify-slh-dsa.mjs
+18-6Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import * as common from '../common/index.mjs';
33
if (!common.hasCrypto)
44
common.skip('missing crypto');
55

6-
import { hasOpenSSL } from '../common/crypto.js';
6+
import { hasOpenSSL, isBoringSSL } from '../common/crypto.js';
77

8-
if (!hasOpenSSL(3, 5))
9-
common.skip('requires OpenSSL >= 3.5');
8+
if (!hasOpenSSL(3, 5) && !isBoringSSL)
9+
common.skip('requires OpenSSL >= 3.5 or BoringSSL');
1010

1111
import * as assert from 'node:assert';
1212
import { promisify } from 'node:util';
13-
import { randomBytes, sign, verify } from 'node:crypto';
13+
import { createPrivateKey, createPublicKey, randomBytes, sign, verify } from 'node:crypto';
1414
import fixtures from '../common/fixtures.js';
1515

1616
const pSign = promisify(sign);
@@ -34,10 +34,20 @@ for (const [asymmetricKeyType, sigLen] of [
3434
['slh-dsa-shake-256f', 49856],
3535
['slh-dsa-shake-256s', 29792],
3636
]) {
37+
if (isBoringSSL && asymmetricKeyType !== 'slh-dsa-sha2-128s' &&
38+
asymmetricKeyType !== 'slh-dsa-shake-256f') {
39+
common.printSkipMessage(`Skipping unsupported ${asymmetricKeyType}`);
40+
continue;
41+
}
3742
const keys = {
3843
public: fixtures.readKey(getKeyFileName(asymmetricKeyType, 'public'), 'ascii'),
3944
private: fixtures.readKey(getKeyFileName(asymmetricKeyType, 'private'), 'ascii'),
4045
};
46+
if (isBoringSSL) {
47+
const jwk = JSON.parse(fixtures.readKey(`${asymmetricKeyType}.json`));
48+
keys.public = createPublicKey({ format: 'jwk', key: jwk });
49+
keys.private = createPrivateKey({ format: 'jwk', key: jwk });
50+
}
4151

4252
const data = randomBytes(32);
4353
// Start the async signature before the sync work to overlap the two.
@@ -59,8 +69,10 @@ for (const [asymmetricKeyType, sigLen] of [
5969
assert.strictEqual(await pVerify(undefined, data, keys.public, signature), true);
6070
}
6171

62-
assert.throws(() => sign('sha256', data, keys.private), { code: 'ERR_OSSL_INVALID_DIGEST' });
72+
const code = isBoringSSL ?
73+
'ERR_OSSL_EVP_COMMAND_NOT_SUPPORTED' : 'ERR_OSSL_INVALID_DIGEST';
74+
assert.throws(() => sign('sha256', data, keys.private), { code });
6375
assert.throws(
6476
() => verify('sha256', data, keys.public, Buffer.alloc(sigLen)),
65-
{ code: 'ERR_OSSL_INVALID_DIGEST' });
77+
{ code });
6678
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.