GeezerVison is showing github.com — crypto: subject some algorithms in Web Cryptography on BoringSSL absence · nodejs/node@a95386f
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: lib/internal/crypto/util.js +54-36Lines changed: 54 additions & 36 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -187,7 +187,6 @@ const kSupportedAlgorithms = { | 187 | 187 | 'AES-CTR': 'AesKeyGenParams', | 188 | 188 | 'AES-CBC': 'AesKeyGenParams', | 189 | 189 | 'AES-GCM': 'AesKeyGenParams', | 190 | | - 'AES-KW': 'AesKeyGenParams', | 191 | 190 | 'HMAC': 'HmacKeyGenParams', | 192 | 191 | 'Ed25519': null, | 193 | 192 | 'X25519': null, | @@ -202,7 +201,6 @@ const kSupportedAlgorithms = { | 202 | 201 | 'AES-CTR': null, | 203 | 202 | 'AES-CBC': null, | 204 | 203 | 'AES-GCM': null, | 205 | | - 'AES-KW': null, | 206 | 204 | 'Ed25519': null, | 207 | 205 | 'X25519': null, | 208 | 206 | }, | @@ -232,7 +230,6 @@ const kSupportedAlgorithms = { | 232 | 230 | 'AES-CTR': null, | 233 | 231 | 'AES-CBC': null, | 234 | 232 | 'AES-GCM': null, | 235 | | - 'AES-KW': null, | 236 | 233 | 'Ed25519': null, | 237 | 234 | 'X25519': null, | 238 | 235 | }, | @@ -258,48 +255,69 @@ const kSupportedAlgorithms = { | 258 | 255 | 'AES-CBC': 'AesDerivedKeyParams', | 259 | 256 | 'AES-CTR': 'AesDerivedKeyParams', | 260 | 257 | 'AES-GCM': 'AesDerivedKeyParams', | 261 | | - 'AES-KW': 'AesDerivedKeyParams', | 262 | 258 | 'HMAC': 'HmacImportParams', | 263 | 259 | 'HKDF': null, | 264 | 260 | 'PBKDF2': null, | 265 | 261 | }, | 266 | | - 'wrapKey': { | 267 | | - 'AES-KW': null, | 268 | | - }, | 269 | | - 'unwrapKey': { | 270 | | - 'AES-KW': null, | 271 | | - }, | | 262 | + 'wrapKey': {}, | | 263 | + 'unwrapKey': {}, | 272 | 264 | }; | 273 | 265 |
| 274 | | -const experimentalAlgorithms = ObjectEntries({ | 275 | | - 'X448': { | 276 | | - generateKey: null, | 277 | | - importKey: null, | 278 | | - deriveBits: 'EcdhKeyDeriveParams', | 279 | | - exportKey: null, | 280 | | - }, | 281 | | - 'Ed448': { | 282 | | - generateKey: null, | 283 | | - sign: 'Ed448Params', | 284 | | - verify: 'Ed448Params', | 285 | | - importKey: null, | 286 | | - exportKey: null, | 287 | | - }, | 288 | | - 'cSHAKE128': { digest: 'CShakeParams' }, | 289 | | - 'cSHAKE256': { digest: 'CShakeParams' }, | 290 | | - 'SHA3-256': { digest: null }, | 291 | | - 'SHA3-384': { digest: null }, | 292 | | - 'SHA3-512': { digest: null }, | 293 | | - 'ChaCha20-Poly1305': { | 294 | | - 'encrypt': 'AeadParams', | 295 | | - 'decrypt': 'AeadParams', | 296 | | - 'generateKey': null, | 297 | | - 'importKey': null, | | 266 | +const conditionalAlgorithms = ObjectEntries({ | | 267 | + 'AES-KW': [{ | | 268 | + 'generateKey': 'AesKeyGenParams', | 298 | 269 | 'exportKey': null, | 299 | | - 'get key length': null, | 300 | | - }, | | 270 | + 'importKey': null, | | 271 | + 'get key length': 'AesDerivedKeyParams', | | 272 | + 'wrapKey': null, | | 273 | + 'unwrapKey': null, | | 274 | + }, !process.features.openssl_is_boringssl], | 301 | 275 | }); | 302 | 276 |
| | 277 | +for (let i = 0; i < conditionalAlgorithms.length; i++) { | | 278 | + if (conditionalAlgorithms[i][1][1]) { | | 279 | + const name = conditionalAlgorithms[i][0]; | | 280 | + const ops = ObjectEntries(conditionalAlgorithms[i][1][0]); | | 281 | + for (let j = 0; j < ops.length; j++) { | | 282 | + const { 0: op, 1: dict } = ops[j]; | | 283 | + kSupportedAlgorithms[op][name] = dict; | | 284 | + } | | 285 | + } | | 286 | +} | | 287 | + | | 288 | +const experimentalAlgorithms = ObjectEntries({}); | | 289 | + | | 290 | +if (!process.features.openssl_is_boringssl) { | | 291 | + ArrayPrototypePush(experimentalAlgorithms, | | 292 | + ['Ed448', { | | 293 | + generateKey: null, | | 294 | + sign: 'Ed448Params', | | 295 | + verify: 'Ed448Params', | | 296 | + importKey: null, | | 297 | + exportKey: null, | | 298 | + }], | | 299 | + ['X448', { | | 300 | + generateKey: null, | | 301 | + importKey: null, | | 302 | + deriveBits: 'EcdhKeyDeriveParams', | | 303 | + exportKey: null, | | 304 | + }], | | 305 | + ['cSHAKE128', { digest: 'CShakeParams' }], | | 306 | + ['cSHAKE256', { digest: 'CShakeParams' }], | | 307 | + ['ChaCha20-Poly1305', { | | 308 | + 'encrypt': 'AeadParams', | | 309 | + 'decrypt': 'AeadParams', | | 310 | + 'generateKey': null, | | 311 | + 'importKey': null, | | 312 | + 'exportKey': null, | | 313 | + 'get key length': null, | | 314 | + }], | | 315 | + ['SHA3-256', { digest: null }], | | 316 | + ['SHA3-384', { digest: null }], | | 317 | + ['SHA3-512', { digest: null }], | | 318 | + ); | | 319 | +} | | 320 | + | 303 | 321 | for (const { 0: algorithm, 1: nid } of [ | 304 | 322 | ['ML-DSA-44', EVP_PKEY_ML_DSA_44], | 305 | 323 | ['ML-DSA-65', EVP_PKEY_ML_DSA_65], | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/crypto/eddsa.js +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| | 3 | +const common = require('../../common'); | | 4 | + | 3 | 5 | module.exports = function() { | 4 | 6 | const pkcs8 = { | 5 | 7 | 'Ed25519': Buffer.from( | @@ -37,7 +39,13 @@ module.exports = function() { | 37 | 39 | '025a2a5a572b9d23b0642f00', 'hex') | 38 | 40 | } | 39 | 41 |
| 40 | | - const algorithms = ['Ed25519', 'Ed448']; | | 42 | + const algorithms = ['Ed25519']; | | 43 | + | | 44 | + if (!process.features.openssl_is_boringssl) { | | 45 | + algorithms.push('Ed448') | | 46 | + } else { | | 47 | + common.printSkipMessage(`Skipping unsupported Ed448 test cases`); | | 48 | + } | 41 | 49 |
| 42 | 50 | const vectors = algorithms.map((algorithm) => ({ | 43 | 51 | publicKeyBuffer: spki[algorithm], | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/webcrypto/supports-level-2.mjs +8-6Lines changed: 8 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,8 @@ const [ECDH, X448, X25519] = await Promise.all([ | 11 | 11 | subtle.generateKey('X25519', false, ['deriveBits', 'deriveKey']), | 12 | 12 | ]); | 13 | 13 |
| | 14 | +const boringSSL = process.features.openssl_is_boringssl; | | 15 | + | 14 | 16 | export const vectors = { | 15 | 17 | 'encrypt': [ | 16 | 18 | [false, 'Invalid'], | @@ -79,7 +81,7 @@ export const vectors = { | 79 | 81 | [false, { name: 'AES-CBC', length: 25 }], | 80 | 82 | [true, { name: 'AES-GCM', length: 128 }], | 81 | 83 | [false, { name: 'AES-GCM', length: 25 }], | 82 | | - [true, { name: 'AES-KW', length: 128 }], | | 84 | + [!boringSSL, { name: 'AES-KW', length: 128 }], | 83 | 85 | [false, { name: 'AES-KW', length: 25 }], | 84 | 86 | [true, { name: 'HMAC', hash: 'SHA-256' }], | 85 | 87 | [true, { name: 'HMAC', hash: 'SHA-256', length: 256 }], | @@ -189,7 +191,7 @@ export const vectors = { | 189 | 191 | [true, 'AES-CTR'], | 190 | 192 | [true, 'AES-CBC'], | 191 | 193 | [true, 'AES-GCM'], | 192 | | - [true, 'AES-KW'], | | 194 | + [!boringSSL, 'AES-KW'], | 193 | 195 | [true, { name: 'HMAC', hash: 'SHA-256' }], | 194 | 196 | [true, { name: 'HMAC', hash: 'SHA-256', length: 256 }], | 195 | 197 | [false, { name: 'HMAC', hash: 'SHA-256', length: 25 }], | @@ -211,18 +213,18 @@ export const vectors = { | 211 | 213 | [true, 'AES-CTR'], | 212 | 214 | [true, 'AES-CBC'], | 213 | 215 | [true, 'AES-GCM'], | 214 | | - [true, 'AES-KW'], | | 216 | + [!boringSSL, 'AES-KW'], | 215 | 217 | [true, 'Ed25519'], | 216 | 218 | [true, 'X25519'], | 217 | 219 | ], | 218 | 220 | 'wrapKey': [ | 219 | 221 | [false, 'AES-KW'], | 220 | | - [true, 'AES-KW', 'AES-CTR'], | 221 | | - [true, 'AES-KW', 'HMAC'], | | 222 | + [!boringSSL, 'AES-KW', 'AES-CTR'], | | 223 | + [!boringSSL, 'AES-KW', 'HMAC'], | 222 | 224 | ], | 223 | 225 | 'unwrapKey': [ | 224 | 226 | [false, 'AES-KW'], | 225 | | - [true, 'AES-KW', 'AES-CTR'], | | 227 | + [!boringSSL, 'AES-KW', 'AES-CTR'], | 226 | 228 | ], | 227 | 229 | 'unsupported operation': [ | 228 | 230 | [false, ''], | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/webcrypto/supports-modern-algorithms.mjs +24-5Lines changed: 24 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import * as crypto from 'node:crypto' | | 2 | + | 1 | 3 | import { hasOpenSSL } from '../../common/crypto.js' | 2 | 4 |
| 3 | 5 | const pqc = hasOpenSSL(3, 5); | | 6 | +const shake128 = crypto.getHashes().includes('shake128'); | | 7 | +const shake256 = crypto.getHashes().includes('shake256'); | | 8 | +const chacha = crypto.getCiphers().includes('chacha20-poly1305'); | 4 | 9 |
| 5 | 10 | export const vectors = { | | 11 | + 'digest': [ | | 12 | + [false, 'cSHAKE128'], | | 13 | + [shake128, { name: 'cSHAKE128', length: 128 }], | | 14 | + [shake128, { name: 'cSHAKE128', length: 128, functionName: Buffer.alloc(0), customization: Buffer.alloc(0) }], | | 15 | + [false, { name: 'cSHAKE128', length: 128, functionName: Buffer.alloc(1) }], | | 16 | + [false, { name: 'cSHAKE128', length: 128, customization: Buffer.alloc(1) }], | | 17 | + [false, { name: 'cSHAKE128', length: 127 }], | | 18 | + [false, 'cSHAKE256'], | | 19 | + [shake256, { name: 'cSHAKE256', length: 256 }], | | 20 | + [shake256, { name: 'cSHAKE256', length: 256, functionName: Buffer.alloc(0), customization: Buffer.alloc(0) }], | | 21 | + [false, { name: 'cSHAKE256', length: 256, functionName: Buffer.alloc(1) }], | | 22 | + [false, { name: 'cSHAKE256', length: 256, customization: Buffer.alloc(1) }], | | 23 | + [false, { name: 'cSHAKE256', length: 255 }], | | 24 | + ], | 6 | 25 | 'sign': [ | 7 | 26 | [pqc, 'ML-DSA-44'], | 8 | 27 | [pqc, 'ML-DSA-65'], | @@ -12,19 +31,19 @@ export const vectors = { | 12 | 31 | [pqc, 'ML-DSA-44'], | 13 | 32 | [pqc, 'ML-DSA-65'], | 14 | 33 | [pqc, 'ML-DSA-87'], | 15 | | - [true, 'ChaCha20-Poly1305'], | | 34 | + [chacha, 'ChaCha20-Poly1305'], | 16 | 35 | ], | 17 | 36 | 'importKey': [ | 18 | 37 | [pqc, 'ML-DSA-44'], | 19 | 38 | [pqc, 'ML-DSA-65'], | 20 | 39 | [pqc, 'ML-DSA-87'], | 21 | | - [true, 'ChaCha20-Poly1305'], | | 40 | + [chacha, 'ChaCha20-Poly1305'], | 22 | 41 | ], | 23 | 42 | 'exportKey': [ | 24 | 43 | [pqc, 'ML-DSA-44'], | 25 | 44 | [pqc, 'ML-DSA-65'], | 26 | 45 | [pqc, 'ML-DSA-87'], | 27 | | - [true, 'ChaCha20-Poly1305'], | | 46 | + [chacha, 'ChaCha20-Poly1305'], | 28 | 47 | ], | 29 | 48 | 'getPublicKey': [ | 30 | 49 | [true, 'RSA-OAEP'], | @@ -44,9 +63,9 @@ export const vectors = { | 44 | 63 | [false, 'ChaCha20-Poly1305'], | 45 | 64 | ], | 46 | 65 | 'encrypt': [ | 47 | | - [true, { name: 'ChaCha20-Poly1305', iv: Buffer.alloc(12) }], | | 66 | + [chacha, { name: 'ChaCha20-Poly1305', iv: Buffer.alloc(12) }], | 48 | 67 | [false, { name: 'ChaCha20-Poly1305', iv: Buffer.alloc(16) }], | 49 | | - [true, { name: 'ChaCha20-Poly1305', iv: Buffer.alloc(12), tagLength: 128 }], | | 68 | + [chacha, { name: 'ChaCha20-Poly1305', iv: Buffer.alloc(12), tagLength: 128 }], | 50 | 69 | [false, { name: 'ChaCha20-Poly1305', iv: Buffer.alloc(12), tagLength: 64 }], | 51 | 70 | [false, 'ChaCha20-Poly1305'], | 52 | 71 | ] | |
Collapse file Copy file name to clipboard +21-18Lines changed: 21 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | const { subtle } = globalThis.crypto; | 2 | 2 |
| 3 | | -const [X448, X25519] = await Promise.all([ | 4 | | - subtle.generateKey('X448', false, ['deriveBits', 'deriveKey']), | 5 | | - subtle.generateKey('X25519', false, ['deriveBits', 'deriveKey']), | 6 | | -]); | | 3 | +const boringSSL = process.features.openssl_is_boringssl; | | 4 | + | | 5 | +const X25519 = await subtle.generateKey('X25519', false, ['deriveBits', 'deriveKey']); | | 6 | +let X448; | | 7 | +if (!boringSSL) { | | 8 | + X448 = await subtle.generateKey('X448', false, ['deriveBits', 'deriveKey']) | | 9 | +} | 7 | 10 |
| 8 | 11 | export const vectors = { | 9 | 12 | 'generateKey': [ | 10 | | - [true, 'X448'], | 11 | | - [true, 'Ed448'], | | 13 | + [!boringSSL, 'X448'], | | 14 | + [!boringSSL, 'Ed448'], | 12 | 15 | ], | 13 | 16 | 'deriveKey': [ | 14 | | - [true, | 15 | | - { name: 'X448', public: X448.publicKey }, | | 17 | + [!boringSSL, | | 18 | + { name: 'X448', public: X448?.publicKey }, | 16 | 19 | { name: 'AES-CBC', length: 128 }], | 17 | | - [true, | 18 | | - { name: 'X448', public: X448.publicKey }, | | 20 | + [!boringSSL, | | 21 | + { name: 'X448', public: X448?.publicKey }, | 19 | 22 | { name: 'HMAC', hash: 'SHA-256' }], | 20 | | - [true, | 21 | | - { name: 'X448', public: X448.publicKey }, | | 23 | + [!boringSSL, | | 24 | + { name: 'X448', public: X448?.publicKey }, | 22 | 25 | 'HKDF'], | 23 | 26 | ], | 24 | 27 | 'deriveBits': [ | 25 | | - [true, { name: 'X448', public: X448.publicKey }], | | 28 | + [!boringSSL, { name: 'X448', public: X448?.publicKey }], | 26 | 29 | [false, { name: 'X448', public: X25519.publicKey }], | 27 | | - [false, { name: 'X448', public: X448.privateKey }], | | 30 | + [false, { name: 'X448', public: X448?.privateKey }], | 28 | 31 | [false, 'X448'], | 29 | 32 | ], | 30 | 33 | 'importKey': [ | 31 | | - [true, 'X448'], | 32 | | - [true, 'Ed448'], | | 34 | + [!boringSSL, 'X448'], | | 35 | + [!boringSSL, 'Ed448'], | 33 | 36 | ], | 34 | 37 | 'exportKey': [ | 35 | | - [true, 'Ed448'], | 36 | | - [true, 'X448'], | | 38 | + [!boringSSL, 'Ed448'], | | 39 | + [!boringSSL, 'X448'], | 37 | 40 | ], | 38 | 41 | }; |
|