Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d0ebf0e

Browse filesBrowse files
panvaaduh95
authored andcommitted
crypto: add TurboSHAKE and KangarooTwelve Web Cryptography algorithms
PR-URL: #62183 Refs: https://wicg.github.io/webcrypto-modern-algos/#kangarootwelve Refs: https://wicg.github.io/webcrypto-modern-algos/#turboshake Refs: https://www.rfc-editor.org/rfc/rfc9861.html Refs: https://redirect.github.com/openssl/openssl/issues/30304 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 61cc747 commit d0ebf0e
Copy full SHA for d0ebf0e

12 files changed

+1,521-2Lines changed: 1521 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/webcrypto.md‎

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 numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
<!-- YAML
44
changes:
5+
- version: REPLACEME
6+
pr-url: https://github.com/nodejs/node/pull/62183
7+
description: TurboSHAKE and KangarooTwelve algorithms
8+
are now supported.
59
- version: v24.8.0
610
pr-url: https://github.com/nodejs/node/pull/59647
711
description: KMAC algorithms are now supported.
@@ -122,6 +126,8 @@ Algorithms:
122126
* `'cSHAKE256'`
123127
* `'KMAC128'`[^openssl30]
124128
* `'KMAC256'`[^openssl30]
129+
* `'KT128'`
130+
* `'KT256'`
125131
* `'ML-DSA-44'`[^openssl35]
126132
* `'ML-DSA-65'`[^openssl35]
127133
* `'ML-DSA-87'`[^openssl35]
@@ -131,6 +137,8 @@ Algorithms:
131137
* `'SHA3-256'`
132138
* `'SHA3-384'`
133139
* `'SHA3-512'`
140+
* `'TurboSHAKE128'`
141+
* `'TurboSHAKE256'`
134142

135143
Key Formats:
136144

@@ -575,6 +583,8 @@ implementation and the APIs supported for each:
575583
| `'HMAC'` | | ✔ | | | | |
576584
| `'KMAC128'`[^modern-algos] | | ✔ | | | | |
577585
| `'KMAC256'`[^modern-algos] | | ✔ | | | | |
586+
| `'KT128'`[^modern-algos] | | | | | | ✔ |
587+
| `'KT256'`[^modern-algos] | | | | | | ✔ |
578588
| `'ML-DSA-44'`[^modern-algos] | | ✔ | | | | |
579589
| `'ML-DSA-65'`[^modern-algos] | | ✔ | | | | |
580590
| `'ML-DSA-87'`[^modern-algos] | | ✔ | | | | |
@@ -592,6 +602,8 @@ implementation and the APIs supported for each:
592602
| `'SHA3-256'`[^modern-algos] | | | | | | ✔ |
593603
| `'SHA3-384'`[^modern-algos] | | | | | | ✔ |
594604
| `'SHA3-512'`[^modern-algos] | | | | | | ✔ |
605+
| `'TurboSHAKE128'`[^modern-algos] | | | | | | ✔ |
606+
| `'TurboSHAKE256'`[^modern-algos] | | | | | | ✔ |
595607
| `'X25519'` | | | ✔ | | | |
596608
| `'X448'`[^secure-curves] | | | ✔ | | | |
597609
@@ -999,6 +1011,10 @@ The algorithms currently supported include:
9991011
<!-- YAML
10001012
added: v15.0.0
10011013
changes:
1014+
- version: REPLACEME
1015+
pr-url: https://github.com/nodejs/node/pull/62183
1016+
description: TurboSHAKE and KangarooTwelve algorithms
1017+
are now supported.
10021018
- version: v24.7.0
10031019
pr-url: https://github.com/nodejs/node/pull/59365
10041020
description: SHA-3 algorithms are now supported.
@@ -1007,7 +1023,7 @@ changes:
10071023
description: SHAKE algorithms are now supported.
10081024
-->
10091025
1010-
* `algorithm` {string|Algorithm|CShakeParams}
1026+
* `algorithm` {string|Algorithm|CShakeParams|TurboShakeParams|KangarooTwelveParams}
10111027
* `data` {ArrayBuffer|TypedArray|DataView|Buffer}
10121028
* Returns: {Promise} Fulfills with an {ArrayBuffer} upon success.
10131029
@@ -1019,13 +1035,17 @@ If `algorithm` is provided as a {string}, it must be one of:
10191035
10201036
* `'cSHAKE128'`[^modern-algos]
10211037
* `'cSHAKE256'`[^modern-algos]
1038+
* `'KT128'`[^modern-algos]
1039+
* `'KT256'`[^modern-algos]
10221040
* `'SHA-1'`
10231041
* `'SHA-256'`
10241042
* `'SHA-384'`
10251043
* `'SHA-512'`
10261044
* `'SHA3-256'`[^modern-algos]
10271045
* `'SHA3-384'`[^modern-algos]
10281046
* `'SHA3-512'`[^modern-algos]
1047+
* `'TurboSHAKE128'`[^modern-algos]
1048+
* `'TurboSHAKE256'`[^modern-algos]
10291049
10301050
If `algorithm` is provided as an {Object}, it must have a `name` property
10311051
whose value is one of the above.
@@ -2316,6 +2336,38 @@ added: v15.0.0
23162336
23172337
* Type: {string}
23182338
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+
23192371
### Class: `KmacImportParams`
23202372
23212373
<!-- YAML
@@ -2686,6 +2738,38 @@ added: v15.0.0
26862738
26872739
The length (in bytes) of the random salt to use.
26882740
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+
26892773
[^secure-curves]: See [Secure Curves in the Web Cryptography API][]
26902774
26912775
[^modern-algos]: See [Modern Algorithms in the Web Cryptography API][]
Collapse file

‎lib/internal/crypto/hash.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/hash.js
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const {
1414
Hmac: _Hmac,
1515
kCryptoJobAsync,
1616
oneShotDigest,
17+
TurboShakeJob,
18+
KangarooTwelveJob,
1719
} = internalBinding('crypto');
1820

1921
const {
@@ -224,6 +226,24 @@ async function asyncDigest(algorithm, data) {
224226
normalizeHashName(algorithm.name),
225227
data,
226228
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));
227247
}
228248

229249
throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
Collapse file

‎lib/internal/crypto/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/util.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ const kAlgorithmDefinitions = {
244244
},
245245
'cSHAKE128': { 'digest': 'CShakeParams' },
246246
'cSHAKE256': { 'digest': 'CShakeParams' },
247+
'KT128': { 'digest': 'KangarooTwelveParams' },
248+
'KT256': { 'digest': 'KangarooTwelveParams' },
249+
'TurboSHAKE128': { 'digest': 'TurboShakeParams' },
250+
'TurboSHAKE256': { 'digest': 'TurboShakeParams' },
247251
'ECDH': {
248252
'generateKey': 'EcKeyGenParams',
249253
'exportKey': null,
@@ -441,6 +445,10 @@ const experimentalAlgorithms = [
441445
'SHA3-256',
442446
'SHA3-384',
443447
'SHA3-512',
448+
'TurboSHAKE128',
449+
'TurboSHAKE256',
450+
'KT128',
451+
'KT256',
444452
'X448',
445453
];
446454

@@ -513,6 +521,10 @@ const simpleAlgorithmDictionaries = {
513521
KmacParams: {
514522
customization: 'BufferSource',
515523
},
524+
KangarooTwelveParams: {
525+
customization: 'BufferSource',
526+
},
527+
TurboShakeParams: {},
516528
};
517529

518530
function validateMaxBufferLength(data, name) {
Collapse file

‎lib/internal/crypto/webidl.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/webidl.js
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,52 @@ converters.KmacParams = createDictionaryConverter(
897897
},
898898
]);
899899

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+
900946
module.exports = {
901947
converters,
902948
requiredArguments,
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@
390390
'src/crypto/crypto_kem.cc',
391391
'src/crypto/crypto_hmac.cc',
392392
'src/crypto/crypto_kmac.cc',
393+
'src/crypto/crypto_turboshake.cc',
393394
'src/crypto/crypto_random.cc',
394395
'src/crypto/crypto_rsa.cc',
395396
'src/crypto/crypto_spkac.cc',
@@ -408,6 +409,7 @@
408409
'src/crypto/crypto_dh.h',
409410
'src/crypto/crypto_hmac.h',
410411
'src/crypto/crypto_kmac.h',
412+
'src/crypto/crypto_turboshake.h',
411413
'src/crypto/crypto_rsa.h',
412414
'src/crypto/crypto_spkac.h',
413415
'src/crypto/crypto_util.h',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.