GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto: warn on invalid authentication tag length · nodejs/node@691cd5a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_crypto.cc
  • test/parallel
    • test-crypto-authenticated.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3525,8 +3525,16 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo<Value>& args) {
35253525

35263526
CipherBase* cipher;
35273527
ASSIGN_OR_RETURN_UNWRAP(&cipher, args.Holder());
3528+
// Restrict GCM tag lengths according to NIST 800-38d, page 9.
3529+
unsigned int tag_len = Buffer::Length(buf);
3530+
if (tag_len > 16 || (tag_len < 12 && tag_len != 8 && tag_len != 4)) {
3531+
ProcessEmitWarning(cipher->env(),
3532+
"Permitting authentication tag lengths of %u bytes is deprecated. "
3533+
"Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.",
3534+
tag_len);
3535+
}
35283536

3529-
if (!cipher->SetAuthTag(Buffer::Data(buf), Buffer::Length(buf)))
3537+
if (!cipher->SetAuthTag(Buffer::Data(buf), tag_len))
35303538
env->ThrowError("Attempting to set auth tag in unsupported state");
35313539
}
35323540

Collapse file

‎test/parallel/test-crypto-authenticated.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-authenticated.js
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ const errMessages = {
314314

315315
const ciphers = crypto.getCiphers();
316316

317+
common.expectWarning('Warning', (common.hasFipsCrypto ? [] : [
318+
'Use Cipheriv for counter mode of aes-192-gcm'
319+
]).concat(
320+
[0, 1, 2, 6, 9, 10, 11, 17]
321+
.map((i) => `Permitting authentication tag lengths of ${i} bytes is ` +
322+
'deprecated. Valid GCM tag lengths are 4, 8, 12, 13, 14, 15, 16.')
323+
));
324+
317325
for (const i in TEST_CASES) {
318326
const test = TEST_CASES[i];
319327

@@ -455,3 +463,14 @@ for (const i in TEST_CASES) {
455463
assert.throws(() => encrypt.setAAD(Buffer.from('123', 'ascii')),
456464
errMessages.state);
457465
}
466+
467+
// GCM only supports specific authentication tag lengths, invalid lengths should
468+
// produce warnings.
469+
{
470+
for (const length of [0, 1, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) {
471+
const decrypt = crypto.createDecipheriv('aes-256-gcm',
472+
'FxLKsqdmv0E9xrQhp0b1ZgI0K7JFZJM8',
473+
'qkuZpJWCewa6Szih');
474+
decrypt.setAuthTag(Buffer.from('1'.repeat(length)));
475+
}
476+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.