From e805b1718b0d01254fc36eaef519330bbbdae697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B8ed=20Tvete?= Date: Mon, 1 Jun 2026 16:59:57 +0200 Subject: [PATCH] feat: AESDecrypt, moved "IV Location" to "IV from input" --- src/core/operations/AESDecrypt.mjs | 52 ++++++++++++++--------------- tests/browser/02_ops.js | 2 +- tests/operations/tests/Crypt.mjs | 48 ++++---------------------- tests/operations/tests/Register.mjs | 1 - 4 files changed, 32 insertions(+), 71 deletions(-) diff --git a/src/core/operations/AESDecrypt.mjs b/src/core/operations/AESDecrypt.mjs index 088a594a..44e6cab2 100644 --- a/src/core/operations/AESDecrypt.mjs +++ b/src/core/operations/AESDecrypt.mjs @@ -44,46 +44,41 @@ class AESDecrypt extends Operation { "type": "number", "value": 16 }, - { - "name": "IV Location", - "type": "option", - "value": ["Start of input", "End of input"], - }, { "name": "Mode", "type": "argSelector", "value": [ { name: "CBC", - off: [7, 8] + off: [6, 7] }, { name: "CFB", - off: [7, 8] + off: [6, 7] }, { name: "OFB", - off: [7, 8] + off: [6, 7] }, { name: "CTR", - off: [7, 8] + off: [6, 7] }, { name: "GCM", - on: [7, 8] + on: [6, 7] }, { name: "ECB", - off: [7, 8] + off: [6, 7] }, { name: "CBC/NoPadding", - off: [7, 8] + off: [6, 7] }, { name: "ECB/NoPadding", - off: [7, 8] + off: [6, 7] } ] }, @@ -116,11 +111,15 @@ class AESDecrypt extends Operation { { name: "Off", on: [1], - off: [2, 3] + off: [2] }, { - name: "On", - on: [2, 3], + name: "From start", + on: [2], + off: [1] + }, { + name: "From end", + on: [2], off: [1] } ] @@ -140,14 +139,13 @@ class AESDecrypt extends Operation { const key = Utils.convertToByteString(args[0].string, args[0].option), ivLength = args[2], - ivFromStart = args[3] === "Start of input", - mode = args[4].split("/")[0], - noPadding = args[4].endsWith("NoPadding"), - inputType = args[5], - outputType = args[6], - gcmTag = Utils.convertToByteString(args[7].string, args[7].option), - aad = Utils.convertToByteString(args[8].string, args[8].option), - ivFromInput = args[9] === "On"; + mode = args[3].split("/")[0], + noPadding = args[3].endsWith("NoPadding"), + inputType = args[4], + outputType = args[5], + gcmTag = Utils.convertToByteString(args[6].string, args[6].option), + aad = Utils.convertToByteString(args[7].string, args[7].option), + ivFromInput = args[8]; if ([16, 24, 32].indexOf(key.length) < 0) { @@ -161,12 +159,12 @@ The following algorithms will be used based on the size of the key: input = Utils.convertToByteString(input, inputType); - if (ivFromInput) { + if (ivFromInput !== "Off") { if (input.length <= ivLength) { throw new OperationError(`Input is too short to contain an IV of ${ivLength} bytes.`); } - if (ivFromStart) { + if (ivFromInput === "From start") { iv = input.substr(0, ivLength); input = input.substr(ivLength); } else { @@ -181,7 +179,7 @@ The following algorithms will be used based on the size of the key: /* Allow for a "no padding" mode */ if (noPadding) { - decipher.mode.unpad = function(output, options) { + decipher.mode.unpad = function (output, options) { return true; }; } diff --git a/tests/browser/02_ops.js b/tests/browser/02_ops.js index d8ab09c9..32bd14d6 100644 --- a/tests/browser/02_ops.js +++ b/tests/browser/02_ops.js @@ -30,7 +30,7 @@ module.exports = { testOp(browser, "A1Z26 Cipher Decode", "20 5 19 20 15 21 20 16 21 20", "testoutput"); testOp(browser, "A1Z26 Cipher Encode", "test input", "20 5 19 20 9 14 16 21 20"); testOp(browser, "ADD", "test input", "Ê»ÉÊv¿ÄÆËÊ", [{ "option": "Hex", "string": "56" }]); - testOp(browser, "AES Decrypt", "b443f7f7c16ac5396a34273f6f639caa", "test output", [{ "option": "Hex", "string": "00112233445566778899aabbccddeeff" }, { "option": "Hex", "string": "00000000000000000000000000000000" }, 16, "Start of input", "CBC", "Hex", "Raw", { "option": "Hex", "string": "" }, { "option": "Hex", "string": "" }, "Off"]); + testOp(browser, "AES Decrypt", "b443f7f7c16ac5396a34273f6f639caa", "test output", [{ "option": "Hex", "string": "00112233445566778899aabbccddeeff" }, { "option": "Hex", "string": "00000000000000000000000000000000" }, 16, "CBC", "Hex", "Raw", { "option": "Hex", "string": "" }, { "option": "Hex", "string": "" }, "Off"]); testOp(browser, "AES Encrypt", "test input", "e42eb8fbfb7a98fff061cd2c1a794d92", [{"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00000000000000000000000000000000"}, "CBC", "Raw", "Hex", "Off"]); testOp(browser, "AND", "test input", "4$04 $044", [{ "option": "Hex", "string": "34" }]); testOp(browser, "Add line numbers", "test input", "1 test input"); diff --git a/tests/operations/tests/Crypt.mjs b/tests/operations/tests/Crypt.mjs index 4169293c..18b1c6e5 100644 --- a/tests/operations/tests/Crypt.mjs +++ b/tests/operations/tests/Crypt.mjs @@ -846,7 +846,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, 16, - "Start of input", "CBC", "Hex", "Raw", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -866,7 +865,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00000000000000000000000000000000"}, 16, - "Start of input", "CBC", "Hex", "Raw", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -886,7 +884,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00000000000000000000000000000000"}, 16, - "Start of input", "CTR", "Hex", "Raw", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -906,7 +903,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, 16, - "Start of input", "CBC", "Hex", "Raw", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -926,7 +922,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, 16, - "Start of input", "CFB", "Hex", "Raw", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -946,7 +941,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, 16, - "Start of input", "OFB", "Hex", "Raw", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -966,7 +960,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, 16, - "Start of input", "CTR", "Hex", "Raw", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -986,7 +979,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": ""}, 16, - "Start of input", "ECB", "Hex", "Raw", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1006,7 +998,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": ""}, 16, - "Start of input", "GCM", "Hex", "Raw", {"option": "Hex", "string": "16a3e732a605cc9ca29108f742ca0743"}, {"option": "Hex", "string": ""}, @@ -1026,7 +1017,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "ffeeddccbbaa99887766554433221100"}, 16, - "Start of input", "GCM", "Hex", "Raw", {"option": "Hex", "string": "3b5378917f67b0aade9891fc6c291646"}, {"option": "UTF8", "string": "additional data"}, @@ -1046,7 +1036,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "CBC", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1066,7 +1055,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "CFB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1086,7 +1074,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "OFB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1106,7 +1093,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "CTR", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1126,7 +1112,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "GCM", "Hex", "Hex", {"option": "Hex", "string": "70fad2ca19412c20f40fd06918736e56"}, {"option": "Hex", "string": ""}, @@ -1146,7 +1131,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "GCM", "Hex", "Hex", {"option": "Hex", "string": "61cc4b70809452b0b3e38f913fa0a109"}, {"option": "UTF8", "string": "additional data"}, @@ -1166,7 +1150,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "ECB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1186,7 +1169,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "CBC", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1206,7 +1188,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "CFB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1226,7 +1207,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "OFB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1246,7 +1226,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "CTR", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1266,7 +1245,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "GCM", "Hex", "Hex", {"option": "Hex", "string": "86db597d5302595223cadbd990f1309b"}, {"option": "Hex", "string": ""}, @@ -1286,7 +1264,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "GCM", "Hex", "Hex", {"option": "Hex", "string": "aeedf3e6ca4201577c0cf3e9ce58159d"}, {"option": "UTF8", "string": "additional data"}, @@ -1306,7 +1283,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "ECB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1326,7 +1302,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "CBC", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1346,7 +1321,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "CFB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1366,7 +1340,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "OFB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1386,7 +1359,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "CTR", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1406,7 +1378,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "GCM", "Hex", "Hex", {"option": "Hex", "string": "821b1e5f32dad052e502775a523d957a"}, {"option": "Hex", "string": ""}, @@ -1426,7 +1397,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "GCM", "Hex", "Hex", {"option": "Hex", "string": "a8f04c4d93bbef82bef61a103371aef9"}, {"option": "UTF8", "string": "additional data"}, @@ -1446,7 +1416,6 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, 16, - "Start of input", "ECB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, @@ -1466,11 +1435,10 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": ""}, 16, - "End of input", "ECB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, - "On" + "From start" ] } ], @@ -1486,11 +1454,10 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": ""}, 16, - "Start of input", "ECB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, - "On" + "From start" ] } ], @@ -1506,17 +1473,16 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": ""}, 16, - "End of input", "ECB", "Hex", "Hex", {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, - "On" + "From end" ] } ], }, { - name: "AES Decrypt: AES-256-GCM with IV from input, Binary, AAD", + name: "AES Decrypt: AES-256-GCM with IV from input start, Binary, AAD", input: "1748e7179bd56570d51fa4ba287cc3e51287f188ad4d7ab0d9ff69b3c29cb11f861389532d8cb9337181da2e8cfc74a84927e8c0dd7a28a32fd485afe694259a63c199b199b95edd87c7aa95329feac340f2b78b72956a85f367044d821766b1b7135815571df44900695f1518cf3ae38ecb650f", expectedOutput: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", recipeConfig: [ @@ -1526,11 +1492,10 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": ""}, 16, - "Start of input", "GCM", "Hex", "Hex", {"option": "Hex", "string": "a8f04c4d93bbef82bef61a103371aef9"}, {"option": "UTF8", "string": "additional data"}, - "On" + "From start" ] } ], @@ -1546,11 +1511,10 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": ""}, 12, - "Start of input", "GCM", "Hex", "Hex", {"option": "Hex", "string": "c311c9144f8ae145ec46e2c69179a4b7"}, {"option": "UTF8", "string": "additional data"}, - "On" + "From start" ] } ], diff --git a/tests/operations/tests/Register.mjs b/tests/operations/tests/Register.mjs index 4fc0d307..e455f0f8 100644 --- a/tests/operations/tests/Register.mjs +++ b/tests/operations/tests/Register.mjs @@ -60,7 +60,6 @@ TestRegister.addTests([ "string": "$R0" }, 16, - "Start of input", "CTR", "Hex", "Raw", { "option": "Hex",