GeezerVison is showing github.com — crypto: add TurboSHAKE and KangarooTwelve Web Cryptography algorithms · nodejs/node@d0ebf0e
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: doc/api/webcrypto.md +85-1Lines changed: 85 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | <!-- YAML | 4 | 4 | changes: | | 5 | + - version: REPLACEME | | 6 | + pr-url: https://github.com/nodejs/node/pull/62183 | | 7 | + description: TurboSHAKE and KangarooTwelve algorithms | | 8 | + are now supported. | 5 | 9 | - version: v24.8.0 | 6 | 10 | pr-url: https://github.com/nodejs/node/pull/59647 | 7 | 11 | description: KMAC algorithms are now supported. | @@ -122,6 +126,8 @@ Algorithms: | 122 | 126 | * `'cSHAKE256'` | 123 | 127 | * `'KMAC128'`[^openssl30] | 124 | 128 | * `'KMAC256'`[^openssl30] | | 129 | +* `'KT128'` | | 130 | +* `'KT256'` | 125 | 131 | * `'ML-DSA-44'`[^openssl35] | 126 | 132 | * `'ML-DSA-65'`[^openssl35] | 127 | 133 | * `'ML-DSA-87'`[^openssl35] | @@ -131,6 +137,8 @@ Algorithms: | 131 | 137 | * `'SHA3-256'` | 132 | 138 | * `'SHA3-384'` | 133 | 139 | * `'SHA3-512'` | | 140 | +* `'TurboSHAKE128'` | | 141 | +* `'TurboSHAKE256'` | 134 | 142 |
| 135 | 143 | Key Formats: | 136 | 144 |
| @@ -575,6 +583,8 @@ implementation and the APIs supported for each: | 575 | 583 | | `'HMAC'` | | ✔ | | | | | | 576 | 584 | | `'KMAC128'`[^modern-algos] | | ✔ | | | | | | 577 | 585 | | `'KMAC256'`[^modern-algos] | | ✔ | | | | | | | 586 | +| `'KT128'`[^modern-algos] | | | | | | ✔ | | | 587 | +| `'KT256'`[^modern-algos] | | | | | | ✔ | | 578 | 588 | | `'ML-DSA-44'`[^modern-algos] | | ✔ | | | | | | 579 | 589 | | `'ML-DSA-65'`[^modern-algos] | | ✔ | | | | | | 580 | 590 | | `'ML-DSA-87'`[^modern-algos] | | ✔ | | | | | | @@ -592,6 +602,8 @@ implementation and the APIs supported for each: | 592 | 602 | | `'SHA3-256'`[^modern-algos] | | | | | | ✔ | | 593 | 603 | | `'SHA3-384'`[^modern-algos] | | | | | | ✔ | | 594 | 604 | | `'SHA3-512'`[^modern-algos] | | | | | | ✔ | | | 605 | +| `'TurboSHAKE128'`[^modern-algos] | | | | | | ✔ | | | 606 | +| `'TurboSHAKE256'`[^modern-algos] | | | | | | ✔ | | 595 | 607 | | `'X25519'` | | | ✔ | | | | | 596 | 608 | | `'X448'`[^secure-curves] | | | ✔ | | | | | 597 | 609 |
| @@ -999,6 +1011,10 @@ The algorithms currently supported include: | 999 | 1011 | <!-- YAML | 1000 | 1012 | added: v15.0.0 | 1001 | 1013 | changes: | | 1014 | + - version: REPLACEME | | 1015 | + pr-url: https://github.com/nodejs/node/pull/62183 | | 1016 | + description: TurboSHAKE and KangarooTwelve algorithms | | 1017 | + are now supported. | 1002 | 1018 | - version: v24.7.0 | 1003 | 1019 | pr-url: https://github.com/nodejs/node/pull/59365 | 1004 | 1020 | description: SHA-3 algorithms are now supported. | @@ -1007,7 +1023,7 @@ changes: | 1007 | 1023 | description: SHAKE algorithms are now supported. | 1008 | 1024 | --> | 1009 | 1025 |
| 1010 | | -* `algorithm` {string|Algorithm|CShakeParams} | | 1026 | +* `algorithm` {string|Algorithm|CShakeParams|TurboShakeParams|KangarooTwelveParams} | 1011 | 1027 | * `data` {ArrayBuffer|TypedArray|DataView|Buffer} | 1012 | 1028 | * Returns: {Promise} Fulfills with an {ArrayBuffer} upon success. | 1013 | 1029 |
| @@ -1019,13 +1035,17 @@ If `algorithm` is provided as a {string}, it must be one of: | 1019 | 1035 |
| 1020 | 1036 | * `'cSHAKE128'`[^modern-algos] | 1021 | 1037 | * `'cSHAKE256'`[^modern-algos] | | 1038 | +* `'KT128'`[^modern-algos] | | 1039 | +* `'KT256'`[^modern-algos] | 1022 | 1040 | * `'SHA-1'` | 1023 | 1041 | * `'SHA-256'` | 1024 | 1042 | * `'SHA-384'` | 1025 | 1043 | * `'SHA-512'` | 1026 | 1044 | * `'SHA3-256'`[^modern-algos] | 1027 | 1045 | * `'SHA3-384'`[^modern-algos] | 1028 | 1046 | * `'SHA3-512'`[^modern-algos] | | 1047 | +* `'TurboSHAKE128'`[^modern-algos] | | 1048 | +* `'TurboSHAKE256'`[^modern-algos] | 1029 | 1049 |
| 1030 | 1050 | If `algorithm` is provided as an {Object}, it must have a `name` property | 1031 | 1051 | whose value is one of the above. | @@ -2316,6 +2336,38 @@ added: v15.0.0 | 2316 | 2336 |
| 2317 | 2337 | * Type: {string} | 2318 | 2338 |
| | 2339 | +### Class: `KangarooTwelveParams` | | 2340 | +
| | 2341 | +<!-- YAML | | 2342 | +added: REPLACEME | | 2343 | +--> | | 2344 | +
| | 2345 | +#### `kangarooTwelveParams.customization` | | 2346 | +
| | 2347 | +<!-- YAML | | 2348 | +added: REPLACEME | | 2349 | +--> | | 2350 | +
| | 2351 | +* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined} | | 2352 | +
| | 2353 | +The optional customization string for KangarooTwelve. | | 2354 | +
| | 2355 | +#### `kangarooTwelveParams.name` | | 2356 | +
| | 2357 | +<!-- YAML | | 2358 | +added: REPLACEME | | 2359 | +--> | | 2360 | +
| | 2361 | +* Type: {string} Must be `'KT128'`[^modern-algos] or `'KT256'`[^modern-algos] | | 2362 | +
| | 2363 | +#### `kangarooTwelveParams.outputLength` | | 2364 | +
| | 2365 | +<!-- YAML | | 2366 | +added: REPLACEME | | 2367 | +--> | | 2368 | +
| | 2369 | +* Type: {number} represents the requested output length in bits. | | 2370 | +
| 2319 | 2371 | ### Class: `KmacImportParams` | 2320 | 2372 |
| 2321 | 2373 | <!-- YAML | @@ -2686,6 +2738,38 @@ added: v15.0.0 | 2686 | 2738 |
| 2687 | 2739 | The length (in bytes) of the random salt to use. | 2688 | 2740 |
| | 2741 | +### Class: `TurboShakeParams` | | 2742 | +
| | 2743 | +<!-- YAML | | 2744 | +added: REPLACEME | | 2745 | +--> | | 2746 | +
| | 2747 | +#### `turboShakeParams.domainSeparation` | | 2748 | +
| | 2749 | +<!-- YAML | | 2750 | +added: REPLACEME | | 2751 | +--> | | 2752 | +
| | 2753 | +* Type: {number|undefined} | | 2754 | +
| | 2755 | +The optional domain separation byte (0x01-0x7f). Defaults to `0x1f`. | | 2756 | +
| | 2757 | +#### `turboShakeParams.name` | | 2758 | +
| | 2759 | +<!-- YAML | | 2760 | +added: REPLACEME | | 2761 | +--> | | 2762 | +
| | 2763 | +* Type: {string} Must be `'TurboSHAKE128'`[^modern-algos] or `'TurboSHAKE256'`[^modern-algos] | | 2764 | +
| | 2765 | +#### `turboShakeParams.outputLength` | | 2766 | +
| | 2767 | +<!-- YAML | | 2768 | +added: REPLACEME | | 2769 | +--> | | 2770 | +
| | 2771 | +* Type: {number} represents the requested output length in bits. | | 2772 | +
| 2689 | 2773 | [^secure-curves]: See [Secure Curves in the Web Cryptography API][] | 2690 | 2774 |
| 2691 | 2775 | [^modern-algos]: See [Modern Algorithms in the Web Cryptography API][] | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/hash.js +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,8 @@ const { | 14 | 14 | Hmac: _Hmac, | 15 | 15 | kCryptoJobAsync, | 16 | 16 | oneShotDigest, | | 17 | + TurboShakeJob, | | 18 | + KangarooTwelveJob, | 17 | 19 | } = internalBinding('crypto'); | 18 | 20 |
| 19 | 21 | const { | @@ -224,6 +226,24 @@ async function asyncDigest(algorithm, data) { | 224 | 226 | normalizeHashName(algorithm.name), | 225 | 227 | data, | 226 | 228 | algorithm.outputLength)); | | 229 | + case 'TurboSHAKE128': | | 230 | + // Fall through | | 231 | + case 'TurboSHAKE256': | | 232 | + return await jobPromise(() => new TurboShakeJob( | | 233 | + kCryptoJobAsync, | | 234 | + algorithm.name, | | 235 | + algorithm.domainSeparation ?? 0x1f, | | 236 | + algorithm.outputLength / 8, | | 237 | + data)); | | 238 | + case 'KT128': | | 239 | + // Fall through | | 240 | + case 'KT256': | | 241 | + return await jobPromise(() => new KangarooTwelveJob( | | 242 | + kCryptoJobAsync, | | 243 | + algorithm.name, | | 244 | + algorithm.customization, | | 245 | + algorithm.outputLength / 8, | | 246 | + data)); | 227 | 247 | } | 228 | 248 |
| 229 | 249 | throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError'); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/util.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -244,6 +244,10 @@ const kAlgorithmDefinitions = { | 244 | 244 | }, | 245 | 245 | 'cSHAKE128': { 'digest': 'CShakeParams' }, | 246 | 246 | 'cSHAKE256': { 'digest': 'CShakeParams' }, | | 247 | + 'KT128': { 'digest': 'KangarooTwelveParams' }, | | 248 | + 'KT256': { 'digest': 'KangarooTwelveParams' }, | | 249 | + 'TurboSHAKE128': { 'digest': 'TurboShakeParams' }, | | 250 | + 'TurboSHAKE256': { 'digest': 'TurboShakeParams' }, | 247 | 251 | 'ECDH': { | 248 | 252 | 'generateKey': 'EcKeyGenParams', | 249 | 253 | 'exportKey': null, | @@ -441,6 +445,10 @@ const experimentalAlgorithms = [ | 441 | 445 | 'SHA3-256', | 442 | 446 | 'SHA3-384', | 443 | 447 | 'SHA3-512', | | 448 | + 'TurboSHAKE128', | | 449 | + 'TurboSHAKE256', | | 450 | + 'KT128', | | 451 | + 'KT256', | 444 | 452 | 'X448', | 445 | 453 | ]; | 446 | 454 |
| @@ -513,6 +521,10 @@ const simpleAlgorithmDictionaries = { | 513 | 521 | KmacParams: { | 514 | 522 | customization: 'BufferSource', | 515 | 523 | }, | | 524 | + KangarooTwelveParams: { | | 525 | + customization: 'BufferSource', | | 526 | + }, | | 527 | + TurboShakeParams: {}, | 516 | 528 | }; | 517 | 529 |
| 518 | 530 | function validateMaxBufferLength(data, name) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/webidl.js +46Lines changed: 46 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -897,6 +897,52 @@ converters.KmacParams = createDictionaryConverter( | 897 | 897 | }, | 898 | 898 | ]); | 899 | 899 |
| | 900 | +converters.KangarooTwelveParams = createDictionaryConverter( | | 901 | + 'KangarooTwelveParams', [ | | 902 | + ...new SafeArrayIterator(dictAlgorithm), | | 903 | + { | | 904 | + key: 'outputLength', | | 905 | + converter: (V, opts) => | | 906 | + converters['unsigned long'](V, { ...opts, enforceRange: true }), | | 907 | + validator: (V, opts) => { | | 908 | + if (V === 0 || V % 8) | | 909 | + throw lazyDOMException('Invalid KangarooTwelveParams outputLength', 'OperationError'); | | 910 | + }, | | 911 | + required: true, | | 912 | + }, | | 913 | + { | | 914 | + key: 'customization', | | 915 | + converter: converters.BufferSource, | | 916 | + }, | | 917 | + ]); | | 918 | + | | 919 | +converters.TurboShakeParams = createDictionaryConverter( | | 920 | + 'TurboShakeParams', [ | | 921 | + ...new SafeArrayIterator(dictAlgorithm), | | 922 | + { | | 923 | + key: 'outputLength', | | 924 | + converter: (V, opts) => | | 925 | + converters['unsigned long'](V, { ...opts, enforceRange: true }), | | 926 | + validator: (V, opts) => { | | 927 | + if (V === 0 || V % 8) | | 928 | + throw lazyDOMException('Invalid TurboShakeParams outputLength', 'OperationError'); | | 929 | + }, | | 930 | + required: true, | | 931 | + }, | | 932 | + { | | 933 | + key: 'domainSeparation', | | 934 | + converter: (V, opts) => | | 935 | + converters.octet(V, { ...opts, enforceRange: true }), | | 936 | + validator: (V) => { | | 937 | + if (V < 0x01 || V > 0x7F) { | | 938 | + throw lazyDOMException( | | 939 | + 'TurboShakeParams.domainSeparation must be in range 0x01-0x7f', | | 940 | + 'OperationError'); | | 941 | + } | | 942 | + }, | | 943 | + }, | | 944 | + ]); | | 945 | + | 900 | 946 | module.exports = { | 901 | 947 | converters, | 902 | 948 | requiredArguments, | |
Collapse file Copy file name to clipboardExpand all lines: node.gyp +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 390 | 390 | 'src/crypto/crypto_kem.cc', | 391 | 391 | 'src/crypto/crypto_hmac.cc', | 392 | 392 | 'src/crypto/crypto_kmac.cc', | | 393 | + 'src/crypto/crypto_turboshake.cc', | 393 | 394 | 'src/crypto/crypto_random.cc', | 394 | 395 | 'src/crypto/crypto_rsa.cc', | 395 | 396 | 'src/crypto/crypto_spkac.cc', | | 408 | 409 | 'src/crypto/crypto_dh.h', | 409 | 410 | 'src/crypto/crypto_hmac.h', | 410 | 411 | 'src/crypto/crypto_kmac.h', | | 412 | + 'src/crypto/crypto_turboshake.h', | 411 | 413 | 'src/crypto/crypto_rsa.h', | 412 | 414 | 'src/crypto/crypto_spkac.h', | 413 | 415 | 'src/crypto/crypto_util.h', | |
|