Skip to content

Commit f990308

Browse files
tniessendanielleadams
authored andcommitted
crypto: fix auth tag length error when mode != GCM
PR-URL: #42383 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 208ab57 commit f990308

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/crypto/crypto_cipher.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ bool CipherBase::InitAuthenticated(
593593
// Tell OpenSSL about the desired length.
594594
if (!EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_SET_TAG, auth_tag_len,
595595
nullptr)) {
596-
THROW_ERR_CRYPTO_INVALID_AUTH_TAG(env());
596+
THROW_ERR_CRYPTO_INVALID_AUTH_TAG(
597+
env(), "Invalid authentication tag length: %u", auth_tag_len);
597598
return false;
598599
}
599600

test/parallel/test-crypto-authenticated.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const errMessages = {
4444
state: / state/,
4545
FIPS: /not supported in FIPS mode/,
4646
length: /Invalid initialization vector/,
47-
authTagLength: /Invalid authentication tag/
47+
authTagLength: /Invalid authentication tag length/
4848
};
4949

5050
const ciphers = crypto.getCiphers();
@@ -687,3 +687,17 @@ for (const test of TEST_CASES) {
687687
});
688688
}
689689
}
690+
691+
{
692+
const key = Buffer.alloc(32);
693+
const iv = Buffer.alloc(12);
694+
695+
for (const authTagLength of [0, 17]) {
696+
assert.throws(() => {
697+
crypto.createCipheriv('chacha20-poly1305', key, iv, { authTagLength });
698+
}, {
699+
code: 'ERR_CRYPTO_INVALID_AUTH_TAG',
700+
message: errMessages.authTagLength
701+
});
702+
}
703+
}

0 commit comments

Comments
 (0)