mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Changed input type for BLAKE hashing ops to ArrayBuffer and tidied
This commit is contained in:
parent
342e11f83e
commit
3dc5b5c31a
5 changed files with 32 additions and 21 deletions
|
@ -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.
|
||||
<br><br> 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.
|
||||
<br><br> Supports the use of an optional key.`;
|
||||
<br><br>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.
|
||||
<br><br>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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue