Skip to content

Commit 460e98e

Browse files
committed
removed support for aad
1 parent f40af6d commit 460e98e

File tree

5 files changed

+31
-283
lines changed

5 files changed

+31
-283
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format
55
## Table of Contents
66

77
- [Unreleased](#unreleased)
8-
- [1.9.15 - 2025-12-09](#1925---2025-12-09)
8+
- [1.9.25 - 2025-12-09](#1925---2025-12-09)
99
- [1.9.24 - 2025-12-09](#1924---2025-12-09)
1010
- [1.9.23 - 2025-12-08](#1923---2025-12-08)
1111
- [1.9.22 - 2025-12-05](#1922---2025-12-04)

docs/reference/primitives.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5025,8 +5025,13 @@ fully compliant AES-GCM encoding will require a compatibility strategy, as
50255025
existing ciphertexts produced by this implementation will otherwise become
50265026
undecryptable.
50275027

5028+
This non-standard padding behavior is retained intentionally for backward
5029+
compatibility: existing ciphertexts in production were generated with this
5030+
encoding, and changing it would render previously encrypted data
5031+
undecryptable by newer versions of the library.
5032+
50285033
```ts
5029-
export function AESGCM(plainText: number[], additionalAuthenticatedData: number[], initializationVector: number[], key: number[]): {
5034+
export function AESGCM(plainText: number[], initializationVector: number[], key: number[]): {
50305035
result: number[];
50315036
authenticationTag: number[];
50325037
}
@@ -5038,7 +5043,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
50385043
### Function: AESGCMDecrypt
50395044

50405045
```ts
5041-
export function AESGCMDecrypt(cipherText: number[], additionalAuthenticatedData: number[], initializationVector: number[], authenticationTag: number[], key: number[]): number[] | null
5046+
export function AESGCMDecrypt(cipherText: number[], initializationVector: number[], authenticationTag: number[], key: number[]): number[] | null
50425047
```
50435048

50445049
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)

src/primitives/AESGCM.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,14 @@ function gctr (
364364
* fully compliant AES-GCM encoding will require a compatibility strategy, as
365365
* existing ciphertexts produced by this implementation will otherwise become
366366
* undecryptable.
367+
*
368+
* This non-standard padding behavior is retained intentionally for backward
369+
* compatibility: existing ciphertexts in production were generated with this
370+
* encoding, and changing it would render previously encrypted data
371+
* undecryptable by newer versions of the library.
367372
*/
368373
export function AESGCM (
369374
plainText: number[],
370-
additionalAuthenticatedData: number[],
371375
initializationVector: number[],
372376
key: number[]
373377
): { result: number[], authenticationTag: number[] } {
@@ -380,7 +384,7 @@ export function AESGCM (
380384
}
381385

382386
let preCounterBlock
383-
let plainTag
387+
let plainTag: number[] = []
384388
const hashSubKey = AES(createZeroBlock(16), key)
385389
preCounterBlock = [...initializationVector]
386390
if (initializationVector.length === 12) {
@@ -400,14 +404,7 @@ export function AESGCM (
400404

401405
const cipherText = gctr(plainText, incrementLeastSignificantThirtyTwoBits(preCounterBlock), key)
402406

403-
plainTag = additionalAuthenticatedData.slice()
404-
405-
if (additionalAuthenticatedData.length === 0) {
406-
plainTag = plainTag.concat(createZeroBlock(16))
407-
} else if (additionalAuthenticatedData.length % 16 !== 0) {
408-
plainTag = plainTag.concat(createZeroBlock(16 - (additionalAuthenticatedData.length % 16)))
409-
}
410-
407+
plainTag = plainTag.concat(createZeroBlock(16))
411408
plainTag = plainTag.concat(cipherText)
412409

413410
if (cipherText.length === 0) {
@@ -417,7 +414,7 @@ export function AESGCM (
417414
}
418415

419416
plainTag = plainTag.concat(createZeroBlock(4))
420-
.concat(getBytes(additionalAuthenticatedData.length * 8))
417+
.concat(getBytes(0))
421418
.concat(createZeroBlock(4)).concat(getBytes(cipherText.length * 8))
422419

423420
return {
@@ -428,7 +425,6 @@ export function AESGCM (
428425

429426
export function AESGCMDecrypt (
430427
cipherText: number[],
431-
additionalAuthenticatedData: number[],
432428
initializationVector: number[],
433429
authenticationTag: number[],
434430
key: number[]
@@ -446,7 +442,7 @@ export function AESGCMDecrypt (
446442
}
447443

448444
let preCounterBlock
449-
let compareTag
445+
let compareTag: number[] = []
450446

451447
// Generate the hash subkey
452448
const hashSubKey = AES(createZeroBlock(16), key)
@@ -467,14 +463,7 @@ export function AESGCMDecrypt (
467463
// Decrypt to obtain the plain text
468464
const plainText = gctr(cipherText, incrementLeastSignificantThirtyTwoBits(preCounterBlock), key)
469465

470-
compareTag = additionalAuthenticatedData.slice()
471-
472-
if (additionalAuthenticatedData.length === 0) {
473-
compareTag = compareTag.concat(createZeroBlock(16))
474-
} else if (additionalAuthenticatedData.length % 16 !== 0) {
475-
compareTag = compareTag.concat(createZeroBlock(16 - (additionalAuthenticatedData.length % 16)))
476-
}
477-
466+
compareTag = compareTag.concat(createZeroBlock(16))
478467
compareTag = compareTag.concat(cipherText)
479468

480469
if (cipherText.length === 0) {
@@ -484,8 +473,9 @@ export function AESGCMDecrypt (
484473
}
485474

486475
compareTag = compareTag.concat(createZeroBlock(4))
487-
.concat(getBytes(additionalAuthenticatedData.length * 8))
488-
.concat(createZeroBlock(4)).concat(getBytes(cipherText.length * 8))
476+
.concat(getBytes(0))
477+
.concat(createZeroBlock(4))
478+
.concat(getBytes(cipherText.length * 8))
489479

490480
// Generate the authentication tag
491481
const calculatedTag = gctr(ghash(compareTag, hashSubKey), preCounterBlock, key)

src/primitives/SymmetricKey.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class SymmetricKey extends BigNumber {
4444
const iv = Random(32)
4545
msg = toArray(msg, enc)
4646
const keyBytes = this.toArray('be', 32)
47-
const { result, authenticationTag } = AESGCM(msg, [], iv, keyBytes)
47+
const { result, authenticationTag } = AESGCM(msg, iv, keyBytes)
4848
const totalLength = iv.length + result.length + authenticationTag.length
4949
const combined = new Array(totalLength)
5050
let offset = 0
@@ -89,7 +89,6 @@ export default class SymmetricKey extends BigNumber {
8989

9090
const result = AESGCMDecrypt(
9191
ciphertext,
92-
[],
9392
iv,
9493
messageTag,
9594
this.toArray('be', 32)

0 commit comments

Comments
 (0)