mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Improved GOST algorithm naming and block size selection
This commit is contained in:
parent
fb818c3149
commit
86d59783fa
7 changed files with 157 additions and 87 deletions
|
@ -55,22 +55,19 @@ class GOSTEncrypt extends Operation {
|
|||
type: "argSelector",
|
||||
value: [
|
||||
{
|
||||
name: "GOST 28147 (Magma, 1989)",
|
||||
off: [5],
|
||||
name: "GOST 28147 (1989)",
|
||||
on: [6]
|
||||
},
|
||||
{
|
||||
name: "GOST R 34.12 (Magma, 2015)",
|
||||
off: [5]
|
||||
},
|
||||
{
|
||||
name: "GOST R 34.12 (Kuznyechik, 2015)",
|
||||
on: [5],
|
||||
off: [6]
|
||||
off: [5]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Block length",
|
||||
type: "option",
|
||||
value: ["64", "128"]
|
||||
},
|
||||
{
|
||||
name: "sBox",
|
||||
type: "option",
|
||||
|
@ -100,14 +97,30 @@ class GOSTEncrypt extends Operation {
|
|||
* @returns {string}
|
||||
*/
|
||||
async run(input, args) {
|
||||
const [keyObj, ivObj, inputType, outputType, version, length, sBox, blockMode, keyMeshing, padding] = args;
|
||||
const [keyObj, ivObj, inputType, outputType, version, sBox, blockMode, keyMeshing, padding] = args;
|
||||
|
||||
const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option));
|
||||
const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option));
|
||||
input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input));
|
||||
|
||||
const versionNum = version === "GOST 28147 (Magma, 1989)" ? 1989 : 2015;
|
||||
const blockLength = versionNum === 1989 ? 64 : parseInt(length, 10);
|
||||
let blockLength, versionNum;
|
||||
switch (version) {
|
||||
case "GOST 28147 (1989)":
|
||||
versionNum = 1989;
|
||||
blockLength = 64;
|
||||
break;
|
||||
case "GOST R 34.12 (Magma, 2015)":
|
||||
versionNum = 2015;
|
||||
blockLength = 64;
|
||||
break;
|
||||
case "GOST R 34.12 (Kuznyechik, 2015)":
|
||||
versionNum = 2015;
|
||||
blockLength = 128;
|
||||
break;
|
||||
default:
|
||||
throw new OperationError(`Unknown algorithm version: ${version}`);
|
||||
}
|
||||
|
||||
const sBoxVal = versionNum === 1989 ? sBox : null;
|
||||
|
||||
const algorithm = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue