MCPcopy Index your code
hub / github.com/gchq/CyberChef / run

Method run

src/core/operations/GOSTDecrypt.mjs:99–147  ·  view source on GitHub ↗

* @param {string} input * @param {Object[]} args * @returns {string}

(input, args)

Source from the content-addressed store, hash-verified

97 * @returns {string}
98 */
99 async run(input, args) {
100 const [keyObj, ivObj, inputType, outputType, version, sBox, blockMode, keyMeshing, padding] = args;
101
102 const key = toHexFast(Utils.convertToByteArray(keyObj.string, keyObj.option));
103 const iv = toHexFast(Utils.convertToByteArray(ivObj.string, ivObj.option));
104 input = inputType === "Hex" ? input : toHexFast(Utils.strToArrayBuffer(input));
105
106 let blockLength, versionNum;
107 switch (version) {
108 case "GOST 28147 (1989)":
109 versionNum = 1989;
110 blockLength = 64;
111 break;
112 case "GOST R 34.12 (Magma, 2015)":
113 versionNum = 2015;
114 blockLength = 64;
115 break;
116 case "GOST R 34.12 (Kuznyechik, 2015)":
117 versionNum = 2015;
118 blockLength = 128;
119 break;
120 default:
121 throw new OperationError(`Unknown algorithm version: ${version}`);
122 }
123
124 const sBoxVal = versionNum === 1989 ? sBox : null;
125
126 const algorithm = {
127 version: versionNum,
128 length: blockLength,
129 mode: "ES",
130 sBox: sBoxVal,
131 block: blockMode,
132 keyMeshing: keyMeshing,
133 padding: padding
134 };
135
136 try {
137 const Hex = CryptoGost.coding.Hex;
138 if (iv) algorithm.iv = Hex.decode(iv);
139
140 const cipher = GostEngine.getGostCipher(algorithm);
141 const out = Hex.encode(cipher.decrypt(Hex.decode(key), Hex.decode(input)));
142
143 return outputType === "Hex" ? out : Utils.byteArrayToChars(fromHex(out));
144 } catch (err) {
145 throw new OperationError(err);
146 }
147 }
148
149}
150

Callers

nothing calls this directly

Calls 8

toHexFastFunction · 0.90
fromHexFunction · 0.90
convertToByteArrayMethod · 0.80
strToArrayBufferMethod · 0.80
decodeMethod · 0.80
encodeMethod · 0.80
byteArrayToCharsMethod · 0.80
decryptMethod · 0.45

Tested by

no test coverage detected