Added 'Key Padding' to Blowfish

This commit is contained in:
Michael Rowley 2022-03-22 23:03:05 +00:00
parent bdef47dad8
commit 80379e3df1
3 changed files with 66 additions and 26 deletions

View file

@ -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

View file

@ -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

View file

@ -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
]
}
],