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 2025-05-19 12:21:08 +01:00 committed by GitHub
parent 38757c906d
commit 1ef99237f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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 // 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 plain = Buffer.from('Hello world', 'utf8');
const key = Buffer.from('0123456789abcdef', 'utf8'); const key = Buffer.from('0123456789abcdefghijklmnopqrstuv', 'utf8');
const iv = Buffer.from('0123456789ab', 'utf8'); const iv = Buffer.from('0123456789ab', 'utf8');
for (const mode of ['gcm', 'ocb']) { for (const alg of ['aes-256-gcm', 'aes-256-ocb', 'chacha20-poly1305']) {
for (const authTagLength of mode === 'gcm' ? [undefined, 8] : [8]) { for (const authTagLength of alg === 'aes-256-gcm' ? [undefined, 8] : [8]) {
const cipher = crypto.createCipheriv(`aes-128-${mode}`, key, iv, { const cipher = crypto.createCipheriv(alg, key, iv, {
authTagLength authTagLength
}); });
const ciphertext = Buffer.concat([cipher.update(plain), cipher.final()]); const ciphertext = Buffer.concat([cipher.update(plain), cipher.final()]);
const authTag = cipher.getAuthTag(); const authTag = cipher.getAuthTag();
for (const authTagBeforeUpdate of [true, false]) { for (const authTagBeforeUpdate of [true, false]) {
const decipher = crypto.createDecipheriv(`aes-128-${mode}`, key, iv, { const decipher = crypto.createDecipheriv(alg, key, iv, {
authTagLength authTagLength
}); });
if (authTagBeforeUpdate) { if (authTagBeforeUpdate) {