gchq / gchq/CyberChef

Bug report: AES Decrypt GCM Mode doesn't support truncated tag size of 12 bytes

Open
#1,546 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
35.8k
Forks
4.1k
Avg merge
2d 26m
Merged PRs (30d)
33

Description

**Describe the bug**
For some reason AES Decrypt fails if the GCM Tag is not 16 bytes.
I assume the fault is in some external crypto library that is used here?

**To Reproduce**
Recipe is AES Decrypt
Key base64: `IZKzlCW70ItujmHF0fG8n0KPxWn7xveMC8SPzNsPQq4=`
IV base64: `4eWS6HIlhHwR2Uho`
Mode: `GCM`
Input: `Hex`
Output: `Raw`
GCM Tag hex: `c1c4876c8853a226d6ce1ed2`

Input: `d5f9d2a874d6e8a10fc397af96d3f8e6965a003d02a88db1c85bdebfc35b11`

Result:
> AES Decrypt - Error in https://gchq.github.io/CyberChef/modules/Ciphers.js on line 2.

Message: Authentication tag does not match tag length.

**Expected behaviour**
Output should be `{"steamId":"76561198049878030"}`

**Additional context**

If we use the untruncated 16 byte tag hex `7b37b10224dc12ba7bc7094584da206a`, it works.

For encryption I used Crypto++ C++ library. I had to truncate the tag to 12 bytes because the .NET AesGcm implementation only accepts a 12 byte tag.
And in .NET it works just fine.

Equivalent .NET 7 code
```cs
string keyb64 = "IZKzlCW70ItujmHF0fG8n0KPxWn7xveMC8SPzNsPQq4=";
string cipherTextb64 = "1fnSqHTW6KEPw5evltP45pZaAD0CqI2xyFvev8NbEQ==";
string ivb64 = "4eWS6HIlhHwR2Uho";
string tagb64 = "wcSHbIhToibWzh7S";

var aesGcm = new System.Security.Cryptography.AesGcm(Convert.FromBase64String("IZKzlCW70ItujmHF0fG8n0KPxWn7xveMC8SPzNsPQq4="));
var result = new byte[128];
aesGcm.Decrypt(
System.Convert.FromBase64String(ivb64),
System.Convert.FromBase64String(cipherTextb64),
System.Convert.FromBase64String(tagb64),
new Span(result, 0, System.Convert.FromBase64String(cipherTextb64).Length)
);
Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
```
You can run it here: https://dotnetfiddle.net/wH0nkE

Also as a by the way, it would be nice if we could choose the Tag length on AES Encrypt.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.