diff --git a/src/core/operations/GOSTHash.mjs b/src/core/operations/GOSTHash.mjs new file mode 100644 index 00000000..c7d4d403 --- /dev/null +++ b/src/core/operations/GOSTHash.mjs @@ -0,0 +1,71 @@ +/** + * @author n1474335 [n1474335@gmail.com] + * @copyright Crown Copyright 2019 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import OperationError from "../errors/OperationError"; +import GostDigest from "../vendor/gost/gostDigest"; +import {toHexFast} from "../lib/Hex"; + +/** + * GOST hash operation + */ +class GOSTHash extends Operation { + + /** + * GOSTHash constructor + */ + constructor() { + super(); + + this.name = "GOST hash"; + this.module = "Hashing"; + this.description = "The GOST hash function, defined in the standards GOST R 34.11-94 and GOST 34.311-95 is a 256-bit cryptographic hash function. It was initially defined in the Russian national standard GOST R 34.11-94 Information Technology – Cryptographic Information Security – Hash Function. The equivalent standard used by other member-states of the CIS is GOST 34.311-95.

This function must not be confused with a different Streebog hash function, which is defined in the new revision of the standard GOST R 34.11-2012.

The GOST hash function is based on the GOST block cipher."; + this.infoURL = "https://wikipedia.org/wiki/GOST_(hash_function)"; + this.inputType = "ArrayBuffer"; + this.outputType = "string"; + this.args = [ + { + "name": "S-Box", + "type": "option", + "value": [ + "D-A", + "D-SC", + "E-TEST", + "E-A", + "E-B", + "E-C", + "E-D", + "E-SC", + "E-Z", + "D-TEST" + ] + } + ]; + } + + /** + * @param {ArrayBuffer} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + try { + const sBox = args[1]; + const gostDigest = new GostDigest({ + name: "GOST R 34.11", + version: 1994, + sBox: sBox + }); + + return toHexFast(gostDigest.digest(input)); + } catch (err) { + throw new OperationError(err); + } + } + +} + +export default GOSTHash;