You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
the argument to define auth tag length in crypto.createDecipheriv cannot work #40272
let decipher = crypto.createDecipheriv('aes-256-gcm', serverKeyArr, iv, {authTagLength: 12});
to define auth tag to 12 bytes, however, when I execute decipher.final(), inside that function, the tag it calculated is still 16 bytes, then when it do xor test for the tag function calculated and the auth Tag I've received (which already cut off by server side from 16 bytes to 12 bytes), it will results in error because the length is different.
I wonder why the argument {authTagLength: 12} do not work?
Besides, is there any way I can use shorter auth tag length to pass decipher.final() function, because in my program, I only can get the first 12 bytes auth tag.
It's always returned 16 bytes for the actual tag data. You will need to manually slice off the first authTagLength bytes of the full tag to get the value you want.
Arguably node should only be returning the appropriate slice of the full tag if the authTagLength is less than 16.
Besides, is there any way I can use shorter auth tag length to pass decipher.final() function, because in my program, I only can get the first 12 bytes auth tag.
You can pass shorter tags to setAuthTag() as long as the length is valid according to SP 800-38D.
Arguably node should only be returning the appropriate slice of the full tag if the authTagLength is less than 16.
constcipher=crypto.createCipheriv('aes-128-gcm',Buffer.alloc(16),Buffer.alloc(16),{authTagLength: 4});cipher.update('foo');cipher.final();console.log(cipher.getAuthTag().byteLength);// prints 4
constcipher=crypto.createCipheriv('aes-256-gcm',serverKeyArr,iv,{authTagLength: 12});constciphertext=cipher.update('foo');cipher.final();// GCM mode is a counter mode, so no output hereconstauthTag=cipher.getAuthTag();console.log(authTag.length);// prints 12
Now decrypting and verifying the tag, taking this line from your example:
Activity
mscdex commentedon Sep 30, 2021
It's always returned 16 bytes for the actual tag data. You will need to manually slice off the first
authTagLengthbytes of the full tag to get the value you want.Arguably node should only be returning the appropriate slice of the full tag if the
authTagLengthis less than 16.tniessen commentedon Nov 3, 2021
You can pass shorter tags to
setAuthTag()as long as the length is valid according to SP 800-38D.This should be working already ever since #20235:
tniessen commentedon Nov 3, 2021
Testing in Node.js v14.17.5:
Producing a 12-byte authentication tag:
Now decrypting and verifying the tag, taking this line from your example:
This works and prints the correct plaintext:
doc: clarify getAuthTag with authTagLength
tniessen commentedon Nov 11, 2021
I am closing this as answered. Feel free to reopen if the problem persists.
doc: clarify getAuthTag with authTagLength
doc: clarify getAuthTag with authTagLength
doc: clarify getAuthTag with authTagLength