From 3dd2734dc7dc8615eef9e3251171efe014524b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Conselheiro?= Date: Sun, 28 Apr 2024 12:42:46 -0300 Subject: [PATCH 1/2] including default value for ADD argument in webcrypto aes-gcm algorithm --- src/webcrypto.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/webcrypto.ts b/src/webcrypto.ts index 3400903..0264c06 100644 --- a/src/webcrypto.ts +++ b/src/webcrypto.ts @@ -75,7 +75,8 @@ type BlockMode = (typeof mode)[keyof typeof mode]; function getCryptParams(algo: BlockMode, nonce: Uint8Array, AAD?: Uint8Array) { if (algo === mode.CBC) return { name: mode.CBC, iv: nonce }; if (algo === mode.CTR) return { name: mode.CTR, counter: nonce, length: 64 }; - if (algo === mode.GCM) return { name: mode.GCM, iv: nonce, additionalData: AAD }; + if (algo === mode.GCM) + return { name: mode.GCM, iv: nonce, additionalData: AAD || new Uint8Array(0) }; throw new Error('unknown aes block mode'); } From f8057394d936231fab12626cf0e43dc0549de8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Conselheiro?= Date: Mon, 29 Apr 2024 08:05:14 -0300 Subject: [PATCH 2/2] removing additionalData for AES-GCM when undefined --- src/webcrypto.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/webcrypto.ts b/src/webcrypto.ts index 0264c06..c4a3ccb 100644 --- a/src/webcrypto.ts +++ b/src/webcrypto.ts @@ -75,8 +75,11 @@ type BlockMode = (typeof mode)[keyof typeof mode]; function getCryptParams(algo: BlockMode, nonce: Uint8Array, AAD?: Uint8Array) { if (algo === mode.CBC) return { name: mode.CBC, iv: nonce }; if (algo === mode.CTR) return { name: mode.CTR, counter: nonce, length: 64 }; - if (algo === mode.GCM) - return { name: mode.GCM, iv: nonce, additionalData: AAD || new Uint8Array(0) }; + if (algo === mode.GCM) { + if (AAD) return { name: mode.GCM, iv: nonce, additionalData: AAD }; + else return { name: mode.GCM, iv: nonce }; + } + throw new Error('unknown aes block mode'); }