Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: fix auth tag length error when mode != GCM #42383

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/crypto/crypto_cipher.cc
Expand Up @@ -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;
}

Expand Down
16 changes: 15 additions & 1 deletion test/parallel/test-crypto-authenticated.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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
});
}
}