test: add chacha20-poly1305 to auth tag order test

Add ChaCha20-Poly1305 to the algorithms for which we ensure that the
authentication tag can be set either before or after calling `update()`.

PR-URL: https://github.com/nodejs/node/pull/58367
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
Tobias Nießen authored and Antoine du Hamel committed 2025-06-10 14:52:17 +02:00
1 parent a3877c53b1
commit 40a03d3d14
1 file changed
+6 -6
+6 -6
View File
@@ -448,22 +448,22 @@ for (const test of TEST_CASES) {
}
// Test that the authentication tag can be set at any point before calling
// final() in GCM or OCB mode.
// final() in GCM mode, OCB mode, and for ChaCha20-Poly1305.
{
const plain = Buffer.from('Hello world', 'utf8');
const key = Buffer.from('0123456789abcdef', 'utf8');
const key = Buffer.from('0123456789abcdefghijklmnopqrstuv', 'utf8');
const iv = Buffer.from('0123456789ab', 'utf8');
for (const mode of ['gcm', 'ocb']) {
for (const authTagLength of mode === 'gcm' ? [undefined, 8] : [8]) {
const cipher = crypto.createCipheriv(`aes-128-${mode}`, key, iv, {
for (const alg of ['aes-256-gcm', 'aes-256-ocb', 'chacha20-poly1305']) {
for (const authTagLength of alg === 'aes-256-gcm' ? [undefined, 8] : [8]) {
const cipher = crypto.createCipheriv(alg, key, iv, {
authTagLength
});
const ciphertext = Buffer.concat([cipher.update(plain), cipher.final()]);
const authTag = cipher.getAuthTag();
for (const authTagBeforeUpdate of [true, false]) {
const decipher = crypto.createDecipheriv(`aes-128-${mode}`, key, iv, {
const decipher = crypto.createDecipheriv(alg, key, iv, {
authTagLength
});
if (authTagBeforeUpdate) {