mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 08:58:30 +01:00
Removed CryptoJS encodings from Blowfish operations.
This commit is contained in:
parent
9fc7e6cd98
commit
68e52d1645
2 changed files with 114 additions and 59 deletions
|
@ -1126,12 +1126,12 @@ const OperationConfig = {
|
||||||
{
|
{
|
||||||
name: "Input",
|
name: "Input",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT3
|
value: Cipher.IO_FORMAT4
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Output",
|
name: "Output",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT2
|
value: Cipher.IO_FORMAT3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "GCM Tag",
|
name: "GCM Tag",
|
||||||
|
@ -1167,12 +1167,12 @@ const OperationConfig = {
|
||||||
{
|
{
|
||||||
name: "Input",
|
name: "Input",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT2
|
value: Cipher.IO_FORMAT3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Output",
|
name: "Output",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT3
|
value: Cipher.IO_FORMAT4
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1202,12 +1202,12 @@ const OperationConfig = {
|
||||||
{
|
{
|
||||||
name: "Input",
|
name: "Input",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT3
|
value: Cipher.IO_FORMAT4
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Output",
|
name: "Output",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT2
|
value: Cipher.IO_FORMAT3
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1237,12 +1237,12 @@ const OperationConfig = {
|
||||||
{
|
{
|
||||||
name: "Input",
|
name: "Input",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT2
|
value: Cipher.IO_FORMAT3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Output",
|
name: "Output",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT3
|
value: Cipher.IO_FORMAT4
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1272,12 +1272,12 @@ const OperationConfig = {
|
||||||
{
|
{
|
||||||
name: "Input",
|
name: "Input",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT3
|
value: Cipher.IO_FORMAT4
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Output",
|
name: "Output",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT2
|
value: Cipher.IO_FORMAT3
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1307,7 +1307,42 @@ const OperationConfig = {
|
||||||
{
|
{
|
||||||
name: "Input",
|
name: "Input",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT2
|
value: Cipher.IO_FORMAT3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Output",
|
||||||
|
type: "option",
|
||||||
|
value: Cipher.IO_FORMAT4
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Blowfish Decrypt": {
|
||||||
|
module: "Ciphers",
|
||||||
|
description: "Blowfish is a symmetric-key block cipher designed in 1993 by Bruce Schneier and included in a large number of cipher suites and encryption products. AES now receives more attention.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.",
|
||||||
|
inputType: "string",
|
||||||
|
outputType: "string",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
name: "Key",
|
||||||
|
type: "toggleString",
|
||||||
|
value: "",
|
||||||
|
toggleValues: Cipher.IO_FORMAT1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "IV",
|
||||||
|
type: "toggleString",
|
||||||
|
value: "",
|
||||||
|
toggleValues: Cipher.IO_FORMAT1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Mode",
|
||||||
|
type: "option",
|
||||||
|
value: Cipher.BLOWFISH_MODES
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Input",
|
||||||
|
type: "option",
|
||||||
|
value: Cipher.BLOWFISH_OUTPUT_TYPES
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Output",
|
name: "Output",
|
||||||
|
@ -1316,33 +1351,9 @@ const OperationConfig = {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"Blowfish Decrypt": {
|
|
||||||
module: "Ciphers",
|
|
||||||
description: "Blowfish is a symmetric-key block cipher designed in 1993 by Bruce Schneier and included in a large number of cipher suites and encryption products. AES now receives more attention.",
|
|
||||||
inputType: "string",
|
|
||||||
outputType: "string",
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
name: "Key",
|
|
||||||
type: "toggleString",
|
|
||||||
value: "",
|
|
||||||
toggleValues: Cipher.CJS_IO_FORMAT
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Mode",
|
|
||||||
type: "option",
|
|
||||||
value: Cipher.BLOWFISH_MODES
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Input format",
|
|
||||||
type: "option",
|
|
||||||
value: Cipher.IO_FORMAT1
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"Blowfish Encrypt": {
|
"Blowfish Encrypt": {
|
||||||
module: "Ciphers",
|
module: "Ciphers",
|
||||||
description: "Blowfish is a symmetric-key block cipher designed in 1993 by Bruce Schneier and included in a large number of cipher suites and encryption products. AES now receives more attention.",
|
description: "Blowfish is a symmetric-key block cipher designed in 1993 by Bruce Schneier and included in a large number of cipher suites and encryption products. AES now receives more attention.<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.",
|
||||||
inputType: "string",
|
inputType: "string",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
args: [
|
args: [
|
||||||
|
@ -1350,7 +1361,13 @@ const OperationConfig = {
|
||||||
name: "Key",
|
name: "Key",
|
||||||
type: "toggleString",
|
type: "toggleString",
|
||||||
value: "",
|
value: "",
|
||||||
toggleValues: Cipher.CJS_IO_FORMAT
|
toggleValues: Cipher.IO_FORMAT1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "IV",
|
||||||
|
type: "toggleString",
|
||||||
|
value: "",
|
||||||
|
toggleValues: Cipher.IO_FORMAT1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Mode",
|
name: "Mode",
|
||||||
|
@ -1358,9 +1375,14 @@ const OperationConfig = {
|
||||||
value: Cipher.BLOWFISH_MODES
|
value: Cipher.BLOWFISH_MODES
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Output format",
|
name: "Input",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Cipher.IO_FORMAT1
|
value: Cipher.IO_FORMAT3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Output",
|
||||||
|
type: "option",
|
||||||
|
value: Cipher.BLOWFISH_OUTPUT_TYPES
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,12 +24,17 @@ const Cipher = {
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT2: ["Raw", "Hex"],
|
IO_FORMAT2: ["UTF8", "Latin1", "Hex", "Base64"],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT3: ["Hex", "Raw"],
|
IO_FORMAT3: ["Raw", "Hex"],
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
IO_FORMAT4: ["Hex", "Raw"],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
|
@ -270,12 +275,29 @@ DES uses a key length of 8 bytes (64 bits).`;
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BLOWFISH_MODES: ["ECB", "CBC", "PCBC", "CFB", "OFB", "CTR"],
|
BLOWFISH_MODES: ["CBC", "PCBC", "CFB", "OFB", "CTR", "ECB"],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BLOWFISH_OUTPUT_TYPES: ["Base64", "Hex", "String", "Raw"],
|
BLOWFISH_OUTPUT_TYPES: ["Hex", "Base64", "Raw"],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup table for Blowfish output types.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_BLOWFISH_OUTPUT_TYPE_LOOKUP: {
|
||||||
|
Base64: 0, Hex: 1, String: 2, Raw: 3
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Lookup table for Blowfish modes.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_BLOWFISH_MODE_LOOKUP: {
|
||||||
|
ECB: 0, CBC: 1, PCBC: 2, CFB: 3, OFB: 4, CTR: 5
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blowfish Encrypt operation.
|
* Blowfish Encrypt operation.
|
||||||
|
@ -285,19 +307,24 @@ DES uses a key length of 8 bytes (64 bits).`;
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runBlowfishEnc: function (input, args) {
|
runBlowfishEnc: function (input, args) {
|
||||||
let key = Cipher._format[args[0].option].parse(args[0].string).toString(Cipher._format.Latin1),
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
mode = args[1],
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
outputFormat = args[2];
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4];
|
||||||
|
|
||||||
if (key.length === 0) return "Enter a key";
|
if (key.length === 0) return "Enter a key";
|
||||||
|
|
||||||
let encHex = Blowfish.encrypt(input, key, {
|
input = Utils.convertToByteString(input, inputType);
|
||||||
outputType: 1,
|
|
||||||
cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode)
|
|
||||||
}),
|
|
||||||
enc = CryptoJS.enc.Hex.parse(encHex);
|
|
||||||
|
|
||||||
return enc.toString(Cipher._format[outputFormat]);
|
Blowfish.setIV(Utils.toBase64(iv), 0);
|
||||||
|
|
||||||
|
const enc = Blowfish.encrypt(input, key, {
|
||||||
|
outputType: Cipher._BLOWFISH_OUTPUT_TYPE_LOOKUP[outputType],
|
||||||
|
cipherMode: Cipher._BLOWFISH_MODE_LOOKUP[mode]
|
||||||
|
});
|
||||||
|
|
||||||
|
return outputType === "Raw" ? Utils.byteArrayToChars(enc) : enc ;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -309,18 +336,24 @@ DES uses a key length of 8 bytes (64 bits).`;
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runBlowfishDec: function (input, args) {
|
runBlowfishDec: function (input, args) {
|
||||||
let key = Cipher._format[args[0].option].parse(args[0].string).toString(Cipher._format.Latin1),
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
mode = args[1],
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
inputFormat = args[2];
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4];
|
||||||
|
|
||||||
if (key.length === 0) return "Enter a key";
|
if (key.length === 0) return "Enter a key";
|
||||||
|
|
||||||
input = Cipher._format[inputFormat].parse(input);
|
input = inputType === "Raw" ? Utils.strToByteArray(input) : input;
|
||||||
|
|
||||||
return Blowfish.decrypt(input.toString(CryptoJS.enc.Base64), key, {
|
Blowfish.setIV(Utils.toBase64(iv), 0);
|
||||||
outputType: 0, // This actually means inputType. The library is weird.
|
|
||||||
cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode)
|
const result = Blowfish.decrypt(input, key, {
|
||||||
|
outputType: Cipher._BLOWFISH_OUTPUT_TYPE_LOOKUP[inputType], // This actually means inputType. The library is weird.
|
||||||
|
cipherMode: Cipher._BLOWFISH_MODE_LOOKUP[mode]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return outputType === "Hex" ? Utils.toHexFast(Utils.strToByteArray(result)) : result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue