GeezerVison is showing github.com — crypto: wire up SLH-DSA with BoringSSL · nodejs/node@89aba56
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: deps/ncrypto/ncrypto.cc +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3607,6 +3607,8 @@ const BoringSSLKeyAlgorithm kBoringSSLKeyAlgorithms[] = { | 3607 | 3607 | {KeyAlgorithm::ML_DSA_87.name(), EVP_PKEY_ML_DSA_87, EVP_pkey_ml_dsa_87}, | 3608 | 3608 | {KeyAlgorithm::ML_KEM_768.name(), EVP_PKEY_ML_KEM_768, EVP_pkey_ml_kem_768}, | 3609 | 3609 | {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}, | 3610 | 3612 | }; | 3611 | 3613 | // NOLINTEND(whitespace/line_length) | 3612 | 3614 | // clang-format on | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -107,13 +107,21 @@ for (const asymmetricKeyType of [ | 107 | 107 | assert.throws(() => createPrivateKey(keys.private), { | 108 | 108 | code: isBoringSSL ? 'ERR_OSSL_EVP_UNSUPPORTED_ALGORITHM' : 'ERR_OSSL_UNSUPPORTED', | 109 | 109 | }); | 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); | 112 | 120 | assertPublicKey(publicKey); | 113 | 121 |
| 114 | | - const pubFromPriv = createPublicKey(keys.private); | | 122 | + const pubFromPriv = createPublicKey(isBoringSSL ? privateKey : keys.private); | 115 | 123 | assertPublicKey(pubFromPriv); | 116 | | - assertPrivateKey(createPrivateKey(keys.private)); | | 124 | + assertPrivateKey(privateKey); | 117 | 125 | assert.strictEqual(pubFromPriv.equals(publicKey), true); | 118 | 126 |
| 119 | 127 | // JWK import error tests | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -4,31 +4,27 @@ const common = require('../common'); | 4 | 4 | if (!common.hasCrypto) | 5 | 5 | common.skip('missing crypto'); | 6 | 6 |
| 7 | | -const { hasOpenSSL } = require('../common/crypto'); | | 7 | +const { hasOpenSSL, isBoringSSL } = require('../common/crypto'); | 8 | 8 |
| 9 | 9 | const assert = require('assert'); | 10 | 10 | const { | 11 | 11 | generateKeyPair, | 12 | 12 | } = require('crypto'); | 13 | 13 |
| 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) { | 20 | 23 | assert.throws(() => generateKeyPair(asymmetricKeyType, common.mustNotCall()), { | 21 | 24 | code: 'ERR_INVALID_ARG_VALUE', | 22 | 25 | message: /The argument 'type' must be a supported key type/ | 23 | 26 | }); | 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 { | 32 | 28 | function assertJwk(jwk) { | 33 | 29 | assert.strictEqual(jwk.kty, 'AKP'); | 34 | 30 | // SLH-DSA algorithm names keep the last character (f/s) lowercase. | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -3,14 +3,14 @@ import * as common from '../common/index.mjs'; | 3 | 3 | if (!common.hasCrypto) | 4 | 4 | common.skip('missing crypto'); | 5 | 5 |
| 6 | | -import { hasOpenSSL } from '../common/crypto.js'; | | 6 | +import { hasOpenSSL, isBoringSSL } from '../common/crypto.js'; | 7 | 7 |
| 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'); | 10 | 10 |
| 11 | 11 | import * as assert from 'node:assert'; | 12 | 12 | import { promisify } from 'node:util'; | 13 | | -import { randomBytes, sign, verify } from 'node:crypto'; | | 13 | +import { createPrivateKey, createPublicKey, randomBytes, sign, verify } from 'node:crypto'; | 14 | 14 | import fixtures from '../common/fixtures.js'; | 15 | 15 |
| 16 | 16 | const pSign = promisify(sign); | @@ -34,10 +34,20 @@ for (const [asymmetricKeyType, sigLen] of [ | 34 | 34 | ['slh-dsa-shake-256f', 49856], | 35 | 35 | ['slh-dsa-shake-256s', 29792], | 36 | 36 | ]) { | | 37 | + if (isBoringSSL && asymmetricKeyType !== 'slh-dsa-sha2-128s' && | | 38 | + asymmetricKeyType !== 'slh-dsa-shake-256f') { | | 39 | + common.printSkipMessage(`Skipping unsupported ${asymmetricKeyType}`); | | 40 | + continue; | | 41 | + } | 37 | 42 | const keys = { | 38 | 43 | public: fixtures.readKey(getKeyFileName(asymmetricKeyType, 'public'), 'ascii'), | 39 | 44 | private: fixtures.readKey(getKeyFileName(asymmetricKeyType, 'private'), 'ascii'), | 40 | 45 | }; | | 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 | + } | 41 | 51 |
| 42 | 52 | const data = randomBytes(32); | 43 | 53 | // Start the async signature before the sync work to overlap the two. | @@ -59,8 +69,10 @@ for (const [asymmetricKeyType, sigLen] of [ | 59 | 69 | assert.strictEqual(await pVerify(undefined, data, keys.public, signature), true); | 60 | 70 | } | 61 | 71 |
| 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 }); | 63 | 75 | assert.throws( | 64 | 76 | () => verify('sha256', data, keys.public, Buffer.alloc(sigLen)), | 65 | | - { code: 'ERR_OSSL_INVALID_DIGEST' }); | | 77 | + { code }); | 66 | 78 | } |
|