From 2574a63975ecced6e066ae673a986ad87394b7db Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Wed, 29 Dec 2021 19:32:39 +0000 Subject: [PATCH 01/10] Minor adjustments --- src/core/lib/Binary.mjs | 26 ++++++++++++---------- src/core/operations/ToUpperCase.mjs | 34 ++++++++++++++--------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/core/lib/Binary.mjs b/src/core/lib/Binary.mjs index dc63fc58..56db4c2a 100644 --- a/src/core/lib/Binary.mjs +++ b/src/core/lib/Binary.mjs @@ -19,27 +19,29 @@ import OperationError from "../errors/OperationError.mjs"; * @returns {string} * * @example - * // returns "00010000 00100000 00110000" + * // returns "00001010 00010100 00011110" * toBinary([10,20,30]); * - * // returns "00010000 00100000 00110000" - * toBinary([10,20,30], ":"); + * // returns "00001010:00010100:00011110" + * toBinary([10,20,30], "Colon"); + * + * // returns "1010:10100:11110" + * toBinary([10,20,30], "Colon", 0); */ export function toBinary(data, delim="Space", padding=8) { - if (!data) return ""; + if (!data) throw new OperationError("Empty input data enocuntered"); delim = Utils.charRep(delim); let output = ""; - for (let i = 0; i < data.length; i++) { - output += data[i].toString(2).padStart(padding, "0") + delim; + output += data[i].toString(2).padStart(padding, "0"); + if (i !== data.length - 1) output += delim; } - if (delim.length) { - return output.slice(0, -delim.length); - } else { - return output; + // Remove the delimiter from the end of the string. + output = output.slice(0, -delim.length); } + return output; } @@ -53,10 +55,10 @@ export function toBinary(data, delim="Space", padding=8) { * * @example * // returns [10,20,30] - * fromBinary("00010000 00100000 00110000"); + * fromBinary("00001010 00010100 00011110"); * * // returns [10,20,30] - * fromBinary("00010000:00100000:00110000", "Colon"); + * fromBinary("00001010:00010100:00011110", "Colon"); */ export function fromBinary(data, delim="Space", byteLen=8) { if (byteLen < 1 || Math.round(byteLen) !== byteLen) diff --git a/src/core/operations/ToUpperCase.mjs b/src/core/operations/ToUpperCase.mjs index 0bc9b5a9..eb0e315a 100644 --- a/src/core/operations/ToUpperCase.mjs +++ b/src/core/operations/ToUpperCase.mjs @@ -38,23 +38,23 @@ class ToUpperCase extends Operation { */ run(input, args) { const scope = args[0]; - - switch (scope) { - case "Word": - return input.replace(/(\b\w)/gi, function(m) { - return m.toUpperCase(); - }); - case "Sentence": - return input.replace(/(?:\.|^)\s*(\b\w)/gi, function(m) { - return m.toUpperCase(); - }); - case "Paragraph": - return input.replace(/(?:\n|^)\s*(\b\w)/gi, function(m) { - return m.toUpperCase(); - }); - case "All": /* falls through */ - default: - return input.toUpperCase(); + if (scope === "All") { + return input.toUpperCase(); + } + const scopeRegex = { + "Word": /(\b\w)/gi, + "Sentence": /(?:\.|^)\s*(\b\w)/gi, + "Paragraph": /(?:\n|^)\s*(\b\w)/gi + }[ scope ]; + if (scopeRegex !== undefined) { + // Use the regexes to capitalize the input. + return input.replace(scopeRegex, function(m) { + return m.toUpperCase(); + }); + } + else { + // The selected scope was invalid. + throw new OperationError("Unrecognized capitalization scope"); } } From ed542582f96541dd90fde52e4f0f07a9b6427ca6 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Wed, 29 Dec 2021 19:59:48 +0000 Subject: [PATCH 02/10] Added more error-handling to ToUpperCase() --- src/core/operations/ToUpperCase.mjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/operations/ToUpperCase.mjs b/src/core/operations/ToUpperCase.mjs index eb0e315a..08ffce87 100644 --- a/src/core/operations/ToUpperCase.mjs +++ b/src/core/operations/ToUpperCase.mjs @@ -37,6 +37,9 @@ class ToUpperCase extends Operation { * @returns {string} */ run(input, args) { + if (!args || args.length === 0) { + throw new OperationException("No capitalization scope was provided."); + } const scope = args[0]; if (scope === "All") { return input.toUpperCase(); From bdef47dad8fae7377738bd6554371c7a6ef2f3b1 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Tue, 22 Mar 2022 22:31:20 +0000 Subject: [PATCH 03/10] Added 'Key Padding' to AES --- src/core/operations/AESDecrypt.mjs | 29 ++++- src/core/operations/AESEncrypt.mjs | 30 ++++- tests/operations/tests/Crypt.mjs | 186 ++++++++++++++++++---------- tests/operations/tests/Register.mjs | 3 +- 4 files changed, 176 insertions(+), 72 deletions(-) diff --git a/src/core/operations/AESDecrypt.mjs b/src/core/operations/AESDecrypt.mjs index 1276d139..8e16515b 100644 --- a/src/core/operations/AESDecrypt.mjs +++ b/src/core/operations/AESDecrypt.mjs @@ -90,6 +90,11 @@ class AESDecrypt extends Operation { "type": "toggleString", "value": "", "toggleValues": ["Hex", "UTF8", "Latin1", "Base64"] + }, + { + "name": "Key Padding", + "type": "option", + "value": ["None", "Null", "Repeat"] } ]; } @@ -102,15 +107,31 @@ class AESDecrypt extends Operation { * @throws {OperationError} if cannot decrypt input or invalid key length */ run(input, args) { - const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteString(args[1].string, args[1].option), + var key = Utils.convertToByteString(args[0].string, args[0].option); + const iv = Utils.convertToByteString(args[1].string, args[1].option), mode = args[2], inputType = args[3], outputType = args[4], gcmTag = Utils.convertToByteString(args[5].string, args[5].option), - aad = Utils.convertToByteString(args[6].string, args[6].option); + aad = Utils.convertToByteString(args[6].string, args[6].option), + keyPadding = args[7], + keySizes = [16, 24, 32]; - if ([16, 24, 32].indexOf(key.length) < 0) { + if (keyPadding !== "None") { + var targetKeySize = 0; + for (var i = 0; i < keySizes.length; i++) { + if (key.length < keySizes[i]) { + targetKeySize = keySizes[i]; + break; + } + } + if (targetKeySize !== 0) { + const originalLength = key.length; + key = key.padEnd(targetKeySize, keyPadding == "Null" ? "\0" : key); + } + } + + if (keySizes.indexOf(key.length) < 0) { throw new OperationError(`Invalid key length: ${key.length} bytes The following algorithms will be used based on the size of the key: diff --git a/src/core/operations/AESEncrypt.mjs b/src/core/operations/AESEncrypt.mjs index 7b52ff03..42fb7b84 100644 --- a/src/core/operations/AESEncrypt.mjs +++ b/src/core/operations/AESEncrypt.mjs @@ -84,6 +84,11 @@ class AESEncrypt extends Operation { "type": "toggleString", "value": "", "toggleValues": ["Hex", "UTF8", "Latin1", "Base64"] + }, + { + "name": "Key Padding", + "type": "option", + "value": ["None", "Null", "Repeat"] } ]; } @@ -96,14 +101,30 @@ class AESEncrypt extends Operation { * @throws {OperationError} if invalid key length */ run(input, args) { - const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteString(args[1].string, args[1].option), + var key = Utils.convertToByteString(args[0].string, args[0].option); + const iv = Utils.convertToByteString(args[1].string, args[1].option), mode = args[2], inputType = args[3], outputType = args[4], - aad = Utils.convertToByteString(args[5].string, args[5].option); + aad = Utils.convertToByteString(args[5].string, args[5].option), + keyPadding = args[6], + keySizes = [16, 24, 32]; - if ([16, 24, 32].indexOf(key.length) < 0) { + if (keyPadding !== "None") { + var targetKeySize = 0; + for (var i = 0; i < keySizes.length; i++) { + if (key.length < keySizes[i]) { + targetKeySize = keySizes[i]; + break; + } + } + if (targetKeySize !== 0) { + const originalLength = key.length; + key = key.padEnd(targetKeySize, keyPadding == "Null" ? "\0" : key); + } + } + + if (keySizes.indexOf(key.length) < 0) { throw new OperationError(`Invalid key length: ${key.length} bytes The following algorithms will be used based on the size of the key: @@ -113,7 +134,6 @@ The following algorithms will be used based on the size of the key: } input = Utils.convertToByteString(input, inputType); - const cipher = forge.cipher.createCipher("AES-" + mode, key); cipher.start({ iv: iv, diff --git a/tests/operations/tests/Crypt.mjs b/tests/operations/tests/Crypt.mjs index 0c424050..f70dc5a9 100644 --- a/tests/operations/tests/Crypt.mjs +++ b/tests/operations/tests/Crypt.mjs @@ -74,7 +74,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, "CBC", "Raw", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -90,7 +91,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00000000000000000000000000000000"}, "CBC", "Raw", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -106,7 +108,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00000000000000000000000000000000"}, "CTR", "Raw", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -122,7 +125,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, "CBC", "Raw", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -138,7 +142,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, "CFB", "Raw", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -154,7 +159,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, "OFB", "Raw", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -170,7 +176,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, "CTR", "Raw", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -186,7 +193,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": ""}, "ECB", "Raw", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -204,7 +212,8 @@ Tag: 16a3e732a605cc9ca29108f742ca0743`, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": ""}, "GCM", "Raw", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -222,7 +231,8 @@ Tag: 3b5378917f67b0aade9891fc6c291646`, {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "ffeeddccbbaa99887766554433221100"}, "GCM", "Raw", "Hex", - {"option": "UTF8", "string": "additional data"} + {"option": "UTF8", "string": "additional data"}, + "None" ] } ], @@ -238,7 +248,8 @@ Tag: 3b5378917f67b0aade9891fc6c291646`, {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CBC", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -254,7 +265,8 @@ Tag: 3b5378917f67b0aade9891fc6c291646`, {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CFB", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -270,7 +282,8 @@ Tag: 3b5378917f67b0aade9891fc6c291646`, {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "OFB", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -286,7 +299,8 @@ Tag: 3b5378917f67b0aade9891fc6c291646`, {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CTR", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -304,7 +318,8 @@ Tag: 70fad2ca19412c20f40fd06918736e56`, {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -322,7 +337,8 @@ Tag: 61cc4b70809452b0b3e38f913fa0a109`, {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", - {"option": "UTF8", "string": "additional data"} + {"option": "UTF8", "string": "additional data"}, + "None" ] } ], @@ -338,7 +354,8 @@ Tag: 61cc4b70809452b0b3e38f913fa0a109`, {"option": "Hex", "string": "51e201d463698ef5f717f71f5b4712af"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "ECB", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -354,7 +371,8 @@ Tag: 61cc4b70809452b0b3e38f913fa0a109`, {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CBC", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -370,7 +388,8 @@ Tag: 61cc4b70809452b0b3e38f913fa0a109`, {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CFB", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -386,7 +405,8 @@ Tag: 61cc4b70809452b0b3e38f913fa0a109`, {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "OFB", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -402,7 +422,8 @@ Tag: 61cc4b70809452b0b3e38f913fa0a109`, {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CTR", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -420,7 +441,8 @@ Tag: 86db597d5302595223cadbd990f1309b`, {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -438,7 +460,8 @@ Tag: aeedf3e6ca4201577c0cf3e9ce58159d`, {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", - {"option": "UTF8", "string": "additional data"} + {"option": "UTF8", "string": "additional data"}, + "None" ] } ], @@ -454,7 +477,8 @@ Tag: aeedf3e6ca4201577c0cf3e9ce58159d`, {"option": "Hex", "string": "6801ed503c9d96ee5f9d78b07ab1b295dba3c2adf81c7816"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "ECB", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -470,7 +494,8 @@ Tag: aeedf3e6ca4201577c0cf3e9ce58159d`, {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CBC", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -486,7 +511,8 @@ Tag: aeedf3e6ca4201577c0cf3e9ce58159d`, {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CFB", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -502,7 +528,8 @@ Tag: aeedf3e6ca4201577c0cf3e9ce58159d`, {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "OFB", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -518,7 +545,8 @@ Tag: aeedf3e6ca4201577c0cf3e9ce58159d`, {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CTR", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -536,7 +564,8 @@ Tag: 821b1e5f32dad052e502775a523d957a`, {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -554,7 +583,8 @@ Tag: a8f04c4d93bbef82bef61a103371aef9`, {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", - {"option": "UTF8", "string": "additional data"} + {"option": "UTF8", "string": "additional data"}, + "None" ] } ], @@ -570,7 +600,8 @@ Tag: a8f04c4d93bbef82bef61a103371aef9`, {"option": "Hex", "string": "2d767f6e9333d1c77581946e160b2b7368c2cdd5e2b80f04ca09d64e02afbfe1"}, {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "ECB", "Hex", "Hex", - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -780,7 +811,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": ""}, "CBC", "Hex", "Raw", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -797,7 +829,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00000000000000000000000000000000"}, "CBC", "Hex", "Raw", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -814,7 +847,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00000000000000000000000000000000"}, "CTR", "Hex", "Raw", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -831,7 +865,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, "CBC", "Hex", "Raw", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -848,7 +883,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, "CFB", "Hex", "Raw", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -865,7 +901,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, "OFB", "Hex", "Raw", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -882,7 +919,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, "CTR", "Hex", "Raw", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -899,7 +937,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": ""}, "ECB", "Hex", "Raw", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -916,7 +955,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": ""}, "GCM", "Hex", "Raw", {"option": "Hex", "string": "16a3e732a605cc9ca29108f742ca0743"}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -933,7 +973,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "ffeeddccbbaa99887766554433221100"}, "GCM", "Hex", "Raw", {"option": "Hex", "string": "3b5378917f67b0aade9891fc6c291646"}, - {"option": "UTF8", "string": "additional data"} + {"option": "UTF8", "string": "additional data"}, + "None" ] } ], @@ -950,7 +991,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CBC", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -967,7 +1009,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CFB", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -984,7 +1027,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "OFB", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1001,7 +1045,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CTR", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1018,7 +1063,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", {"option": "Hex", "string": "70fad2ca19412c20f40fd06918736e56"}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1035,7 +1081,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", {"option": "Hex", "string": "61cc4b70809452b0b3e38f913fa0a109"}, - {"option": "UTF8", "string": "additional data"} + {"option": "UTF8", "string": "additional data"}, + "None" ] } ], @@ -1052,7 +1099,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "ECB", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1069,7 +1117,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CBC", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1086,7 +1135,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CFB", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1103,7 +1153,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "OFB", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1120,7 +1171,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CTR", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1137,7 +1189,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", {"option": "Hex", "string": "86db597d5302595223cadbd990f1309b"}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1154,7 +1207,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", {"option": "Hex", "string": "aeedf3e6ca4201577c0cf3e9ce58159d"}, - {"option": "UTF8", "string": "additional data"} + {"option": "UTF8", "string": "additional data"}, + "None" ] } ], @@ -1171,7 +1225,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "ECB", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1188,7 +1243,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CBC", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1205,7 +1261,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CFB", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1222,7 +1279,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "OFB", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1239,7 +1297,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "CTR", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1256,7 +1315,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", {"option": "Hex", "string": "821b1e5f32dad052e502775a523d957a"}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], @@ -1273,7 +1333,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "GCM", "Hex", "Hex", {"option": "Hex", "string": "a8f04c4d93bbef82bef61a103371aef9"}, - {"option": "UTF8", "string": "additional data"} + {"option": "UTF8", "string": "additional data"}, + "None" ] } ], @@ -1290,7 +1351,8 @@ The following algorithms will be used based on the size of the key: {"option": "Hex", "string": "1748e7179bd56570d51fa4ba287cc3e5"}, "ECB", "Hex", "Hex", {"option": "Hex", "string": ""}, - {"option": "Hex", "string": ""} + {"option": "Hex", "string": ""}, + "None" ] } ], diff --git a/tests/operations/tests/Register.mjs b/tests/operations/tests/Register.mjs index 3ef7ef94..306990c8 100644 --- a/tests/operations/tests/Register.mjs +++ b/tests/operations/tests/Register.mjs @@ -67,7 +67,8 @@ TestRegister.addTests([ { "option": "Hex", "string": "" - } + }, + "None" ] } ] From 80379e3df164735ac8bb7c15628899d36790e4bc Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Tue, 22 Mar 2022 23:03:05 +0000 Subject: [PATCH 04/10] Added 'Key Padding' to Blowfish --- src/core/operations/BlowfishDecrypt.mjs | 16 +++++-- src/core/operations/BlowfishEncrypt.mjs | 16 +++++-- tests/operations/tests/Crypt.mjs | 60 ++++++++++++++++--------- 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/src/core/operations/BlowfishDecrypt.mjs b/src/core/operations/BlowfishDecrypt.mjs index f7dc8d17..2f4f9d26 100644 --- a/src/core/operations/BlowfishDecrypt.mjs +++ b/src/core/operations/BlowfishDecrypt.mjs @@ -54,6 +54,11 @@ class BlowfishDecrypt extends Operation { "name": "Output", "type": "option", "value": ["Raw", "Hex"] + }, + { + "name": "Key Padding", + "type": "option", + "value": ["None", "Null", "Repeat"] } ]; } @@ -64,11 +69,16 @@ class BlowfishDecrypt extends Operation { * @returns {string} */ run(input, args) { - const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteString(args[1].string, args[1].option), + var key = Utils.convertToByteString(args[0].string, args[0].option); + const iv = Utils.convertToByteString(args[1].string, args[1].option), mode = args[2], inputType = args[3], - outputType = args[4]; + outputType = args[4], + keyPadding = args[5]; + + if (keyPadding !== "None" && key.length < 8) { + key = key.padEnd(8, keyPadding === "Null" ? "\0" : key); + } if (key.length !== 8) { throw new OperationError(`Invalid key length: ${key.length} bytes diff --git a/src/core/operations/BlowfishEncrypt.mjs b/src/core/operations/BlowfishEncrypt.mjs index 2cf3672b..c09205e1 100644 --- a/src/core/operations/BlowfishEncrypt.mjs +++ b/src/core/operations/BlowfishEncrypt.mjs @@ -54,6 +54,11 @@ class BlowfishEncrypt extends Operation { "name": "Output", "type": "option", "value": ["Hex", "Raw"] + }, + { + "name": "Key Padding", + "type": "option", + "value": ["None", "Null", "Repeat"] } ]; } @@ -64,11 +69,16 @@ class BlowfishEncrypt extends Operation { * @returns {string} */ run(input, args) { - const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteString(args[1].string, args[1].option), + var key = Utils.convertToByteString(args[0].string, args[0].option); + const iv = Utils.convertToByteString(args[1].string, args[1].option), mode = args[2], inputType = args[3], - outputType = args[4]; + outputType = args[4], + keyPadding = args[5]; + + if (keyPadding !== "None" && key.length < 8) { + key = key.padEnd(8, keyPadding === "Null" ? "\0" : key); + } if (key.length !== 8) { throw new OperationError(`Invalid key length: ${key.length} bytes diff --git a/tests/operations/tests/Crypt.mjs b/tests/operations/tests/Crypt.mjs index f70dc5a9..3cf7b27e 100644 --- a/tests/operations/tests/Crypt.mjs +++ b/tests/operations/tests/Crypt.mjs @@ -1670,7 +1670,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "0000000000000000"}, // IV "ECB", // Mode "Raw", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1687,7 +1688,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "0000000000000000"}, // IV "ECB", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1704,7 +1706,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "0000000000000000"}, // IV "ECB", // Mode "Hex", // Input - "Raw" // Output + "Raw", // Output + "None" // Key Padding ] } ], @@ -1721,7 +1724,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "0000000000000000"}, // IV "ECB", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1738,7 +1742,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "CBC", // Mode "Raw", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1755,7 +1760,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "CBC", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1772,7 +1778,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "CBC", // Mode "Hex", // Input - "Raw" // Output + "Raw", // Output + "None" // Key Padding ] } ], @@ -1789,7 +1796,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "CBC", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1808,7 +1816,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "CFB", // Mode "Raw", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1826,7 +1835,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "CFB", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1844,7 +1854,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "CFB", // Mode "Hex", // Input - "Raw" // Output + "Raw", // Output + "None" // Key Padding ] } ], @@ -1862,7 +1873,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "CFB", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1879,7 +1891,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "OFB", // Mode "Raw", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1896,7 +1909,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "OFB", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1913,7 +1927,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "OFB", // Mode "Hex", // Input - "Raw" // Output + "Raw", // Output + "None" // Key Padding ] } ], @@ -1930,7 +1945,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "ffeeddccbbaa9988"}, // IV "OFB", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1951,7 +1967,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "0000000000000000"}, // IV (nonce) "CTR", // Mode "Raw", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1969,7 +1986,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "0000000000000000"}, // IV (nonce) "CTR", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], @@ -1987,7 +2005,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "0000000000000000"}, // IV (nonce) "CTR", // Mode "Hex", // Input - "Raw" // Output + "Raw", // Output + "None" // Key Padding ] } ], @@ -2005,7 +2024,8 @@ DES uses a key length of 8 bytes (64 bits).`, {"option": "Hex", "string": "0000000000000000"}, // IV (nonce) "CTR", // Mode "Hex", // Input - "Hex" // Output + "Hex", // Output + "None" // Key Padding ] } ], From a811041fe2d98b1f5fa664b3968d0fee63619ee2 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Tue, 22 Mar 2022 23:03:30 +0000 Subject: [PATCH 05/10] Corrected equivalence in AES key padding --- src/core/operations/AESDecrypt.mjs | 1 - src/core/operations/AESEncrypt.mjs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/operations/AESDecrypt.mjs b/src/core/operations/AESDecrypt.mjs index 8e16515b..b3381b01 100644 --- a/src/core/operations/AESDecrypt.mjs +++ b/src/core/operations/AESDecrypt.mjs @@ -126,7 +126,6 @@ class AESDecrypt extends Operation { } } if (targetKeySize !== 0) { - const originalLength = key.length; key = key.padEnd(targetKeySize, keyPadding == "Null" ? "\0" : key); } } diff --git a/src/core/operations/AESEncrypt.mjs b/src/core/operations/AESEncrypt.mjs index 42fb7b84..219dd007 100644 --- a/src/core/operations/AESEncrypt.mjs +++ b/src/core/operations/AESEncrypt.mjs @@ -119,8 +119,7 @@ class AESEncrypt extends Operation { } } if (targetKeySize !== 0) { - const originalLength = key.length; - key = key.padEnd(targetKeySize, keyPadding == "Null" ? "\0" : key); + key = key.padEnd(targetKeySize, keyPadding === "Null" ? "\0" : key); } } From 99afd014f2561b0057f62447a12eee0f13ec8136 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Tue, 22 Mar 2022 23:15:03 +0000 Subject: [PATCH 06/10] Added 'Key Padding' to DES --- src/core/operations/DESDecrypt.mjs | 15 ++++++++++++--- src/core/operations/DESEncrypt.mjs | 15 ++++++++++++--- tests/operations/tests/Crypt.mjs | 24 ++++++++++++------------ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/core/operations/DESDecrypt.mjs b/src/core/operations/DESDecrypt.mjs index 14bbe832..95c01a3d 100644 --- a/src/core/operations/DESDecrypt.mjs +++ b/src/core/operations/DESDecrypt.mjs @@ -53,6 +53,11 @@ class DESDecrypt extends Operation { "name": "Output", "type": "option", "value": ["Raw", "Hex"] + }, + { + "name": "Key Padding", + "type": "option", + "value": ["None", "Null", "Repeat"] } ]; } @@ -63,9 +68,13 @@ class DESDecrypt extends Operation { * @returns {string} */ run(input, args) { - const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteArray(args[1].string, args[1].option), - [,, mode, inputType, outputType] = args; + const key = Utils.convertToByteString(args[0].string, args[0].option); + var iv = Utils.convertToByteArray(args[1].string, args[1].option), + [,, mode, inputType, outputType, keyPadding] = args; + + if (keyPadding !== "None" && key.length < 8) { + key = key.padEnd(8, keyPadding == "Null" ? "\0" : key); + } if (key.length !== 8) { throw new OperationError(`Invalid key length: ${key.length} bytes diff --git a/src/core/operations/DESEncrypt.mjs b/src/core/operations/DESEncrypt.mjs index 9472abe8..eb834e2b 100644 --- a/src/core/operations/DESEncrypt.mjs +++ b/src/core/operations/DESEncrypt.mjs @@ -53,6 +53,11 @@ class DESEncrypt extends Operation { "name": "Output", "type": "option", "value": ["Hex", "Raw"] + }, + { + "name": "Key Padding", + "type": "option", + "value": ["None", "Null", "Repeat"] } ]; } @@ -63,9 +68,13 @@ class DESEncrypt extends Operation { * @returns {string} */ run(input, args) { - const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteArray(args[1].string, args[1].option), - [,, mode, inputType, outputType] = args; + var key = Utils.convertToByteString(args[0].string, args[0].option); + const iv = Utils.convertToByteArray(args[1].string, args[1].option), + [,, mode, inputType, outputType, keyPadding] = args; + + if (keyPadding !== "None" && key.length < 8) { + key = key.padEnd(8, keyPadding == "Null" ? "\0" : key); + } if (key.length !== 8) { throw new OperationError(`Invalid key length: ${key.length} bytes diff --git a/tests/operations/tests/Crypt.mjs b/tests/operations/tests/Crypt.mjs index 3cf7b27e..6675fda6 100644 --- a/tests/operations/tests/Crypt.mjs +++ b/tests/operations/tests/Crypt.mjs @@ -619,7 +619,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, - "CBC", "Hex", "Hex" + "CBC", "Hex", "Hex", "None" ] } ], @@ -634,7 +634,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "CBC", "Hex", "Hex" + "CBC", "Hex", "Hex", "None" ] } ], @@ -649,7 +649,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "CFB", "Hex", "Hex" + "CFB", "Hex", "Hex", "None" ] } ], @@ -664,7 +664,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "OFB", "Hex", "Hex" + "OFB", "Hex", "Hex", "None" ] } ], @@ -680,7 +680,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "CTR", "Hex", "Hex" + "CTR", "Hex", "Hex", "None" ] } ], @@ -695,7 +695,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "ECB", "Hex", "Hex" + "ECB", "Hex", "Hex", "None" ] } ], @@ -1370,7 +1370,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, - "CBC", "Hex", "Hex" + "CBC", "Hex", "Hex", "None" ] } ], @@ -1385,7 +1385,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "CBC", "Hex", "Hex" + "CBC", "Hex", "Hex", "None" ] } ], @@ -1400,7 +1400,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "CFB", "Hex", "Hex" + "CFB", "Hex", "Hex", "None" ] } ], @@ -1415,7 +1415,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "OFB", "Hex", "Hex" + "OFB", "Hex", "Hex", "None" ] } ], @@ -1431,7 +1431,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "CTR", "Hex", "Hex" + "CTR", "Hex", "Hex", "None" ] } ], @@ -1446,7 +1446,7 @@ Triple DES uses a key length of 24 bytes (192 bits).`, "args": [ {"option": "Hex", "string": "58345efb0a64e87e"}, {"option": "Hex", "string": "533ed1378bfd929e"}, - "ECB", "Hex", "Hex" + "ECB", "Hex", "Hex", "None" ] } ], From 0fce9ccced0041cfd5e59817f854e9ae46153c6c Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Wed, 23 Mar 2022 14:54:07 +0000 Subject: [PATCH 07/10] Added DES test cases --- src/core/operations/DESDecrypt.mjs | 2 +- tests/operations/tests/Crypt.mjs | 131 ++++++++++++++++++++++++++++- 2 files changed, 131 insertions(+), 2 deletions(-) diff --git a/src/core/operations/DESDecrypt.mjs b/src/core/operations/DESDecrypt.mjs index 95c01a3d..853b4c82 100644 --- a/src/core/operations/DESDecrypt.mjs +++ b/src/core/operations/DESDecrypt.mjs @@ -68,7 +68,7 @@ class DESDecrypt extends Operation { * @returns {string} */ run(input, args) { - const key = Utils.convertToByteString(args[0].string, args[0].option); + var key = Utils.convertToByteString(args[0].string, args[0].option); var iv = Utils.convertToByteArray(args[1].string, args[1].option), [,, mode, inputType, outputType, keyPadding] = args; diff --git a/tests/operations/tests/Crypt.mjs b/tests/operations/tests/Crypt.mjs index 6675fda6..d865579c 100644 --- a/tests/operations/tests/Crypt.mjs +++ b/tests/operations/tests/Crypt.mjs @@ -80,6 +80,40 @@ The following algorithms will be used based on the size of the key: } ], }, + { + name: "AES Encrypt: Null key padding", + input: "The quick brown fox jumps over the lazy dog.", + expectedOutput: "96a46d1f3796b5fffd6117f0a51bf88504b7b6e3ea036e30fee34bf7450d6547c9729ab67afb6cd5596c63b557ce9c23", + recipeConfig: [ + { + "op": "AES Encrypt", + "args": [ + {"option": "Hex", "string": "01020304"}, + {"option": "Hex", "string": "00000000000000000000000000000000"}, + "CBC", "Raw", "Hex", + {"option": "Hex", "string": ""}, + "Null" + ] + } + ], + }, + { + name: "AES Encrypt: Repeat key padding", + input: "The quick brown fox jumps over the lazy dog.", + expectedOutput: "f12f09d6a74ac64e1600af169e25fe9a17b419741ef4bcee253d8faccb24e9ffcb592bfdad855d80c5fa6f1a1ba055a7", + recipeConfig: [ + { + "op": "AES Encrypt", + "args": [ + {"option": "Hex", "string": "01020304"}, + {"option": "Hex", "string": "00000000000000000000000000000000"}, + "CBC", "Raw", "Hex", + {"option": "Hex", "string": ""}, + "Repeat" + ] + } + ], + }, { name: "AES Encrypt: AES-128-CBC with IV0, ASCII", input: "The quick brown fox jumps over the lazy dog.", @@ -624,6 +658,36 @@ Triple DES uses a key length of 24 bytes (192 bits).`, } ], }, + { + name: "DES Encrypt: Null key padding", + input: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", + expectedOutput: "6726f7460726374d6e3b7efe7034313b2a6fb6cb0dd504dd5a03a97e9aa514d7d4caf105f260d652bd75639faa827b9565896952b6dd965a8fc731dd41d5491cdd35723edb0a2c965174266e9dca415bdb60d4804c226c320746e48b455e761e827ec8caf2d47c3f", + recipeConfig: [ + { + "op": "DES Encrypt", + "args": [ + {"option": "Hex", "string": "58345efb"}, + {"option": "Hex", "string": "533ed1378bfd929e"}, + "CBC", "Hex", "Hex", "Null" + ] + } + ], + }, + { + name: "DES Encrypt: Repeat key padding", + input: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", + expectedOutput: "bb8098d737005184a6ecb05a0c0cdd1e17191bb83f1da02e578d28aacb2fd013082180dd67960dd70e35957e8bc16e3e3704ab384cb22cdd0bcdde383ef329564a56a0babca7bce290ff7c587d66bdd37ed56dcbbd8d8f3de1d259f983e4dc6b6e82a83ea07cd73e", + recipeConfig: [ + { + "op": "DES Encrypt", + "args": [ + {"option": "Hex", "string": "58345efb"}, + {"option": "Hex", "string": "533ed1378bfd929e"}, + "CBC", "Hex", "Hex", "Repeat" + ] + } + ], + }, { name: "DES Encrypt: DES-CBC, Binary", input: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", @@ -835,6 +899,42 @@ The following algorithms will be used based on the size of the key: } ], }, + { + name: "AES Decrypt: Null key padding", + input: "96a46d1f3796b5fffd6117f0a51bf88504b7b6e3ea036e30fee34bf7450d6547c9729ab67afb6cd5596c63b557ce9c23", + expectedOutput: "The quick brown fox jumps over the lazy dog.", + recipeConfig: [ + { + "op": "AES Decrypt", + "args": [ + {"option": "Hex", "string": "01020304"}, + {"option": "Hex", "string": "00000000000000000000000000000000"}, + "CBC", "Hex", "Raw", + {"option": "Hex", "string": ""}, + {"option": "Hex", "string": ""}, + "Null" + ] + } + ], + }, + { + name: "AES Decrypt: Repeat key padding", + input: "f12f09d6a74ac64e1600af169e25fe9a17b419741ef4bcee253d8faccb24e9ffcb592bfdad855d80c5fa6f1a1ba055a7", + expectedOutput: "The quick brown fox jumps over the lazy dog.", + recipeConfig: [ + { + "op": "AES Decrypt", + "args": [ + {"option": "Hex", "string": "01020304"}, + {"option": "Hex", "string": "00000000000000000000000000000000"}, + "CBC", "Hex", "Raw", + {"option": "Hex", "string": ""}, + {"option": "Hex", "string": ""}, + "Repeat" + ] + } + ], + }, { name: "AES Decrypt: AES-128-CTR with IV0, ASCII", input: "a98c9e8e3b7c894384d740e4f0f4ed0be2bbb1e0e13a255812c3c6b0a629e4ad759c075b2469c6f4fb2c0cf9", @@ -1375,6 +1475,36 @@ Triple DES uses a key length of 24 bytes (192 bits).`, } ], }, + { + name: "DES Decrypt: Repeat key padding", + input: "97e5507b01e9847f20e2d6f28e743f698f4cf26cf159b8acd637c27628dd6b7e7fc9f5371dd31b1729d0d1346f1c50a625e99ed4c09824f2f99e73d93566e78322b0dd93f5d8b1c939f2a5039c6cc8aec3e4c2b1ebdfd01451f224787e92593750efa4e47e3cba35", + expectedOutput: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", + recipeConfig: [ + { + "op": "DES Decrypt", + "args": [ + {"option": "Hex", "string": "01000100"}, + {"option": "Hex", "string": "533ed1378bfd929e"}, + "CBC", "Hex", "Hex", "Repeat" + ] + } + ], + }, + { + name: "DES Decrypt: Null key padding", + input: "97e5507b01e9847f20e2d6f28e743f698f4cf26cf159b8acd637c27628dd6b7e7fc9f5371dd31b1729d0d1346f1c50a625e99ed4c09824f2f99e73d93566e78322b0dd93f5d8b1c939f2a5039c6cc8aec3e4c2b1ebdfd01451f224787e92593750efa4e47e3cba35", + expectedOutput: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", + recipeConfig: [ + { + "op": "DES Decrypt", + "args": [ + {"option": "Hex", "string": "01000100"}, + {"option": "Hex", "string": "533ed1378bfd929e"}, + "CBC", "Hex", "Hex", "Null" + ] + } + ], + }, { name: "DES Decrypt: DES-CBC, Binary", input: "6500defb824b0eb8ccbf1fa9689c6f5bcc65247d93ecb0e573232824bca82dd41e2361f8fd82ef187de9f3b74f7ba3ca2b4e735f3ca6304fb8dd1675933c576424b1ea72b3219bdab62fce56d49c820d5ac02a4702a6d688e90b0933de97da21e4829e5cf85caae8", @@ -1421,7 +1551,6 @@ Triple DES uses a key length of 24 bytes (192 bits).`, ], }, { - // play.golang.org/p/FpvqncmPk7R name: "DES Decrypt: DES-CTR, Binary", input: "09015087e15b0937ab0ae5a84d66e520893690a6ea066382bf1330e8876cb3aa82ccc634f8f0d458bbe0257df6f4637cdac89f311168ba91208a21ba4bdd13c4b1a92cb93b33364b5b94a5d3d7fba68f6eed5807d9f5afeb7fbffcd94792131d264004ae", expectedOutput: "7a0e643132750e96b76dc9efa7810bea2b8feaa5b97887e44f96c0e6d506cc4dd4665683c6f63139221f8d887fd0a05b39741f8a67d87d6ac6f8dc6b668bd3e4a97b8bd3a19eafd5cdf50c3e1b3f17d61087d0b67cf6db31fec338b75f5954942c852829", From 61a19e45ccd41b4daf2afa8ace2f73167d87fb3b Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Wed, 23 Mar 2022 14:54:24 +0000 Subject: [PATCH 08/10] Revert "Added more error-handling to ToUpperCase()" This reverts commit ed542582f96541dd90fde52e4f0f07a9b6427ca6. --- src/core/operations/ToUpperCase.mjs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/core/operations/ToUpperCase.mjs b/src/core/operations/ToUpperCase.mjs index 08ffce87..eb0e315a 100644 --- a/src/core/operations/ToUpperCase.mjs +++ b/src/core/operations/ToUpperCase.mjs @@ -37,9 +37,6 @@ class ToUpperCase extends Operation { * @returns {string} */ run(input, args) { - if (!args || args.length === 0) { - throw new OperationException("No capitalization scope was provided."); - } const scope = args[0]; if (scope === "All") { return input.toUpperCase(); From 82da498c2408f7ab19f8751669bf58ad1abd4d39 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Wed, 23 Mar 2022 14:54:36 +0000 Subject: [PATCH 09/10] Revert "Minor adjustments" This reverts commit 2574a63975ecced6e066ae673a986ad87394b7db. --- src/core/lib/Binary.mjs | 26 ++++++++++------------ src/core/operations/ToUpperCase.mjs | 34 ++++++++++++++--------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/core/lib/Binary.mjs b/src/core/lib/Binary.mjs index 56db4c2a..dc63fc58 100644 --- a/src/core/lib/Binary.mjs +++ b/src/core/lib/Binary.mjs @@ -19,29 +19,27 @@ import OperationError from "../errors/OperationError.mjs"; * @returns {string} * * @example - * // returns "00001010 00010100 00011110" + * // returns "00010000 00100000 00110000" * toBinary([10,20,30]); * - * // returns "00001010:00010100:00011110" - * toBinary([10,20,30], "Colon"); - * - * // returns "1010:10100:11110" - * toBinary([10,20,30], "Colon", 0); + * // returns "00010000 00100000 00110000" + * toBinary([10,20,30], ":"); */ export function toBinary(data, delim="Space", padding=8) { - if (!data) throw new OperationError("Empty input data enocuntered"); + if (!data) return ""; delim = Utils.charRep(delim); let output = ""; + for (let i = 0; i < data.length; i++) { - output += data[i].toString(2).padStart(padding, "0"); - if (i !== data.length - 1) output += delim; + output += data[i].toString(2).padStart(padding, "0") + delim; } + if (delim.length) { - // Remove the delimiter from the end of the string. - output = output.slice(0, -delim.length); + return output.slice(0, -delim.length); + } else { + return output; } - return output; } @@ -55,10 +53,10 @@ export function toBinary(data, delim="Space", padding=8) { * * @example * // returns [10,20,30] - * fromBinary("00001010 00010100 00011110"); + * fromBinary("00010000 00100000 00110000"); * * // returns [10,20,30] - * fromBinary("00001010:00010100:00011110", "Colon"); + * fromBinary("00010000:00100000:00110000", "Colon"); */ export function fromBinary(data, delim="Space", byteLen=8) { if (byteLen < 1 || Math.round(byteLen) !== byteLen) diff --git a/src/core/operations/ToUpperCase.mjs b/src/core/operations/ToUpperCase.mjs index eb0e315a..0bc9b5a9 100644 --- a/src/core/operations/ToUpperCase.mjs +++ b/src/core/operations/ToUpperCase.mjs @@ -38,23 +38,23 @@ class ToUpperCase extends Operation { */ run(input, args) { const scope = args[0]; - if (scope === "All") { - return input.toUpperCase(); - } - const scopeRegex = { - "Word": /(\b\w)/gi, - "Sentence": /(?:\.|^)\s*(\b\w)/gi, - "Paragraph": /(?:\n|^)\s*(\b\w)/gi - }[ scope ]; - if (scopeRegex !== undefined) { - // Use the regexes to capitalize the input. - return input.replace(scopeRegex, function(m) { - return m.toUpperCase(); - }); - } - else { - // The selected scope was invalid. - throw new OperationError("Unrecognized capitalization scope"); + + switch (scope) { + case "Word": + return input.replace(/(\b\w)/gi, function(m) { + return m.toUpperCase(); + }); + case "Sentence": + return input.replace(/(?:\.|^)\s*(\b\w)/gi, function(m) { + return m.toUpperCase(); + }); + case "Paragraph": + return input.replace(/(?:\n|^)\s*(\b\w)/gi, function(m) { + return m.toUpperCase(); + }); + case "All": /* falls through */ + default: + return input.toUpperCase(); } } From 8d7b4a6b7d513510bdec5e191e53ec96333d5512 Mon Sep 17 00:00:00 2001 From: Michael Rowley Date: Wed, 23 Mar 2022 15:43:38 +0000 Subject: [PATCH 10/10] Added 'Key Padding' to Triple DES --- src/core/operations/TripleDESDecrypt.mjs | 16 ++++- src/core/operations/TripleDESEncrypt.mjs | 16 ++++- tests/operations/tests/Crypt.mjs | 84 ++++++++++++++++++++---- 3 files changed, 98 insertions(+), 18 deletions(-) diff --git a/src/core/operations/TripleDESDecrypt.mjs b/src/core/operations/TripleDESDecrypt.mjs index c90bf926..c9d4040b 100644 --- a/src/core/operations/TripleDESDecrypt.mjs +++ b/src/core/operations/TripleDESDecrypt.mjs @@ -53,6 +53,11 @@ class TripleDESDecrypt extends Operation { "name": "Output", "type": "option", "value": ["Raw", "Hex"] + }, + { + "name": "Key Padding", + "type": "option", + "value": ["None", "Null", "Repeat"] } ]; } @@ -63,11 +68,16 @@ class TripleDESDecrypt extends Operation { * @returns {string} */ run(input, args) { - const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteArray(args[1].string, args[1].option), + var key = Utils.convertToByteString(args[0].string, args[0].option); + const iv = Utils.convertToByteArray(args[1].string, args[1].option), mode = args[2], inputType = args[3], - outputType = args[4]; + outputType = args[4], + keyPadding = args[5]; + + if (keyPadding !== "None" && key.length < 24) { + key = key.padEnd(24, keyPadding === "Null" ? "\0" : key); + } if (key.length !== 24) { throw new OperationError(`Invalid key length: ${key.length} bytes diff --git a/src/core/operations/TripleDESEncrypt.mjs b/src/core/operations/TripleDESEncrypt.mjs index 237020a2..a1bf8ad5 100644 --- a/src/core/operations/TripleDESEncrypt.mjs +++ b/src/core/operations/TripleDESEncrypt.mjs @@ -53,6 +53,11 @@ class TripleDESEncrypt extends Operation { "name": "Output", "type": "option", "value": ["Hex", "Raw"] + }, + { + "name": "Key Padding", + "type": "option", + "value": ["None", "Null", "Repeat"] } ]; } @@ -63,11 +68,16 @@ class TripleDESEncrypt extends Operation { * @returns {string} */ run(input, args) { - const key = Utils.convertToByteString(args[0].string, args[0].option), - iv = Utils.convertToByteArray(args[1].string, args[1].option), + var key = Utils.convertToByteString(args[0].string, args[0].option); + const iv = Utils.convertToByteArray(args[1].string, args[1].option), mode = args[2], inputType = args[3], - outputType = args[4]; + outputType = args[4], + keyPadding = args[5]; + + if (keyPadding !== "None" && key.length < 24) { + key = key.padEnd(24, keyPadding === "Null" ? "\0" : key); + } if (key.length !== 24) { throw new OperationError(`Invalid key length: ${key.length} bytes diff --git a/tests/operations/tests/Crypt.mjs b/tests/operations/tests/Crypt.mjs index d865579c..3d7f616c 100644 --- a/tests/operations/tests/Crypt.mjs +++ b/tests/operations/tests/Crypt.mjs @@ -777,7 +777,37 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, - "CBC", "Hex", "Hex" + "CBC", "Hex", "Hex", "None" + ] + } + ], + }, + { + name: "Triple DES Encrypt: Null key padding", + input: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", + expectedOutput: "d81502f7af1f75823729f319fcc658f27cd180b8e3e471f81518dea8a6a91c2a030edea1d0e3e6b439c3ce64970dcc945f1293fd0fa2acda421fed39b5385a5a2ede1ed97351cb05ba16cf6697114a30985d5a0a785fa5883baaae9fc5a296486228bd01064d061c6083a1d3ca68640dbc13c65b8a9812b28b0592c27a197e74f31dd0f9169aaecfc43232f531c25462ee6059ced7994cd24bdf35bd4880c24b103fa68427e22a5449a34e62b51c01d2f64f60014075b526bc3f055aa02a7e6a2330bd4fed558559fdb0488bbc5bfb34", + recipeConfig: [ + { + "op": "Triple DES Encrypt", + "args": [ + {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, + {"option": "Hex", "string": "14f67ac044a84da6"}, + "CBC", "Hex", "Hex", "Null" + ] + } + ], + }, + { + name: "Triple DES Encrypt: Repeat key padding", + input: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", + expectedOutput: "72949667dbf3ebb6ea6ad62644fb4c2de74aaa2de2e159b3822c594f6ee52df5f79ddfa51f4d641874acf91d396ab06cbb07c7ce926a2420e4e9a29ab4dff5216628a5590c15bbe51d4c0ba46ebf7b588bc087cf05bad4476a4e8fa43c8feb2e473505fad2cb4b927a9fae2ad2a6dd12e5424c8727cb199e64e93312cc4ee39425b0ce919145549810c2ea87aa9a2a76d4221d774f1756e52e5a7aa97a7657f51396a5a30fcbbb532ae7b7554a3aa5dedabf625c8c049f53d3e059c14ed256644a207c5070d8a4ffd71ef610689f90cb", + recipeConfig: [ + { + "op": "Triple DES Encrypt", + "args": [ + {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, + {"option": "Hex", "string": "14f67ac044a84da6"}, + "CBC", "Hex", "Hex", "Repeat" ] } ], @@ -792,7 +822,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "CBC", "Hex", "Hex" + "CBC", "Hex", "Hex", "None" ] } ], @@ -807,7 +837,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "CFB", "Hex", "Hex" + "CFB", "Hex", "Hex", "None" ] } ], @@ -822,7 +852,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "OFB", "Hex", "Hex" + "OFB", "Hex", "Hex", "None" ] } ], @@ -838,7 +868,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "CTR", "Hex", "Hex" + "CTR", "Hex", "Hex", "None" ] } ], @@ -853,7 +883,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "ECB", "Hex", "Hex" + "ECB", "Hex", "Hex", "None" ] } ], @@ -1593,7 +1623,37 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": ""}, {"option": "Hex", "string": ""}, - "CBC", "Hex", "Hex" + "CBC", "Hex", "Hex", "None" + ] + } + ], + }, + { + name: "Triple DES Decrypt: Null key padding", + input: "d81502f7af1f75823729f319fcc658f27cd180b8e3e471f81518dea8a6a91c2a030edea1d0e3e6b439c3ce64970dcc945f1293fd0fa2acda421fed39b5385a5a2ede1ed97351cb05ba16cf6697114a30985d5a0a785fa5883baaae9fc5a296486228bd01064d061c6083a1d3ca68640dbc13c65b8a9812b28b0592c27a197e74f31dd0f9169aaecfc43232f531c25462ee6059ced7994cd24bdf35bd4880c24b103fa68427e22a5449a34e62b51c01d2f64f60014075b526bc3f055aa02a7e6a2330bd4fed558559fdb0488bbc5bfb34", + expectedOutput: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", + recipeConfig: [ + { + "op": "Triple DES Decrypt", + "args": [ + {"option": "Hex", "string": "190da55fb54b9e7dd6de05f4"}, + {"option": "Hex", "string": "14f67ac044a84da6"}, + "CBC", "Hex", "Hex", "Null" + ] + } + ], + }, + { + name: "Triple DES Decrypt: Repeat key padding", + input: "72949667dbf3ebb6ea6ad62644fb4c2de74aaa2de2e159b3822c594f6ee52df5f79ddfa51f4d641874acf91d396ab06cbb07c7ce926a2420e4e9a29ab4dff5216628a5590c15bbe51d4c0ba46ebf7b588bc087cf05bad4476a4e8fa43c8feb2e473505fad2cb4b927a9fae2ad2a6dd12e5424c8727cb199e64e93312cc4ee39425b0ce919145549810c2ea87aa9a2a76d4221d774f1756e52e5a7aa97a7657f51396a5a30fcbbb532ae7b7554a3aa5dedabf625c8c049f53d3e059c14ed256644a207c5070d8a4ffd71ef610689f90cb", + expectedOutput: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018", + recipeConfig: [ + { + "op": "Triple DES Decrypt", + "args": [ + {"option": "Hex", "string": "190da55fb54b9e7dd6de05f4"}, + {"option": "Hex", "string": "14f67ac044a84da6"}, + "CBC", "Hex", "Hex", "Repeat" ] } ], @@ -1608,7 +1668,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "CBC", "Hex", "Hex" + "CBC", "Hex", "Hex", "None" ] } ], @@ -1623,7 +1683,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "CFB", "Hex", "Hex" + "CFB", "Hex", "Hex", "None" ] } ], @@ -1638,7 +1698,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "OFB", "Hex", "Hex" + "OFB", "Hex", "Hex", "None" ] } ], @@ -1654,7 +1714,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "CTR", "Hex", "Hex" + "CTR", "Hex", "Hex", "None" ] } ], @@ -1669,7 +1729,7 @@ DES uses a key length of 8 bytes (64 bits).`, "args": [ {"option": "Hex", "string": "190da55fb54b9e7dd6de05f43bf3347ef203cd34a5829b23"}, {"option": "Hex", "string": "14f67ac044a84da6"}, - "ECB", "Hex", "Hex" + "ECB", "Hex", "Hex", "None" ] } ],