diff --git a/src/core/operations/AESDecrypt.mjs b/src/core/operations/AESDecrypt.mjs index 5501ca32..e69a3348 100644 --- a/src/core/operations/AESDecrypt.mjs +++ b/src/core/operations/AESDecrypt.mjs @@ -41,8 +41,33 @@ class AESDecrypt extends Operation { }, { "name": "Mode", - "type": "option", - "value": ["CBC", "CFB", "OFB", "CTR", "GCM", "ECB"] + "type": "argSelector", + "value": [ + { + name: "CBC", + off: [5, 6] + }, + { + name: "CFB", + off: [5, 6] + }, + { + name: "OFB", + off: [5, 6] + }, + { + name: "CTR", + off: [5, 6] + }, + { + name: "GCM", + on: [5, 6] + }, + { + name: "ECB", + off: [5, 6] + } + ] }, { "name": "Input", @@ -59,6 +84,11 @@ class AESDecrypt extends Operation { "type": "toggleString", "value": "", "toggleValues": ["Hex", "UTF8", "Latin1", "Base64"] + }, + { + "name": "Additional Authenticated Data", + "type": "binaryString", + "value": "" } ]; } @@ -76,7 +106,8 @@ class AESDecrypt extends Operation { mode = args[2], inputType = args[3], outputType = args[4], - gcmTag = Utils.convertToByteString(args[5].string, args[5].option); + gcmTag = Utils.convertToByteString(args[5].string, args[5].option), + aad = args[6]; if ([16, 24, 32].indexOf(key.length) < 0) { throw new OperationError(`Invalid key length: ${key.length} bytes @@ -92,7 +123,8 @@ The following algorithms will be used based on the size of the key: const decipher = forge.cipher.createDecipher("AES-" + mode, key); decipher.start({ iv: iv.length === 0 ? "" : iv, - tag: gcmTag + tag: mode === "GCM" ? gcmTag : undefined, + additionalData: mode === "GCM" ? aad : undefined }); decipher.update(forge.util.createBuffer(input)); const result = decipher.finish(); diff --git a/src/core/operations/AESEncrypt.mjs b/src/core/operations/AESEncrypt.mjs index ebe4f584..20405694 100644 --- a/src/core/operations/AESEncrypt.mjs +++ b/src/core/operations/AESEncrypt.mjs @@ -56,7 +56,7 @@ class AESEncrypt extends Operation { off: [5] }, { - name:"CTR", + name: "CTR", off: [5] }, { @@ -81,7 +81,7 @@ class AESEncrypt extends Operation { }, { "name": "Additional Authenticated Data", - "type": "string", + "type": "binaryString", "value": "" } ]; @@ -99,7 +99,8 @@ class AESEncrypt extends Operation { iv = Utils.convertToByteString(args[1].string, args[1].option), mode = args[2], inputType = args[3], - outputType = args[4]; + outputType = args[4], + aad = args[5]; if ([16, 24, 32].indexOf(key.length) < 0) { throw new OperationError(`Invalid key length: ${key.length} bytes @@ -113,12 +114,10 @@ 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); - - if (args[5]) - cipher.start({iv: iv, additionalData: args[5]}); - else - cipher.start({iv: iv}); - + cipher.start({ + iv: iv, + additionalData: mode === "GCM" ? aad : undefined + }); cipher.update(forge.util.createBuffer(input)); cipher.finish(); diff --git a/tests/operations/tests/Bombe.mjs b/tests/operations/tests/Bombe.mjs index 2d391211..70df5bea 100644 --- a/tests/operations/tests/Bombe.mjs +++ b/tests/operations/tests/Bombe.mjs @@ -104,26 +104,26 @@ TestRegister.addTests([ } ] }, - // This test is a bit slow - it takes about 12s on my test hardware - { - name: "Bombe: 4 rotor", - input: "LUOXGJSHGEDSRDOQQX", - expectedMatch: /LHSC<\/td> {2}SS<\/td> {2}HHHSSSGQUUQPKSEKWK<\/td>/, - recipeConfig: [ - { - "op": "Bombe", - "args": [ - "4-rotor", - "LEYJVCNIXWPBQMDRTAKZGFUHOS", // Beta - "EKMFLGDQVZNTOWYHXUSPAIBRCJLHSC<\/td> {2}SS<\/td> {2}HHHSSSGQUUQPKSEKWK<\/td>/, + // recipeConfig: [ + // { + // "op": "Bombe", + // "args": [ + // "4-rotor", + // "LEYJVCNIXWPBQMDRTAKZGFUHOS", // Beta + // "EKMFLGDQVZNTOWYHXUSPAIBRCJ