mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-14 10:06:58 -04:00
Merge pull request #2023 from xumptex/feature/add-BLAKE3
This commit is contained in:
commit
f92238bf04
6 changed files with 122 additions and 0 deletions
58
src/core/operations/BLAKE3.mjs
Normal file
58
src/core/operations/BLAKE3.mjs
Normal file
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* @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;
|
Loading…
Add table
Add a link
Reference in a new issue