From 3dc5b5c31af7689c8dd82795da37cc6b019c5849 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Sun, 31 Mar 2019 22:40:54 +0100 Subject: [PATCH] Changed input type for BLAKE hashing ops to ArrayBuffer and tidied --- CHANGELOG.md | 6 ++++++ src/core/config/Categories.json | 6 +++--- src/core/operations/BLAKE2b.mjs | 10 ++++++---- src/core/operations/BLAKE2s.mjs | 15 +++++++++------ src/core/operations/GenerateAllHashes.mjs | 16 ++++++++-------- 5 files changed, 32 insertions(+), 21 deletions(-) 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/src/core/config/Categories.json b/src/core/config/Categories.json index c3ed15b0..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", @@ -313,9 +315,7 @@ "Adler-32 Checksum", "CRC-16 Checksum", "CRC-32 Checksum", - "TCP/IP Checksum", - "BLAKE2b", - "BLAKE2s" + "TCP/IP Checksum" ] }, { diff --git a/src/core/operations/BLAKE2b.mjs b/src/core/operations/BLAKE2b.mjs index 39e9b5fd..60bca3b5 100644 --- a/src/core/operations/BLAKE2b.mjs +++ b/src/core/operations/BLAKE2b.mjs @@ -27,7 +27,7 @@ class BLAKE2b extends Operation {

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 = "string"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -48,18 +48,20 @@ class BLAKE2b extends Operation { } /** - * @param {string} input + * @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){ + if (key.length === 0) { key = null; - } else if (key.length > 64){ + } 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); diff --git a/src/core/operations/BLAKE2s.mjs b/src/core/operations/BLAKE2s.mjs index 7ddb9d2b..72cf1988 100644 --- a/src/core/operations/BLAKE2s.mjs +++ b/src/core/operations/BLAKE2s.mjs @@ -9,6 +9,7 @@ import blakejs from "blakejs"; import OperationError from "../errors/OperationError"; import Utils from "../Utils"; import { toBase64 } from "../lib/Base64"; + /** * BLAKE2s Operation */ @@ -23,10 +24,10 @@ class BLAKE2s extends Operation { 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.`; +

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 = "string"; + this.inputType = "ArrayBuffer"; this.outputType = "string"; this.args = [ { @@ -48,18 +49,20 @@ class BLAKE2s extends Operation { } /** - * @param {string} input + * @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){ + if (key.length === 0) { key = null; - } else if (key.length > 32){ + } 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); diff --git a/src/core/operations/GenerateAllHashes.mjs b/src/core/operations/GenerateAllHashes.mjs index 53a6fcf9..6663d4e8 100644 --- a/src/core/operations/GenerateAllHashes.mjs +++ b/src/core/operations/GenerateAllHashes.mjs @@ -88,16 +88,16 @@ 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) + - "\nBLAKE2b-512: " + (new BLAKE2b).run(str, ["512", "Hex", {string: "", option: "UTF8"}]) + - "\nBLAKE2b-384: " + (new BLAKE2b).run(str, ["384", "Hex", {string: "", option: "UTF8"}]) + - "\nBLAKE2b-256: " + (new BLAKE2b).run(str, ["256", "Hex", {string: "", option: "UTF8"}]) + - "\nBLAKE2b-160: " + (new BLAKE2b).run(str, ["160", "Hex", {string: "", option: "UTF8"}]) + - "\nBLAKE2b-128: " + (new BLAKE2b).run(str, ["128", "Hex", {string: "", option: "UTF8"}]) + - "\nBLAKE2s-256: " + (new BLAKE2s).run(str, ["256", "Hex", {string: "", option: "UTF8"}]) + - "\nBLAKE2s-160: " + (new BLAKE2s).run(str, ["160", "Hex", {string: "", option: "UTF8"}]) + - "\nBLAKE2s-128: " + (new BLAKE2s).run(str, ["128", "Hex", {string: "", option: "UTF8"}]) + "\n\nChecksums:" + "\nFletcher-8: " + (new Fletcher8Checksum).run(byteArray, []) + "\nFletcher-16: " + (new Fletcher16Checksum).run(byteArray, []) +