From 23de98f892ae88776e9c7731d80cec232fd3e23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Vi=C3=A9?= Date: Wed, 26 Mar 2025 11:46:47 +0100 Subject: [PATCH 1/3] Add ECB/NoPadding and CBC/NoPadding Encryption --- src/core/operations/AESEncrypt.mjs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/core/operations/AESEncrypt.mjs b/src/core/operations/AESEncrypt.mjs index 7b52ff03..0c5b1689 100644 --- a/src/core/operations/AESEncrypt.mjs +++ b/src/core/operations/AESEncrypt.mjs @@ -66,6 +66,14 @@ class AESEncrypt extends Operation { { name: "ECB", off: [5] + }, + { + name: "CBC/NoPadding", + off: [5] + }, + { + name: "ECB/NoPadding", + off: [5] } ] }, @@ -98,7 +106,8 @@ class AESEncrypt extends Operation { run(input, args) { const key = Utils.convertToByteString(args[0].string, args[0].option), iv = Utils.convertToByteString(args[1].string, args[1].option), - mode = args[2], + mode = args[2].substring(0, 3), + noPadding = args[2].endsWith("NoPadding"), inputType = args[3], outputType = args[4], aad = Utils.convertToByteString(args[5].string, args[5].option); @@ -114,11 +123,20 @@ The following algorithms will be used based on the size of the key: input = Utils.convertToByteString(input, inputType); + // Handle NoPadding modes + if (noPadding && input.length % 16 !== 0) { + throw new OperationError("Input length must be a multiple of 16 bytes for NoPadding modes."); + } const cipher = forge.cipher.createCipher("AES-" + mode, key); cipher.start({ iv: iv, additionalData: mode === "GCM" ? aad : undefined }); + if (noPadding) { + cipher.mode.pad = function(output, options) { + return true; + } + } cipher.update(forge.util.createBuffer(input)); cipher.finish(); From e00a636fc0983d0a6497fc8e36c48b8063f1e829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Vi=C3=A9?= Date: Fri, 4 Apr 2025 18:40:27 +0200 Subject: [PATCH 2/3] fix semicolon --- src/core/operations/AESEncrypt.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/operations/AESEncrypt.mjs b/src/core/operations/AESEncrypt.mjs index 0c5b1689..0bc85303 100644 --- a/src/core/operations/AESEncrypt.mjs +++ b/src/core/operations/AESEncrypt.mjs @@ -135,7 +135,7 @@ The following algorithms will be used based on the size of the key: if (noPadding) { cipher.mode.pad = function(output, options) { return true; - } + }; } cipher.update(forge.util.createBuffer(input)); cipher.finish(); From fa559fdbed6a45772f788d511207c365f9db3a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Vi=C3=A9?= Date: Sat, 5 Apr 2025 14:28:14 +0200 Subject: [PATCH 3/3] split edit --- src/core/operations/AESDecrypt.mjs | 2 +- src/core/operations/AESEncrypt.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/operations/AESDecrypt.mjs b/src/core/operations/AESDecrypt.mjs index e24a5119..5e6cec26 100644 --- a/src/core/operations/AESDecrypt.mjs +++ b/src/core/operations/AESDecrypt.mjs @@ -112,7 +112,7 @@ class AESDecrypt extends Operation { run(input, args) { const key = Utils.convertToByteString(args[0].string, args[0].option), iv = Utils.convertToByteString(args[1].string, args[1].option), - mode = args[2].substring(0, 3), + mode = args[2].split("/")[0], noPadding = args[2].endsWith("NoPadding"), inputType = args[3], outputType = args[4], diff --git a/src/core/operations/AESEncrypt.mjs b/src/core/operations/AESEncrypt.mjs index 0bc85303..84e1c540 100644 --- a/src/core/operations/AESEncrypt.mjs +++ b/src/core/operations/AESEncrypt.mjs @@ -106,7 +106,7 @@ class AESEncrypt extends Operation { run(input, args) { const key = Utils.convertToByteString(args[0].string, args[0].option), iv = Utils.convertToByteString(args[1].string, args[1].option), - mode = args[2].substring(0, 3), + mode = args[2].split("/")[0], noPadding = args[2].endsWith("NoPadding"), inputType = args[3], outputType = args[4],