* @param {string} input * @param {Object[]} args * @returns {string}
(input, args)
| 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 |
nothing calls this directly
no test coverage detected