Tidied up Streebog operation, splitting out GOST hash into a separate op.
This commit is contained in:
parent
666c447e36
commit
99f4091c1a
@ -106,8 +106,7 @@
|
|||||||
"Enigma",
|
"Enigma",
|
||||||
"Bombe",
|
"Bombe",
|
||||||
"Multiple Bombe",
|
"Multiple Bombe",
|
||||||
"Typex",
|
"Typex"
|
||||||
"Streebog"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -303,6 +302,8 @@
|
|||||||
"Snefru",
|
"Snefru",
|
||||||
"BLAKE2b",
|
"BLAKE2b",
|
||||||
"BLAKE2s",
|
"BLAKE2s",
|
||||||
|
"GOST hash",
|
||||||
|
"Streebog",
|
||||||
"SSDEEP",
|
"SSDEEP",
|
||||||
"CTPH",
|
"CTPH",
|
||||||
"Compare SSDEEP hashes",
|
"Compare SSDEEP hashes",
|
||||||
|
@ -12,7 +12,7 @@ import Utils from "../Utils";
|
|||||||
/**
|
/**
|
||||||
* Convert a byte array into a hex string.
|
* Convert a byte array into a hex string.
|
||||||
*
|
*
|
||||||
* @param {Uint8Array|byteArray} data
|
* @param {byteArray|Uint8Array|ArrayBuffer} data
|
||||||
* @param {string} [delim=" "]
|
* @param {string} [delim=" "]
|
||||||
* @param {number} [padding=2]
|
* @param {number} [padding=2]
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@ -26,6 +26,7 @@ import Utils from "../Utils";
|
|||||||
*/
|
*/
|
||||||
export function toHex(data, delim=" ", padding=2) {
|
export function toHex(data, delim=" ", padding=2) {
|
||||||
if (!data) return "";
|
if (!data) return "";
|
||||||
|
if (data instanceof ArrayBuffer) data = new Uint8Array(data);
|
||||||
|
|
||||||
let output = "";
|
let output = "";
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ export function toHex(data, delim=" ", padding=2) {
|
|||||||
/**
|
/**
|
||||||
* Convert a byte array into a hex string as efficiently as possible with no options.
|
* Convert a byte array into a hex string as efficiently as possible with no options.
|
||||||
*
|
*
|
||||||
* @param {byteArray} data
|
* @param {byteArray|Uint8Array|ArrayBuffer} data
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@ -56,6 +57,7 @@ export function toHex(data, delim=" ", padding=2) {
|
|||||||
*/
|
*/
|
||||||
export function toHexFast(data) {
|
export function toHexFast(data) {
|
||||||
if (!data) return "";
|
if (!data) return "";
|
||||||
|
if (data instanceof ArrayBuffer) data = new Uint8Array(data);
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import GostCoding from "../vendor/streebog/gostCoding";
|
import GostDigest from "../vendor/gost/gostDigest";
|
||||||
import GostDigest from "../vendor/streebog/gostDigest";
|
import {toHexFast} from "../lib/Hex";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Streebog operation
|
* Streebog operation
|
||||||
@ -21,37 +21,14 @@ class Streebog extends Operation {
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
this.name = "Streebog";
|
this.name = "Streebog";
|
||||||
this.module = "Crypto";
|
this.module = "Hashing";
|
||||||
this.description = "Streebog is a cryptographic hash function defined in the Russian national standard GOST R 34.11-2012 Information Technology \u2013 Cryptographic Information Security \u2013 Hash Function. It was created to replace an obsolete GOST hash function defined in the old standard GOST R 34.11-94, and as an asymmetric reply to SHA-3 competition by the US National Institute of Standards and Technology.";
|
this.description = "Streebog is a cryptographic hash function defined in the Russian national standard GOST R 34.11-2012 <i>Information Technology \u2013 Cryptographic Information Security \u2013 Hash Function</i>. It was created to replace an obsolete GOST hash function defined in the old standard GOST R 34.11-94, and as an asymmetric reply to SHA-3 competition by the US National Institute of Standards and Technology.";
|
||||||
this.infoURL = "https://en.wikipedia.org/wiki/Streebog";
|
this.infoURL = "https://wikipedia.org/wiki/Streebog";
|
||||||
this.inputType = "string";
|
this.inputType = "ArrayBuffer";
|
||||||
this.outputType = "string";
|
this.outputType = "string";
|
||||||
this.args = [
|
this.args = [
|
||||||
{
|
{
|
||||||
"name": "Version",
|
"name": "Size",
|
||||||
"type": "option",
|
|
||||||
"value": ["2012", "1994"]
|
|
||||||
},
|
|
||||||
// Paramset sBox for GOST 28147-89. Used only if version = 1994
|
|
||||||
{
|
|
||||||
"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"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
// 512 bits digest, valid only for algorithm "Streebog"
|
|
||||||
{
|
|
||||||
"name": "Length",
|
|
||||||
"type": "option",
|
"type": "option",
|
||||||
"value": ["256", "512"]
|
"value": ["256", "512"]
|
||||||
}
|
}
|
||||||
@ -59,34 +36,22 @@ class Streebog extends Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
try {
|
try {
|
||||||
const version = parseInt(args[0], 10);
|
const length = parseInt(args[0], 10);
|
||||||
let sBox = args[1];
|
const gostDigest = new GostDigest({
|
||||||
let length = parseInt(args[2], 10);
|
name: "GOST R 34.11",
|
||||||
|
version: 2012,
|
||||||
|
length: length
|
||||||
|
});
|
||||||
|
|
||||||
// 1994 old-style 256 bits digest based on GOST 28147-89
|
return toHexFast(gostDigest.digest(input));
|
||||||
if (version === 1994) {
|
|
||||||
length = 256;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version === 2012) {
|
|
||||||
sBox = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
const gostDigest = new GostDigest({name: "GOST R 34.11", version, sBox, length });
|
|
||||||
const gostCoding = new GostCoding();
|
|
||||||
|
|
||||||
const decode = gostCoding.Chars.decode(input);
|
|
||||||
const hexEncode = gostCoding.Hex.encode(gostDigest.digest(decode));
|
|
||||||
|
|
||||||
return hexEncode.replace(/[^\-A-Fa-f0-9]/g, "").toLowerCase();
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new OperationError(`Invalid Input, Details ${err.message}`);
|
throw new OperationError(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1192,8 +1192,8 @@ function GostDigest(algorithm) // <editor-fold defaultstate="collapsed">
|
|||||||
// Define chiper algorithm
|
// Define chiper algorithm
|
||||||
this.sBox = (algorithm.sBox || (algorithm.procreator === 'SC' ? 'D-SC' : 'D-A')).toUpperCase();
|
this.sBox = (algorithm.sBox || (algorithm.procreator === 'SC' ? 'D-SC' : 'D-A')).toUpperCase();
|
||||||
|
|
||||||
if (!GostCipher)
|
//if (!GostCipher)
|
||||||
GostCipher = root.GostCipher;
|
// GostCipher = root.GostCipher;
|
||||||
if (!GostCipher)
|
if (!GostCipher)
|
||||||
throw new NotSupportedError('Object GostCipher not found');
|
throw new NotSupportedError('Object GostCipher not found');
|
||||||
|
|
@ -1040,9 +1040,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Streebog",
|
op: "Streebog",
|
||||||
args: [
|
args: ["256"]
|
||||||
"2012", "D-A", "256"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -1053,9 +1051,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Streebog",
|
op: "Streebog",
|
||||||
args: [
|
args: ["256"]
|
||||||
"2012", "D-A", "256"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -1066,9 +1062,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Streebog",
|
op: "Streebog",
|
||||||
args: [
|
args: ["512"]
|
||||||
"2012", "D-A", "512"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -1079,9 +1073,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Streebog",
|
op: "Streebog",
|
||||||
args: [
|
args: ["512"]
|
||||||
"2012", "D-A", "512"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -1091,10 +1083,8 @@ TestRegister.addTests([
|
|||||||
expectedOutput: "981e5f3ca30c841487830f84fb433e13ac1101569b9c13584ac483234cd656c0",
|
expectedOutput: "981e5f3ca30c841487830f84fb433e13ac1101569b9c13584ac483234cd656c0",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Streebog",
|
op: "GOST hash",
|
||||||
args: [
|
args: ["D-A"]
|
||||||
"1994", "D-A", "256"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -1104,10 +1094,8 @@ TestRegister.addTests([
|
|||||||
expectedOutput: "2cefc2f7b7bdc514e18ea57fa74ff357e7fa17d652c75f69cb1be7893ede48eb",
|
expectedOutput: "2cefc2f7b7bdc514e18ea57fa74ff357e7fa17d652c75f69cb1be7893ede48eb",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Streebog",
|
op: "GOST hash",
|
||||||
args: [
|
args: ["D-A"]
|
||||||
"1994", "D-A", "256"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user