Skip to content

Commit d14d6ae

Browse files
committed
crypto: deprecate implicitly shortened GCM tags
This introduces a doc-only deprecation of using GCM authentication tags that are shorter than the cipher's block size, unless the user specified the authTagLength option. Refs: nodejs#52327
1 parent 2c024cd commit d14d6ae

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

doc/api/crypto.md

+5
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,11 @@ When passing a string as the `buffer`, please consider
891891
<!-- YAML
892892
added: v1.0.0
893893
changes:
894+
- version: REPLACEME
895+
pr-url: https://github.com/nodejs/node/pull/52345
896+
description: Using GCM tag lengths other than 128 bits without specifying
897+
the `authTagLength` option when creating `decipher` is
898+
deprecated.
894899
- version: v15.0.0
895900
pr-url: https://github.com/nodejs/node/pull/35093
896901
description: The buffer argument can be a string or ArrayBuffer and is

doc/api/deprecations.md

+19
Original file line numberDiff line numberDiff line change
@@ -3619,6 +3619,25 @@ Calling `Hmac` class directly with `Hmac()` or `new Hmac()` is
36193619
deprecated due to being internals, not intended for public use.
36203620
Please use the [`crypto.createHmac()`][] method to create Hmac instances.
36213621

3622+
### DEP0182: Short GCM authentication tags without explicit `authTagLength`
3623+
3624+
<!-- YAML
3625+
changes:
3626+
- version: REPLACEME
3627+
pr-url: https://github.com/nodejs/node/pull/52345
3628+
description: Documentation-only deprecation.
3629+
-->
3630+
3631+
Type: Documentation-only (supports [`--pending-deprecation`][])
3632+
3633+
Applications that intend to use authentication tags that are shorter than the
3634+
default authentication tag length should set the `authTagLength` option of the
3635+
[`crypto.createDecipheriv()`][] function to the appropriate length.
3636+
3637+
For ciphers in GCM mode, the [`decipher.setAuthTag()`][] function accepts
3638+
authentication tags of any valid length (see [DEP0090](#DEP0090)). This behavior
3639+
is deprecated to better align with recommendations per [NIST SP 800-38D][].
3640+
36223641
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
36233642
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
36243643
[RFC 8247 Section 2.4]: https://www.rfc-editor.org/rfc/rfc8247#section-2.4

src/crypto/crypto_cipher.cc

+13
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,19 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
697697
env, "Invalid authentication tag length: %u", tag_len);
698698
}
699699

700+
if (mode == EVP_CIPH_GCM_MODE && cipher->auth_tag_len_ == kNoAuthTagLength &&
701+
tag_len != 16 && env->options()->pending_deprecation &&
702+
env->EmitProcessEnvWarning()) {
703+
if (ProcessEmitDeprecationWarning(
704+
env,
705+
"Using AES-GCM authentication tags of less than 128 bits without "
706+
"specifying the authTagLength option when initializing decryption "
707+
"is deprecated.",
708+
"DEP0182")
709+
.IsNothing())
710+
return;
711+
}
712+
700713
cipher->auth_tag_len_ = tag_len;
701714
cipher->auth_tag_state_ = kAuthTagKnown;
702715
CHECK_LE(cipher->auth_tag_len_, sizeof(cipher->auth_tag_));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Flags: --pending-deprecation
2+
'use strict';
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const { createDecipheriv, randomBytes } = require('crypto');
8+
9+
common.expectWarning({
10+
DeprecationWarning: [
11+
['Using AES-GCM authentication tags of less than 128 bits without ' +
12+
'specifying the authTagLength option when initializing decryption is ' +
13+
'deprecated.',
14+
'DEP0182'],
15+
]
16+
});
17+
18+
const key = randomBytes(32);
19+
const iv = randomBytes(16);
20+
const tag = randomBytes(12);
21+
createDecipheriv('aes-256-gcm', key, iv).setAuthTag(tag);

0 commit comments

Comments
 (0)