mirror of
https://github.com/gchq/CyberChef
synced 2024-12-25 03:53:19 +00:00
Added SHA3, Keccak and Shake hashing algorithms
This commit is contained in:
parent
6e875393d9
commit
73561993a7
5 changed files with 144 additions and 9 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -4198,6 +4198,11 @@
|
|||
"integrity": "sha1-8OgK4DmkvWVLXygfyT8EqRSn/M4=",
|
||||
"dev": true
|
||||
},
|
||||
"js-sha3": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.6.1.tgz",
|
||||
"integrity": "sha1-W4n3enR3Z5h39YxKB1JAk0sflcA="
|
||||
},
|
||||
"js-tokens": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
"exif-parser": "^0.1.12",
|
||||
"google-code-prettify": "^1.0.5",
|
||||
"jquery": "^3.1.1",
|
||||
"js-sha3": "^0.6.1",
|
||||
"jsbn": "^1.1.0",
|
||||
"jsonpath": "^0.2.12",
|
||||
"jsrsasign": "8.0.3",
|
||||
|
|
|
@ -252,6 +252,8 @@ const Categories = [
|
|||
"SHA1",
|
||||
"SHA2",
|
||||
"SHA3",
|
||||
"Keccak",
|
||||
"Shake",
|
||||
"RIPEMD-160",
|
||||
"HMAC",
|
||||
"Fletcher-8 Checksum",
|
||||
|
|
|
@ -2920,7 +2920,7 @@ const OperationConfig = {
|
|||
args: []
|
||||
},
|
||||
"SHA2": {
|
||||
description: "The SHA-2 (Secure Hash Algorithm 2) hash functions were designed by the NSA. SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA224, SHA256, SHA384, SHA512.<br><ul><li>SHA-256 operates on 32-bit words.</li><li>SHA-512 operates on 64-bit words.</li><li>SHA-224 is largely identical to SHA-256 but is truncated to 224 bytes.</li><li>SHA-384 is largely identical to SHA-512 but is truncated to 384 bytes.</li></ul>",
|
||||
description: "The SHA-2 (Secure Hash Algorithm 2) hash functions were designed by the NSA. SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA224, SHA256, SHA384, SHA512.<br><ul><li>SHA-512 operates on 64-bit words.</li><li>SHA-256 operates on 32-bit words.</li><li>SHA-384 is largely identical to SHA-512 but is truncated to 384 bytes.</li><li>SHA-224 is largely identical to SHA-256 but is truncated to 224 bytes.</li></ul>",
|
||||
run: Hash.runSHA2,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
|
@ -2933,7 +2933,7 @@ const OperationConfig = {
|
|||
]
|
||||
},
|
||||
"SHA3": {
|
||||
description: "This is an implementation of Keccak[c=2d]. SHA3 functions based on different implementations of Keccak will give different results.",
|
||||
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ël Peeters, and Gilles Van Assche, building upon RadioGatún.",
|
||||
run: Hash.runSHA3,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
|
@ -2945,6 +2945,38 @@ const OperationConfig = {
|
|||
}
|
||||
]
|
||||
},
|
||||
"Keccak": {
|
||||
description: "The Keccak hash algorithm was designed by Guido Bertoni, Joan Daemen, Michaël Peeters, and Gilles Van Assche, building upon RadioGatún. It was selected as the winner of the SHA-3 design competition.<br><br>This version of the algorithm is Keccak[c=2d] and differs from the SHA-3 specification.",
|
||||
run: Hash.runKeccak,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Size",
|
||||
type: "option",
|
||||
value: Hash.KECCAK_SIZE
|
||||
}
|
||||
]
|
||||
},
|
||||
"Shake": {
|
||||
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.",
|
||||
run: Hash.runShake,
|
||||
inputType: "string",
|
||||
outputType: "string",
|
||||
args: [
|
||||
{
|
||||
name: "Capacity",
|
||||
type: "option",
|
||||
value: Hash.SHAKE_CAPACITY
|
||||
},
|
||||
{
|
||||
name: "Size",
|
||||
type: "number",
|
||||
value: Hash.SHAKE_SIZE
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
"RIPEMD-160": {
|
||||
description: "RIPEMD (RACE Integrity Primitives Evaluation Message Digest) is a family of cryptographic hash functions developed in Leuven, Belgium, by Hans Dobbertin, Antoon Bosselaers and Bart Preneel at the COSIC research group at the Katholieke Universiteit Leuven, and first published in 1996.<br><br>RIPEMD was based upon the design principles used in MD4, and is similar in performance to the more popular SHA-1.<br><br>RIPEMD-160 is an improved, 160-bit version of the original RIPEMD, and the most common version in the family.",
|
||||
run: Hash.runRIPEMD160,
|
||||
|
|
|
@ -2,6 +2,7 @@ import Utils from "../Utils.js";
|
|||
import CryptoJS from "crypto-js";
|
||||
import CryptoApi from "crypto-api";
|
||||
import MD6 from "node-md6";
|
||||
import * as SHA3 from "js-sha3";
|
||||
import Checksum from "./Checksum.js";
|
||||
|
||||
|
||||
|
@ -114,7 +115,7 @@ const Hash = {
|
|||
* @constant
|
||||
* @default
|
||||
*/
|
||||
SHA2_SIZE: ["256", "512", "224", "384"],
|
||||
SHA2_SIZE: ["512", "256", "384", "224"],
|
||||
|
||||
/**
|
||||
* SHA2 operation.
|
||||
|
@ -163,12 +164,106 @@ const Hash = {
|
|||
* @returns {string}
|
||||
*/
|
||||
runSHA3: function (input, args) {
|
||||
input = CryptoJS.enc.Latin1.parse(input);
|
||||
let sha3Length = args[0],
|
||||
options = {
|
||||
outputLength: parseInt(sha3Length, 10)
|
||||
};
|
||||
return CryptoJS.SHA3(input, options).toString(CryptoJS.enc.Hex);
|
||||
const size = parseInt(args[0], 10);
|
||||
let algo;
|
||||
|
||||
switch (size) {
|
||||
case 224:
|
||||
algo = SHA3.sha3_224;
|
||||
break;
|
||||
case 384:
|
||||
algo = SHA3.sha3_384;
|
||||
break;
|
||||
case 256:
|
||||
algo = SHA3.sha3_256;
|
||||
break;
|
||||
case 512:
|
||||
algo = SHA3.sha3_512;
|
||||
break;
|
||||
default:
|
||||
return "Invalid size";
|
||||
}
|
||||
|
||||
return algo(input);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
KECCAK_SIZE: ["512", "384", "256", "224"],
|
||||
|
||||
/**
|
||||
* Keccak operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runKeccak: function (input, args) {
|
||||
const size = parseInt(args[0], 10);
|
||||
let algo;
|
||||
|
||||
switch (size) {
|
||||
case 224:
|
||||
algo = SHA3.keccak224;
|
||||
break;
|
||||
case 384:
|
||||
algo = SHA3.keccak384;
|
||||
break;
|
||||
case 256:
|
||||
algo = SHA3.keccak256;
|
||||
break;
|
||||
case 512:
|
||||
algo = SHA3.keccak512;
|
||||
break;
|
||||
default:
|
||||
return "Invalid size";
|
||||
}
|
||||
|
||||
return algo(input);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
SHAKE_CAPACITY: ["256", "128"],
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
SHAKE_SIZE: 512,
|
||||
|
||||
/**
|
||||
* Shake operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
runShake: function (input, args) {
|
||||
const capacity = parseInt(args[0], 10),
|
||||
size = args[1];
|
||||
let algo;
|
||||
|
||||
if (size < 0)
|
||||
return "Size must be greater than 0";
|
||||
|
||||
switch (capacity) {
|
||||
case 128:
|
||||
algo = SHA3.shake128;
|
||||
break;
|
||||
case 256:
|
||||
algo = SHA3.shake256;
|
||||
break;
|
||||
default:
|
||||
return "Invalid size";
|
||||
}
|
||||
|
||||
return algo(input, size);
|
||||
},
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue