GeezerVison is showing github.com — test: update WPT for WebCryptoAPI to 55ce71bb9d · nodejs/node@7874489
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: test/fixtures/wpt/WebCryptoAPI/encap_decap/encap_decap_bits.tentative.https.any.js +16-19Lines changed: 16 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -// META: title=WebCryptoAPI: ML-KEM encapsulateBits() and decapsulateBits() tests | 2 | | -// META: script=ml_kem_vectors.js | | 1 | +// META: title=WebCryptoAPI: KEM encapsulateBits() and decapsulateBits() tests | 3 | 2 | // META: script=../util/helpers.js | | 3 | +// META: script=ml_kem_vectors.js | | 4 | +// META: script=hybrid_kem_vectors.js | 4 | 5 | // META: timeout=long | 5 | 6 |
| 6 | 7 | function define_bits_tests() { | 7 | 8 | var subtle = self.crypto.subtle; | 8 | | - var variants = ['ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024']; | | 9 | + var variants = [ | | 10 | + { name: 'ML-KEM-512', ciphertextLength: 768 }, | | 11 | + { name: 'ML-KEM-768', ciphertextLength: 1088 }, | | 12 | + { name: 'ML-KEM-1024', ciphertextLength: 1568 }, | | 13 | + { name: 'MLKEM768-P256', ciphertextLength: 1153 }, | | 14 | + { name: 'MLKEM768-X25519', ciphertextLength: 1120 }, | | 15 | + { name: 'MLKEM1024-P384', ciphertextLength: 1665 }, | | 16 | + ]; | | 17 | + | | 18 | + variants.forEach(function (variant) { | | 19 | + var algorithmName = variant.name; | 9 | 20 |
| 10 | | - variants.forEach(function (algorithmName) { | 11 | 21 | // Test encapsulateBits operation | 12 | 22 | promise_test(async function (test) { | 13 | 23 | // Generate a key pair for testing | @@ -50,24 +60,11 @@ function define_bits_tests() { | 50 | 60 | 'Shared key should be 32 bytes' | 51 | 61 | ); | 52 | 62 |
| 53 | | - // Verify ciphertext length based on algorithm variant | 54 | | - var expectedCiphertextLength; | 55 | | - switch (algorithmName) { | 56 | | - case 'ML-KEM-512': | 57 | | - expectedCiphertextLength = 768; | 58 | | - break; | 59 | | - case 'ML-KEM-768': | 60 | | - expectedCiphertextLength = 1088; | 61 | | - break; | 62 | | - case 'ML-KEM-1024': | 63 | | - expectedCiphertextLength = 1568; | 64 | | - break; | 65 | | - } | 66 | 63 | assert_equals( | 67 | 64 | encapsulatedBits.ciphertext.byteLength, | 68 | | - expectedCiphertextLength, | | 65 | + variant.ciphertextLength, | 69 | 66 | 'Ciphertext should be ' + | 70 | | - expectedCiphertextLength + | | 67 | + variant.ciphertextLength + | 71 | 68 | ' bytes for ' + | 72 | 69 | algorithmName | 73 | 70 | ); | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/encap_decap/encap_decap_keys.tentative.https.any.js +16-19Lines changed: 16 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -// META: title=WebCryptoAPI: ML-KEM encapsulateKey() and decapsulateKey() tests | 2 | | -// META: script=ml_kem_vectors.js | | 1 | +// META: title=WebCryptoAPI: KEM encapsulateKey() and decapsulateKey() tests | 3 | 2 | // META: script=../util/helpers.js | | 3 | +// META: script=ml_kem_vectors.js | | 4 | +// META: script=hybrid_kem_vectors.js | 4 | 5 | // META: timeout=long | 5 | 6 |
| 6 | 7 | function define_key_tests() { | 7 | 8 | var subtle = self.crypto.subtle; | 8 | | - var variants = ['ML-KEM-512', 'ML-KEM-768', 'ML-KEM-1024']; | | 9 | + var variants = [ | | 10 | + { name: 'ML-KEM-512', ciphertextLength: 768 }, | | 11 | + { name: 'ML-KEM-768', ciphertextLength: 1088 }, | | 12 | + { name: 'ML-KEM-1024', ciphertextLength: 1568 }, | | 13 | + { name: 'MLKEM768-P256', ciphertextLength: 1153 }, | | 14 | + { name: 'MLKEM768-X25519', ciphertextLength: 1120 }, | | 15 | + { name: 'MLKEM1024-P384', ciphertextLength: 1665 }, | | 16 | + ]; | 9 | 17 |
| 10 | 18 | // Test various 256-bit shared key algorithms | 11 | 19 | var sharedKeyConfigs = [ | @@ -36,7 +44,9 @@ function define_key_tests() { | 36 | 44 | }, | 37 | 45 | ]; | 38 | 46 |
| 39 | | - variants.forEach(function (algorithmName) { | | 47 | + variants.forEach(function (variant) { | | 48 | + var algorithmName = variant.name; | | 49 | + | 40 | 50 | sharedKeyConfigs.forEach(function (config) { | 41 | 51 | [true, false].forEach(function (extractable) { | 42 | 52 | // Test encapsulateKey operation | @@ -115,24 +125,11 @@ function define_key_tests() { | 115 | 125 | ); | 116 | 126 | } | 117 | 127 |
| 118 | | - // Verify ciphertext length based on algorithm variant | 119 | | - var expectedCiphertextLength; | 120 | | - switch (algorithmName) { | 121 | | - case 'ML-KEM-512': | 122 | | - expectedCiphertextLength = 768; | 123 | | - break; | 124 | | - case 'ML-KEM-768': | 125 | | - expectedCiphertextLength = 1088; | 126 | | - break; | 127 | | - case 'ML-KEM-1024': | 128 | | - expectedCiphertextLength = 1568; | 129 | | - break; | 130 | | - } | 131 | 128 | assert_equals( | 132 | 129 | encapsulatedKey.ciphertext.byteLength, | 133 | | - expectedCiphertextLength, | | 130 | + variant.ciphertextLength, | 134 | 131 | 'Ciphertext should be ' + | 135 | | - expectedCiphertextLength + | | 132 | + variant.ciphertextLength + | 136 | 133 | ' bytes for ' + | 137 | 134 | algorithmName | 138 | 135 | ); | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/encap_decap/hybrid_kem_vectors.js +50Lines changed: 50 additions & 0 deletions Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/encap_decap/ml_kem_vectors.js +36-646Lines changed: 36 additions & 646 deletions Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/generateKey/algorithm_registry.js +3Lines changed: 3 additions & 0 deletions Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: title=WebCryptoAPI: generateKey() for Failures | | 2 | +// META: timeout=long | | 3 | +// META: script=../util/helpers.js | | 4 | +// META: script=algorithm_registry.js | | 5 | +// META: script=failures.js | | 6 | +run_test(["MLKEM768-P256", "MLKEM768-X25519", "MLKEM1024-P384"]); |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/generateKey/successes.js +17-18Lines changed: 17 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,23 +47,22 @@ function run_test(algorithmNames, slowTest) { | 47 | 47 | assert_unreached("generateKey threw an unexpected error: " + err.toString()); | 48 | 48 | }) | 49 | 49 | .then(async function (result) { | 50 | | - // TODO: remove this block to enable ML-KEM JWK when its definition is done in IETF JOSE WG | 51 | | - if (result.publicKey?.algorithm.name.startsWith('ML-KEM')) { | 52 | | - const promises = [ | 53 | | - subtle.exportKey('spki', result.publicKey), | 54 | | - extractable ? subtle.exportKey('pkcs8', result.privateKey) : undefined, | 55 | | - subtle.exportKey('raw-public', result.publicKey), | 56 | | - ]; | 57 | | - if (extractable) | 58 | | - promises.push(subtle.exportKey('raw-seed', result.privateKey)); | 59 | | - await Promise.all(promises); | 60 | | - } else if (resultType === "CryptoKeyPair") { | 61 | | - const promises = [ | 62 | | - subtle.exportKey('jwk', result.publicKey), | 63 | | - extractable ? subtle.exportKey('jwk', result.privateKey) : undefined, | 64 | | - subtle.exportKey('spki', result.publicKey), | 65 | | - extractable ? subtle.exportKey('pkcs8', result.privateKey) : undefined, | 66 | | - ]; | | 50 | + if (resultType === "CryptoKeyPair") { | | 51 | + // TODO: enable ML-KEM JWK when its definition is done in IETF JOSE WG. | | 52 | + const isMlKem = result.publicKey.algorithm.name.startsWith('ML-KEM'); | | 53 | + const isHybridKem = result.publicKey.algorithm.name.startsWith('MLKEM'); | | 54 | + const promises = []; | | 55 | + | | 56 | + if (!isMlKem) { | | 57 | + promises.push(subtle.exportKey('jwk', result.publicKey)); | | 58 | + promises.push(extractable ? subtle.exportKey('jwk', result.privateKey) : undefined); | | 59 | + } | | 60 | + | | 61 | + if (!isHybridKem) { | | 62 | + promises.push(subtle.exportKey('spki', result.publicKey)); | | 63 | + if (extractable) | | 64 | + promises.push(subtle.exportKey('pkcs8', result.privateKey)); | | 65 | + } | 67 | 66 |
| 68 | 67 | switch (result.publicKey.algorithm.name.substring(0, 2)) { | 69 | 68 | case 'ML': | @@ -90,7 +89,7 @@ function run_test(algorithmNames, slowTest) { | 90 | 89 |
| 91 | 90 | const [jwkPub, jwkPriv] = await Promise.all(promises); | 92 | 91 |
| 93 | | - if (extractable) { | | 92 | + if (extractable && !isMlKem) { | 94 | 93 | // Test that the JWK public key is a superset of the JWK private key. | 95 | 94 | for (const [prop, value] of Object.entries(jwkPub)) { | 96 | 95 | if (prop !== 'key_ops') { | |
Collapse file Copy file name to clipboard +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: title=WebCryptoAPI: generateKey() Successful Calls | | 2 | +// META: timeout=long | | 3 | +// META: script=../util/helpers.js | | 4 | +// META: script=/common/subset-tests.js | | 5 | +// META: script=algorithm_registry.js | | 6 | +// META: script=successes.js | | 7 | +run_test(["MLKEM768-P256", "MLKEM768-X25519", "MLKEM1024-P384"]); |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/getPublicKey.tentative.https.any.js +21-2Lines changed: 21 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -109,6 +109,24 @@ const algorithms = [ | 109 | 109 | generateKeyParams: { name: "ML-KEM-1024" }, | 110 | 110 | usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"], | 111 | 111 | publicKeyUsages: ["encapsulateBits", "encapsulateKey"] | | 112 | + }, | | 113 | + { | | 114 | + name: "MLKEM768-P256", | | 115 | + generateKeyParams: { name: "MLKEM768-P256" }, | | 116 | + usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"], | | 117 | + publicKeyUsages: ["encapsulateBits", "encapsulateKey"] | | 118 | + }, | | 119 | + { | | 120 | + name: "MLKEM768-X25519", | | 121 | + generateKeyParams: { name: "MLKEM768-X25519" }, | | 122 | + usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"], | | 123 | + publicKeyUsages: ["encapsulateBits", "encapsulateKey"] | | 124 | + }, | | 125 | + { | | 126 | + name: "MLKEM1024-P384", | | 127 | + generateKeyParams: { name: "MLKEM1024-P384" }, | | 128 | + usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"], | | 129 | + publicKeyUsages: ["encapsulateBits", "encapsulateKey"] | 112 | 130 | } | 113 | 131 | ]; | 114 | 132 |
| @@ -145,8 +163,9 @@ algorithms.forEach(function(algorithm) { | 145 | 163 |
| 146 | 164 | // Verify that the derived public key matches the original public key | 147 | 165 | // by comparing their exported forms | 148 | | - const originalExported = await crypto.subtle.exportKey("spki", keyPair.publicKey); | 149 | | - const derivedExported = await crypto.subtle.exportKey("spki", publicKey); | | 166 | + const exportFormat = algorithm.name.startsWith("MLKEM") ? "raw-public" : "spki"; | | 167 | + const originalExported = await crypto.subtle.exportKey(exportFormat, keyPair.publicKey); | | 168 | + const derivedExported = await crypto.subtle.exportKey(exportFormat, publicKey); | 150 | 169 |
| 151 | 170 | assert_array_equals( | 152 | 171 | new Uint8Array(originalExported), | |
Collapse file Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: title=WebCryptoAPI: importKey() for Hybrid KEM keys | | 2 | +// META: timeout=long | | 3 | +// META: script=../util/helpers.js | | 4 | +// META: script=Hybrid-KEM_importKey_fixtures.js | | 5 | +// META: script=ml_importKey.js | | 6 | + | | 7 | +var keyData = hybridKemKeyData; | | 8 | + | | 9 | +runTests("MLKEM768-P256"); | | 10 | +runTests("MLKEM768-X25519"); | | 11 | +runTests("MLKEM1024-P384"); |
|