Skip to content

Commit 6217745

Browse files
twisspanva
andauthored
Add notes about non-integer numbers of bytes for cSHAKE and KMAC (#84)
Note that using cSHAKE and KMAC with inputs or outputs with a non-integer number of bytes may not be supported, and may lead to surprising results in the case of `deriveKey`. Co-authored-by: Filip Skokan <panva.ip@gmail.com>
1 parent f3eee15 commit 6217745

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎index.html‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7053,6 +7053,13 @@ <h4><dfn data-idl id="dfn-CShakeParams">CShakeParams</dfn> dictionary</h4>
70537053
};
70547054
</pre>
70557055
<p>The <dfn data-dfn-for=CShakeParams id=dfn-CShakeParams-outputLength>outputLength</dfn> member represents the requested output length in bits.</p>
7056+
<p class="note">
7057+
Byte-oriented implementations of cSHAKE may not support outputting a
7058+
non-integer number of bytes. In that case, the implementation should
7059+
throw a {{NotSupportedError}} in the Digest operation
7060+
(and return `false` from {{SubtleCrypto/supports()}})
7061+
when {{CShakeParams/outputLength}} is not a multiple of 8.
7062+
</p>
70567063
<p>The <dfn data-dfn-for=CShakeParams id=dfn-CShakeParams-functionName>functionName</dfn> member represents the function name, used by NIST to define functions based on cSHAKE. When used, it should only be set to values defined by NIST.</p>
70577064
<p>The <dfn data-dfn-for=CShakeParams id=dfn-CShakeParams-customization>customization</dfn> member represents the customization string. The application selects this string to define a variant of the function.</p>
70587065
</section>
@@ -7462,6 +7469,13 @@ <h4><dfn data-idl id="dfn-KmacKeyGenParams">KmacKeyGenParams</dfn> dictionary</h
74627469
};
74637470
</pre>
74647471
<p>The <dfn data-dfn-for=KmacKeyGenParams id=dfn-KmacKeyGenParams-length>length</dfn> member represents the length (in bits) of the key to generate. If unspecified, the recommended length will be used, which is 128 for KMAC128 and 256 for KMAC256.</p>
7472+
<p class="note">
7473+
Byte-oriented implementations of KMAC may not support keys with a
7474+
non-integer number of bytes. In that case, the implementation should
7475+
throw a {{NotSupportedError}} in the Generate Key operation
7476+
(and return `false` from {{SubtleCrypto/supports()}})
7477+
when {{KmacKeyGenParams/length}} is not a multiple of 8.
7478+
</p>
74657479
</section>
74667480
<section id="kmac-importparams">
74677481
<h4><dfn data-idl id="dfn-KmacImportParams">KmacImportParams</dfn> dictionary</h4>
@@ -7471,6 +7485,22 @@ <h4><dfn data-idl id="dfn-KmacImportParams">KmacImportParams</dfn> dictionary</h
74717485
};
74727486
</pre>
74737487
<p>The <dfn data-dfn-for=KmacImportParams id=dfn-KmacImportParams-length>length</dfn> member represents the length (in bits) of the key.</p>
7488+
<div class="note">
7489+
<p>
7490+
Byte-oriented implementations of KMAC may not support keys with a
7491+
non-integer number of bytes. In that case, the implementation should
7492+
throw a {{NotSupportedError}} in the Import Key operation
7493+
(and return `false` from {{SubtleCrypto/supports()}})
7494+
when {{KmacImportParams/length}} is not a multiple of 8.
7495+
</p>
7496+
<p>
7497+
Furthermore, when importing a key derived using {{SubtleCrypto/deriveKey()}},
7498+
the least significant bits are read first
7499+
(due to the [= Keccak decoding | Keccak decoding steps =]),
7500+
rather than the most significant bits. Therefore, when deriving
7501+
a key with a non-integer number of bytes, bits will be lost.
7502+
</p>
7503+
</div>
74747504
</section>
74757505
<section id="KmacKeyAlgorithm-dictionary">
74767506
<h4><dfn data-idl id="dfn-KmacKeyAlgorithm">KmacKeyAlgorithm</dfn> dictionary</h4>
@@ -7490,6 +7520,13 @@ <h4><dfn data-idl id="dfn-KmacParams">KmacParams</dfn> dictionary</h4>
74907520
};
74917521
</pre>
74927522
<p>The <dfn data-dfn-for=KmacParams id=dfn-KmacParams-outputLength>outputLength</dfn> member represents the requested output length in bits.</p>
7523+
<p class="note">
7524+
Byte-oriented implementations of KMAC may not support outputting a
7525+
non-integer number of bytes. In that case, the implementation should
7526+
throw a {{NotSupportedError}} in the Sign and Verify operations
7527+
(and return `false` from {{SubtleCrypto/supports()}})
7528+
when {{KmacParams/outputLength}} is not a multiple of 8.
7529+
</p>
74937530
<p>The <dfn data-dfn-for=KmacParams id=dfn-KmacParams-customization>customization</dfn> member represents the customization string. The application selects this string to define a variant of the function.</p>
74947531
</section>
74957532

0 commit comments

Comments
 (0)