2
0
mirror of https://github.com/gchq/CyberChef synced 2026-01-06 10:33:18 +00:00

Compare commits

..

4 Commits

Author SHA1 Message Date
n1474335
7eb887ca51 10.18.7 2024-06-06 17:08:58 +01:00
n1474335
74d0166682 Fixed GOST sBox arg bug 2024-06-06 17:08:37 +01:00
n1474335
18159ce806 10.18.6 2024-05-16 18:09:22 +01:00
n1474335
86d59783fa Improved GOST algorithm naming and block size selection 2024-05-16 18:09:12 +01:00
9 changed files with 166 additions and 96 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "cyberchef", "name": "cyberchef",
"version": "10.18.5", "version": "10.18.7",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "cyberchef", "name": "cyberchef",
"version": "10.18.5", "version": "10.18.7",
"hasInstallScript": true, "hasInstallScript": true,
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "cyberchef", "name": "cyberchef",
"version": "10.18.5", "version": "10.18.7",
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
"author": "n1474335 <n1474335@gmail.com>", "author": "n1474335 <n1474335@gmail.com>",
"homepage": "https://gchq.github.io/CyberChef", "homepage": "https://gchq.github.io/CyberChef",

View File

@@ -55,22 +55,19 @@ class GOSTDecrypt extends Operation {
type: "argSelector", type: "argSelector",
value: [ value: [
{ {
name: "GOST 28147 (Magma, 1989)", name: "GOST 28147 (1989)",
off: [5], on: [5]
on: [6] },
{
name: "GOST R 34.12 (Magma, 2015)",
off: [5]
}, },
{ {
name: "GOST R 34.12 (Kuznyechik, 2015)", name: "GOST R 34.12 (Kuznyechik, 2015)",
on: [5], off: [5]
off: [6]
} }
] ]
}, },
{
name: "Block length",
type: "option",
value: ["64", "128"]
},
{ {
name: "sBox", name: "sBox",
type: "option", type: "option",
@@ -100,14 +97,30 @@ class GOSTDecrypt extends Operation {
* @returns {string} * @returns {string}
*/ */
async run(input, args) { 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 key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option));
const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option)); const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option));
input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input)); input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input));
const versionNum = version === "GOST 28147 (Magma, 1989)" ? 1989 : 2015; let blockLength, versionNum;
const blockLength = versionNum === 1989 ? 64 : parseInt(length, 10); 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 sBoxVal = versionNum === 1989 ? sBox : null;
const algorithm = { const algorithm = {

View File

@@ -55,22 +55,19 @@ class GOSTEncrypt extends Operation {
type: "argSelector", type: "argSelector",
value: [ value: [
{ {
name: "GOST 28147 (Magma, 1989)", name: "GOST 28147 (1989)",
off: [5], on: [5]
on: [6] },
{
name: "GOST R 34.12 (Magma, 2015)",
off: [5]
}, },
{ {
name: "GOST R 34.12 (Kuznyechik, 2015)", name: "GOST R 34.12 (Kuznyechik, 2015)",
on: [5], off: [5]
off: [6]
} }
] ]
}, },
{
name: "Block length",
type: "option",
value: ["64", "128"]
},
{ {
name: "sBox", name: "sBox",
type: "option", type: "option",
@@ -100,14 +97,30 @@ class GOSTEncrypt extends Operation {
* @returns {string} * @returns {string}
*/ */
async run(input, args) { 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 key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option));
const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option)); const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option));
input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input)); input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input));
const versionNum = version === "GOST 28147 (Magma, 1989)" ? 1989 : 2015; let blockLength, versionNum;
const blockLength = versionNum === 1989 ? 64 : parseInt(length, 10); 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 sBoxVal = versionNum === 1989 ? sBox : null;
const algorithm = { const algorithm = {

View File

@@ -55,22 +55,19 @@ class GOSTKeyUnwrap extends Operation {
type: "argSelector", type: "argSelector",
value: [ value: [
{ {
name: "GOST 28147 (Magma, 1989)", name: "GOST 28147 (1989)",
off: [5], on: [5]
on: [6] },
{
name: "GOST R 34.12 (Magma, 2015)",
off: [5]
}, },
{ {
name: "GOST R 34.12 (Kuznyechik, 2015)", name: "GOST R 34.12 (Kuznyechik, 2015)",
on: [5], off: [5]
off: [6]
} }
] ]
}, },
{
name: "Block length",
type: "option",
value: ["64", "128"]
},
{ {
name: "sBox", name: "sBox",
type: "option", type: "option",
@@ -90,14 +87,30 @@ class GOSTKeyUnwrap extends Operation {
* @returns {string} * @returns {string}
*/ */
async run(input, args) { async run(input, args) {
const [keyObj, ukmObj, inputType, outputType, version, length, sBox, keyWrapping] = args; const [keyObj, ukmObj, inputType, outputType, version, sBox, keyWrapping] = args;
const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option)); const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option));
const ukm = toHexFast(Utils.convertToByteArray(ukmObj.string, ukmObj.option)); const ukm = toHexFast(Utils.convertToByteArray(ukmObj.string, ukmObj.option));
input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input)); input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input));
const versionNum = version === "GOST 28147 (Magma, 1989)" ? 1989 : 2015; let blockLength, versionNum;
const blockLength = versionNum === 1989 ? 64 : parseInt(length, 10); 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 sBoxVal = versionNum === 1989 ? sBox : null;
const algorithm = { const algorithm = {

View File

@@ -55,22 +55,19 @@ class GOSTKeyWrap extends Operation {
type: "argSelector", type: "argSelector",
value: [ value: [
{ {
name: "GOST 28147 (Magma, 1989)", name: "GOST 28147 (1989)",
off: [5], on: [5]
on: [6] },
{
name: "GOST R 34.12 (Magma, 2015)",
off: [5]
}, },
{ {
name: "GOST R 34.12 (Kuznyechik, 2015)", name: "GOST R 34.12 (Kuznyechik, 2015)",
on: [5], off: [5]
off: [6]
} }
] ]
}, },
{
name: "Block length",
type: "option",
value: ["64", "128"]
},
{ {
name: "sBox", name: "sBox",
type: "option", type: "option",
@@ -90,14 +87,30 @@ class GOSTKeyWrap extends Operation {
* @returns {string} * @returns {string}
*/ */
async run(input, args) { async run(input, args) {
const [keyObj, ukmObj, inputType, outputType, version, length, sBox, keyWrapping] = args; const [keyObj, ukmObj, inputType, outputType, version, sBox, keyWrapping] = args;
const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option)); const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option));
const ukm = toHexFast(Utils.convertToByteArray(ukmObj.string, ukmObj.option)); const ukm = toHexFast(Utils.convertToByteArray(ukmObj.string, ukmObj.option));
input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input)); input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input));
const versionNum = version === "GOST 28147 (Magma, 1989)" ? 1989 : 2015; let blockLength, versionNum;
const blockLength = versionNum === 1989 ? 64 : parseInt(length, 10); 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 sBoxVal = versionNum === 1989 ? sBox : null;
const algorithm = { const algorithm = {

View File

@@ -55,22 +55,19 @@ class GOSTSign extends Operation {
type: "argSelector", type: "argSelector",
value: [ value: [
{ {
name: "GOST 28147 (Magma, 1989)", name: "GOST 28147 (1989)",
off: [5], on: [5]
on: [6] },
{
name: "GOST R 34.12 (Magma, 2015)",
off: [5]
}, },
{ {
name: "GOST R 34.12 (Kuznyechik, 2015)", name: "GOST R 34.12 (Kuznyechik, 2015)",
on: [5], off: [5]
off: [6]
} }
] ]
}, },
{
name: "Block length",
type: "option",
value: ["64", "128"]
},
{ {
name: "sBox", name: "sBox",
type: "option", type: "option",
@@ -93,14 +90,30 @@ class GOSTSign extends Operation {
* @returns {string} * @returns {string}
*/ */
async run(input, args) { async run(input, args) {
const [keyObj, ivObj, inputType, outputType, version, length, sBox, macLength] = args; const [keyObj, ivObj, inputType, outputType, version, sBox, macLength] = args;
const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option)); const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option));
const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option)); const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option));
input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input)); input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input));
const versionNum = version === "GOST 28147 (Magma, 1989)" ? 1989 : 2015; let blockLength, versionNum;
const blockLength = versionNum === 1989 ? 64 : parseInt(length, 10); 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 sBoxVal = versionNum === 1989 ? sBox : null;
const algorithm = { const algorithm = {

View File

@@ -56,22 +56,19 @@ class GOSTVerify extends Operation {
type: "argSelector", type: "argSelector",
value: [ value: [
{ {
name: "GOST 28147 (Magma, 1989)", name: "GOST 28147 (1989)",
off: [5], on: [5]
on: [6] },
{
name: "GOST R 34.12 (Magma, 2015)",
off: [5]
}, },
{ {
name: "GOST R 34.12 (Kuznyechik, 2015)", name: "GOST R 34.12 (Kuznyechik, 2015)",
on: [5], off: [5]
off: [6]
} }
] ]
}, },
{
name: "Block length",
type: "option",
value: ["64", "128"]
},
{ {
name: "sBox", name: "sBox",
type: "option", type: "option",
@@ -86,15 +83,31 @@ class GOSTVerify extends Operation {
* @returns {string} * @returns {string}
*/ */
async run(input, args) { async run(input, args) {
const [keyObj, ivObj, macObj, inputType, version, length, sBox] = args; const [keyObj, ivObj, macObj, inputType, version, sBox] = args;
const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option)); const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option));
const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option)); const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option));
const mac = toHexFast(Utils.convertToByteArray(macObj.string, macObj.option)); const mac = toHexFast(Utils.convertToByteArray(macObj.string, macObj.option));
input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input)); input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input));
const versionNum = version === "GOST 28147 (Magma, 1989)" ? 1989 : 2015; let blockLength, versionNum;
const blockLength = versionNum === 1989 ? 64 : parseInt(length, 10); 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 sBoxVal = versionNum === 1989 ? sBox : null;
const algorithm = { const algorithm = {

View File

@@ -14,7 +14,7 @@ import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([ TestRegister.addTests([
{ {
name: "GOST Encrypt: Magma", name: "GOST Encrypt: 1989",
input: "Hello, World!", input: "Hello, World!",
expectedOutput: "f124ac5c0853870906dbaf9b56", expectedOutput: "f124ac5c0853870906dbaf9b56",
recipeConfig: [ recipeConfig: [
@@ -25,8 +25,7 @@ TestRegister.addTests([
{ "option": "Hex", "string": "0011223344556677" }, { "option": "Hex", "string": "0011223344556677" },
"Raw", "Raw",
"Hex", "Hex",
"GOST 28147 (Magma, 1989)", "GOST 28147 (1989)",
"64",
"E-SC", "E-SC",
"OFB", "OFB",
"CP", "CP",
@@ -48,7 +47,6 @@ TestRegister.addTests([
"Raw", "Raw",
"Hex", "Hex",
"GOST R 34.12 (Kuznyechik, 2015)", "GOST R 34.12 (Kuznyechik, 2015)",
"128",
"E-SC", "E-SC",
"CBC", "CBC",
"CP", "CP",
@@ -58,7 +56,7 @@ TestRegister.addTests([
], ],
}, },
{ {
name: "GOST Decrypt: Magma", name: "GOST Decrypt: 1989",
input: "f124ac5c0853870906dbaf9b56", input: "f124ac5c0853870906dbaf9b56",
expectedOutput: "Hello, World!", expectedOutput: "Hello, World!",
recipeConfig: [ recipeConfig: [
@@ -69,8 +67,7 @@ TestRegister.addTests([
{ "option": "Hex", "string": "0011223344556677" }, { "option": "Hex", "string": "0011223344556677" },
"Hex", "Hex",
"Raw", "Raw",
"GOST 28147 (Magma, 1989)", "GOST 28147 (1989)",
"128",
"E-SC", "E-SC",
"OFB", "OFB",
"CP", "CP",
@@ -92,7 +89,6 @@ TestRegister.addTests([
"Hex", "Hex",
"Raw", "Raw",
"GOST R 34.12 (Kuznyechik, 2015)", "GOST R 34.12 (Kuznyechik, 2015)",
"128",
"E-TEST", "E-TEST",
"CBC", "CBC",
"CP", "CP",
@@ -113,8 +109,7 @@ TestRegister.addTests([
{ "option": "Hex", "string": "0011223344556677" }, { "option": "Hex", "string": "0011223344556677" },
"Raw", "Raw",
"Hex", "Hex",
"GOST 28147 (Magma, 1989)", "GOST 28147 (1989)",
"64",
"E-C", "E-C",
48 48
] ]
@@ -134,7 +129,6 @@ TestRegister.addTests([
{ "option": "Hex", "string": "42b77fb3d6f6bf04" }, { "option": "Hex", "string": "42b77fb3d6f6bf04" },
"Raw", "Raw",
"GOST R 34.12 (Kuznyechik, 2015)", "GOST R 34.12 (Kuznyechik, 2015)",
"128",
"E-TEST" "E-TEST"
] ]
} }
@@ -152,8 +146,7 @@ TestRegister.addTests([
{ "option": "Hex", "string": "0011223344556677" }, { "option": "Hex", "string": "0011223344556677" },
"Raw", "Raw",
"Hex", "Hex",
"GOST R 34.12 (Kuznyechik, 2015)", "GOST R 34.12 (Magma, 2015)",
"64",
"E-TEST", "E-TEST",
"CP" "CP"
] ]
@@ -172,8 +165,7 @@ TestRegister.addTests([
{ "option": "Latin1", "string": "00112233" }, { "option": "Latin1", "string": "00112233" },
"Hex", "Hex",
"Raw", "Raw",
"GOST 28147 (Magma, 1989)", "GOST 28147 (1989)",
"64",
"E-Z", "E-Z",
"CP" "CP"
] ]