mirror of
https://github.com/gchq/CyberChef.git
synced 2025-06-14 10:14:53 -04:00
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
/**
|
|
* @author xumptex [xumptex@outlook.fr]
|
|
* @copyright Crown Copyright 2025
|
|
* @license Apache-2.0
|
|
*/
|
|
|
|
import Operation from "../Operation.mjs";
|
|
import OperationError from "../errors/OperationError.mjs";
|
|
import { blake3 } from "hash-wasm";
|
|
/**
|
|
* BLAKE3 operation
|
|
*/
|
|
class BLAKE3 extends Operation {
|
|
|
|
/**
|
|
* BLAKE3 constructor
|
|
*/
|
|
constructor() {
|
|
super();
|
|
|
|
this.name = "BLAKE3";
|
|
this.module = "Hashing";
|
|
this.description = "Hashes the input using BLAKE3 (UTF-8 encoded), with an optional key (also UTF-8), and outputs the result in hexadecimal format.";
|
|
this.infoURL = "https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3";
|
|
this.inputType = "string";
|
|
this.outputType = "string";
|
|
this.args = [
|
|
{
|
|
"name": "Size (bytes)",
|
|
"type": "number"
|
|
}, {
|
|
"name": "Key",
|
|
"type": "string",
|
|
"value": ""
|
|
}
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param {string} input
|
|
* @param {Object[]} args
|
|
* @returns {string}
|
|
*/
|
|
run(input, args) {
|
|
const key = args[1];
|
|
const size = args[0];
|
|
// Check if the user want a key hash or not
|
|
if (key === "") {
|
|
return blake3(input, size*8);
|
|
} if (key.length !== 32) {
|
|
throw new OperationError("The key must be exactly 32 bytes long");
|
|
}
|
|
return blake3(input, size*8, key);
|
|
}
|
|
|
|
}
|
|
|
|
export default BLAKE3;
|