mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
crypto: support ML-DSA in Web Cryptography
PR-URL: https://github.com/nodejs/node/pull/59365 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
1 parent
b68e0d1eca
commit
a55382214f
14 files changed
+1349
-145
No files matched your search
+233
-122
@@ -2,6 +2,9 @@
|
||||
|
||||
<!-- YAML
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/59365
|
||||
description: ML-DSA algorithms are now supported.
|
||||
- version:
|
||||
- v23.5.0
|
||||
- v22.13.0
|
||||
@@ -52,7 +55,7 @@ changes:
|
||||
|
||||
> Stability: 2 - Stable
|
||||
|
||||
Node.js provides an implementation of the standard [Web Crypto API][].
|
||||
Node.js provides an implementation of the [Web Crypto API][] standard.
|
||||
|
||||
Use `globalThis.crypto` or `require('node:crypto').webcrypto` to access this
|
||||
module.
|
||||
@@ -78,6 +81,39 @@ const { subtle } = globalThis.crypto;
|
||||
})();
|
||||
```
|
||||
|
||||
## Modern Algorithms in the Web Cryptography API
|
||||
|
||||
> Stability: 1.1 - Active development
|
||||
|
||||
Node.js provides an implementation of the following features from the
|
||||
[Modern Algorithms in the Web Cryptography API](https://wicg.github.io/webcrypto-modern-algos/)
|
||||
WICG proposal:
|
||||
|
||||
Algorithms:
|
||||
|
||||
* `'ML-DSA-44'`[^openssl35]
|
||||
* `'ML-DSA-65'`[^openssl35]
|
||||
* `'ML-DSA-87'`[^openssl35]
|
||||
|
||||
Key Formats:
|
||||
|
||||
* `'raw-public'`
|
||||
* `'raw-secret'`
|
||||
* `'raw-seed'`
|
||||
|
||||
## Secure Curves in the Web Cryptography API
|
||||
|
||||
> Stability: 1.1 - Active development
|
||||
|
||||
Node.js provides an implementation of the following features from the
|
||||
[Secure Curves in the Web Cryptography API](https://wicg.github.io/webcrypto-secure-curves/)
|
||||
WICG proposal:
|
||||
|
||||
Algorithms:
|
||||
|
||||
* `'Ed448'`
|
||||
* `'X448'`
|
||||
|
||||
## Examples
|
||||
|
||||
### Generating keys
|
||||
@@ -356,28 +392,31 @@ async function digest(data, algorithm = 'SHA-512') {
|
||||
The table details the algorithms supported by the Node.js Web Crypto API
|
||||
implementation and the APIs supported for each:
|
||||
|
||||
| Algorithm | `generateKey` | `exportKey` | `importKey` | `encrypt` | `decrypt` | `wrapKey` | `unwrapKey` | `deriveBits` | `deriveKey` | `sign` | `verify` | `digest` |
|
||||
| ------------------------------------------------------- | ------------- | ----------- | ----------- | --------- | --------- | --------- | ----------- | ------------ | ----------- | ------ | -------- | -------- |
|
||||
| `'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'RSA-PSS'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'RSA-OAEP'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |
|
||||
| `'ECDSA'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'Ed25519'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'Ed448'` <span class="experimental-inline"></span>[^1] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'ECDH'` | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
| `'X25519'` | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
| `'X448'` <span class="experimental-inline"></span>[^1] | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
| `'AES-CTR'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |
|
||||
| `'AES-CBC'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |
|
||||
| `'AES-GCM'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |
|
||||
| `'AES-KW'` | ✔ | ✔ | ✔ | | | ✔ | ✔ | | | | | |
|
||||
| `'HMAC'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'HKDF'` | | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
| `'PBKDF2'` | | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
| `'SHA-1'` | | | | | | | | | | | | ✔ |
|
||||
| `'SHA-256'` | | | | | | | | | | | | ✔ |
|
||||
| `'SHA-384'` | | | | | | | | | | | | ✔ |
|
||||
| `'SHA-512'` | | | | | | | | | | | | ✔ |
|
||||
| Algorithm | `generateKey` | `exportKey` | `importKey` | `encrypt` | `decrypt` | `wrapKey` | `unwrapKey` | `deriveBits` | `deriveKey` | `sign` | `verify` | `digest` |
|
||||
| ---------------------------- | ------------- | ----------- | ----------- | --------- | --------- | --------- | ----------- | ------------ | ----------- | ------ | -------- | -------- |
|
||||
| `'AES-CBC'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |
|
||||
| `'AES-CTR'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |
|
||||
| `'AES-GCM'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |
|
||||
| `'AES-KW'` | ✔ | ✔ | ✔ | | | ✔ | ✔ | | | | | |
|
||||
| `'ECDH'` | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
| `'ECDSA'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'Ed25519'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'Ed448'`[^secure-curves] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'HKDF'` | | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
| `'HMAC'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'ML-DSA-44'`[^modern-algos] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'ML-DSA-65'`[^modern-algos] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'ML-DSA-87'`[^modern-algos] | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'PBKDF2'` | | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
| `'RSA-OAEP'` | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | | | | |
|
||||
| `'RSA-PSS'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | | | | | | | ✔ | ✔ | |
|
||||
| `'SHA-1'` | | | | | | | | | | | | ✔ |
|
||||
| `'SHA-256'` | | | | | | | | | | | | ✔ |
|
||||
| `'SHA-384'` | | | | | | | | | | | | ✔ |
|
||||
| `'SHA-512'` | | | | | | | | | | | | ✔ |
|
||||
| `'X25519'` | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
| `'X448'`[^secure-curves] | ✔ | ✔ | ✔ | | | | | ✔ | ✔ | | | |
|
||||
|
||||
## Class: `Crypto`
|
||||
|
||||
@@ -499,24 +538,27 @@ The possible usages are:
|
||||
Valid key usages depend on the key algorithm (identified by
|
||||
`cryptokey.algorithm.name`).
|
||||
|
||||
| Supported Key Algorithm | `'encrypt'` | `'decrypt'` | `'sign'` | `'verify'` | `'deriveKey'` | `'deriveBits'` | `'wrapKey'` | `'unwrapKey'` |
|
||||
| ------------------------------------------------------- | ----------- | ----------- | -------- | ---------- | ------------- | -------------- | ----------- | ------------- |
|
||||
| `'AES-CBC'` | ✔ | ✔ | | | | | ✔ | ✔ |
|
||||
| `'AES-CTR'` | ✔ | ✔ | | | | | ✔ | ✔ |
|
||||
| `'AES-GCM'` | ✔ | ✔ | | | | | ✔ | ✔ |
|
||||
| `'AES-KW'` | | | | | | | ✔ | ✔ |
|
||||
| `'ECDH'` | | | | | ✔ | ✔ | | |
|
||||
| `'X25519'` | | | | | ✔ | ✔ | | |
|
||||
| `'X448'` <span class="experimental-inline"></span>[^1] | | | | | ✔ | ✔ | | |
|
||||
| `'ECDSA'` | | | ✔ | ✔ | | | | |
|
||||
| `'Ed25519'` | | | ✔ | ✔ | | | | |
|
||||
| `'Ed448'` <span class="experimental-inline"></span>[^1] | | | ✔ | ✔ | | | | |
|
||||
| `'HDKF'` | | | | | ✔ | ✔ | | |
|
||||
| `'HMAC'` | | | ✔ | ✔ | | | | |
|
||||
| `'PBKDF2'` | | | | | ✔ | ✔ | | |
|
||||
| `'RSA-OAEP'` | ✔ | ✔ | | | | | ✔ | ✔ |
|
||||
| `'RSA-PSS'` | | | ✔ | ✔ | | | | |
|
||||
| `'RSASSA-PKCS1-v1_5'` | | | ✔ | ✔ | | | | |
|
||||
| Supported Key Algorithm | `'encrypt'` | `'decrypt'` | `'sign'` | `'verify'` | `'deriveKey'` | `'deriveBits'` | `'wrapKey'` | `'unwrapKey'` |
|
||||
| ---------------------------- | ----------- | ----------- | -------- | ---------- | ------------- | -------------- | ----------- | ------------- |
|
||||
| `'AES-CBC'` | ✔ | ✔ | | | | | ✔ | ✔ |
|
||||
| `'AES-CTR'` | ✔ | ✔ | | | | | ✔ | ✔ |
|
||||
| `'AES-GCM'` | ✔ | ✔ | | | | | ✔ | ✔ |
|
||||
| `'AES-KW'` | | | | | | | ✔ | ✔ |
|
||||
| `'ECDH'` | | | | | ✔ | ✔ | | |
|
||||
| `'ECDSA'` | | | ✔ | ✔ | | | | |
|
||||
| `'Ed25519'` | | | ✔ | ✔ | | | | |
|
||||
| `'Ed448'`[^secure-curves] | | | ✔ | ✔ | | | | |
|
||||
| `'HDKF'` | | | | | ✔ | ✔ | | |
|
||||
| `'HMAC'` | | | ✔ | ✔ | | | | |
|
||||
| `'ML-DSA-44'`[^modern-algos] | | | ✔ | ✔ | | | | |
|
||||
| `'ML-DSA-65'`[^modern-algos] | | | ✔ | ✔ | | | | |
|
||||
| `'ML-DSA-87'`[^modern-algos] | | | ✔ | ✔ | | | | |
|
||||
| `'PBKDF2'` | | | | | ✔ | ✔ | | |
|
||||
| `'RSA-OAEP'` | ✔ | ✔ | | | | | ✔ | ✔ |
|
||||
| `'RSA-PSS'` | | | ✔ | ✔ | | | | |
|
||||
| `'RSASSA-PKCS1-v1_5'` | | | ✔ | ✔ | | | | |
|
||||
| `'X25519'` | | | | | ✔ | ✔ | | |
|
||||
| `'X448'`[^secure-curves] | | | | | ✔ | ✔ | | |
|
||||
|
||||
## Class: `CryptoKeyPair`
|
||||
|
||||
@@ -567,10 +609,10 @@ an {ArrayBuffer} containing the plaintext result.
|
||||
|
||||
The algorithms currently supported include:
|
||||
|
||||
* `'RSA-OAEP'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-CBC'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-GCM'`
|
||||
* `'RSA-OAEP'`
|
||||
|
||||
### `subtle.deriveBits(algorithm, baseKey[, length])`
|
||||
|
||||
@@ -605,7 +647,7 @@ material provided by `baseKey`, `subtle.deriveBits()` attempts to generate
|
||||
`length` bits.
|
||||
|
||||
When `length` is not provided or `null` the maximum number of bits for a given
|
||||
algorithm is generated. This is allowed for the `'ECDH'`, `'X25519'`, and `'X448'`
|
||||
algorithm is generated. This is allowed for the `'ECDH'`, `'X25519'`, and `'X448'`[^secure-curves]
|
||||
algorithms, for other algorithms `length` is required to be a number.
|
||||
|
||||
If successful, the returned promise will be resolved with an {ArrayBuffer}
|
||||
@@ -614,10 +656,10 @@ containing the generated data.
|
||||
The algorithms currently supported include:
|
||||
|
||||
* `'ECDH'`
|
||||
* `'X25519'`
|
||||
* `'X448'` <span class="experimental-inline"></span>[^1]
|
||||
* `'HKDF'`
|
||||
* `'PBKDF2'`
|
||||
* `'X25519'`
|
||||
* `'X448'`[^secure-curves]
|
||||
|
||||
### `subtle.deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages)`
|
||||
|
||||
@@ -654,10 +696,10 @@ generate raw keying material, then passing the result into the
|
||||
The algorithms currently supported include:
|
||||
|
||||
* `'ECDH'`
|
||||
* `'X25519'`
|
||||
* `'X448'` <span class="experimental-inline"></span>[^1]
|
||||
* `'HKDF'`
|
||||
* `'PBKDF2'`
|
||||
* `'X25519'`
|
||||
* `'X448'`[^secure-curves]
|
||||
|
||||
### `subtle.digest(algorithm, data)`
|
||||
|
||||
@@ -701,16 +743,19 @@ containing the encrypted result.
|
||||
|
||||
The algorithms currently supported include:
|
||||
|
||||
* `'RSA-OAEP'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-CBC'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-GCM'`
|
||||
* `'RSA-OAEP'`
|
||||
|
||||
### `subtle.exportKey(format, key)`
|
||||
|
||||
<!-- YAML
|
||||
added: v15.0.0
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/59365
|
||||
description: ML-DSA algorithms are now supported.
|
||||
- version:
|
||||
- v18.4.0
|
||||
- v16.17.0
|
||||
@@ -722,7 +767,8 @@ changes:
|
||||
description: Removed `'NODE-DSA'` JWK export.
|
||||
-->
|
||||
|
||||
* `format` {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
|
||||
* `format` {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, `'jwk'`, `'raw-secret'`[^modern-algos],
|
||||
`'raw-public'`[^modern-algos], or `'raw-seed'`[^modern-algos].
|
||||
* `key` {CryptoKey}
|
||||
* Returns: {Promise} Fulfills with an {ArrayBuffer|Object} upon success.
|
||||
|
||||
@@ -738,25 +784,32 @@ When `format` is `'jwk'` and the export is successful, the returned promise
|
||||
will be resolved with a JavaScript object conforming to the [JSON Web Key][]
|
||||
specification.
|
||||
|
||||
| Supported Key Algorithm | `'spki'` | `'pkcs8'` | `'jwk'` | `'raw'` |
|
||||
| ------------------------------------------------------- | -------- | --------- | ------- | ------- |
|
||||
| `'AES-CBC'` | | | ✔ | ✔ |
|
||||
| `'AES-CTR'` | | | ✔ | ✔ |
|
||||
| `'AES-GCM'` | | | ✔ | ✔ |
|
||||
| `'AES-KW'` | | | ✔ | ✔ |
|
||||
| `'ECDH'` | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'ECDSA'` | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'Ed25519'` | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'Ed448'` <span class="experimental-inline"></span>[^1] | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'HMAC'` | | | ✔ | ✔ |
|
||||
| `'RSA-OAEP'` | ✔ | ✔ | ✔ | |
|
||||
| `'RSA-PSS'` | ✔ | ✔ | ✔ | |
|
||||
| `'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | |
|
||||
| Supported Key Algorithm | `'spki'` | `'pkcs8'` | `'jwk'` | `'raw'` | `'raw-secret'` | `'raw-public'` | `'raw-seed'` |
|
||||
| ---------------------------- | -------- | --------- | ------- | ------- | -------------- | -------------- | ------------ |
|
||||
| `'AES-CBC'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'AES-CTR'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'AES-GCM'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'AES-KW'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'ECDH'` | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
| `'ECDSA'` | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
| `'Ed25519'` | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
| `'Ed448'`[^secure-curves] | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
| `'HMAC'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'ML-DSA-44'`[^modern-algos] | | | ✔ | | | ✔ | ✔ |
|
||||
| `'ML-DSA-65'`[^modern-algos] | | | ✔ | | | ✔ | ✔ |
|
||||
| `'ML-DSA-87'`[^modern-algos] | | | ✔ | | | ✔ | ✔ |
|
||||
| `'RSA-OAEP'` | ✔ | ✔ | ✔ | | | | |
|
||||
| `'RSA-PSS'` | ✔ | ✔ | ✔ | | | | |
|
||||
| `'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | | | | |
|
||||
|
||||
### `subtle.generateKey(algorithm, extractable, keyUsages)`
|
||||
|
||||
<!-- YAML
|
||||
added: v15.0.0
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/59365
|
||||
description: ML-DSA algorithms are now supported.
|
||||
-->
|
||||
|
||||
<!--lint disable maximum-line-length remark-lint-->
|
||||
@@ -776,29 +829,35 @@ may generate either a single {CryptoKey} or a {CryptoKeyPair}.
|
||||
The {CryptoKeyPair} (public and private key) generating algorithms supported
|
||||
include:
|
||||
|
||||
* `'RSASSA-PKCS1-v1_5'`
|
||||
* `'RSA-PSS'`
|
||||
* `'RSA-OAEP'`
|
||||
* `'ECDH'`
|
||||
* `'ECDSA'`
|
||||
* `'Ed25519'`
|
||||
* `'Ed448'` <span class="experimental-inline"></span>[^1]
|
||||
* `'ECDH'`
|
||||
* `'Ed448'`[^secure-curves]
|
||||
* `'ML-DSA-44'`[^modern-algos]
|
||||
* `'ML-DSA-65'`[^modern-algos]
|
||||
* `'ML-DSA-87'`[^modern-algos]
|
||||
* `'RSA-OAEP'`
|
||||
* `'RSA-PSS'`
|
||||
* `'RSASSA-PKCS1-v1_5'`
|
||||
* `'X25519'`
|
||||
* `'X448'` <span class="experimental-inline"></span>[^1]
|
||||
* `'X448'`[^secure-curves]
|
||||
|
||||
The {CryptoKey} (secret key) generating algorithms supported include:
|
||||
|
||||
* `'HMAC'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-CBC'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-GCM'`
|
||||
* `'AES-KW'`
|
||||
* `'HMAC'`
|
||||
|
||||
### `subtle.importKey(format, keyData, algorithm, extractable, keyUsages)`
|
||||
|
||||
<!-- YAML
|
||||
added: v15.0.0
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/59365
|
||||
description: ML-DSA algorithms are now supported.
|
||||
- version:
|
||||
- v18.4.0
|
||||
- v16.17.0
|
||||
@@ -810,7 +869,8 @@ changes:
|
||||
description: Removed `'NODE-DSA'` JWK import.
|
||||
-->
|
||||
|
||||
* `format` {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
|
||||
* `format` {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, `'jwk'`, `'raw-secret'`[^modern-algos],
|
||||
`'raw-public'`[^modern-algos], or `'raw-seed'`[^modern-algos].
|
||||
* `keyData` {ArrayBuffer|TypedArray|DataView|Buffer|Object}
|
||||
|
||||
<!--lint disable maximum-line-length remark-lint-->
|
||||
@@ -832,30 +892,36 @@ If importing a `'PBKDF2'` key, `extractable` must be `false`.
|
||||
|
||||
The algorithms currently supported include:
|
||||
|
||||
| Supported Key Algorithm | `'spki'` | `'pkcs8'` | `'jwk'` | `'raw'` |
|
||||
| ------------------------------------------------------- | -------- | --------- | ------- | ------- |
|
||||
| `'AES-CBC'` | | | ✔ | ✔ |
|
||||
| `'AES-CTR'` | | | ✔ | ✔ |
|
||||
| `'AES-GCM'` | | | ✔ | ✔ |
|
||||
| `'AES-KW'` | | | ✔ | ✔ |
|
||||
| `'ECDH'` | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'X25519'` | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'X448'` <span class="experimental-inline"></span>[^1] | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'ECDSA'` | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'Ed25519'` | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'Ed448'` <span class="experimental-inline"></span>[^1] | ✔ | ✔ | ✔ | ✔ |
|
||||
| `'HDKF'` | | | | ✔ |
|
||||
| `'HMAC'` | | | ✔ | ✔ |
|
||||
| `'PBKDF2'` | | | | ✔ |
|
||||
| `'RSA-OAEP'` | ✔ | ✔ | ✔ | |
|
||||
| `'RSA-PSS'` | ✔ | ✔ | ✔ | |
|
||||
| `'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | |
|
||||
| Supported Key Algorithm | `'spki'` | `'pkcs8'` | `'jwk'` | `'raw'` | `'raw-secret'` | `'raw-public'` | `'raw-seed'` |
|
||||
| ---------------------------- | -------- | --------- | ------- | ------- | -------------- | -------------- | ------------ |
|
||||
| `'AES-CBC'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'AES-CTR'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'AES-GCM'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'AES-KW'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'ECDH'` | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
| `'ECDSA'` | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
| `'Ed25519'` | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
| `'Ed448'`[^secure-curves] | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
| `'HDKF'` | | | | ✔ | ✔ | | |
|
||||
| `'HMAC'` | | | ✔ | ✔ | ✔ | | |
|
||||
| `'ML-DSA-44'`[^modern-algos] | | | ✔ | | | ✔ | ✔ |
|
||||
| `'ML-DSA-65'`[^modern-algos] | | | ✔ | | | ✔ | ✔ |
|
||||
| `'ML-DSA-87'`[^modern-algos] | | | ✔ | | | ✔ | ✔ |
|
||||
| `'PBKDF2'` | | | | ✔ | ✔ | | |
|
||||
| `'RSA-OAEP'` | ✔ | ✔ | ✔ | | | | |
|
||||
| `'RSA-PSS'` | ✔ | ✔ | ✔ | | | | |
|
||||
| `'RSASSA-PKCS1-v1_5'` | ✔ | ✔ | ✔ | | | | |
|
||||
| `'X25519'` | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
| `'X448'`[^secure-curves] | ✔ | ✔ | ✔ | ✔ | | ✔ | |
|
||||
|
||||
### `subtle.sign(algorithm, key, data)`
|
||||
|
||||
<!-- YAML
|
||||
added: v15.0.0
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/59365
|
||||
description: ML-DSA algorithms are now supported.
|
||||
- version:
|
||||
- v18.4.0
|
||||
- v16.17.0
|
||||
@@ -865,7 +931,7 @@ changes:
|
||||
|
||||
<!--lint disable maximum-line-length remark-lint-->
|
||||
|
||||
* `algorithm` {string|Algorithm|RsaPssParams|EcdsaParams|Ed448Params}
|
||||
* `algorithm` {string|Algorithm|RsaPssParams|EcdsaParams|Ed448Params|ContextParams}
|
||||
* `key` {CryptoKey}
|
||||
* `data` {ArrayBuffer|TypedArray|DataView|Buffer}
|
||||
* Returns: {Promise} Fulfills with an {ArrayBuffer} upon success.
|
||||
@@ -879,12 +945,15 @@ an {ArrayBuffer} containing the generated signature.
|
||||
|
||||
The algorithms currently supported include:
|
||||
|
||||
* `'RSASSA-PKCS1-v1_5'`
|
||||
* `'RSA-PSS'`
|
||||
* `'ECDSA'`
|
||||
* `'Ed25519'`
|
||||
* `'Ed448'` <span class="experimental-inline"></span>[^1]
|
||||
* `'Ed448'`[^secure-curves]
|
||||
* `'HMAC'`
|
||||
* `'ML-DSA-44'`[^modern-algos]
|
||||
* `'ML-DSA-65'`[^modern-algos]
|
||||
* `'ML-DSA-87'`[^modern-algos]
|
||||
* `'RSA-PSS'`
|
||||
* `'RSASSA-PKCS1-v1_5'`
|
||||
|
||||
### `subtle.unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgo, unwrappedKeyAlgo, extractable, keyUsages)`
|
||||
|
||||
@@ -892,7 +961,8 @@ The algorithms currently supported include:
|
||||
added: v15.0.0
|
||||
-->
|
||||
|
||||
* `format` {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
|
||||
* `format` {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, `'jwk'`, `'raw-secret'`[^modern-algos],
|
||||
`'raw-public'`[^modern-algos], or `'raw-seed'`[^modern-algos].
|
||||
* `wrappedKey` {ArrayBuffer|TypedArray|DataView|Buffer}
|
||||
* `unwrappingKey` {CryptoKey}
|
||||
|
||||
@@ -918,34 +988,40 @@ promise is resolved with a {CryptoKey} object.
|
||||
|
||||
The wrapping algorithms currently supported include:
|
||||
|
||||
* `'RSA-OAEP'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-CBC'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-GCM'`
|
||||
* `'AES-KW'`
|
||||
* `'RSA-OAEP'`
|
||||
|
||||
The unwrapped key algorithms supported include:
|
||||
|
||||
* `'RSASSA-PKCS1-v1_5'`
|
||||
* `'RSA-PSS'`
|
||||
* `'RSA-OAEP'`
|
||||
* `'ECDSA'`
|
||||
* `'Ed25519'`
|
||||
* `'Ed448'` <span class="experimental-inline"></span>[^1]
|
||||
* `'ECDH'`
|
||||
* `'X25519'`
|
||||
* `'X448'` <span class="experimental-inline"></span>[^1]
|
||||
* `'HMAC'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-CBC'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-GCM'`
|
||||
* `'AES-KW'`
|
||||
* `'ECDH'`
|
||||
* `'ECDSA'`
|
||||
* `'Ed25519'`
|
||||
* `'Ed448'`[^secure-curves]
|
||||
* `'HMAC'`
|
||||
* `'ML-DSA-44'`[^modern-algos]
|
||||
* `'ML-DSA-65'`[^modern-algos]
|
||||
* `'ML-DSA-87'`[^modern-algos]
|
||||
* `'RSA-OAEP'`
|
||||
* `'RSA-PSS'`
|
||||
* `'RSASSA-PKCS1-v1_5'`
|
||||
* `'X25519'`
|
||||
* `'X448'`[^secure-curves]
|
||||
|
||||
### `subtle.verify(algorithm, key, signature, data)`
|
||||
|
||||
<!-- YAML
|
||||
added: v15.0.0
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/59365
|
||||
description: ML-DSA algorithms are now supported.
|
||||
- version:
|
||||
- v18.4.0
|
||||
- v16.17.0
|
||||
@@ -955,7 +1031,7 @@ changes:
|
||||
|
||||
<!--lint disable maximum-line-length remark-lint-->
|
||||
|
||||
* `algorithm` {string|Algorithm|RsaPssParams|EcdsaParams|Ed448Params}
|
||||
* `algorithm` {string|Algorithm|RsaPssParams|EcdsaParams|Ed448Params|ContextParams}
|
||||
* `key` {CryptoKey}
|
||||
* `signature` {ArrayBuffer|TypedArray|DataView|Buffer}
|
||||
* `data` {ArrayBuffer|TypedArray|DataView|Buffer}
|
||||
@@ -970,12 +1046,15 @@ with either `true` or `false`.
|
||||
|
||||
The algorithms currently supported include:
|
||||
|
||||
* `'RSASSA-PKCS1-v1_5'`
|
||||
* `'RSA-PSS'`
|
||||
* `'ECDSA'`
|
||||
* `'Ed25519'`
|
||||
* `'Ed448'` <span class="experimental-inline"></span>[^1]
|
||||
* `'Ed448'`[^secure-curves]
|
||||
* `'HMAC'`
|
||||
* `'ML-DSA-44'`[^modern-algos]
|
||||
* `'ML-DSA-65'`[^modern-algos]
|
||||
* `'ML-DSA-87'`[^modern-algos]
|
||||
* `'RSA-PSS'`
|
||||
* `'RSASSA-PKCS1-v1_5'`
|
||||
|
||||
### `subtle.wrapKey(format, key, wrappingKey, wrapAlgo)`
|
||||
|
||||
@@ -985,7 +1064,8 @@ added: v15.0.0
|
||||
|
||||
<!--lint disable maximum-line-length remark-lint-->
|
||||
|
||||
* `format` {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
|
||||
* `format` {string} Must be one of `'raw'`, `'pkcs8'`, `'spki'`, `'jwk'`, `'raw-secret'`[^modern-algos],
|
||||
`'raw-public'`[^modern-algos], or `'raw-seed'`[^modern-algos].
|
||||
* `key` {CryptoKey}
|
||||
* `wrappingKey` {CryptoKey}
|
||||
* `wrapAlgo` {string|Algorithm|RsaOaepParams|AesCtrParams|AesCbcParams|AesGcmParams}
|
||||
@@ -1005,11 +1085,11 @@ containing the encrypted key data.
|
||||
|
||||
The wrapping algorithms currently supported include:
|
||||
|
||||
* `'RSA-OAEP'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-CBC'`
|
||||
* `'AES-CTR'`
|
||||
* `'AES-GCM'`
|
||||
* `'AES-KW'`
|
||||
* `'RSA-OAEP'`
|
||||
|
||||
## Algorithm parameters
|
||||
|
||||
@@ -1221,6 +1301,33 @@ added: v15.0.0
|
||||
* Type: {string} Must be one of `'AES-CBC'`, `'AES-CTR'`, `'AES-GCM'`, or
|
||||
`'AES-KW'`
|
||||
|
||||
### Class: `ContextParams`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
#### `contextParams.name`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
* Type: {string} Must be `'ML-DSA-44'`[^modern-algos], `'ML-DSA-65'`[^modern-algos], or `'ML-DSA-87'`[^modern-algos].
|
||||
|
||||
#### `contextParams.context`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined}
|
||||
|
||||
The `context` member represents the optional context data to associate with
|
||||
the message.
|
||||
The Node.js Web Crypto API implementation only supports zero-length context
|
||||
which is equivalent to not providing context at all.
|
||||
|
||||
### Class: `EcdhKeyDeriveParams`
|
||||
|
||||
<!-- YAML
|
||||
@@ -1233,7 +1340,7 @@ added: v15.0.0
|
||||
added: v15.0.0
|
||||
-->
|
||||
|
||||
* Type: {string} Must be `'ECDH'`, `'X25519'`, or `'X448'`.
|
||||
* Type: {string} Must be `'ECDH'`, `'X25519'`, or `'X448'`[^secure-curves].
|
||||
|
||||
#### `ecdhKeyDeriveParams.public`
|
||||
|
||||
@@ -1360,7 +1467,7 @@ added:
|
||||
- v16.17.0
|
||||
-->
|
||||
|
||||
* Type: {string} Must be `'Ed448'`.
|
||||
* Type: {string} Must be `'Ed448'`[^secure-curves].
|
||||
|
||||
#### `ed448Params.context`
|
||||
|
||||
@@ -1802,12 +1909,16 @@ added: v15.0.0
|
||||
|
||||
The length (in bytes) of the random salt to use.
|
||||
|
||||
[^1]: An experimental implementation of Ed448 and X448 algorithms from
|
||||
[Secure Curves in the Web Cryptography API][] as of 21 October 2024
|
||||
[^secure-curves]: See [Secure Curves in the Web Cryptography API][]
|
||||
|
||||
[^modern-algos]: See [Modern Algorithms in the Web Cryptography API][]
|
||||
|
||||
[^openssl35]: Requires OpenSSL >= 3.5
|
||||
|
||||
[JSON Web Key]: https://tools.ietf.org/html/rfc7517
|
||||
[Key usages]: #cryptokeyusages
|
||||
[Modern Algorithms in the Web Cryptography API]: #modern-algorithms-in-the-web-cryptography-api
|
||||
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
|
||||
[RFC 4122]: https://www.rfc-editor.org/rfc/rfc4122.txt
|
||||
[Secure Curves in the Web Cryptography API]: https://wicg.github.io/webcrypto-secure-curves/
|
||||
[Secure Curves in the Web Cryptography API]: #secure-curves-in-the-web-cryptography-api
|
||||
[Web Crypto API]: https://www.w3.org/TR/WebCryptoAPI/
|
||||
@@ -293,6 +293,14 @@ const {
|
||||
result = require('internal/crypto/cfrg')
|
||||
.cfrgImportKey('KeyObject', this, algorithm, extractable, keyUsages);
|
||||
break;
|
||||
case 'ML-DSA-44':
|
||||
// Fall through
|
||||
case 'ML-DSA-65':
|
||||
// Fall through
|
||||
case 'ML-DSA-87':
|
||||
result = require('internal/crypto/ml_dsa')
|
||||
.mlDsaImportKey('KeyObject', this, algorithm, extractable, keyUsages);
|
||||
break;
|
||||
default:
|
||||
throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
SafeSet,
|
||||
} = primordials;
|
||||
|
||||
const { Buffer } = require('buffer');
|
||||
|
||||
const {
|
||||
KeyObjectHandle,
|
||||
SignJob,
|
||||
kCryptoJobAsync,
|
||||
kKeyTypePrivate,
|
||||
kKeyTypePublic,
|
||||
kSignJobModeSign,
|
||||
kSignJobModeVerify,
|
||||
} = internalBinding('crypto');
|
||||
|
||||
const {
|
||||
codes: {
|
||||
ERR_CRYPTO_INVALID_JWK,
|
||||
},
|
||||
} = require('internal/errors');
|
||||
|
||||
const {
|
||||
getUsagesUnion,
|
||||
hasAnyNotIn,
|
||||
jobPromise,
|
||||
validateKeyOps,
|
||||
kHandle,
|
||||
kKeyObject,
|
||||
} = require('internal/crypto/util');
|
||||
|
||||
const {
|
||||
lazyDOMException,
|
||||
promisify,
|
||||
} = require('internal/util');
|
||||
|
||||
const {
|
||||
generateKeyPair: _generateKeyPair,
|
||||
} = require('internal/crypto/keygen');
|
||||
|
||||
const {
|
||||
InternalCryptoKey,
|
||||
PrivateKeyObject,
|
||||
PublicKeyObject,
|
||||
createPublicKey,
|
||||
} = require('internal/crypto/keys');
|
||||
|
||||
const generateKeyPair = promisify(_generateKeyPair);
|
||||
|
||||
function verifyAcceptableMlDsaKeyUse(name, isPublic, usages) {
|
||||
const checkSet = isPublic ? ['verify'] : ['sign'];
|
||||
if (hasAnyNotIn(usages, checkSet)) {
|
||||
throw lazyDOMException(
|
||||
`Unsupported key usage for a ${name} key`,
|
||||
'SyntaxError');
|
||||
}
|
||||
}
|
||||
|
||||
function createMlDsaRawKey(name, keyData, isPublic) {
|
||||
const handle = new KeyObjectHandle();
|
||||
const keyType = isPublic ? kKeyTypePublic : kKeyTypePrivate;
|
||||
if (!handle.initMlDsaRaw(name, keyData, keyType)) {
|
||||
throw lazyDOMException('Invalid keyData', 'DataError');
|
||||
}
|
||||
|
||||
return isPublic ? new PublicKeyObject(handle) : new PrivateKeyObject(handle);
|
||||
}
|
||||
|
||||
async function mlDsaGenerateKey(algorithm, extractable, keyUsages) {
|
||||
const { name } = algorithm;
|
||||
|
||||
const usageSet = new SafeSet(keyUsages);
|
||||
if (hasAnyNotIn(usageSet, ['sign', 'verify'])) {
|
||||
throw lazyDOMException(
|
||||
`Unsupported key usage for an ${name} key`,
|
||||
'SyntaxError');
|
||||
}
|
||||
|
||||
const keyPair = await generateKeyPair(name.toLowerCase()).catch((err) => {
|
||||
throw lazyDOMException(
|
||||
'The operation failed for an operation-specific reason',
|
||||
{ name: 'OperationError', cause: err });
|
||||
});
|
||||
|
||||
const publicUsages = getUsagesUnion(usageSet, 'verify');
|
||||
const privateUsages = getUsagesUnion(usageSet, 'sign');
|
||||
|
||||
const keyAlgorithm = { name };
|
||||
|
||||
const publicKey =
|
||||
new InternalCryptoKey(
|
||||
keyPair.publicKey,
|
||||
keyAlgorithm,
|
||||
publicUsages,
|
||||
true);
|
||||
|
||||
const privateKey =
|
||||
new InternalCryptoKey(
|
||||
keyPair.privateKey,
|
||||
keyAlgorithm,
|
||||
privateUsages,
|
||||
extractable);
|
||||
|
||||
return { __proto__: null, privateKey, publicKey };
|
||||
}
|
||||
|
||||
function mlDsaExportKey(key) {
|
||||
try {
|
||||
if (key.type === 'private') {
|
||||
const { priv } = key[kKeyObject][kHandle].exportJwk({}, false);
|
||||
return Buffer.alloc(32, priv, 'base64url').buffer;
|
||||
}
|
||||
|
||||
const { pub } = key[kKeyObject][kHandle].exportJwk({}, false);
|
||||
return Buffer.alloc(Buffer.byteLength(pub, 'base64url'), pub, 'base64url').buffer;
|
||||
} catch (err) {
|
||||
throw lazyDOMException(
|
||||
'The operation failed for an operation-specific reason',
|
||||
{ name: 'OperationError', cause: err });
|
||||
}
|
||||
}
|
||||
|
||||
function mlDsaImportKey(
|
||||
format,
|
||||
keyData,
|
||||
algorithm,
|
||||
extractable,
|
||||
keyUsages) {
|
||||
|
||||
const { name } = algorithm;
|
||||
let keyObject;
|
||||
const usagesSet = new SafeSet(keyUsages);
|
||||
switch (format) {
|
||||
case 'KeyObject': {
|
||||
verifyAcceptableMlDsaKeyUse(name, keyData.type === 'public', usagesSet);
|
||||
keyObject = keyData;
|
||||
break;
|
||||
}
|
||||
case 'jwk': {
|
||||
if (!keyData.kty)
|
||||
throw lazyDOMException('Invalid keyData', 'DataError');
|
||||
if (keyData.kty !== 'AKP')
|
||||
throw lazyDOMException('Invalid JWK "kty" Parameter', 'DataError');
|
||||
if (keyData.alg !== name)
|
||||
throw lazyDOMException(
|
||||
'JWK "alg" Parameter and algorithm name mismatch', 'DataError');
|
||||
const isPublic = keyData.priv === undefined;
|
||||
|
||||
if (usagesSet.size > 0 && keyData.use !== undefined) {
|
||||
if (keyData.use !== 'sig')
|
||||
throw lazyDOMException('Invalid JWK "use" Parameter', 'DataError');
|
||||
}
|
||||
|
||||
validateKeyOps(keyData.key_ops, usagesSet);
|
||||
|
||||
if (keyData.ext !== undefined &&
|
||||
keyData.ext === false &&
|
||||
extractable === true) {
|
||||
throw lazyDOMException(
|
||||
'JWK "ext" Parameter and extractable mismatch',
|
||||
'DataError');
|
||||
}
|
||||
|
||||
if (!isPublic && typeof keyData.pub !== 'string') {
|
||||
throw lazyDOMException('Invalid JWK', 'DataError');
|
||||
}
|
||||
|
||||
verifyAcceptableMlDsaKeyUse(
|
||||
name,
|
||||
isPublic,
|
||||
usagesSet);
|
||||
|
||||
try {
|
||||
const publicKeyObject = createMlDsaRawKey(
|
||||
name,
|
||||
Buffer.from(keyData.pub, 'base64url'),
|
||||
true);
|
||||
|
||||
if (isPublic) {
|
||||
keyObject = publicKeyObject;
|
||||
} else {
|
||||
keyObject = createMlDsaRawKey(
|
||||
name,
|
||||
Buffer.from(keyData.priv, 'base64url'),
|
||||
false);
|
||||
|
||||
if (!createPublicKey(keyObject).equals(publicKeyObject)) {
|
||||
throw new ERR_CRYPTO_INVALID_JWK();
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
throw lazyDOMException('Invalid keyData', { name: 'DataError', cause: err });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'raw-public':
|
||||
case 'raw-seed': {
|
||||
const isPublic = format === 'raw-public';
|
||||
verifyAcceptableMlDsaKeyUse(name, isPublic, usagesSet);
|
||||
|
||||
try {
|
||||
keyObject = createMlDsaRawKey(name, keyData, isPublic);
|
||||
} catch (err) {
|
||||
throw lazyDOMException('Invalid keyData', { name: 'DataError', cause: err });
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (keyObject.asymmetricKeyType !== name.toLowerCase()) {
|
||||
throw lazyDOMException('Invalid key type', 'DataError');
|
||||
}
|
||||
|
||||
return new InternalCryptoKey(
|
||||
keyObject,
|
||||
{ name },
|
||||
keyUsages,
|
||||
extractable);
|
||||
}
|
||||
|
||||
function mlDsaSignVerify(key, data, algorithm, signature) {
|
||||
const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify;
|
||||
const type = mode === kSignJobModeSign ? 'private' : 'public';
|
||||
|
||||
if (key.type !== type)
|
||||
throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError');
|
||||
|
||||
return jobPromise(() => new SignJob(
|
||||
kCryptoJobAsync,
|
||||
mode,
|
||||
key[kKeyObject][kHandle],
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
data,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
signature));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mlDsaExportKey,
|
||||
mlDsaImportKey,
|
||||
mlDsaGenerateKey,
|
||||
mlDsaSignVerify,
|
||||
};
|
||||
@@ -33,6 +33,9 @@ const {
|
||||
secureHeapUsed: _secureHeapUsed,
|
||||
getCachedAliases,
|
||||
getOpenSSLSecLevelCrypto: getOpenSSLSecLevel,
|
||||
EVP_PKEY_ML_DSA_44,
|
||||
EVP_PKEY_ML_DSA_65,
|
||||
EVP_PKEY_ML_DSA_87,
|
||||
} = internalBinding('crypto');
|
||||
|
||||
const { getOptionValue } = require('internal/options');
|
||||
@@ -284,6 +287,22 @@ const experimentalAlgorithms = ObjectEntries({
|
||||
},
|
||||
});
|
||||
|
||||
for (const { 0: algorithm, 1: nid } of [
|
||||
['ML-DSA-44', EVP_PKEY_ML_DSA_44],
|
||||
['ML-DSA-65', EVP_PKEY_ML_DSA_65],
|
||||
['ML-DSA-87', EVP_PKEY_ML_DSA_87],
|
||||
]) {
|
||||
if (nid) {
|
||||
ArrayPrototypePush(experimentalAlgorithms, [algorithm, {
|
||||
generateKey: null,
|
||||
sign: 'ContextParams',
|
||||
verify: 'ContextParams',
|
||||
importKey: null,
|
||||
exportKey: null,
|
||||
}]);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < experimentalAlgorithms.length; i++) {
|
||||
const name = experimentalAlgorithms[i][0];
|
||||
const ops = ObjectEntries(experimentalAlgorithms[i][1]);
|
||||
@@ -314,6 +333,7 @@ const simpleAlgorithmDictionaries = {
|
||||
info: 'BufferSource',
|
||||
},
|
||||
Ed448Params: { context: 'BufferSource' },
|
||||
ContextParams: { context: 'BufferSource' },
|
||||
Pbkdf2Params: { hash: 'HashAlgorithmIdentifier', salt: 'BufferSource' },
|
||||
RsaOaepParams: { label: 'BufferSource' },
|
||||
RsaHashedImportParams: { hash: 'HashAlgorithmIdentifier' },
|
||||
|
||||
@@ -152,6 +152,15 @@ async function generateKey(
|
||||
result = await require('internal/crypto/aes')
|
||||
.aesGenerateKey(algorithm, extractable, keyUsages);
|
||||
break;
|
||||
case 'ML-DSA-44':
|
||||
// Fall through
|
||||
case 'ML-DSA-65':
|
||||
// Fall through
|
||||
case 'ML-DSA-87':
|
||||
resultType = 'CryptoKeyPair';
|
||||
result = await require('internal/crypto/ml_dsa')
|
||||
.mlDsaGenerateKey(algorithm, extractable, keyUsages);
|
||||
break;
|
||||
default:
|
||||
throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
|
||||
}
|
||||
@@ -311,7 +320,7 @@ async function deriveKey(
|
||||
return ReflectApply(
|
||||
importKey,
|
||||
this,
|
||||
['raw', bits, derivedKeyAlgorithm, extractable, keyUsages],
|
||||
['raw-secret', bits, derivedKeyAlgorithm, extractable, keyUsages],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -371,7 +380,7 @@ async function exportKeyPkcs8(key) {
|
||||
}
|
||||
}
|
||||
|
||||
async function exportKeyRawPublic(key) {
|
||||
async function exportKeyRawPublic(key, format) {
|
||||
switch (key.algorithm.name) {
|
||||
case 'ECDSA':
|
||||
// Fall through
|
||||
@@ -387,6 +396,33 @@ async function exportKeyRawPublic(key) {
|
||||
case 'X448':
|
||||
return require('internal/crypto/cfrg')
|
||||
.cfrgExportKey(key, kWebCryptoKeyFormatRaw);
|
||||
case 'ML-DSA-44':
|
||||
// Fall through
|
||||
case 'ML-DSA-65':
|
||||
// Fall through
|
||||
case 'ML-DSA-87': {
|
||||
// ML-DSA keys don't recognize "raw"
|
||||
if (format !== 'raw-public') {
|
||||
return undefined;
|
||||
}
|
||||
return require('internal/crypto/ml_dsa')
|
||||
.mlDsaExportKey(key, kWebCryptoKeyFormatRaw);
|
||||
}
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async function exportKeyRawSeed(key) {
|
||||
switch (key.algorithm.name) {
|
||||
case 'ML-DSA-44':
|
||||
// Fall through
|
||||
case 'ML-DSA-65':
|
||||
// Fall through
|
||||
case 'ML-DSA-87': {
|
||||
return require('internal/crypto/ml_dsa')
|
||||
.mlDsaExportKey(key, kWebCryptoKeyFormatRaw);
|
||||
}
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
@@ -437,6 +473,12 @@ async function exportKeyJWK(key) {
|
||||
case 'X25519':
|
||||
// Fall through
|
||||
case 'X448':
|
||||
// Fall through
|
||||
case 'ML-DSA-44':
|
||||
// Fall through
|
||||
case 'ML-DSA-65':
|
||||
// Fall through
|
||||
case 'ML-DSA-87':
|
||||
break;
|
||||
case 'Ed25519':
|
||||
// Fall through
|
||||
@@ -508,15 +550,29 @@ async function exportKey(format, key) {
|
||||
result = await exportKeyJWK(key);
|
||||
break;
|
||||
}
|
||||
case 'raw-secret': {
|
||||
if (key.type === 'secret') {
|
||||
result = await exportKeyRawSecret(key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'raw-public': {
|
||||
if (key.type === 'public') {
|
||||
result = await exportKeyRawPublic(key, format);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'raw-seed': {
|
||||
if (key.type === 'private') {
|
||||
result = await exportKeyRawSeed(key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'raw': {
|
||||
if (key.type === 'secret') {
|
||||
result = await exportKeyRawSecret(key);
|
||||
break;
|
||||
}
|
||||
|
||||
if (key.type === 'public') {
|
||||
result = await exportKeyRawPublic(key);
|
||||
break;
|
||||
} else if (key.type === 'public') {
|
||||
result = await exportKeyRawPublic(key, format);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -531,6 +587,16 @@ async function exportKey(format, key) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function aliasKeyFormat(format) {
|
||||
switch (format) {
|
||||
case 'raw-public':
|
||||
case 'raw-secret':
|
||||
return 'raw';
|
||||
default:
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
async function importKey(
|
||||
format,
|
||||
keyData,
|
||||
@@ -572,12 +638,14 @@ async function importKey(
|
||||
case 'RSA-PSS':
|
||||
// Fall through
|
||||
case 'RSA-OAEP':
|
||||
format = aliasKeyFormat(format);
|
||||
result = require('internal/crypto/rsa')
|
||||
.rsaImportKey(format, keyData, algorithm, extractable, keyUsages);
|
||||
break;
|
||||
case 'ECDSA':
|
||||
// Fall through
|
||||
case 'ECDH':
|
||||
format = aliasKeyFormat(format);
|
||||
result = require('internal/crypto/ec')
|
||||
.ecImportKey(format, keyData, algorithm, extractable, keyUsages);
|
||||
break;
|
||||
@@ -588,10 +656,12 @@ async function importKey(
|
||||
case 'X25519':
|
||||
// Fall through
|
||||
case 'X448':
|
||||
format = aliasKeyFormat(format);
|
||||
result = require('internal/crypto/cfrg')
|
||||
.cfrgImportKey(format, keyData, algorithm, extractable, keyUsages);
|
||||
break;
|
||||
case 'HMAC':
|
||||
format = aliasKeyFormat(format);
|
||||
result = require('internal/crypto/mac')
|
||||
.hmacImportKey(format, keyData, algorithm, extractable, keyUsages);
|
||||
break;
|
||||
@@ -602,12 +672,14 @@ async function importKey(
|
||||
case 'AES-GCM':
|
||||
// Fall through
|
||||
case 'AES-KW':
|
||||
format = aliasKeyFormat(format);
|
||||
result = require('internal/crypto/aes')
|
||||
.aesImportKey(algorithm, format, keyData, extractable, keyUsages);
|
||||
break;
|
||||
case 'HKDF':
|
||||
// Fall through
|
||||
case 'PBKDF2':
|
||||
format = aliasKeyFormat(format);
|
||||
result = importGenericSecretKey(
|
||||
algorithm,
|
||||
format,
|
||||
@@ -615,6 +687,14 @@ async function importKey(
|
||||
extractable,
|
||||
keyUsages);
|
||||
break;
|
||||
case 'ML-DSA-44':
|
||||
// Fall through
|
||||
case 'ML-DSA-65':
|
||||
// Fall through
|
||||
case 'ML-DSA-87':
|
||||
result = require('internal/crypto/ml_dsa')
|
||||
.mlDsaImportKey(format, keyData, algorithm, extractable, keyUsages);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
@@ -796,6 +876,13 @@ function signVerify(algorithm, key, data, signature) {
|
||||
case 'HMAC':
|
||||
return require('internal/crypto/mac')
|
||||
.hmacSignVerify(key, data, algorithm, signature);
|
||||
case 'ML-DSA-44':
|
||||
// Fall through
|
||||
case 'ML-DSA-65':
|
||||
// Fall through
|
||||
case 'ML-DSA-87':
|
||||
return require('internal/crypto/ml_dsa')
|
||||
.mlDsaSignVerify(key, data, algorithm, signature);
|
||||
}
|
||||
throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
|
||||
}
|
||||
|
||||
@@ -332,6 +332,10 @@ converters.AlgorithmIdentifier = (V, opts) => {
|
||||
|
||||
converters.KeyFormat = createEnumConverter('KeyFormat', [
|
||||
'raw',
|
||||
'raw-public',
|
||||
'raw-seed',
|
||||
'raw-secret',
|
||||
'raw-private',
|
||||
'pkcs8',
|
||||
'spki',
|
||||
'jwk',
|
||||
@@ -464,6 +468,15 @@ function validateHmacKeyAlgorithm(length) {
|
||||
throw lazyDOMException('Unsupported algorithm.length', 'NotSupportedError');
|
||||
}
|
||||
|
||||
function validateZeroLength(parameterName) {
|
||||
return (V, dict) => {
|
||||
if (V.byteLength) {
|
||||
throw lazyDOMException(
|
||||
`Non zero-length ${parameterName} is not supported.`, 'NotSupportedError');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
converters.RsaPssParams = createDictionaryConverter(
|
||||
'RsaPssParams', [
|
||||
...new SafeArrayIterator(dictAlgorithm),
|
||||
@@ -545,6 +558,8 @@ converters.JsonWebKey = createDictionaryConverter(
|
||||
simpleDomStringKey('dp'),
|
||||
simpleDomStringKey('dq'),
|
||||
simpleDomStringKey('qi'),
|
||||
simpleDomStringKey('pub'),
|
||||
simpleDomStringKey('priv'),
|
||||
{
|
||||
key: 'oth',
|
||||
converter: converters['sequence<RsaOtherPrimesInfo>'],
|
||||
@@ -694,20 +709,17 @@ converters.EcdhKeyDeriveParams = createDictionaryConverter(
|
||||
},
|
||||
]);
|
||||
|
||||
converters.Ed448Params = createDictionaryConverter(
|
||||
'Ed448Params', [
|
||||
...new SafeArrayIterator(dictAlgorithm),
|
||||
{
|
||||
key: 'context',
|
||||
converter: converters.BufferSource,
|
||||
validator: (V, dict) => {
|
||||
if (V.byteLength)
|
||||
throw lazyDOMException(
|
||||
'Non zero-length context is not supported.', 'NotSupportedError');
|
||||
for (const name of ['Ed448Params', 'ContextParams']) {
|
||||
converters[name] = createDictionaryConverter(
|
||||
name, [
|
||||
...new SafeArrayIterator(dictAlgorithm),
|
||||
{
|
||||
key: 'context',
|
||||
converter: converters.BufferSource,
|
||||
validator: validateZeroLength(`${name}.context`),
|
||||
},
|
||||
required: false,
|
||||
},
|
||||
]);
|
||||
]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
converters,
|
||||
|
||||
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
const fixtures = require('../../common/fixtures');
|
||||
|
||||
function getKeyFileName(type, suffix) {
|
||||
return `${type.replaceAll('-', '_')}_${suffix}.pem`;
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
const pkcs8 = {
|
||||
'ML-DSA-44': fixtures.readKey(getKeyFileName('ml-dsa-44', 'private_seed_only'), 'ascii'),
|
||||
'ML-DSA-65': fixtures.readKey(getKeyFileName('ml-dsa-65', 'private_seed_only'), 'ascii'),
|
||||
'ML-DSA-87': fixtures.readKey(getKeyFileName('ml-dsa-87', 'private_seed_only'), 'ascii'),
|
||||
}
|
||||
|
||||
const spki = {
|
||||
'ML-DSA-44': fixtures.readKey(getKeyFileName('ml-dsa-44', 'public'), 'ascii'),
|
||||
'ML-DSA-65': fixtures.readKey(getKeyFileName('ml-dsa-65', 'public'), 'ascii'),
|
||||
'ML-DSA-87': fixtures.readKey(getKeyFileName('ml-dsa-87', 'public'), 'ascii'),
|
||||
}
|
||||
|
||||
const data = Buffer.from(
|
||||
'2b7ed0bc7795694ab4acd35903fe8cd7d80f6a1c8688a6c3414409457514a1457855bb' +
|
||||
'b219e30a1beea8fe869082d99fc8282f9050d024e59eaf0730ba9db70a', 'hex');
|
||||
|
||||
// For verification tests.
|
||||
const signatures = {
|
||||
// eslint-disable-next-line @stylistic/js/max-len
|
||||
'ML-DSA-44': Buffer.from('f4d00cfbf585bc0178c62de0a37a3e3a2593a8fb4ea7147ae35c3020e0084b0a1ec21f6523695ca7e14a267083b95f56e9423b3487fb09be59c84f1ea80c8ec573e8e8d2eaa9a52dd7739295f6614fc705a2dc9b0122f9d32b731b3743d8bb44f47c5a4488cbaabbd44bc3aad0bbad9fa9ca6d29c4c3cf6a87f1c8654b2fd7c955f2721d0da7e39a01a7fa39b1b1a0c603da985a4b02e6951bb7b5ab0943fdb199defbdea65f64b619ab3334337a67b4547efa7e6e132f18b8abbe66875fc3f9fa95d9d4613f55356dfdb2357c7b7556560695aae35dbfa69d2c259ba7966dad1640fa6fefdfdcdee71aaf2a35784b19f8f6118ecb5a8f174bda4589f13dbfd21b5d90a68bca5c31a270ab3aecf9ac549568396396b40b2fba1e5e1500a9f127eb5d08685be93a4298f03351715a917e1cbedd4db605389b69448c06607d7f38a25746f9d1acae6c7827b620ea6e8526fce50e6ec4cdef1a7a154fb52db77cd3b0c4de8e54f43426fc9342aa4b9077dbc62b30a71af3eab48ccd83dd84122bdae87173bd9520c6caba46d8184340cb34da8a97803a21a670714096efc925f6920df3dd8b29aea13788040328192c44245275c562ffec15cbdca5bfd5a3514080353872b8d88bf4ecc58b6db8d16d00d16e13d536eb91df584c8aa8ac560f752c1d5b0c7247d628f4a569a6a3810562d1364055f3cef73f1b2f51a0f2595f50a3a09840c59a497f3cd837aa29f64f28b635fd0500b4b62766987c99cc5d3c79b01178a7fd2f84d588858905a74da8b725d094a7c255a12be113cd7907d44ebbabdae92ae21d9affb25dbd08524fa5fffa513d772df135bdd8bc99e48af30ea46567f8336cdb546cb2db23817b23c0915b5da6e56a83cf19ab742faf7eefc9f95e22ca95d0587b3dcc580cd2a932b884e0d7b6e72124cdcdd6f49caa63e4f85aac04825ffefcf223f4537ab04cb718dc18ba72993aa51d4d712e9a42fe3e1834e6c70b19762a5895ee4fe1e2329dadd053d296bc18084bac81431280433f8b73d3d7a63f9a9ce7a09b90698e467517382bd0d3e305e212381065bd2e01d6ac4b30a9ddb95f9af7b9724fe3e38d97b6324d90dae256fe389b3b835b63a47d80da3e9389b8970d58ff5b8bdc62c6984c86ae7629b9b6e728e87341515d2420275d00a5a65d9bd512af1b1d47fa84e422d6757a9a70244d0aa64ca818d5259f9efb80e5d251a6e1c4e1768ec9c77c6822246d2cbe18ed72b7877cf95002ebf4aefd93caacc5e130dedd3b35c782fb75a57ed29bf6dce66041e13ebeb54e98ea35eeaa6b32e943f6a7b668d5ecd563fa03be46151d863e9747cb1c355c2e3cb0b7627172e1ecaa50d295ed93ac0529d606b8c4c8285d9dce0c9b061ad93a12dc1832710bf1e4c5799fc0b7383c8055ea14a9a039d3f1ed8334741b7ec8bf2d8f7b1d6ad9db22b44a170aed2d358e5a20fc19e1ada04c390ec7647c49bde13924a9650dcc356d45acdbbcad1b2ec21a5eb835689dc958078e3c41898bad8989c5d816bbf403babe96661215e68e59f0ba747e433a3073afb957ba3ae3a435666dc287c2def5aba859674b181c522a6a54ed613faadcd26729725fffaed54692634b13908dd52db47d441306d8f31aafe6b1146cc736290ab4f8e01d54f10525a1454b5a49d389451d071076d8cac0b8d09ddbe44e2f5648a617cc075da438014eeb1c3bb3de26a2d1a332f82b1cdf11544e9f459334cd61e94d9ba2ba57b2db7e9d22b86950e2a2ef5bc5ecee6efb60d5123a7507b6fb73f2ffeab60c9a70de6098427aabaf8fd29f32335e2d14964b56d5bc86361fe01ab0ea6278579b4e7c3866c9e79ce006997a74d7964be9a632b376df797fb593ded91c802959792b3c38fc92186ae2eeb38dae94181f15c8a4abb5e1740c8eb3460fc88de5ca6a558a81381b29e2fafd2bca4dcabdaa4e45c9cd334614757c6a7be7788c93e27b6fe8a4135db82312274c57e98f06f8114e11ba5a4354cae97d44ae4f5b4682e34f955d5535b859a6cb59028feb0309470177163da3a7c1a76fb37f021f16678cdcb07bd2b49b0c77211560e02bc08446e0af3d1c7f736cf620a0a79d2a849117cf1af585e26b4984c157f5012557f96d41dabf98d1533c31df28bb8a43183e592d890bc111c0a94db3d081c34bd6c003cca0abef79bb8c95c62c6647de01e47962874a68b671042e315e6f192175ace030aa9b76ffa9f4e199c6a4f56453a2b312477eafa4c383ad2429fa453ac15bfde030532fa2e26cb200e3c7b7061f076fe28dda68cc07e7c58ccdc22fd164cf5643238d9a39945da27372f600b80f88d641734a1f8f5e4e47d0cdfc083139198f42908d766f308a3409f56b853dda9c4eeef87f9e772bc8a1a3d5f7c4ebf865a722d5181da636297161f8a7e23d54b8523e2b52c17ddcf8f388032e4b8780a5698dda7fcca8fb6fdeb5e4328d6a886da5015bd58087a0cc43a72f5b88a78a7a12b0daaf470ed049e170b8b03ef8620b654e744859bba5d5543f1e823eacb59511230aff547900091a37227c9021549e4eb954c2b7b587764fc88dcd224067d9639cbc8c3fcbef71651d4273f21f5813626c710c12f16cd0757b3d8b8ed19b474e53072207502b66faaf756fa8846304fbb20ece8ce87cb71dd8344d7b10c7e516fc3eec7854e6048a893bd456421402994612a52fef16a97ab642edd69c30b1cbbe0f8e73b8f12db6574f7c9c7de94cbd698688060de7a63c8247aa3b95bbabbfdbdab7fa637e5404123ebafba52383c459621c154a2a23eec97382eb531b2ca83cdf075ee5bd54ba3bc3e19dc3ccfff08e5e61e8b49b080809a57db3548845ae9f5e15fa10024e2b86b283259aa11f3620d5104561fc32afffe54526c5f26e1c941928fed2fc4ad247ae0f590484265589cf0ead253f0a9fd50ae2d8cf02deab6a0f715148f905274186f0c30743e3542bd6ee93563f596c43baa6e0b99be127d722fe17299af2716365a7e72ebc20eb811291ce489b739ad2d3f79a4e81a2090cf81b7a45ff782ba3655bc717e0f80e4a276c0c3db48036c67d1e95797e2c7c9e183a861e28c9604f3e2187e470cd0b37a7d2e78b3415f6391b7fa04c492edc03c5a728507f234fb6fa885ab1939f64291a2058538bf83cc7cc3ea785774332d92b816c76d8d99b94fb8c237113a24b90768b2314aeba2846a645e623834a3a947856e7c85eddd63a1865700d8ad5e36521fa1f90478601a557ce111bc7eed0b7542ff6e8e887e2253db793abed45581fbe9ff0a3100308102026616a7a858f9e9fa1b0e10e2254607f84b1b3b9c2cce4e7fe08162b31384354627b8296a5b4c6e3e6f1f6f7020a191c213b686f8491929c9faae3fb000000000000000000000000000000000f1d3040', 'hex'),
|
||||
// eslint-disable-next-line @stylistic/js/max-len
|
||||
'ML-DSA-65': Buffer.from('0d7f54a113bc87e6be6abc34282a0abf0dd12e8b3ef64f338d62be9986eff721776a3ba2992b069c8c2d15e0b948f2615a7a71ba42650abcddf147f50e6ff7de01aea560ead3b540ca1754b4749ad345f750d75c379804b7893cdfd059345297c8776fca5378ebbe1ee1fceadae9bcd01baf39c8f01e8791730e7e1e5d0efdfae2acdb34e6be09a258b83eb29da9e48506c5d1029d1b7157b103fa4fd77c8b305a0e4f2dc82b68936254bf3a345143920f67bada15d3038f76c160281085a666aba741ee44b12ed4018e9a41d77c642bfefd658255ef560958575c338635d140bf73c2daf923f26898fdf45fd48ec24c4ecb8adbef15bcec7ef5302fb58ce6a16628bae20a55c497c0897f86f0ec22323b96e1bce5e0cd7c608aed5706a2c73d5d4d05cc637f86320a8eac06b8e26a13874bcaa9131db6c9e237841df21789a47fe48a13895575b77e141e3285197b5a16f19a00bccb1d384ae026a17d64a55152188b88a682562340f667a19dc3bd6b5592d39e8b7b408c1ecbf768628038fa4333a475a72c03f3cd8aef346b1910724a47ed915ff1b2bc71ae17f127b903c679b103026c2aeda967b0d6497a30790e2507cc79bb78e9326f66c8d015f20baab3311a7b436c357356f20cb03209bc82863004597439d0905d73eb6213d14ef4505879e5ac3f4988956d5483bd0665d0d9b3e9353de68e7108dd0a6af6d23422fe193294419c3887571b7470d206f23cd059895ed5a53cdaa6ec94969b43eb9c98ae53b909a4162d6230717b3105dd4d511a40b9817a71e037df02d95c508df1a392aa40d9516811bd520442c00b8377023cce3f1462e50636813ba1e4350942c435743939cb540d4688d0db69885ec2d2e3d37a408030737dc8fbd42cf19df941fa5f8b532cbf839ab13b940b5b37200b900d27681ad97a4f92c256c29d63888302b076665d5b9c2ce219fcb12f80dce2b94e6001dcf3f662e01f905694a78ca5e2afdf8ab7cc1fb72e04521d9998662d423936d5ad359ab44091b53467406b7c306c0a0ad2e480c968f2d9e4f392ecf983fd2a4ad198bd701d09a1e2efc5c313999ceb83695d99a5ef25daf159d26f4c0ffbe3c2ae03cde0962cbf1a4e6a98dfc660922c2a399190abcf933a73f68d491c4ad8806cc450bf23d4e1c1377f6168a3c4df5b6bf8e1cb4be11bda24b6d9c113ed4d40fc2dba9f541d97739b5e40e915be1e10eb01c30ef609b6eaaf5d570f886d031df36fb7614080dfc088e821d1ac4fc50a48c5dd7ca6f08c7ac280bfcca640cf738f08f7da29639341e396a46d7204cc514d9c8dbc213b967657f4a67a29458947687b55ecf26d833239a7c0915f10334befa61b74372a8e1f4adf44906ea6395e15dda5e4b2d2005d574a943abd9d224c7f904298e2b1e249ab33d93089f239de6ce6b0c2e1b856940b7b08ccf1f98a65dfb3fc615457e2ba436bc63cce72510757380a5c07d56b47c93430b6bf9a89e5f6e1721d7d50b7417432471dc2ee0b02430fe71f4122c0e3363db446e4f7ad21cee944f3e6072fc1fa57d175329707f52c51f97eb287d7af70ef91c0632ad5b89929507a2d01609993c2ff8bb991e232b554430cbc0ae4f6b3225013e1fd0f8e0a485f7b55c1f96dc0fb6b395ce104d9c3d780567cc9f7bcda296f665a5eca11a94fd1d0f35d10e0b017880e16f31de961f7b5fabafadd1c99c80cf7535e7df7b807fde38b530ee527234983e25eace30c4be8fe18edc58ae53ad79a145ee0700be63b636a18a4eedfab826383a9e5d9f2b7e490c6bbcc3ec0f37ee44b8e301091c6636cf212e3519b706919af41b872d6b4778cca8ca3373f62dbd8f68b59ca29467c63e10b886a18d2a32864ebca2ebb2f602b736ac8587d544d74d9aacbe6e436646ffccf2ca3da2121af8b3431b523e09a538bdd07ad3cd4c71a76cfcb67273f277e18094ca9730d06af60c354824abc84f623e1727a4f43c7021ca18d463c5aa1c53cd4adb77f13156103ac0907f6487689bf5eb2202a6ace8c9f55b5a285311d2e243090ce07e9cd2bcd253edc4ca57c1c42383184ef08d3f7b4ddc05fee25e8d72a6fa0dbe545dd3240edfc8081fa49542bc23d426ad286010920ad92b0fbae5833523a94ae59b87d90e1ae4cb504f06512b9c0c47d854750b45bb01a0a2788c51d808748f6cfab177fdd943965187fabc8419292f45f57718f709228a9d51dc43e21ed3af2bc5cf8ba75a4d22203a77662a71675b15bf91d3c7074657948b43e87837449bfc5eab1fb1fa9f8f91df5669b4957eceb02d013b0c04b493444ef673a103f630923c9ecc5c2cfb9fe40c1877fb9a67e54f7f0ea0c49d0a624220eea68bbe0e23d20092ae73a8a0f7749cf85499dbf4846308a190bf9ce68fb712a20db6910923eba88f42e93e76230bdbfa9890b6bce07a5ecffc396cbb314d3152bf1677a26a0245fd8373a1288d97e713d2326194e2e26990ef413a1076035e7e04be3d07cbf9403ce9f8b7f10c70badf62efd144324c1d37ead93ea94edff937b0d62820baeca5f56cdf30487097f5058ed3d74639543b1c160d6e876021c96feceff84bb2b1588c72f5f9a6a843b85d9b78da39a085f258296538467ae9568d23d9006e768445f9752ee754dc5ddf9b44998e90dae1a5c720d0abd3e81b750ff8a689547998a45b5a6155b462e8ed38c7b6c44bb81e64630449191a38ddff8eacb3f0cc675bd84aeb6acba135a65d2e7233e6b3d59f57d5a1bdf215a3a847a96306a203ff4a564524e03526fe3c35906fac3316cd19cbf39fa9b3a37bf2624c4f7eab0b98d43b967598349e7b0e69ae7a110aa5614e68afde1ac453bd8b02a39307c6423339d49df4a1d7c3042d0bd34ab9c36894eacaf1872ac70f0691dfec0ace938d17f1f61c7a0b6a12542f0d5e0438d2f0c69dc4f0a2eb5eebc56155954d97855a5e95d133663f29402279d39e41750c0667a721cee486847913d383940419dc9fbc118d1f608abf2f2ca244a7486d1ca2e883958a0d36e290edeea0e5dc8b44f22a6ae7efacec2ee642e8417d5b6338d58ef540b5438a2de2589e3c911d93570d1f7043da7f04f6a97c64af34f25a99c57662ddc27264d5fd880d6538a81661b8e83ce0f00e41a09dedc2dcf0935842b46c7b0560f0fef6c7e45d20de5566cd68c4bea75af56f68ec6f8061b59bad47d346c02d4ba89ed92ebe9276090a70f119faf4038cac4d655682285dd53707d00063f89f97dcda0e370a2b83bb6c8d9a4db2dc85efbf93d76b007de3566ae416a817d1fe9d7383451b8789d4892a4144befbf784a837dda4963cd20cca292273121b370cd1d0dbdc9e42aee99ea7c833779cd1fcd570f2c502c791ce06b082ca2f820eb75fa2b5ca072c915e3bdbc6eaa3cce642e1001fcca516c6635ee21c4a921af590d50d5127da0acb8ea48d11ea777192a540e588855acfe2ab0aa23e7743da7dddf11cb5fd7c3b0536b1dde5156b2968420b58d502d5Line truncated
|
||||
// eslint-disable-next-line @stylistic/js/max-len
|
||||
'ML-DSA-87': Buffer.from('737897d83f7fb82c704f4660c16c544212f3d3d280b3390c43d356c281aca7a3c90637a5dea83bf3504e593b178b17ec38a8175507a6c28b80c21cee28146af2161af60fb123420578e0576fbb9d579631efda9a4304c0ed67572d393d813155024ceab089c1cf1d0a5e9716948312f70b4a7deff76853f5cdf29737160901c14ac2f24ea4c7f819d86fa9758b8ca6aa6ffcfcd6d60f90ce31d31cd9d88586b9a38a22402be7c89c9d57c2b194179011c4fd185a5bd737032c1e54da0108f355130ffecae3f39a47148dacafdf25f9590bf6c8fdd9d9b7cdfe30607a235993c59631f29fe01453e2fd61cd4e8e3be21ddffa054c5e91fec88ecd531090ce21d68b7b11888ae9372fe2dabdb00ea311bfa564f86de46c61f284a246e420dd8056f021448a2fa6dfa2391e5beb6ef0a5a28180dcdf20e00dff4f9628a99054ce72061b0359cc67d4329545faea8943d90bb0f85bcdc88ef2acfd72056d2b5fbfed40034f2d344a395434d604a336c1e418e2598d07e8611f9c28c23bd2771c4d4dd5f820f197b50e58bfea502f6a53893d7fe6a7460a62b8ee892d17dedf606cf61fd5f27e002230bd15f0e3d5d951df3c54228c20d58fe5e5d072a1869bdeba1d90cf019c6bc3fb0df24a11894bb3a2d279c67d3a6d4342e0e2913861bd3f684bce8ffccbd6358dc0778c02896b719d675b584621edceabec3a8e679686363825e6bcdf6579ec67ecafdf23d6e23b747e340fc0982422865b8002590f9e35c8332ac47be5c4be6eeac3ee4ba79574f7c0aee0fac0e5cc7a9b7288814c36b10e2dbc900acee6841c386fec11c69580a87244fc9f995f6adec68b308b28eaa17129c1edfcbb8592b4bfdf6604afbf1f206010b47e92d08d830052d109f0265213fffd6ecc47aef5bd6f4d5fc19d2b06924cb96309945168f382977e9f6a2f59237b4a91bdde2d00453df0e7c516b7a53b0b8582aaa7ad8af9f40723d09a247b653ee48999148b5c160a25f5e9cbbdb53642429909a5af11c6f36db3fe8f8916f36f565fdbcd863565a6dd63b974304b6aaeddf91decc981d21cc93c11d8f76dfeca8444b6b882ff59be214fb1ae9fd90108f65d4f533031c35bbc552950b1a96f4be7ea9cd167231d7a7fbbb203d34bd764dab3ed2eeaba3419ae3674f7f01347427b84ddb5b86969e57e6bbf86b61bbda8fe830f357d12d15eea0df7d5fa2d641b03077f058719bf11819f0eb1dd921b783b9c648b5b3cad3d22e9442e514e9eef96d53c1de328dbb79eb801974b88e179d98d28bcc75469a2be46ae9fcafbfdb22d302ad2b535d7c09d06cc5ce1a50a569dbb13debeee5cbdd3341d06d8be28681c7716b466284efb4bb1b316b72f50c85c2a260c68231e2c516265f156e5f5ac735b9a420878db52950cdfcf21dcd9da62e41a4e117386b624f638ed51b4d2e156573b6a327698bd41a3d036414b201b0a31d818fcdce9c1e4d55def388fff5fcf5110b680e5ba3808f244dccf7fb01e8197ba3c3a3a2be74f44551f5bc03f77ca5010d1c9d8020fcc7c354e3ce9fa25d4900943f564695da56a6e4388d1bc69a68d413fc80e5913d22d2414b081052c216afc67ecce4ed126a8e0762191558cbbdd8d4150af7bae41f4941ed42fdae4fed9a40d70a0159d4a8ae48006022dccb6b4ae05dd484c065dbcce9b253b40d1eb542073fac64dca11b6e1196c5b50fb33d6bb831b9977602bc9d43c80713a5d714116e62fda8e9aa2c790e8d5adbf8025dbfa5f80bb92b661d45fb972eafa25303f1db7839efab7271ae41ce9f7c28a7cb8349a3eb2734c6b13caab678d53eb742fbe84f53b8ec89e6c155ddb0a4908799372123023f4c8d6f97d30fb70ff2d192be0928fdfabb9aedd04f944b2c7e0ef143390a20a5d5ea93d3a8f425470666dbf8733a2e2564f27e1878b2805d71069e55b225e3d133a7cccbe0db3f2b14ee77d717bcef348df09259efe12bfef08cbb0e8d58f08bf10c6a7b0c2820b442c06209e9b8134aa20d05e8e2c763a8b88b5d4ec544aeb1ccd9468901f6ccfc20eb632a75d051a0295590e02f5ded6efb33e54479b7e1104062ccb73bb5bcea1da9d4d659e1ed40a42ec13a6f27606a002097565264954625103e921886df888740b7166640132b428a97062241d083cf8b4892c159902a9cf35921df2966b50f6f31209773d1bd10c61d14409cf1e90a7d06d3fa226a865fb241299a859b8dcc898b4bb1dcf65ea17353a130e71ad184e9e89f0676e666352ff4614d8a7046588d97038a449ec426b67c9ee3101b8091efdd10867366cdcdff3581c0e973ab6ed71c984b33a58c2e3a865ab1bd055e629a21fb07a8a23e998f2db958ccbc89fd1b3512330f2cc69c3d74e16f8848556011881701b213dd39e123aca241c7231052a7bfd4738fd69bbfcd0ab74276907c1be3f75311e395a485d15b592d16d22c33ebf91d64e81d500ea23d53f130804ea1cf51c4bf2b0474f4f62264ac7bd90e6e9dda4d2b627b1e8043dfae64c6920a4f9a14ef15826996035af30cfa59a6a2411c61d16938004e2ae2ec72c32825a44c3200853fce28e36620fd0c71121346aff28e19218899f8e894fd6e477571f2a5c6c850104495a89cdc0998496b979b038f65ebd15ffc477ef22e943358de58612bc734d06bf8b77fac755b64f4c71966c699c43c5c38b7fd647a8b82cf354b1da4d31c9e918e146a997f2b4fc612e2ec73ab8e017728308e589efe326d4a14eeb55de34849938446911b9f3c62ee51992da1ea284650e0fd6f6078301a46948abd7d6ec2ca9ee202f26b9aab99fc29271697d8565a5147631ddbc9295c44812262a9c39cf0df4e08c52749823bd51d117d6cc106d74fe329c658c1034dd7d9a2f073fdf8bec519aa4a2f9caf8d0d719cb37138a0383b263c1c28a8b15c1d18a63e366a9892299b507da6bc9926672289a4f9f679e645db6c85e1cc1f4e6f9581984b2f72283a8efa471614e3e3d4a58921bd0d5feb85dc9cccfe4a7eda2be3d8118b2f4ca35ef6824e1a2d09162fc81791c2e30fba9368022ce8e01e1601944f05a0771b2d3c970f88841389b11eff76c853570c66022c3d35c4e94714277cad948c1a2b3273c6b3d675f9606b8b1a5d1848a8fbaf0f6e108b0029b6fe2ca230cf0e5a24049616db1b5bbaa0116308fe5948c45a4569fb5e3aa0bc5ebfeeffec460935477ce1c06dab0a1e7012859435e9887052293ad68a92df2b498b07dc991f16d04dd96bff885bb49a381b27c7e3701aefedaac8472f9d547da1aa8e226db691fe48c0593c8824803e564f57bf6b1c927742c909666b07f92f77236a2268a6148b517c1d2dea60321ff1baa5f47c5dfc000c8abc1c78384e1d6ad67dd343ad5ca3577b254d0ff85f12953f2100e6ec07d3c87d8cb79538cc75aa60fb936823009a55a1e7642a18efb94ec2eb44724f5b492263070a3e5481d091820459691507ccca318ffdfa4a0f5bc079e4c6a0fd41e715Line truncated
|
||||
}
|
||||
|
||||
const algorithms = ['ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87'];
|
||||
|
||||
const vectors = algorithms.map((algorithm) => ({
|
||||
publicKeyPem: spki[algorithm],
|
||||
privateKeyPem: pkcs8[algorithm],
|
||||
name: algorithm,
|
||||
data,
|
||||
signature: signatures[algorithm],
|
||||
}));
|
||||
|
||||
return vectors;
|
||||
}
|
||||
@@ -4,6 +4,8 @@ const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const { hasOpenSSL } = require('../common/crypto');
|
||||
|
||||
const assert = require('assert');
|
||||
const {
|
||||
createSecretKey,
|
||||
@@ -180,3 +182,23 @@ function assertCryptoKey(cryptoKey, keyObject, algorithm, extractable, usages) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasOpenSSL(3, 5)) {
|
||||
for (const name of ['ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87']) {
|
||||
const { publicKey, privateKey } = generateKeyPairSync(name.toLowerCase());
|
||||
assert.throws(() => {
|
||||
privateKey.toCryptoKey(name, true, []);
|
||||
}, {
|
||||
name: 'SyntaxError',
|
||||
message: 'Usages cannot be empty when importing a private key.'
|
||||
});
|
||||
for (const key of [publicKey, privateKey]) {
|
||||
const usages = key.type === 'public' ? ['verify'] : ['sign'];
|
||||
for (const extractable of [true, false]) {
|
||||
const cryptoKey = key.toCryptoKey({ name }, extractable, usages);
|
||||
assertCryptoKey(cryptoKey, key, name, extractable, usages);
|
||||
assert.strictEqual(cryptoKey.algorithm.name, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const { hasOpenSSL } = require('../common/crypto');
|
||||
|
||||
if (!hasOpenSSL(3, 5))
|
||||
common.skip('requires OpenSSL >= 3.5');
|
||||
|
||||
const assert = require('assert');
|
||||
const { subtle } = globalThis.crypto;
|
||||
|
||||
const keyData = {
|
||||
'ML-DSA-44': {
|
||||
jwk: {
|
||||
kty: 'AKP',
|
||||
alg: 'ML-DSA-44',
|
||||
// eslint-disable-next-line @stylistic/js/max-len
|
||||
pub: 'gtP6UVGz71mY6VgeI-VIcelf_Dr6FrqOpyU_uU3Vm6NsWHuLd5RhxYdMdi-yZLV2auTSvjL-vaHIdnAatD1bw_ggrvPSIGFdEL4MCM6XTvEovOP_vk9KUBf9w44YZhV5VYezSpJxlT7eYPmCp_yHu2Se6bIqmCBgibi5-ZBhwBM6W4Aojq2a6G-a4M5aH4tBNT7nemoOEiqgteqDWx-xaduFjRShqTzn5OT6TXn1hNIeavnUuTDgxnveA5z_SrIQs_IVMlzgN2a1nnPr0rjO4WLhpNk3vMZ4zqeqQ2iIXMauh0yAM9zI9kR3AIshIg6oWXF7_bq7RXdPobaIWzAhVdhqllyhKnwKhY-mPbYvHz7h1G7lhye1QOwC63gtBxlZ64KAi73nTnxKlaWRFm96gSKBwNZuZVxNLUkpNDmGWZVBjXlnPCCaZ8CYSM2kiuRUJcZaQnS9JJmvf-ZYsZdQvG-crEVGq56MwjUSJtuSPFYdwD5k7Pz1BVJADmI9ushzFVFo8pgfGGkxR9fStg_gVpD4rwnB3-DmiXeRtIcsxkFGzhjUorLauAP1ZQSYqCHZc3OCtLV77bBaGc0I8Xbu-QbF82Cm1xepulXF1MqbroGUqH-sWZn6_7dy8pg1gAXvED-rTZVACr90HnxIcfzRMWpUpbbUk7H1ywA6qHMIXJXKsNjo2gqkae5PVRCskf1NLZ4z8xyDiCC3vkw9_Hd4dUGUhhLwifFOoHuffZg3a5Sxinc4DHW2qyClZ7iN-QfJ00Uz0wZPts1Acwl1dfo2B7UAFpYeL9YlVehQgJvAcfsrffwvSVIWt9XHBmydABVJctrwz-p4s4EJNSK-tXrpgGS6w4uo7_6gDoZyukLYLJOy-YBhMSUrdJg4RhnjezTekV8huCk6qq4oj1JNAzOjKjc-X-CHnhIsyNjxfjcrO2SVntJLMDJWr52eyxcyhKmrmcjJaL39dE21WxGIcAdFAvD9IoAL6fuaSpOwxi2XTDBmXBJwWmdHY2HXGUma2RlfMNe0el-XcPxgAyv1nbypBW1pcK3k9e82mrE0ldNYwPifaZZp9ebQpYJ5Snj6m59twNCGFmiKUn3N67seCEkxzUeLnxcHTGmpQxIt5y53VHY535npd-H0dxRMnISTSrQ2tVtf-vQPU5QW_ldcqiYHRBSNv2Art8NDjYJZQU4qvvRyox5mhH94g3Xoiq5N3lFBtUtBIrMCNFxGHye8sNaOjJcimWBqZdoM1bScDflqnR1W_tOnIlLHJzrNtKHDObdtHbWf0K30Y93g239CZ_pSz7JsKmu2h5CnXRYMKxYY8tzwje222rlvqh8XcDHFBOHGDFT3etQvD7hD1_XaglYwNm_UIl1XRjQuYTNIvekUHFoA7GDOBfE17Txdbir1Ne_QUt_tufBuU5p8CuWbJMWKq50Dt0Oj6GT6eK7rfELsJWrqezcKzXQzm4xTXLKdfx1Lz_INsekVZUu4963VPubqNir0zBGFScznG_zUeGlMIYyLUGxqk7BPXLql_xaaeLblx8HfeMSRi6k4Cw0OFHX6Vy6sPIk5r00D6_ROD6DN8bcExC_3bF8K2qCrg914EY4pZ9BjgVqKVGvp2HWPpgQqvQCq6M5C_FKVhtfsd3f1flO3_xu08R2edvfL-1bSqCy9zEUpEc5vGBfKLY3DnTU5dG5V-xZNwqjWrZKDNQVf5wOyl-PZlWlp3DI36PH5NNlktUy0rMXkT-X-Odjy5xGbFQ',
|
||||
priv: '1Z0s934w8QPUceWNuRN5dfrhQb5_4GxQYICWnBFxnOE',
|
||||
},
|
||||
},
|
||||
'ML-DSA-65': {
|
||||
jwk: {
|
||||
kty: 'AKP',
|
||||
alg: 'ML-DSA-65',
|
||||
// eslint-disable-next-line @stylistic/js/max-len
|
||||
pub: 'gMe-7J_WYur_NsxzG0iYWqh0LHtK8rbArEnvuNwNHYVmB1gLqnMjYMeK7_ScIGigoMddrW0Rjy7iv1srvbIpsx75K0ifzIqtf8z-gjguZCKWLihbt58KuhPmwPmTUmYtW-oztmVGpAMk5oH6dhxAyPJQO8hP5ZIh78e4bcRjYeyA3yCvQtT4tpDRtCDBnXA7mvdDLmitQI0-rvHtA3638EHZmbho1FxAf_BrmdLdUZR3d9-KlEN-7NWRkn52VYGitaG14SXcCorKvaxfo01v0v-BqAeLxBFzwa93NZKVQKrjHx0m8wXKJGkZ7qQPC1HSm40HGps7kxRNjSDL0T7pOwEZorCqL5n1W6GWzMY0NCm5B_t7hQdZenBkSarWJjHKDiRTWpKygDOQLwqKXUjX42Y5kKh4N2H2iXqsCyb5b2p3D8CzXn5OMkTFHARpP4lGr88m22zq_r6f_L-Q_cW0gWhFILxyUQdzwQYtDfVIJVvdrkCEwCyN66nPKQR9b393j1uunJh4iSfV9SVgL3Ok1P5UT7h65cufsaikMNEnsN4XAtUXtFivUkxLFJwSJZMnZpZnVpzgIJWYnmqrHoRhPiHK1JtH9o1XxQcnGpYWDiW6_-WLycpfSbo4pRNkMjr-fGv7xmdXejQELByZMDxcM-QY3B_BRK7gTgmhr-_hjwg6B4x5MUQXKFeON2qmqYqcelkLWi3q-8UuGm5WIRF3u0ODHxqo896wVnq6nTbgycrLfvLUT_AM2qAAxR-w4SfQ6KZxGeGidNe6dFN4TacW8-NbsMzGTuyhzWsZxLIG8kTyveyNMFwqOYMj2mpPTcg52tRu2izczeFQqXiFhRVGATt-KXGMjmfaKavGkf2SUMcTSJqnTHJaZv7QmMNosgXYinkQAz4XyOfwsi8fgXVyfbh_05o2roM6AiEDff3aqD-m0Vp1d-AFHLxYDkRFvuW9BxbQe24sTopODF6hn42Hh_ZQF2EU1cIqFGzecPV1XGeGfP6Df0rO78701LOw1PemGXCsU30Mn1sIK1fmbqK8gHyZwP9mwS6WjxX5ByIMS_iyqQwWvzcFI3d4h5vYCKC9o0uetorwpvcv8SRTR7959qvPF6eYFO8OgvckB1Ydq6KREMpphL7-EXb1Ot-wxm8v9X2ZhUvTtV-LPxx-pq17qmcAM_ifwinktBrbvGifxGJ7Ku4ZFO7RtuCCB7FOWucGXGsHfs7LMwHdF8XRmTeci-XsG983zAKGYDxyulLD81TGrO2o9ongsG4XIAH9y85ebnfCG9QKfOSdPBxtk8nSJXVb4gSOpioeyt0WSnNBxiUyqOUKTLsrzmK4FZPvEQgZhJSbamoE6_MNkuJ40FOmH28Xb56WETJNJjibd9Mj0d6_ozq0ykpAdHLTDO1EHGIVImEqDQlCyp2zQRun4SVH7MDP8zZpSI2g6GlofDT2A5Yft4OPX6VTX3uaePxIOPmZr1MrBiRNrP9NboJQ_uw6X9pWFCu93jts7XQWnVubfKPcDDHFzZhUMy1y7GaZxqxuW0AlI60XrVElqR_RPa6o2LVd1_CAMWPPj3UAIOoZ4tfkDUo_Ss9HStkDV6gswh9whvTCOW-Nt7C4z3dunvtiT4chxq_0d3_xHzqY7xAnbENIdIIVDWhRUQI53_ThwBVGGpKzijNj_IZxFfz0R4pDyp4msYII8jIe4K87bZ0SuKf2MTLL_sI7E0Rqv-kGasONULQGkVoEMqprOS7BY4P7VrADU_riVLBeasJ3gZ0rh9YaN7GkUDsYa0Lp2Ts_NKIOjH3pZOY8MYyuv2bIfgWE4zYVlmmxyACC2K8EwQQe0QArx2DZAKQ6k-MwrwidGRQfe4dJ0-XCYD5947Zx44sTLmYri00awyuCk_o9NG_KLOZU8mpLUmFFQazh2wEsyY0fYgtK95hZfGLsVcci5LPQPl_B8WhgFoKNXxqGAqht7-8YXwGEdUxT68EvAPFXFuQKyOZu4_q64ApPxe1YWTDntePR1_bhOLlK8as0zZB8iJEeZDTVRmTA5CknGDfIt5rSA1_jcSfteXecNk4xTH_iU4CPSpePUES79kQGVG82cD6sQ03N8Y_buP0GDpViZJOB187hh3NhosghozMoqFnFUgcQaYpMxqMYyVEZczaJdQbWnEWdb1ygfmosfRxceHFF9Sb7-SwE8jRXa_5QMTOhu1nohV27Zownoq0Bd9bqBLMNYsuUOa-s6frJkOZVVvr97v6qJMaq9r8Ol-1dXQag1pca-JdNvGizHFp8a1qGY9b7ywgku5MdyL6THA4KCRvgM7Mj1gQ8sQBF9iMtNSn1BVqdjDxaYITe5J77DBqO4piGzTqonhHhxtRFDYmkk9hSe_GkF_ZMqrBtpcQkI1Xl0vHIJc6i8y2rOe_XCYO_cAQYhgBOz6sF6OCSkYkz82ygaM6HEGE16tTT7HPD47uy1iO3kR3yIq43yeqUByfAp8Y2V4t2rKGG7Lfpne1tnXpO53wEeLWiwlQ6--J-DCfoZLTT9PrKhGbh_z7329QRQWfKXTtWD39qA5IjK458oUBSqVpEN5kXXFA08dEIqEAn3YQW3mDTzRliA_3SOycOV0I',
|
||||
priv: 'wS0n9kCle6HZA6M7BXlaAyCvUUqeMiEqaiiN4Y0KPM0',
|
||||
},
|
||||
},
|
||||
'ML-DSA-87': {
|
||||
jwk: {
|
||||
kty: 'AKP',
|
||||
alg: 'ML-DSA-87',
|
||||
// eslint-disable-next-line @stylistic/js/max-len
|
||||
pub: 'R21Wwut7jawo2a2nJrqIk5cm9ay478z7u01197SY4kVDB7FBYqb3XNFrLIlV8N7Adx8MVKu99A0QdmnaoCN133FDlIU8ys9Q92Px9AaUjVWaRoKFLBSwaP-WF3jGckZwBIm5kScwbkQlK60CKlrOpdwobXYKR-2zXH0bDKSTl2kfx6N9uRPm1tYv0ELyRhVGWFG1-OFcN2ir9Tt8Nd4zfPPdpkj938K4Wytoc9V13iqwsYTKMOFBE4RE28Mq_Wx1XYUu1UOCKjYznHUwUQsqTeA62o_IPQapxfcz0wsIqU1ZSdqWvkxFmRXw7kKspvVjgpZEsY6Qj9105-dup8jeOVpWhdwqQ-2tyJtwCorgWlY9UycHXdX0XZlyGYFsI9HZO6oA0LsI8aaZeFEuGwZKoXmkABkyQt6db8kLgua5nowy3Jm5FfZ3aqGukZiS35E98oVSodRywnzDdugQ9KZ_Nt0UTUVzfm-qJFBuw24Ahsf4dRqappZPgA6szFZLa3u7sdFah9HbsYT_PoLLwJ9RzBtS0HdhZr5UHKpcGP96iIxl88tz56NEWNrzMB0XpHDx4wrS8Qdn9Sm3oWnfQFkC61u4vuLSPNDpqQlJfCKac75_-bxxDoB7Pv7KbAJisyBgRgaiilCOWHNF28K_x8dIT_meop4TTbBZzh1tuy_uV0z2sIu-YV9f6ZntDLcLgYCILEqFAWTuXhouFwRes1DwAluIgI9TCfGGPHJ6IFIaenY7-igcJqy2nGulL8gJqiVg8zh1HSOx9puqvYn_GJj7i_kgu7uSDsrpsGSxoKsnVRQ7SGpWmTOvT1lE0-5N6ETAop1jGFzKvW570_NlAcWXoLPnm4qYBKyEs2pAUe8V1bS5xxTL6dkkz1G2w3rAr4iEzpCj_iFHmeapcP4bdsPcHJjSikKZN5kLsgqXWCq1ofTRk2JbkMKgsjiVrU2Yno_2lWm7qYWlsUf5MG4P6fLkuYE8nIb1HGSa52zWa_s0s537IWaGoJloaH2I1rT8KXNx8-JEtyobkqLvwlgkcVHAtIiMD3owGc_3QD9kvVVFV2d104OU_dVPsP4GRvAyCGbyjdB4XheciXgTRKDJunM7_-sKr-8Bn_5vU0QRlzeJsb4bxczppYYz5zcWodcYtfbIcXbwkjLMMO0LkCL7ri59kGbwYxnmDhVfhUxqLmlTbB9_mFm7JlJ9G6ZTQB_zGxmYYQpm8iSPP4fQO-KsqSky-wqfC75K7Xyghu1jAZp5M2cpxQsclUG64MCUOEYpSODSlrkdnkkjc8O-ll8tgj9JuknAl5rqVvyRHLmIPLaKVXMrMxDdyiJWc2niIWSqrg-XPiFda9S92HNV82qyj_QBrMxAuIGNFI3Nrup7MYlVAVFGQkkAAvfbuxbOZB0SBr9a8k3q_Urb65aXnJxo-CGddeyDKe4jUXAp6CB8X9KIFyzIYBTxf7rp-4WcsnLi7_mpNK0BiTKfgeHMKD7c8cygyFft2AMnHDfVH30R9LbTTf_4HGT_UQhlhw3dUaECGrrqJ87dbNBxDK0_5DNa3NUxNIB4uo3VYRaJToV3yCmIZSPy3_REUXLNqMzodMDWsy6FUIV_mi8D2sh6C8iy0tXuAcIjDJTsiHV5w85_yQpZ-KnYJz5Bxn1CtakKf8szA1WQ0ZSxvd0KN6hr-NG-9YKtaqUddWWor9uyNA26x6oKl12GWTCjNI369OJ5s8x0at4Sf6ie8jXUljDmn4JCzwMhAg5T1cu18OIxiiqhGj7lMVHL0CH9uUVy7a6pAzvcSrx5frclHa49Ztj8Op7DOpjBQrkEh_u6Qx4b8Y1PzcjoeZHUrCBnBqKKxD17lchEntc6Mioc1WRrff-pQ1wuHd9vZMKYqMe9_REHeaEq7spmYT8_n1SK9H2zcraeKOflmlNKkDqRtj_uKJvuYIKvIx-9ZgHuXxpoQLlQpSmQvpfZsX2CN8t87TFwPaMIu3OQsA73awnFIDCfESG7RmmC93Nh0R0OlSOU5AgVwoQWzYnOJS4ondQ9DE5dF49XEG49L6zrl2Ka5BXWHwjN357Jx_X-9wyfwwOpUqzJuYrG_CayF_uKqtF-BibLMV0eYdsOdk5icTFJPbBMY_Hkjsg0YtOgchMx3CuGEgU0fK06iGm-lSzvtAlx4OP14PXxcQJDcvRfvumH-AD8NKjHYMFH8LiUPz8FVj-onWx8ikTuSPpjjAEshDp7C3KP0Ck6lloPe6cPIcgs4RB_YNfLPMErIDmxHfiIDjCDKZR5X-NBw-D1P3DIOqi9Ma1AeaMWK-AErHgwz6tz5OLySoC7DbWevXF2bUZhvQuts851HXXDtQ1Is2hiKTqSNFz1s0PRnQRuw-L_CxuNn7R16Q9fakfNCzeE8ucgtYKe8eiLPMNWTLaOr6bgrooTLxFBXWJ8Cy0HC4GQPXSi7p1IJLjk6EST1eBUYym_fq01K8-mD0R25gOVoHgKD5KQs6by0DYGRqZiyd5OwuwF97T3C-oDOoUtHsKvWzsD0b0kyMAwXfUs_kXhcA33y2hV9Hw0CX7aaNkny_9inkgze81BpwO0e_wn3iIqGvJXhRKJ8hSMWzfg7pQnZH6FmgNUXMlon3OWwOXx4UurJBdm7FfsMW49ScV3K050a-DCficbTScYho7cWTUFbAGrytJSwYSSbCdInimycblYmtDKQigwP35HQFOBvbarD6MBP9CHcbvdRaorffBEICEiMry63wxKjkfBv3HYnyGvPp0sAEFujf3kr9pRez8hGNicbw-AC_CusUX-1hZcWfNZiaI-GICBsI894oMVSAs0WHbrQWdqZq8S0SnM1USTFuatTSyrg0NjnPYmPl__-xvYsidSW3xk5jF9Rb4UG9et8wSjqv6ltd192ibcjlYRoUoaMt1T49A83fuHLCZuUYhgV9iB-H5Ysak8b7xJWJpK-ZxVqL8VdEIDLdG0a9Wjedu5NtZ_EWpYj_b2PsJ8lxhGdb58kkunYU7vXShuqfyXhHMRmBuxlHoN3_6tjqmzPtJ91oWU6zi-Ep_n3gohl4SzJbLMl00rJEadlxL7TNiLpAZXAF2ybPC1WrLx-4dRXIQeWnsoZvgrzKvmZWKoVFpWbTWFwUOgcE93z6UhPezw-S2h5fmWsHfGFqMt_Z45DR-NTQqGQAWuO3XaHCaWqpxneIqo8Z5rTrc1w4KH8dsva8AJWrrw7QHmfU6foLllGv04lR73Kf4fVIvUmDhu0FJ1uEulu24cA0AH7-uZcWxIDDQSwDeU79GlxbIYAW8hUOA7Z1iQ6xF4akOIKMqOxRuVRHi8GvmF2r2avSPaltYoHQR5G-EYNIR5bRcE1BNaxN0hhVMyX5UbKCXOkiT4HDU4ckJ_pWjZDT7HhlckpmwPrJXnf-0NT1DqzR-bMeZQQhWljfSsQ3cwThRtiBSqVYOPBIAeYVfpBBLQFvAMgANE',
|
||||
priv: 'i4_fRfJesALZ5T9fxzvpXvFtAbSsyAGdaMU-DzQsr5g',
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const testVectors = [
|
||||
{
|
||||
name: 'ML-DSA-44',
|
||||
privateUsages: ['sign'],
|
||||
publicUsages: ['verify']
|
||||
},
|
||||
{
|
||||
name: 'ML-DSA-65',
|
||||
privateUsages: ['sign'],
|
||||
publicUsages: ['verify']
|
||||
},
|
||||
{
|
||||
name: 'ML-DSA-87',
|
||||
privateUsages: ['sign'],
|
||||
publicUsages: ['verify']
|
||||
},
|
||||
];
|
||||
|
||||
async function testImportJwk({ name, publicUsages, privateUsages }, extractable) {
|
||||
|
||||
const jwk = keyData[name].jwk;
|
||||
|
||||
const tests = [
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{
|
||||
kty: jwk.kty,
|
||||
alg: jwk.alg,
|
||||
pub: jwk.pub,
|
||||
},
|
||||
{ name },
|
||||
extractable, publicUsages),
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
jwk,
|
||||
{ name },
|
||||
extractable,
|
||||
privateUsages),
|
||||
];
|
||||
|
||||
const [
|
||||
publicKey,
|
||||
privateKey,
|
||||
] = await Promise.all(tests);
|
||||
|
||||
assert.strictEqual(publicKey.type, 'public');
|
||||
assert.strictEqual(privateKey.type, 'private');
|
||||
assert.strictEqual(publicKey.extractable, extractable);
|
||||
assert.strictEqual(privateKey.extractable, extractable);
|
||||
assert.deepStrictEqual(publicKey.usages, publicUsages);
|
||||
assert.deepStrictEqual(privateKey.usages, privateUsages);
|
||||
assert.strictEqual(publicKey.algorithm.name, name);
|
||||
assert.strictEqual(privateKey.algorithm.name, name);
|
||||
assert.strictEqual(privateKey.algorithm, privateKey.algorithm);
|
||||
assert.strictEqual(privateKey.usages, privateKey.usages);
|
||||
assert.strictEqual(publicKey.algorithm, publicKey.algorithm);
|
||||
assert.strictEqual(publicKey.usages, publicKey.usages);
|
||||
|
||||
if (extractable) {
|
||||
// Test the round trip
|
||||
const [
|
||||
pubJwk,
|
||||
pvtJwk,
|
||||
] = await Promise.all([
|
||||
subtle.exportKey('jwk', publicKey),
|
||||
subtle.exportKey('jwk', privateKey),
|
||||
]);
|
||||
|
||||
assert.deepStrictEqual(pubJwk.key_ops, publicUsages);
|
||||
assert.strictEqual(pubJwk.ext, true);
|
||||
assert.strictEqual(pubJwk.kty, 'AKP');
|
||||
assert.strictEqual(pubJwk.pub, jwk.pub);
|
||||
|
||||
assert.deepStrictEqual(pvtJwk.key_ops, privateUsages);
|
||||
assert.strictEqual(pvtJwk.ext, true);
|
||||
assert.strictEqual(pvtJwk.kty, 'AKP');
|
||||
assert.strictEqual(pvtJwk.pub, jwk.pub);
|
||||
assert.strictEqual(pvtJwk.priv, jwk.priv);
|
||||
|
||||
assert.strictEqual(pubJwk.alg, jwk.alg);
|
||||
assert.strictEqual(pvtJwk.alg, jwk.alg);
|
||||
} else {
|
||||
await assert.rejects(
|
||||
subtle.exportKey('jwk', publicKey), {
|
||||
message: /key is not extractable/
|
||||
});
|
||||
await assert.rejects(
|
||||
subtle.exportKey('jwk', privateKey), {
|
||||
message: /key is not extractable/
|
||||
});
|
||||
}
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ ...jwk, use: 'enc' },
|
||||
{ name },
|
||||
extractable,
|
||||
privateUsages),
|
||||
{ message: 'Invalid JWK "use" Parameter' });
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ ...jwk, pub: undefined },
|
||||
{ name },
|
||||
extractable,
|
||||
privateUsages),
|
||||
{ message: 'Invalid JWK' });
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ ...jwk, priv: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' }, // Public vs private mismatch
|
||||
{ name },
|
||||
extractable,
|
||||
privateUsages),
|
||||
{ message: 'Invalid keyData' });
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ ...jwk, kty: 'OKP' },
|
||||
{ name },
|
||||
extractable,
|
||||
privateUsages),
|
||||
{ message: 'Invalid JWK "kty" Parameter' });
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ ...jwk },
|
||||
{ name },
|
||||
extractable,
|
||||
publicUsages), // Invalid for a private key
|
||||
{ message: /Unsupported key usage/ });
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ ...jwk, ext: false },
|
||||
{ name },
|
||||
true,
|
||||
privateUsages),
|
||||
{ message: 'JWK "ext" Parameter and extractable mismatch' });
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ ...jwk, priv: undefined },
|
||||
{ name },
|
||||
extractable,
|
||||
privateUsages), // Invalid for a public key
|
||||
{ message: /Unsupported key usage/ });
|
||||
|
||||
for (const alg of [undefined, name === 'ML-DSA-44' ? 'ML-DSA-87' : 'ML-DSA-44']) {
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ kty: jwk.kty, pub: jwk.pub, alg },
|
||||
{ name },
|
||||
extractable,
|
||||
publicUsages),
|
||||
{ message: 'JWK "alg" Parameter and algorithm name mismatch' });
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ ...jwk, alg },
|
||||
{ name },
|
||||
extractable,
|
||||
privateUsages),
|
||||
{ message: 'JWK "alg" Parameter and algorithm name mismatch' });
|
||||
}
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ ...jwk },
|
||||
{ name },
|
||||
extractable,
|
||||
[/* empty usages */]),
|
||||
{ name: 'SyntaxError', message: 'Usages cannot be empty when importing a private key.' });
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'jwk',
|
||||
{ kty: jwk.kty, /* missing pub */ alg: jwk.alg },
|
||||
{ name },
|
||||
extractable,
|
||||
publicUsages),
|
||||
{ name: 'DataError', message: 'Invalid keyData' });
|
||||
}
|
||||
|
||||
async function testImportRawPublic({ name, publicUsages }, extractable) {
|
||||
const jwk = keyData[name].jwk;
|
||||
const pub = Buffer.from(jwk.pub, 'base64url');
|
||||
|
||||
const publicKey = await subtle.importKey(
|
||||
'raw-public',
|
||||
pub,
|
||||
{ name },
|
||||
extractable, publicUsages);
|
||||
|
||||
assert.strictEqual(publicKey.type, 'public');
|
||||
assert.deepStrictEqual(publicKey.usages, publicUsages);
|
||||
assert.strictEqual(publicKey.algorithm.name, name);
|
||||
assert.strictEqual(publicKey.algorithm, publicKey.algorithm);
|
||||
assert.strictEqual(publicKey.usages, publicKey.usages);
|
||||
assert.strictEqual(publicKey.extractable, extractable);
|
||||
|
||||
if (extractable) {
|
||||
const value = await subtle.exportKey('raw-public', publicKey);
|
||||
assert.deepStrictEqual(Buffer.from(value), pub);
|
||||
|
||||
await assert.rejects(subtle.exportKey('raw', publicKey), {
|
||||
name: 'NotSupportedError',
|
||||
message: `Unable to export ${publicKey.algorithm.name} public key using raw format`,
|
||||
});
|
||||
}
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'raw-public',
|
||||
pub.subarray(0, pub.byteLength - 1),
|
||||
{ name },
|
||||
extractable, publicUsages),
|
||||
{ message: 'Invalid keyData' });
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'raw-public',
|
||||
pub,
|
||||
{ name: name === 'ML-DSA-44' ? 'ML-DSA-65' : 'ML-DSA-44' },
|
||||
extractable, publicUsages),
|
||||
{ message: 'Invalid keyData' });
|
||||
}
|
||||
|
||||
async function testImportRawSeed({ name, privateUsages }, extractable) {
|
||||
const jwk = keyData[name].jwk;
|
||||
const seed = Buffer.from(jwk.priv, 'base64url');
|
||||
|
||||
const privateKey = await subtle.importKey(
|
||||
'raw-seed',
|
||||
seed,
|
||||
{ name },
|
||||
extractable, privateUsages);
|
||||
|
||||
assert.strictEqual(privateKey.type, 'private');
|
||||
assert.deepStrictEqual(privateKey.usages, privateUsages);
|
||||
assert.strictEqual(privateKey.algorithm.name, name);
|
||||
assert.strictEqual(privateKey.algorithm, privateKey.algorithm);
|
||||
assert.strictEqual(privateKey.usages, privateKey.usages);
|
||||
assert.strictEqual(privateKey.extractable, extractable);
|
||||
|
||||
if (extractable) {
|
||||
const value = await subtle.exportKey('raw-seed', privateKey);
|
||||
assert.deepStrictEqual(Buffer.from(value), seed);
|
||||
}
|
||||
|
||||
await assert.rejects(
|
||||
subtle.importKey(
|
||||
'raw-seed',
|
||||
seed.subarray(0, 30),
|
||||
{ name },
|
||||
extractable,
|
||||
privateUsages),
|
||||
{ message: 'Invalid keyData' });
|
||||
}
|
||||
|
||||
(async function() {
|
||||
const tests = [];
|
||||
for (const vector of testVectors) {
|
||||
for (const extractable of [true, false]) {
|
||||
tests.push(testImportJwk(vector, extractable));
|
||||
tests.push(testImportRawSeed(vector, extractable));
|
||||
tests.push(testImportRawPublic(vector, extractable));
|
||||
}
|
||||
}
|
||||
await Promise.all(tests);
|
||||
})().then(common.mustCall());
|
||||
|
||||
(async function() {
|
||||
const alg = 'ML-DSA-44';
|
||||
const pub = Buffer.from(keyData[alg].jwk.pub, 'base64url');
|
||||
await assert.rejects(subtle.importKey('raw', pub, alg, false, []), {
|
||||
name: 'NotSupportedError',
|
||||
message: 'Unable to import ML-DSA-44 using raw format',
|
||||
});
|
||||
})().then(common.mustCall());
|
||||
@@ -6,6 +6,8 @@ const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const { hasOpenSSL } = require('../common/crypto');
|
||||
|
||||
const assert = require('assert');
|
||||
const { types: { isCryptoKey } } = require('util');
|
||||
const {
|
||||
@@ -157,6 +159,18 @@ const vectors = {
|
||||
},
|
||||
};
|
||||
|
||||
if (hasOpenSSL(3, 5)) {
|
||||
for (const name of ['ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87']) {
|
||||
vectors[name] = {
|
||||
result: 'CryptoKeyPair',
|
||||
usages: [
|
||||
'sign',
|
||||
'verify',
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Test invalid algorithms
|
||||
{
|
||||
async function test(algorithm) {
|
||||
@@ -683,3 +697,46 @@ assert.throws(() => new CryptoKey(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
|
||||
|
||||
Promise.all(tests).then(common.mustCall());
|
||||
}
|
||||
|
||||
// Test ML-DSA Key Generation
|
||||
if (hasOpenSSL(3, 5)) {
|
||||
async function test(
|
||||
name,
|
||||
privateUsages,
|
||||
publicUsages = privateUsages) {
|
||||
|
||||
let usages = privateUsages;
|
||||
if (publicUsages !== privateUsages)
|
||||
usages = usages.concat(publicUsages);
|
||||
|
||||
const { publicKey, privateKey } = await subtle.generateKey({
|
||||
name,
|
||||
}, true, usages);
|
||||
|
||||
assert(publicKey);
|
||||
assert(privateKey);
|
||||
assert(isCryptoKey(publicKey));
|
||||
assert(isCryptoKey(privateKey));
|
||||
|
||||
assert.strictEqual(publicKey.type, 'public');
|
||||
assert.strictEqual(privateKey.type, 'private');
|
||||
assert.strictEqual(publicKey.toString(), '[object CryptoKey]');
|
||||
assert.strictEqual(privateKey.toString(), '[object CryptoKey]');
|
||||
assert.strictEqual(publicKey.extractable, true);
|
||||
assert.strictEqual(privateKey.extractable, true);
|
||||
assert.deepStrictEqual(publicKey.usages, publicUsages);
|
||||
assert.deepStrictEqual(privateKey.usages, privateUsages);
|
||||
assert.strictEqual(publicKey.algorithm.name, name);
|
||||
assert.strictEqual(privateKey.algorithm.name, name);
|
||||
assert.strictEqual(privateKey.algorithm, privateKey.algorithm);
|
||||
assert.strictEqual(privateKey.usages, privateKey.usages);
|
||||
assert.strictEqual(publicKey.algorithm, publicKey.algorithm);
|
||||
assert.strictEqual(publicKey.usages, publicKey.usages);
|
||||
}
|
||||
|
||||
const kTests = ['ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87'];
|
||||
|
||||
const tests = kTests.map((name) => test(name, ['sign'], ['verify']));
|
||||
|
||||
Promise.all(tests).then(common.mustCall());
|
||||
}
|
||||
@@ -241,10 +241,10 @@ async function testSign({ name,
|
||||
await subtle.verify({ name: 'Ed448', context: Buffer.alloc(0) }, publicKey, sig, vector.data), true);
|
||||
|
||||
await assert.rejects(subtle.sign({ name: 'Ed448', context: Buffer.alloc(1) }, privateKey, vector.data), {
|
||||
message: /Non zero-length context is not supported/
|
||||
message: /Non zero-length Ed448Params\.context is not supported/
|
||||
});
|
||||
await assert.rejects(subtle.verify({ name: 'Ed448', context: Buffer.alloc(1) }, publicKey, sig, vector.data), {
|
||||
message: /Non zero-length context is not supported/
|
||||
message: /Non zero-length Ed448Params\.context is not supported/
|
||||
});
|
||||
}).then(common.mustCall());
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const { hasOpenSSL } = require('../common/crypto');
|
||||
|
||||
if (!hasOpenSSL(3, 5))
|
||||
common.skip('requires OpenSSL >= 3.5');
|
||||
|
||||
const assert = require('assert');
|
||||
const crypto = require('crypto');
|
||||
const { subtle } = globalThis.crypto;
|
||||
|
||||
const vectors = require('../fixtures/crypto/ml-dsa')();
|
||||
|
||||
async function testVerify({ name,
|
||||
publicKeyPem,
|
||||
privateKeyPem,
|
||||
signature,
|
||||
data }) {
|
||||
const [
|
||||
publicKey,
|
||||
noVerifyPublicKey,
|
||||
privateKey,
|
||||
hmacKey,
|
||||
rsaKeys,
|
||||
ecKeys,
|
||||
] = await Promise.all([
|
||||
crypto.createPublicKey(publicKeyPem)
|
||||
.toCryptoKey(name, false, ['verify']),
|
||||
crypto.createPublicKey(publicKeyPem)
|
||||
.toCryptoKey(name, false, [ /* No usages */ ]),
|
||||
crypto.createPrivateKey(privateKeyPem)
|
||||
.toCryptoKey(name, false, ['sign']),
|
||||
subtle.generateKey(
|
||||
{ name: 'HMAC', hash: 'SHA-256' },
|
||||
false,
|
||||
['sign']),
|
||||
subtle.generateKey(
|
||||
{
|
||||
name: 'RSA-PSS',
|
||||
modulusLength: 1024,
|
||||
publicExponent: new Uint8Array([1, 0, 1]),
|
||||
hash: 'SHA-256',
|
||||
},
|
||||
false,
|
||||
['sign']),
|
||||
subtle.generateKey(
|
||||
{
|
||||
name: 'ECDSA',
|
||||
namedCurve: 'P-256'
|
||||
},
|
||||
false,
|
||||
['sign']),
|
||||
]);
|
||||
|
||||
assert(await subtle.verify({ name }, publicKey, signature, data));
|
||||
|
||||
// Test verification with altered buffers
|
||||
const copy = Buffer.from(data);
|
||||
const sigcopy = Buffer.from(signature);
|
||||
const p = subtle.verify({ name }, publicKey, sigcopy, copy);
|
||||
copy[0] = 255 - copy[0];
|
||||
sigcopy[0] = 255 - sigcopy[0];
|
||||
assert(await p);
|
||||
|
||||
// Test failure when using wrong key
|
||||
await assert.rejects(
|
||||
subtle.verify({ name }, privateKey, signature, data), {
|
||||
message: /Unable to use this key to verify/
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
subtle.verify({ name }, noVerifyPublicKey, signature, data), {
|
||||
message: /Unable to use this key to verify/
|
||||
});
|
||||
|
||||
// Test failure when using the wrong algorithms
|
||||
await assert.rejects(
|
||||
subtle.verify({ name }, hmacKey, signature, data), {
|
||||
message: /Unable to use this key to verify/
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
subtle.verify({ name }, rsaKeys.publicKey, signature, data), {
|
||||
message: /Unable to use this key to verify/
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
subtle.verify({ name }, ecKeys.publicKey, signature, data), {
|
||||
message: /Unable to use this key to verify/
|
||||
});
|
||||
|
||||
// Test failure when signature is altered
|
||||
{
|
||||
const copy = Buffer.from(signature);
|
||||
copy[0] = 255 - copy[0];
|
||||
assert(!(await subtle.verify(
|
||||
{ name },
|
||||
publicKey,
|
||||
copy,
|
||||
data)));
|
||||
assert(!(await subtle.verify(
|
||||
{ name },
|
||||
publicKey,
|
||||
copy.slice(1),
|
||||
data)));
|
||||
}
|
||||
|
||||
// Test failure when data is altered
|
||||
{
|
||||
const copy = Buffer.from(data);
|
||||
copy[0] = 255 - copy[0];
|
||||
assert(!(await subtle.verify({ name }, publicKey, signature, copy)));
|
||||
}
|
||||
}
|
||||
|
||||
async function testSign({ name,
|
||||
publicKeyPem,
|
||||
privateKeyPem,
|
||||
signature,
|
||||
data }) {
|
||||
const [
|
||||
publicKey,
|
||||
privateKey,
|
||||
hmacKey,
|
||||
rsaKeys,
|
||||
ecKeys,
|
||||
] = await Promise.all([
|
||||
crypto.createPublicKey(publicKeyPem)
|
||||
.toCryptoKey(name, false, ['verify']),
|
||||
crypto.createPrivateKey(privateKeyPem)
|
||||
.toCryptoKey(name, false, ['sign']),
|
||||
subtle.generateKey(
|
||||
{ name: 'HMAC', hash: 'SHA-256' },
|
||||
false,
|
||||
['sign']),
|
||||
subtle.generateKey(
|
||||
{
|
||||
name: 'RSA-PSS',
|
||||
modulusLength: 1024,
|
||||
publicExponent: new Uint8Array([1, 0, 1]),
|
||||
hash: 'SHA-256',
|
||||
},
|
||||
false,
|
||||
['sign']),
|
||||
subtle.generateKey(
|
||||
{
|
||||
name: 'ECDSA',
|
||||
namedCurve: 'P-256'
|
||||
},
|
||||
false,
|
||||
['sign']),
|
||||
]);
|
||||
|
||||
{
|
||||
const sig = await subtle.sign({ name }, privateKey, data);
|
||||
assert.strictEqual(sig.byteLength, signature.byteLength);
|
||||
assert(await subtle.verify({ name }, publicKey, sig, data));
|
||||
}
|
||||
|
||||
{
|
||||
const copy = Buffer.from(data);
|
||||
const p = subtle.sign({ name }, privateKey, copy);
|
||||
copy[0] = 255 - copy[0];
|
||||
const sig = await p;
|
||||
assert(await subtle.verify({ name }, publicKey, sig, data));
|
||||
}
|
||||
|
||||
// Test failure when using wrong key
|
||||
await assert.rejects(
|
||||
subtle.sign({ name }, publicKey, data), {
|
||||
message: /Unable to use this key to sign/
|
||||
});
|
||||
|
||||
// Test failure when using the wrong algorithms
|
||||
await assert.rejects(
|
||||
subtle.sign({ name }, hmacKey, data), {
|
||||
message: /Unable to use this key to sign/
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
subtle.sign({ name }, rsaKeys.privateKey, data), {
|
||||
message: /Unable to use this key to sign/
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
subtle.sign({ name }, ecKeys.privateKey, data), {
|
||||
message: /Unable to use this key to sign/
|
||||
});
|
||||
}
|
||||
|
||||
(async function() {
|
||||
const variations = [];
|
||||
|
||||
vectors.forEach((vector) => {
|
||||
variations.push(testVerify(vector));
|
||||
variations.push(testSign(vector));
|
||||
});
|
||||
|
||||
await Promise.all(variations);
|
||||
})().then(common.mustCall());
|
||||
|
||||
// ContextParams context not supported
|
||||
{
|
||||
const vector = vectors[0];
|
||||
const name = vector.name;
|
||||
const publicKey = crypto.createPublicKey(vector.publicKeyPem)
|
||||
.toCryptoKey(vector.name, false, ['verify']);
|
||||
const privateKey = crypto.createPrivateKey(vector.privateKeyPem)
|
||||
.toCryptoKey(vector.name, false, ['sign']);
|
||||
|
||||
(async () => {
|
||||
const sig = await subtle.sign({ name, context: Buffer.alloc(0) }, privateKey, vector.data);
|
||||
assert.strictEqual(
|
||||
await subtle.verify({ name, context: Buffer.alloc(0) }, publicKey, sig, vector.data), true);
|
||||
|
||||
await assert.rejects(subtle.sign({ name, context: Buffer.alloc(1) }, privateKey, vector.data), {
|
||||
message: /Non zero-length ContextParams\.context is not supported/
|
||||
});
|
||||
await assert.rejects(subtle.verify({ name, context: Buffer.alloc(1) }, publicKey, sig, vector.data), {
|
||||
message: /Non zero-length ContextParams\.context is not supported/
|
||||
});
|
||||
})().then(common.mustCall());
|
||||
}
|
||||
@@ -5,6 +5,8 @@ const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const { hasOpenSSL } = require('../common/crypto');
|
||||
|
||||
const assert = require('assert');
|
||||
const { subtle } = globalThis.crypto;
|
||||
|
||||
@@ -147,3 +149,25 @@ const { subtle } = globalThis.crypto;
|
||||
test('hello world').then(common.mustCall());
|
||||
}
|
||||
}
|
||||
|
||||
// Test Sign/Verify ML-DSA
|
||||
if (hasOpenSSL(3, 5)) {
|
||||
async function test(name, data) {
|
||||
const ec = new TextEncoder();
|
||||
const { publicKey, privateKey } = await subtle.generateKey({
|
||||
name,
|
||||
}, true, ['sign', 'verify']);
|
||||
|
||||
const signature = await subtle.sign({
|
||||
name,
|
||||
}, privateKey, ec.encode(data));
|
||||
|
||||
assert(await subtle.verify({
|
||||
name,
|
||||
}, publicKey, signature, ec.encode(data)));
|
||||
}
|
||||
|
||||
test('ML-DSA-44', 'hello world').then(common.mustCall());
|
||||
test('ML-DSA-65', 'hello world').then(common.mustCall());
|
||||
test('ML-DSA-87', 'hello world').then(common.mustCall());
|
||||
}
|
||||
@@ -120,6 +120,7 @@ const customTypesMap = {
|
||||
'EcdsaParams': 'webcrypto.html#class-ecdsaparams',
|
||||
'RsaPssParams': 'webcrypto.html#class-rsapssparams',
|
||||
'Ed448Params': 'webcrypto.html#class-ed448params',
|
||||
'ContextParams': 'webcrypto.html#class-contextparams',
|
||||
|
||||
'dgram.Socket': 'dgram.html#class-dgramsocket',
|
||||
|
||||
|
||||
Reference in new issue
Block a user