Skip to content

Commit ca4ab2f

Browse files
committed
crypto: rename cSHAKEParams and KmacParams length to outputLength
1 parent ca90ab1 commit ca4ab2f

File tree

10 files changed

+116
-59
lines changed

10 files changed

+116
-59
lines changed

doc/api/webcrypto.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,19 +1869,27 @@ the message.
18691869
18701870
<!-- YAML
18711871
added: v24.7.0
1872+
changes:
1873+
- version: REPLACEME
1874+
pr-url: https://github.com/nodejs/node/pull/XXXX
1875+
description: Renamed `cShakeParams.length` to `cShakeParams.outputLength`.
18721876
-->
18731877
1874-
#### `cShakeParams.customization`
1878+
#### `cShakeParams.name`
18751879
18761880
<!-- YAML
18771881
added: v24.7.0
18781882
-->
18791883
1880-
* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined}
1884+
* Type: {string} Must be `'cSHAKE128'`[^modern-algos] or `'cSHAKE256'`[^modern-algos]
18811885
1882-
The `customization` member represents the customization string.
1883-
The Node.js Web Crypto API implementation only supports zero-length customization
1884-
which is equivalent to not providing customization at all.
1886+
#### `cShakeParams.outputLength`
1887+
1888+
<!-- YAML
1889+
added: REPLACEME
1890+
-->
1891+
1892+
* Type: {number} represents the requested output length in bits.
18851893
18861894
#### `cShakeParams.functionName`
18871895
@@ -1896,21 +1904,17 @@ functions based on cSHAKE.
18961904
The Node.js Web Crypto API implementation only supports zero-length functionName
18971905
which is equivalent to not providing functionName at all.
18981906
1899-
#### `cShakeParams.length`
1907+
#### `cShakeParams.customization`
19001908
19011909
<!-- YAML
19021910
added: v24.7.0
19031911
-->
19041912
1905-
* Type: {number} represents the requested output length in bits.
1906-
1907-
#### `cShakeParams.name`
1908-
1909-
<!-- YAML
1910-
added: v24.7.0
1911-
-->
1913+
* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined}
19121914
1913-
* Type: {string} Must be `'cSHAKE128'`[^modern-algos] or `'cSHAKE256'`[^modern-algos]
1915+
The `customization` member represents the customization string.
1916+
The Node.js Web Crypto API implementation only supports zero-length customization
1917+
which is equivalent to not providing customization at all.
19141918
19151919
### Class: `EcdhKeyDeriveParams`
19161920
@@ -2387,6 +2391,10 @@ added: v24.8.0
23872391
23882392
<!-- YAML
23892393
added: v24.8.0
2394+
changes:
2395+
- version: REPLACEME
2396+
pr-url: https://github.com/nodejs/node/pull/XXXX
2397+
description: Renamed `kmacParams.length` to `kmacParams.outputLength`.
23902398
-->
23912399
23922400
#### `kmacParams.algorithm`
@@ -2397,25 +2405,25 @@ added: v24.8.0
23972405
23982406
* Type: {string} Must be `'KMAC128'` or `'KMAC256'`.
23992407
2400-
#### `kmacParams.customization`
2408+
#### `kmacParams.outputLength`
24012409
24022410
<!-- YAML
2403-
added: v24.8.0
2411+
added: REPLACEME
24042412
-->
24052413
2406-
* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined}
2414+
* Type: {number}
24072415
2408-
The `customization` member represents the optional customization string.
2416+
The length of the output in bytes. This must be a positive integer.
24092417
2410-
#### `kmacParams.length`
2418+
#### `kmacParams.customization`
24112419
24122420
<!-- YAML
24132421
added: v24.8.0
24142422
-->
24152423
2416-
* Type: {number}
2424+
* Type: {ArrayBuffer|TypedArray|DataView|Buffer|undefined}
24172425
2418-
The length of the output in bytes. This must be a positive integer.
2426+
The `customization` member represents the optional customization string.
24192427
24202428
### Class: `Pbkdf2Params`
24212429

lib/internal/crypto/hash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ async function asyncDigest(algorithm, data) {
223223
kCryptoJobAsync,
224224
normalizeHashName(algorithm.name),
225225
data,
226-
algorithm.length));
226+
algorithm.outputLength));
227227
}
228228

229229
throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');

lib/internal/crypto/mac.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ function kmacSignVerify(key, data, algorithm, signature) {
234234
key[kKeyObject][kHandle],
235235
algorithm.name,
236236
algorithm.customization,
237-
algorithm.length / 8,
237+
algorithm.outputLength / 8,
238238
data,
239239
signature));
240240
}

lib/internal/crypto/webidl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,14 @@ converters.CShakeParams = createDictionaryConverter(
589589
'CShakeParams', [
590590
...new SafeArrayIterator(dictAlgorithm),
591591
{
592-
key: 'length',
592+
key: 'outputLength',
593593
converter: (V, opts) =>
594594
converters['unsigned long'](V, { ...opts, enforceRange: true }),
595595
validator: (V, opts) => {
596596
// The Web Crypto spec allows for SHAKE output length that are not multiples of
597597
// 8. We don't.
598598
if (V % 8)
599-
throw lazyDOMException('Unsupported CShakeParams length', 'NotSupportedError');
599+
throw lazyDOMException('Unsupported CShakeParams outputLength', 'NotSupportedError');
600600
},
601601
required: true,
602602
},
@@ -879,13 +879,13 @@ converters.KmacParams = createDictionaryConverter(
879879
'KmacParams', [
880880
...new SafeArrayIterator(dictAlgorithm),
881881
{
882-
key: 'length',
882+
key: 'outputLength',
883883
converter: (V, opts) =>
884884
converters['unsigned long'](V, { ...opts, enforceRange: true }),
885885
validator: (V, opts) => {
886886
// The Web Crypto spec allows for KMAC output length that are not multiples of 8. We don't.
887887
if (V % 8)
888-
throw lazyDOMException('Unsupported KmacParams length', 'NotSupportedError');
888+
throw lazyDOMException('Unsupported KmacParams outputLength', 'NotSupportedError');
889889
},
890890
required: true,
891891
},

test/fixtures/crypto/kmac.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function() {
1313
]),
1414
data: Buffer.from([0x00, 0x01, 0x02, 0x03]),
1515
customization: undefined,
16-
length: 256,
16+
outputLength: 256,
1717
expected: Buffer.from([
1818
0xe5, 0x78, 0x0b, 0x0d, 0x3e, 0xa6, 0xf7, 0xd3, 0xa4, 0x29, 0xc5, 0x70,
1919
0x6a, 0xa4, 0x3a, 0x00, 0xfa, 0xdb, 0xd7, 0xd4, 0x96, 0x28, 0x83, 0x9e,
@@ -30,7 +30,7 @@ module.exports = function() {
3030
]),
3131
data: Buffer.from([0x00, 0x01, 0x02, 0x03]),
3232
customization: Buffer.from('My Tagged Application'),
33-
length: 256,
33+
outputLength: 256,
3434
expected: Buffer.from([
3535
0x3b, 0x1f, 0xba, 0x96, 0x3c, 0xd8, 0xb0, 0xb5, 0x9e, 0x8c, 0x1a, 0x6d,
3636
0x71, 0x88, 0x8b, 0x71, 0x43, 0x65, 0x1a, 0xf8, 0xba, 0x0a, 0x70, 0x70,
@@ -47,7 +47,7 @@ module.exports = function() {
4747
]),
4848
data: Buffer.from(Array.from({ length: 200 }, (_, i) => i)), // 0x00-0xC7
4949
customization: Buffer.from('My Tagged Application'),
50-
length: 256,
50+
outputLength: 256,
5151
expected: Buffer.from([
5252
0x1f, 0x5b, 0x4e, 0x6c, 0xca, 0x02, 0x20, 0x9e, 0x0d, 0xcb, 0x5c, 0xa6,
5353
0x35, 0xb8, 0x9a, 0x15, 0xe2, 0x71, 0xec, 0xc7, 0x60, 0x07, 0x1d, 0xfd,
@@ -64,7 +64,7 @@ module.exports = function() {
6464
]),
6565
data: Buffer.from([0x00, 0x01, 0x02, 0x03]),
6666
customization: Buffer.from('My Tagged Application'),
67-
length: 512,
67+
outputLength: 512,
6868
expected: Buffer.from([
6969
0x20, 0xc5, 0x70, 0xc3, 0x13, 0x46, 0xf7, 0x03, 0xc9, 0xac, 0x36, 0xc6,
7070
0x1c, 0x03, 0xcb, 0x64, 0xc3, 0x97, 0x0d, 0x0c, 0xfc, 0x78, 0x7e, 0x9b,
@@ -84,7 +84,7 @@ module.exports = function() {
8484
]),
8585
data: Buffer.from(Array.from({ length: 200 }, (_, i) => i)), // 0x00-0xC7
8686
customization: undefined,
87-
length: 512,
87+
outputLength: 512,
8888
expected: Buffer.from([
8989
0x75, 0x35, 0x8c, 0xf3, 0x9e, 0x41, 0x49, 0x4e, 0x94, 0x97, 0x07, 0x92,
9090
0x7c, 0xee, 0x0a, 0xf2, 0x0a, 0x3f, 0xf5, 0x53, 0x90, 0x4c, 0x86, 0xb0,
@@ -104,7 +104,7 @@ module.exports = function() {
104104
]),
105105
data: Buffer.from(Array.from({ length: 200 }, (_, i) => i)), // 0x00-0xC7
106106
customization: Buffer.from('My Tagged Application'),
107-
length: 512,
107+
outputLength: 512,
108108
expected: Buffer.from([
109109
0xb5, 0x86, 0x18, 0xf7, 0x1f, 0x92, 0xe1, 0xd5, 0x6c, 0x1b, 0x8c, 0x55,
110110
0xdd, 0xd7, 0xcd, 0x18, 0x8b, 0x97, 0xb4, 0xca, 0x4d, 0x99, 0x83, 0x1e,

test/fixtures/webcrypto/supports-modern-algorithms.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ const X25519 = await subtle.generateKey('X25519', false, ['deriveBits', 'deriveK
1717
export const vectors = {
1818
'digest': [
1919
[false, 'cSHAKE128'],
20-
[shake128, { name: 'cSHAKE128', length: 128 }],
21-
[shake128, { name: 'cSHAKE128', length: 128, functionName: Buffer.alloc(0), customization: Buffer.alloc(0) }],
22-
[false, { name: 'cSHAKE128', length: 128, functionName: Buffer.alloc(1) }],
23-
[false, { name: 'cSHAKE128', length: 128, customization: Buffer.alloc(1) }],
24-
[false, { name: 'cSHAKE128', length: 127 }],
20+
[shake128, { name: 'cSHAKE128', outputLength: 128 }],
21+
[shake128, { name: 'cSHAKE128', outputLength: 128, functionName: Buffer.alloc(0), customization: Buffer.alloc(0) }],
22+
[false, { name: 'cSHAKE128', outputLength: 128, functionName: Buffer.alloc(1) }],
23+
[false, { name: 'cSHAKE128', outputLength: 128, customization: Buffer.alloc(1) }],
24+
[false, { name: 'cSHAKE128', outputLength: 127 }],
2525
[false, 'cSHAKE256'],
26-
[shake256, { name: 'cSHAKE256', length: 256 }],
27-
[shake256, { name: 'cSHAKE256', length: 256, functionName: Buffer.alloc(0), customization: Buffer.alloc(0) }],
28-
[false, { name: 'cSHAKE256', length: 256, functionName: Buffer.alloc(1) }],
29-
[false, { name: 'cSHAKE256', length: 256, customization: Buffer.alloc(1) }],
30-
[false, { name: 'cSHAKE256', length: 255 }],
26+
[shake256, { name: 'cSHAKE256', outputLength: 256 }],
27+
[shake256, { name: 'cSHAKE256', outputLength: 256, functionName: Buffer.alloc(0), customization: Buffer.alloc(0) }],
28+
[false, { name: 'cSHAKE256', outputLength: 256, functionName: Buffer.alloc(1) }],
29+
[false, { name: 'cSHAKE256', outputLength: 256, customization: Buffer.alloc(1) }],
30+
[false, { name: 'cSHAKE256', outputLength: 255 }],
3131
],
3232
'sign': [
3333
[pqc, 'ML-DSA-44'],
@@ -44,8 +44,8 @@ export const vectors = {
4444
[false, 'Argon2id'],
4545
[false, 'KMAC128'],
4646
[false, 'KMAC256'],
47-
[kmac, { name: 'KMAC128', length: 256 }],
48-
[kmac, { name: 'KMAC256', length: 256 }],
47+
[kmac, { name: 'KMAC128', outputLength: 256 }],
48+
[kmac, { name: 'KMAC256', outputLength: 256 }],
4949
],
5050
'generateKey': [
5151
[pqc, 'ML-DSA-44'],

test/parallel/test-webcrypto-digest.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const kTests = [
1919

2020
if (!process.features.openssl_is_boringssl) {
2121
kTests.push(
22-
[{ name: 'cSHAKE128', length: 256 }, ['shake128', { outputLength: 256 >> 3 }], 256],
23-
[{ name: 'cSHAKE256', length: 512 }, ['shake256', { outputLength: 512 >> 3 }], 512],
22+
[{ name: 'cSHAKE128', outputLength: 256 }, ['shake128', { outputLength: 256 >> 3 }], 256],
23+
[{ name: 'cSHAKE256', outputLength: 512 }, ['shake256', { outputLength: 512 >> 3 }], 512],
2424
['SHA3-256', ['sha3-256'], 256],
2525
['SHA3-384', ['sha3-384'], 384],
2626
['SHA3-512', ['sha3-512'], 512],
@@ -223,10 +223,10 @@ async function testDigest(size, alg) {
223223

224224
function applyXOF(name) {
225225
if (name.match(/cshake128/i)) {
226-
return { name, length: 256 };
226+
return { name, outputLength: 256 };
227227
}
228228
if (name.match(/cshake256/i)) {
229-
return { name, length: 512 };
229+
return { name, outputLength: 512 };
230230
}
231231
return name;
232232

@@ -259,13 +259,13 @@ function applyXOF(name) {
259259
if (getHashes().includes('shake128')) {
260260
(async () => {
261261
assert.deepStrictEqual(
262-
new Uint8Array(await subtle.digest({ name: 'cSHAKE128', length: 0 }, Buffer.alloc(1))),
262+
new Uint8Array(await subtle.digest({ name: 'cSHAKE128', outputLength: 0 }, Buffer.alloc(1))),
263263
new Uint8Array(0),
264264
);
265265

266-
await assert.rejects(subtle.digest({ name: 'cSHAKE128', length: 7 }, Buffer.alloc(1)), {
266+
await assert.rejects(subtle.digest({ name: 'cSHAKE128', outputLength: 7 }, Buffer.alloc(1)), {
267267
name: 'NotSupportedError',
268-
message: 'Unsupported CShakeParams length',
268+
message: 'Unsupported CShakeParams outputLength',
269269
});
270270
})().then(common.mustCall());
271271
}

test/parallel/test-webcrypto-sign-verify-kmac.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function testVerify({ algorithm,
1919
key,
2020
data,
2121
customization,
22-
length,
22+
outputLength,
2323
expected }) {
2424
const [
2525
verifyKey,
@@ -46,7 +46,7 @@ async function testVerify({ algorithm,
4646

4747
const signParams = {
4848
name: algorithm,
49-
length,
49+
outputLength,
5050
customization,
5151
};
5252

@@ -112,7 +112,7 @@ async function testVerify({ algorithm,
112112
{
113113
assert(!(await subtle.verify({
114114
...signParams,
115-
length: length === 256 ? 512 : 256,
115+
outputLength: outputLength === 256 ? 512 : 256,
116116
}, verifyKey, expected, data)));
117117
}
118118
}
@@ -121,7 +121,7 @@ async function testSign({ algorithm,
121121
key,
122122
data,
123123
customization,
124-
length,
124+
outputLength,
125125
expected }) {
126126
const [
127127
signKey,
@@ -148,7 +148,7 @@ async function testSign({ algorithm,
148148

149149
const signParams = {
150150
name: algorithm,
151-
length,
151+
outputLength,
152152
customization,
153153
};
154154

test/parallel/test-webcrypto-sign-verify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ if (hasOpenSSL(3)) {
118118

119119
const signature = await subtle.sign({
120120
name,
121-
length: 256,
121+
outputLength: 256,
122122
}, key, ec.encode(data));
123123

124124
assert(await subtle.verify({
125125
name,
126-
length: 256,
126+
outputLength: 256,
127127
}, key, signature, ec.encode(data)));
128128
}
129129

0 commit comments

Comments
 (0)