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
67
src/core/operations/SHA3.mjs
Normal file
67
src/core/operations/SHA3.mjs
Normal file
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import JSSHA3 from "js-sha3";
|
||||
import OperationError from "../errors/OperationError";
|
||||
|
||||
/**
|
||||
* SHA3 operation
|
||||
*/
|
||||
class SHA3 extends Operation {
|
||||
|
||||
/**
|
||||
* SHA3 constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "SHA3";
|
||||
this.module = "Hashing";
|
||||
this.description = "The SHA-3 (Secure Hash Algorithm 3) hash functions were released by NIST on August 5, 2015. Although part of the same series of standards, SHA-3 is internally quite different from the MD5-like structure of SHA-1 and SHA-2.<br><br>SHA-3 is a subset of the broader cryptographic primitive family Keccak designed by Guido Bertoni, Joan Daemen, Micha\xebl Peeters, and Gilles Van Assche, building upon RadioGat\xfan.";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Size",
|
||||
"type": "option",
|
||||
"value": ["512", "384", "256", "224"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const size = parseInt(args[0], 10);
|
||||
let algo;
|
||||
|
||||
switch (size) {
|
||||
case 224:
|
||||
algo = JSSHA3.sha3_224;
|
||||
break;
|
||||
case 384:
|
||||
algo = JSSHA3.sha3_384;
|
||||
break;
|
||||
case 256:
|
||||
algo = JSSHA3.sha3_256;
|
||||
break;
|
||||
case 512:
|
||||
algo = JSSHA3.sha3_512;
|
||||
break;
|
||||
default:
|
||||
throw new OperationError("Invalid size");
|
||||
}
|
||||
|
||||
return algo(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default SHA3;
|
Loading…
Add table
Add a link
Reference in a new issue