Skip to content

Commit cbf9e24

Browse files
committed
feat: add Web Cryptography-based TurboSHAKE KDF exports
1 parent b69da55 commit cbf9e24

File tree

9 files changed

+134
-4
lines changed

9 files changed

+134
-4
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ Below are the algorithms built in (based on Web Cryptography) and their runtime
112112
| HKDF-SHA512 <sub>`0x0003`</sub> |||||||
113113
| SHAKE128 <sub>`0x0010`</sub> |[^24.7] | | | | ||
114114
| SHAKE256 <sub>`0x0011`</sub> |[^24.7] | | | | ||
115-
| TurboSHAKE128 <sub>`0x0012`</sub> | | | | | ||
116-
| TurboSHAKE256 <sub>`0x0013`</sub> | | | | | ||
115+
| TurboSHAKE128 <sub>`0x0012`</sub> | [^todo] | | | | ||
116+
| TurboSHAKE256 <sub>`0x0013`</sub> | [^todo] | | | | ||
117117

118118
### Authenticated Encryption (AEAD)
119119

@@ -146,3 +146,5 @@ specifications.
146146
[browsers]: https://panva.github.io/hpke/
147147

148148
[^24.7]: Available in Node.js versions >= 24.7.0
149+
150+
[^todo]: Available in Node.js versions >= TODO

docs/README.md

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/type-aliases/KDFFactory.md

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/variables/KDF_TurboSHAKE128.md

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/variables/KDF_TurboSHAKE256.md

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,8 @@ export type KEMFactory = () => Readonly<KEM>
13311331
* - {@link KDF_HKDF_SHA512 | HKDF-SHA512}
13321332
* - {@link KDF_SHAKE128 | SHAKE128}
13331333
* - {@link KDF_SHAKE256 | SHAKE256}
1334+
* - {@link KDF_TurboSHAKE128 | TurboSHAKE128}
1335+
* - {@link KDF_TurboSHAKE256 | TurboSHAKE256}
13341336
*
13351337
* > [!TIP]\
13361338
* > {@link CipherSuite} is not limited to using only these exported KDF implementations. Any function
@@ -2532,6 +2534,66 @@ export const KDF_SHAKE256: KDFFactory = function (): SHAKE {
25322534
}
25332535
}
25342536

2537+
/**
2538+
* TurboSHAKE128 key derivation function.
2539+
*
2540+
* A one-stage KDF using the TurboSHAKE128 extendable-output function (XOF) with an output length
2541+
* (Nh) of 32 bytes.
2542+
*
2543+
* Depends on the following Web Cryptography algorithms being supported in the runtime:
2544+
*
2545+
* - TurboSHAKE128 digest
2546+
*
2547+
* This is a factory function that must be passed to the {@link CipherSuite} constructor.
2548+
*
2549+
* > [!TIP]\
2550+
* > An implementation of this algorithm not reliant on Web Cryptography is also exported by
2551+
* > [`@panva/hpke-noble`](https://www.npmjs.com/package/@panva/hpke-noble)
2552+
*
2553+
* @group KDF Algorithms
2554+
* @see [HPKE-PQ One-Stage KDFs](https://datatracker.ietf.org/doc/html/draft-ietf-hpke-pq-04.html#section-5)
2555+
*/
2556+
export const KDF_TurboSHAKE128: KDFFactory = function (): SHAKE {
2557+
return {
2558+
id: 0x0012,
2559+
type: 'KDF',
2560+
name: 'TurboSHAKE128',
2561+
Nh: 32,
2562+
algorithm: 'TurboSHAKE128',
2563+
...SHAKE_SHARED(),
2564+
}
2565+
}
2566+
2567+
/**
2568+
* TurboSHAKE256 key derivation function.
2569+
*
2570+
* A one-stage KDF using the TurboSHAKE256 extendable-output function (XOF) with an output length
2571+
* (Nh) of 64 bytes.
2572+
*
2573+
* Depends on the following Web Cryptography algorithms being supported in the runtime:
2574+
*
2575+
* - TurboSHAKE256 digest
2576+
*
2577+
* This is a factory function that must be passed to the {@link CipherSuite} constructor.
2578+
*
2579+
* > [!TIP]\
2580+
* > An implementation of this algorithm not reliant on Web Cryptography is also exported by
2581+
* > [`@panva/hpke-noble`](https://www.npmjs.com/package/@panva/hpke-noble)
2582+
*
2583+
* @group KDF Algorithms
2584+
* @see [HPKE-PQ One-Stage KDFs](https://datatracker.ietf.org/doc/html/draft-ietf-hpke-pq-04.html#section-5)
2585+
*/
2586+
export const KDF_TurboSHAKE256: KDFFactory = function (): SHAKE {
2587+
return {
2588+
id: 0x0013,
2589+
type: 'KDF',
2590+
name: 'TurboSHAKE256',
2591+
Nh: 64,
2592+
algorithm: 'TurboSHAKE256',
2593+
...SHAKE_SHARED(),
2594+
}
2595+
}
2596+
25352597
async function getPublicKeyByExport(
25362598
name: string,
25372599
key: CryptoKey,

test/run-workerd.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ const unsupported = {
1717
'KEM_MLKEM768_P256',
1818
'KEM_MLKEM1024_P384',
1919
],
20-
kdf: ['KDF_SHAKE128', 'KDF_SHAKE256'],
20+
kdf: [
21+
'KDF_SHAKE128',
22+
'KDF_SHAKE256',
23+
'KDF_TurboSHAKE128',
24+
'KDF_TurboSHAKE256',
25+
],
2126
aead: ['AEAD_ChaCha20Poly1305'],
2227
}
2328

test/support.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ export const supported: Record<string, () => boolean | undefined> = {
5858
// @ts-expect-error
5959
return supports('digest', { name: 'cSHAKE256', outputLength: 512, length: 512 })
6060
},
61+
KDF_TurboSHAKE128() {
62+
// @ts-expect-error
63+
return supports('digest', { name: 'TurboSHAKE128', outputLength: 256 })
64+
},
65+
KDF_TurboSHAKE256() {
66+
// @ts-expect-error
67+
return supports('digest', { name: 'TurboSHAKE256', outputLength: 512 })
68+
},
6169
KEM_ML_KEM_512() {
6270
return supports('generateKey', 'ML-KEM-512')
6371
},

0 commit comments

Comments
 (0)