mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 14:11:02 +01:00
Merged all SHA-2 operations into one with a size argument
This commit is contained in:
parent
bbd85a491b
commit
6e875393d9
@ -250,10 +250,7 @@ const Categories = [
|
|||||||
"MD6",
|
"MD6",
|
||||||
"SHA0",
|
"SHA0",
|
||||||
"SHA1",
|
"SHA1",
|
||||||
"SHA224",
|
"SHA2",
|
||||||
"SHA256",
|
|
||||||
"SHA384",
|
|
||||||
"SHA512",
|
|
||||||
"SHA3",
|
"SHA3",
|
||||||
"RIPEMD-160",
|
"RIPEMD-160",
|
||||||
"HMAC",
|
"HMAC",
|
||||||
|
@ -2883,7 +2883,7 @@ const OperationConfig = {
|
|||||||
args: []
|
args: []
|
||||||
},
|
},
|
||||||
"MD6": {
|
"MD6": {
|
||||||
description: "TODO",
|
description: "The MD6 (Message-Digest 6) algorithm is a cryptographic hash function. It uses a Merkle tree-like structure to allow for immense parallel computation of hashes for very long inputs.",
|
||||||
run: Hash.runMD6,
|
run: Hash.runMD6,
|
||||||
inputType: "string",
|
inputType: "string",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
@ -2919,33 +2919,18 @@ const OperationConfig = {
|
|||||||
outputType: "string",
|
outputType: "string",
|
||||||
args: []
|
args: []
|
||||||
},
|
},
|
||||||
"SHA224": {
|
"SHA2": {
|
||||||
description: "SHA-224 is largely identical to SHA-256 but is truncated to 224 bytes.",
|
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>",
|
||||||
run: Hash.runSHA224,
|
run: Hash.runSHA2,
|
||||||
inputType: "string",
|
inputType: "string",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
args: []
|
args: [
|
||||||
},
|
{
|
||||||
"SHA256": {
|
name: "Size",
|
||||||
description: "SHA-256 is one of the four variants in the SHA-2 set. It isn't as widely used as SHA-1, though it provides much better security.",
|
type: "option",
|
||||||
run: Hash.runSHA256,
|
value: Hash.SHA2_SIZE
|
||||||
inputType: "string",
|
}
|
||||||
outputType: "string",
|
]
|
||||||
args: []
|
|
||||||
},
|
|
||||||
"SHA384": {
|
|
||||||
description: "SHA-384 is largely identical to SHA-512 but is truncated to 384 bytes.",
|
|
||||||
run: Hash.runSHA384,
|
|
||||||
inputType: "string",
|
|
||||||
outputType: "string",
|
|
||||||
args: []
|
|
||||||
},
|
|
||||||
"SHA512": {
|
|
||||||
description: "SHA-512 is largely identical to SHA-256 but operates on 64-bit words rather than 32.",
|
|
||||||
run: Hash.runSHA512,
|
|
||||||
inputType: "string",
|
|
||||||
outputType: "string",
|
|
||||||
args: []
|
|
||||||
},
|
},
|
||||||
"SHA3": {
|
"SHA3": {
|
||||||
description: "This is an implementation of Keccak[c=2d]. SHA3 functions based on different implementations of Keccak will give different results.",
|
description: "This is an implementation of Keccak[c=2d]. SHA3 functions based on different implementations of Keccak will give different results.",
|
||||||
@ -2954,9 +2939,9 @@ const OperationConfig = {
|
|||||||
outputType: "string",
|
outputType: "string",
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
name: "Output length",
|
name: "Size",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: Hash.SHA3_LENGTH
|
value: Hash.SHA3_SIZE
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -111,54 +111,41 @@ const Hash = {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SHA224 operation.
|
* @constant
|
||||||
*
|
* @default
|
||||||
* @param {string} input
|
|
||||||
* @param {Object[]} args
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
*/
|
||||||
runSHA224: function (input, args) {
|
SHA2_SIZE: ["256", "512", "224", "384"],
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
|
||||||
return CryptoJS.SHA224(input).toString(CryptoJS.enc.Hex);
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SHA256 operation.
|
* SHA2 operation.
|
||||||
*
|
*
|
||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runSHA256: function (input, args) {
|
runSHA2: function (input, args) {
|
||||||
|
const size = parseInt(args[0], 10);
|
||||||
|
let algo;
|
||||||
|
|
||||||
|
switch (size) {
|
||||||
|
case 224:
|
||||||
|
algo = CryptoJS.SHA224;
|
||||||
|
break;
|
||||||
|
case 384:
|
||||||
|
algo = CryptoJS.SHA384;
|
||||||
|
break;
|
||||||
|
case 256:
|
||||||
|
algo = CryptoJS.SHA256;
|
||||||
|
break;
|
||||||
|
case 512:
|
||||||
|
algo = CryptoJS.SHA512;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return "Invalid size";
|
||||||
|
}
|
||||||
|
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
input = CryptoJS.enc.Latin1.parse(input);
|
||||||
return CryptoJS.SHA256(input).toString(CryptoJS.enc.Hex);
|
return algo(input).toString(CryptoJS.enc.Hex);
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SHA384 operation.
|
|
||||||
*
|
|
||||||
* @param {string} input
|
|
||||||
* @param {Object[]} args
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
runSHA384: function (input, args) {
|
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
|
||||||
return CryptoJS.SHA384(input).toString(CryptoJS.enc.Hex);
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SHA512 operation.
|
|
||||||
*
|
|
||||||
* @param {string} input
|
|
||||||
* @param {Object[]} args
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
runSHA512: function (input, args) {
|
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
|
||||||
return CryptoJS.SHA512(input).toString(CryptoJS.enc.Hex);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -166,7 +153,7 @@ const Hash = {
|
|||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SHA3_LENGTH: ["512", "384", "256", "224"],
|
SHA3_SIZE: ["512", "384", "256", "224"],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SHA3 operation.
|
* SHA3 operation.
|
||||||
@ -243,10 +230,10 @@ const Hash = {
|
|||||||
"\nMD6: " + Hash.runMD6(input, []) +
|
"\nMD6: " + Hash.runMD6(input, []) +
|
||||||
"\nSHA0: " + Hash.runSHA0(input, []) +
|
"\nSHA0: " + Hash.runSHA0(input, []) +
|
||||||
"\nSHA1: " + Hash.runSHA1(input, []) +
|
"\nSHA1: " + Hash.runSHA1(input, []) +
|
||||||
"\nSHA2 224: " + Hash.runSHA224(input, []) +
|
"\nSHA2 224: " + Hash.runSHA2(input, ["224"]) +
|
||||||
"\nSHA2 256: " + Hash.runSHA256(input, []) +
|
"\nSHA2 256: " + Hash.runSHA2(input, ["256"]) +
|
||||||
"\nSHA2 384: " + Hash.runSHA384(input, []) +
|
"\nSHA2 384: " + Hash.runSHA2(input, ["384"]) +
|
||||||
"\nSHA2 512: " + Hash.runSHA512(input, []) +
|
"\nSHA2 512: " + Hash.runSHA2(input, ["512"]) +
|
||||||
"\nSHA3 224: " + Hash.runSHA3(input, ["224"]) +
|
"\nSHA3 224: " + Hash.runSHA3(input, ["224"]) +
|
||||||
"\nSHA3 256: " + Hash.runSHA3(input, ["256"]) +
|
"\nSHA3 256: " + Hash.runSHA3(input, ["256"]) +
|
||||||
"\nSHA3 384: " + Hash.runSHA3(input, ["384"]) +
|
"\nSHA3 384: " + Hash.runSHA3(input, ["384"]) +
|
||||||
|
Loading…
Reference in New Issue
Block a user