diff options
author | Tobias Nießen <tniessen@tnie.de> | 2022-03-20 15:18:52 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2022-04-24 05:47:22 +0300 |
commit | f990308972f5b255f5620739fc0e083a7372815e (patch) | |
tree | c066b92707c0642c08185e673d2afd81c2051b74 | |
parent | 208ab5723efd0b08b945746a277d3269a5c78f27 (diff) |
crypto: fix auth tag length error when mode != GCM
PR-URL: https://github.com/nodejs/node/pull/42383
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
-rw-r--r-- | src/crypto/crypto_cipher.cc | 3 | ||||
-rw-r--r-- | test/parallel/test-crypto-authenticated.js | 16 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/crypto/crypto_cipher.cc b/src/crypto/crypto_cipher.cc index 90a0c4d1fd0..d6c6f0c4375 100644 --- a/src/crypto/crypto_cipher.cc +++ b/src/crypto/crypto_cipher.cc @@ -593,7 +593,8 @@ bool CipherBase::InitAuthenticated( // Tell OpenSSL about the desired length. if (!EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_SET_TAG, auth_tag_len, nullptr)) { - THROW_ERR_CRYPTO_INVALID_AUTH_TAG(env()); + THROW_ERR_CRYPTO_INVALID_AUTH_TAG( + env(), "Invalid authentication tag length: %u", auth_tag_len); return false; } diff --git a/test/parallel/test-crypto-authenticated.js b/test/parallel/test-crypto-authenticated.js index 21c5af6cfe3..3749895769f 100644 --- a/test/parallel/test-crypto-authenticated.js +++ b/test/parallel/test-crypto-authenticated.js @@ -44,7 +44,7 @@ const errMessages = { state: / state/, FIPS: /not supported in FIPS mode/, length: /Invalid initialization vector/, - authTagLength: /Invalid authentication tag/ + authTagLength: /Invalid authentication tag length/ }; const ciphers = crypto.getCiphers(); @@ -687,3 +687,17 @@ for (const test of TEST_CASES) { }); } } + +{ + const key = Buffer.alloc(32); + const iv = Buffer.alloc(12); + + for (const authTagLength of [0, 17]) { + assert.throws(() => { + crypto.createCipheriv('chacha20-poly1305', key, iv, { authTagLength }); + }, { + code: 'ERR_CRYPTO_INVALID_AUTH_TAG', + message: errMessages.authTagLength + }); + } +} |