test: add chacha20-poly1305 to auth tag order test · nodejs/node@33f6158

@@ -448,22 +448,22 @@ for (const test of TEST_CASES) {

448448

}

449449450450

// Test that the authentication tag can be set at any point before calling

451-

// final() in GCM or OCB mode.

451+

// final() in GCM mode, OCB mode, and for ChaCha20-Poly1305.

452452

{

453453

const plain = Buffer.from('Hello world', 'utf8');

454-

const key = Buffer.from('0123456789abcdef', 'utf8');

454+

const key = Buffer.from('0123456789abcdefghijklmnopqrstuv', 'utf8');

455455

const iv = Buffer.from('0123456789ab', 'utf8');

456456457-

for (const mode of ['gcm', 'ocb']) {

458-

for (const authTagLength of mode === 'gcm' ? [undefined, 8] : [8]) {

459-

const cipher = crypto.createCipheriv(`aes-128-${mode}`, key, iv, {

457+

for (const alg of ['aes-256-gcm', 'aes-256-ocb', 'chacha20-poly1305']) {

458+

for (const authTagLength of alg === 'aes-256-gcm' ? [undefined, 8] : [8]) {

459+

const cipher = crypto.createCipheriv(alg, key, iv, {

460460

authTagLength

461461

});

462462

const ciphertext = Buffer.concat([cipher.update(plain), cipher.final()]);

463463

const authTag = cipher.getAuthTag();

464464465465

for (const authTagBeforeUpdate of [true, false]) {

466-

const decipher = crypto.createDecipheriv(`aes-128-${mode}`, key, iv, {

466+

const decipher = crypto.createDecipheriv(alg, key, iv, {

467467

authTagLength

468468

});

469469

if (authTagBeforeUpdate) {