diff --git a/CHANGELOG.md b/CHANGELOG.md
index d00c7d7d..3d177bb2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,10 @@
# Changelog
All major and minor version changes will be documented in this file. Details of patch-level version changes can be found in [commit messages](https://github.com/gchq/CyberChef/commits/master).
+
+### [8.29.0] - 2019-03-31
+- 'BLAKE2s' and 'BLAKE2b' hashing operations added [@h345983745] | [#525]
+
### [8.28.0] - 2019-03-31
- 'Heatmap Chart', 'Hex Density Chart', 'Scatter Chart' and 'Series Chart' operation added [@artemisbot] [@tlwr] | [#496] [#143]
@@ -120,6 +124,7 @@ All major and minor version changes will be documented in this file. Details of
+[8.29.0]: https://github.com/gchq/CyberChef/releases/tag/v8.29.0
[8.28.0]: https://github.com/gchq/CyberChef/releases/tag/v8.28.0
[8.27.0]: https://github.com/gchq/CyberChef/releases/tag/v8.27.0
[8.26.0]: https://github.com/gchq/CyberChef/releases/tag/v8.26.0
@@ -217,3 +222,4 @@ All major and minor version changes will be documented in this file. Details of
[#496]: https://github.com/gchq/CyberChef/pull/496
[#506]: https://github.com/gchq/CyberChef/pull/506
[#516]: https://github.com/gchq/CyberChef/pull/516
+[#525]: https://github.com/gchq/CyberChef/pull/525
diff --git a/package-lock.json b/package-lock.json
index cb35fd7b..4b9ceaa9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2315,6 +2315,11 @@
"integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==",
"dev": true
},
+ "blakejs": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.1.0.tgz",
+ "integrity": "sha1-ad+S75U6qIylGjLfarHFShVfx6U="
+ },
"block-stream": {
"version": "0.0.9",
"resolved": "https://registry.npmjs.org/block-stream/-/block-stream-0.0.9.tgz",
diff --git a/package.json b/package.json
index 9dec1738..cdbc6dc6 100644
--- a/package.json
+++ b/package.json
@@ -85,6 +85,7 @@
"babel-plugin-transform-builtin-extend": "1.1.2",
"bcryptjs": "^2.4.3",
"bignumber.js": "^8.1.1",
+ "blakejs": "^1.1.0",
"bootstrap": "4.2.1",
"bootstrap-colorpicker": "^2.5.3",
"bootstrap-material-design": "^4.1.1",
diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json
index e0bb61c8..e9451a28 100755
--- a/src/core/config/Categories.json
+++ b/src/core/config/Categories.json
@@ -297,6 +297,8 @@
"HAS-160",
"Whirlpool",
"Snefru",
+ "BLAKE2b",
+ "BLAKE2s",
"SSDEEP",
"CTPH",
"Compare SSDEEP hashes",
diff --git a/src/core/operations/BLAKE2b.mjs b/src/core/operations/BLAKE2b.mjs
new file mode 100644
index 00000000..60bca3b5
--- /dev/null
+++ b/src/core/operations/BLAKE2b.mjs
@@ -0,0 +1,79 @@
+/**
+ * @author h345983745
+ * @copyright Crown Copyright 2019
+ * @license Apache-2.0
+ */
+
+import Operation from "../Operation";
+import blakejs from "blakejs";
+import OperationError from "../errors/OperationError";
+import Utils from "../Utils";
+import { toBase64 } from "../lib/Base64";
+
+/**
+ * BLAKE2b operation
+ */
+class BLAKE2b extends Operation {
+
+ /**
+ * BLAKE2b constructor
+ */
+ constructor() {
+ super();
+
+ this.name = "BLAKE2b";
+ this.module = "Hashing";
+ this.description = `Performs BLAKE2b hashing on the input.
+
BLAKE2b is a flavour of the BLAKE cryptographic hash function that is optimized for 64-bit platforms and produces digests of any size between 1 and 64 bytes.
+
Supports the use of an optional key.`;
+ this.infoURL = "https://wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2b_algorithm";
+ this.inputType = "ArrayBuffer";
+ this.outputType = "string";
+ this.args = [
+ {
+ "name": "Size",
+ "type": "option",
+ "value": ["512", "384", "256", "160", "128"]
+ }, {
+ "name": "Output Encoding",
+ "type": "option",
+ "value": ["Hex", "Base64", "Raw"]
+ }, {
+ "name": "Key",
+ "type": "toggleString",
+ "value": "",
+ "toggleValues": ["UTF8", "Decimal", "Base64", "Hex", "Latin1"]
+ }
+ ];
+ }
+
+ /**
+ * @param {ArrayBuffer} input
+ * @param {Object[]} args
+ * @returns {string} The input having been hashed with BLAKE2b in the encoding format speicifed.
+ */
+ run(input, args) {
+ const [outSize, outFormat] = args;
+ let key = Utils.convertToByteArray(args[2].string || "", args[2].option);
+ if (key.length === 0) {
+ key = null;
+ } else if (key.length > 64) {
+ throw new OperationError(["Key cannot be greater than 64 bytes", "It is currently " + key.length + " bytes."].join("\n"));
+ }
+
+ input = new Uint8Array(input);
+ switch (outFormat) {
+ case "Hex":
+ return blakejs.blake2bHex(input, key, outSize / 8);
+ case "Base64":
+ return toBase64(blakejs.blake2b(input, key, outSize / 8));
+ case "Raw":
+ return Utils.arrayBufferToStr(blakejs.blake2b(input, key, outSize / 8).buffer);
+ default:
+ return new OperationError("Unsupported Output Type");
+ }
+ }
+
+}
+
+export default BLAKE2b;
diff --git a/src/core/operations/BLAKE2s.mjs b/src/core/operations/BLAKE2s.mjs
new file mode 100644
index 00000000..72cf1988
--- /dev/null
+++ b/src/core/operations/BLAKE2s.mjs
@@ -0,0 +1,80 @@
+/**
+ * @author h345983745
+ * @copyright Crown Copyright 2019
+ * @license Apache-2.0
+ */
+
+import Operation from "../Operation";
+import blakejs from "blakejs";
+import OperationError from "../errors/OperationError";
+import Utils from "../Utils";
+import { toBase64 } from "../lib/Base64";
+
+/**
+ * BLAKE2s Operation
+ */
+class BLAKE2s extends Operation {
+
+ /**
+ * BLAKE2s constructor
+ */
+ constructor() {
+ super();
+
+ this.name = "BLAKE2s";
+ this.module = "Hashing";
+ this.description = `Performs BLAKE2s hashing on the input.
+
BLAKE2s is a flavour of the BLAKE cryptographic hash function that is optimized for 8- to 32-bit platforms and produces digests of any size between 1 and 32 bytes.
+
Supports the use of an optional key.`;
+ this.infoURL = "https://wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2";
+ this.inputType = "ArrayBuffer";
+ this.outputType = "string";
+ this.args = [
+ {
+ "name": "Size",
+ "type": "option",
+ "value": ["256", "160", "128"]
+ }, {
+ "name": "Output Encoding",
+ "type": "option",
+ "value": ["Hex", "Base64", "Raw"]
+ },
+ {
+ "name": "Key",
+ "type": "toggleString",
+ "value": "",
+ "toggleValues": ["UTF8", "Decimal", "Base64", "Hex", "Latin1"]
+ }
+ ];
+ }
+
+ /**
+ * @param {ArrayBuffer} input
+ * @param {Object[]} args
+ * @returns {string} The input having been hashed with BLAKE2s in the encoding format speicifed.
+ */
+ run(input, args) {
+ const [outSize, outFormat] = args;
+ let key = Utils.convertToByteArray(args[2].string || "", args[2].option);
+ if (key.length === 0) {
+ key = null;
+ } else if (key.length > 32) {
+ throw new OperationError(["Key cannot be greater than 32 bytes", "It is currently " + key.length + " bytes."].join("\n"));
+ }
+
+ input = new Uint8Array(input);
+ switch (outFormat) {
+ case "Hex":
+ return blakejs.blake2sHex(input, key, outSize / 8);
+ case "Base64":
+ return toBase64(blakejs.blake2s(input, key, outSize / 8));
+ case "Raw":
+ return Utils.arrayBufferToStr(blakejs.blake2s(input, key, outSize / 8).buffer);
+ default:
+ return new OperationError("Unsupported Output Type");
+ }
+ }
+
+}
+
+export default BLAKE2s;
diff --git a/src/core/operations/GenerateAllHashes.mjs b/src/core/operations/GenerateAllHashes.mjs
index 633337f0..6663d4e8 100644
--- a/src/core/operations/GenerateAllHashes.mjs
+++ b/src/core/operations/GenerateAllHashes.mjs
@@ -28,6 +28,8 @@ import Fletcher64Checksum from "./Fletcher64Checksum";
import Adler32Checksum from "./Adler32Checksum";
import CRC16Checksum from "./CRC16Checksum";
import CRC32Checksum from "./CRC32Checksum";
+import BLAKE2b from "./BLAKE2b";
+import BLAKE2s from "./BLAKE2s";
/**
* Generate all hashes operation
@@ -86,6 +88,14 @@ class GenerateAllHashes extends Operation {
"\nWhirlpool-0: " + (new Whirlpool()).run(arrayBuffer, ["Whirlpool-0"]) +
"\nWhirlpool-T: " + (new Whirlpool()).run(arrayBuffer, ["Whirlpool-T"]) +
"\nWhirlpool: " + (new Whirlpool()).run(arrayBuffer, ["Whirlpool"]) +
+ "\nBLAKE2b-128: " + (new BLAKE2b).run(arrayBuffer, ["128", "Hex", {string: "", option: "UTF8"}]) +
+ "\nBLAKE2b-160: " + (new BLAKE2b).run(arrayBuffer, ["160", "Hex", {string: "", option: "UTF8"}]) +
+ "\nBLAKE2b-256: " + (new BLAKE2b).run(arrayBuffer, ["256", "Hex", {string: "", option: "UTF8"}]) +
+ "\nBLAKE2b-384: " + (new BLAKE2b).run(arrayBuffer, ["384", "Hex", {string: "", option: "UTF8"}]) +
+ "\nBLAKE2b-512: " + (new BLAKE2b).run(arrayBuffer, ["512", "Hex", {string: "", option: "UTF8"}]) +
+ "\nBLAKE2s-128: " + (new BLAKE2s).run(arrayBuffer, ["128", "Hex", {string: "", option: "UTF8"}]) +
+ "\nBLAKE2s-160: " + (new BLAKE2s).run(arrayBuffer, ["160", "Hex", {string: "", option: "UTF8"}]) +
+ "\nBLAKE2s-256: " + (new BLAKE2s).run(arrayBuffer, ["256", "Hex", {string: "", option: "UTF8"}]) +
"\nSSDEEP: " + (new SSDEEP()).run(str) +
"\nCTPH: " + (new CTPH()).run(str) +
"\n\nChecksums:" +
diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs
index ca6d0e1b..e9fc6271 100644
--- a/tests/operations/index.mjs
+++ b/tests/operations/index.mjs
@@ -87,6 +87,8 @@ import "./tests/Enigma";
import "./tests/Bombe";
import "./tests/MultipleBombe";
import "./tests/Typex";
+import "./tests/BLAKE2b";
+import "./tests/BLAKE2s";
// Cannot test operations that use the File type yet
//import "./tests/SplitColourChannels";
diff --git a/tests/operations/tests/BLAKE2b.mjs b/tests/operations/tests/BLAKE2b.mjs
new file mode 100644
index 00000000..94c4fab9
--- /dev/null
+++ b/tests/operations/tests/BLAKE2b.mjs
@@ -0,0 +1,56 @@
+/**
+ * BitwiseOp tests
+ *
+ * @author h345983745
+ * @copyright Crown Copyright 2019
+ * @license Apache-2.0
+ */
+import TestRegister from "../TestRegister";
+
+TestRegister.addTests([
+ {
+ name: "BLAKE2b: 512 - Hello World",
+ input: "Hello World",
+ expectedOutput: "4386a08a265111c9896f56456e2cb61a64239115c4784cf438e36cc851221972da3fb0115f73cd02486254001f878ab1fd126aac69844ef1c1ca152379d0a9bd",
+ recipeConfig: [
+ { "op": "BLAKE2b",
+ "args": ["512", "Hex", {string: "", option: "UTF8"}] }
+ ]
+ },
+ {
+ name: "BLAKE2b: 384 - Hello World",
+ input: "Hello World",
+ expectedOutput: "4d388e82ca8f866e606b6f6f0be910abd62ad6e98c0adfc27cf35acf948986d5c5b9c18b6f47261e1e679eb98edf8e2d",
+ recipeConfig: [
+ { "op": "BLAKE2b",
+ "args": ["384", "Hex", {string: "", option: "UTF8"}] }
+ ]
+ },
+ {
+ name: "BLAKE2b: 256 - Hello World",
+ input: "Hello World",
+ expectedOutput: "1dc01772ee0171f5f614c673e3c7fa1107a8cf727bdf5a6dadb379e93c0d1d00",
+ recipeConfig: [
+ { "op": "BLAKE2b",
+ "args": ["256", "Hex", {string: "", option: "UTF8"}] }
+ ]
+ },
+ {
+ name: "BLAKE2b: 160 - Hello World",
+ input: "Hello World",
+ expectedOutput: "6a8489e6fd6e51fae12ab271ec7fc8134dd5d737",
+ recipeConfig: [
+ { "op": "BLAKE2b",
+ "args": ["160", "Hex", {string: "", option: "UTF8"}] }
+ ]
+ },
+ {
+ name: "BLAKE2b: Key Test",
+ input: "message data",
+ expectedOutput: "3d363ff7401e02026f4a4687d4863ced",
+ recipeConfig: [
+ { "op": "BLAKE2b",
+ "args": ["128", "Hex", {string: "pseudorandom key", option: "UTF8"}] }
+ ]
+ }
+]);
diff --git a/tests/operations/tests/BLAKE2s.mjs b/tests/operations/tests/BLAKE2s.mjs
new file mode 100755
index 00000000..09d53b6a
--- /dev/null
+++ b/tests/operations/tests/BLAKE2s.mjs
@@ -0,0 +1,47 @@
+/**
+ * BitwiseOp tests
+ *
+ * @author h345983745
+ * @copyright Crown Copyright 2019
+ * @license Apache-2.0
+ */
+import TestRegister from "../TestRegister";
+
+TestRegister.addTests([
+ {
+ name: "BLAKE2s: 256 - Hello World",
+ input: "Hello World",
+ expectedOutput: "7706af019148849e516f95ba630307a2018bb7bf03803eca5ed7ed2c3c013513",
+ recipeConfig: [
+ { "op": "BLAKE2s",
+ "args": ["256", "Hex", {string: "", option: "UTF8"}] }
+ ]
+ },
+ {
+ name: "BLAKE2s: 160 - Hello World",
+ input: "Hello World",
+ expectedOutput: "0e4fcfc2ee0097ac1d72d70b595a39e09a3c7c7e",
+ recipeConfig: [
+ { "op": "BLAKE2s",
+ "args": ["160", "Hex", {string: "", option: "UTF8"}] }
+ ]
+ },
+ {
+ name: "BLAKE2s: 128 - Hello World",
+ input: "Hello World",
+ expectedOutput: "9964ee6f36126626bf864363edfa96f6",
+ recipeConfig: [
+ { "op": "BLAKE2s",
+ "args": ["128", "Hex", {string: "", option: "UTF8"}] }
+ ]
+ },
+ {
+ name: "BLAKE2s: Key Test",
+ input: "Hello World",
+ expectedOutput: "9964ee6f36126626bf864363edfa96f6",
+ recipeConfig: [
+ { "op": "BLAKE2s",
+ "args": ["128", "Hex", {string: "", option: "UTF8"}] }
+ ]
+ }
+]);