mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
ESM: Ported all Hash and Checksum operations
This commit is contained in:
parent
5362508a99
commit
3fd1f4e6d9
43 changed files with 1971 additions and 9 deletions
70
src/core/operations/Shake.mjs
Normal file
70
src/core/operations/Shake.mjs
Normal file
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import JSSHA3 from "js-sha3";
|
||||
|
||||
/**
|
||||
* Shake operation
|
||||
*/
|
||||
class Shake extends Operation {
|
||||
|
||||
/**
|
||||
* Shake constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Shake";
|
||||
this.module = "Hashing";
|
||||
this.description = "Shake is an Extendable Output Function (XOF) of the SHA-3 hash algorithm, part of the Keccak family, allowing for variable output length/size.";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Capacity",
|
||||
"type": "option",
|
||||
"value": ["256", "128"]
|
||||
},
|
||||
{
|
||||
"name": "Size",
|
||||
"type": "number",
|
||||
"value": 512
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const capacity = parseInt(args[0], 10),
|
||||
size = args[1];
|
||||
let algo;
|
||||
|
||||
if (size < 0)
|
||||
throw new OperationError("Size must be greater than 0");
|
||||
|
||||
switch (capacity) {
|
||||
case 128:
|
||||
algo = JSSHA3.shake128;
|
||||
break;
|
||||
case 256:
|
||||
algo = JSSHA3.shake256;
|
||||
break;
|
||||
default:
|
||||
throw new OperationError("Invalid size");
|
||||
}
|
||||
|
||||
return algo(input, size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Shake;
|
Loading…
Add table
Add a link
Reference in a new issue