mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Parameterise All hashes
This commit is contained in:
parent
037590f831
commit
f450240094
3 changed files with 208 additions and 44 deletions
|
@ -51,7 +51,73 @@ class GenerateAllHashes extends Operation {
|
|||
this.infoURL = "https://wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
this.args = [
|
||||
{
|
||||
"name": "Length",
|
||||
"type": "option",
|
||||
"value": [
|
||||
"All", "32", "40", "56", "64", "80", "96", "128"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Output hash names",
|
||||
"type": "boolean",
|
||||
"value": true
|
||||
},
|
||||
];
|
||||
this.hashes = [
|
||||
{"name": "MD2", "hash": (new MD2()), "type": "arrayBuffer", params: []},
|
||||
{"name": "MD4", "hash": (new MD4()), "type": "arrayBuffer", params: []},
|
||||
{"name": "MD5", "hash": (new MD5()), "type": "arrayBuffer", params: []},
|
||||
{"name": "MD6", "hash": (new MD6()), "type": "str", params: []},
|
||||
{"name": "SHA0", "hash": (new SHA0()), "type": "arrayBuffer", params: []},
|
||||
{"name": "SHA1", "hash": (new SHA1()), "type": "arrayBuffer", params: []},
|
||||
{"name": "SHA2 224", "hash": (new SHA2()), "type": "arrayBuffer", params: ["224"]},
|
||||
{"name": "SHA2 256", "hash": (new SHA2()), "type": "arrayBuffer", params: ["256"]},
|
||||
{"name": "SHA2 384", "hash": (new SHA2()), "type": "arrayBuffer", params: ["384"]},
|
||||
{"name": "SHA2 512", "hash": (new SHA2()), "type": "arrayBuffer", params: ["512"]},
|
||||
{"name": "SHA3 224", "hash": (new SHA3()), "type": "arrayBuffer", params: ["224"]},
|
||||
{"name": "SHA3 256", "hash": (new SHA3()), "type": "arrayBuffer", params: ["256"]},
|
||||
{"name": "SHA3 384", "hash": (new SHA3()), "type": "arrayBuffer", params: ["384"]},
|
||||
{"name": "SHA3 512", "hash": (new SHA3()), "type": "arrayBuffer", params: ["512"]},
|
||||
{"name": "Keccak 224", "hash": (new Keccak()), "type": "arrayBuffer", params: ["224"]},
|
||||
{"name": "Keccak 256", "hash": (new Keccak()), "type": "arrayBuffer", params: ["256"]},
|
||||
{"name": "Keccak 384", "hash": (new Keccak()), "type": "arrayBuffer", params: ["384"]},
|
||||
{"name": "Keccak 512", "hash": (new Keccak()), "type": "arrayBuffer", params: ["512"]},
|
||||
{"name": "Shake 128", "hash": (new Shake()), "type": "arrayBuffer", params: ["128", 256]},
|
||||
{"name": "Shake 256", "hash": (new Shake()), "type": "arrayBuffer", params: ["256", 512]},
|
||||
{"name": "RIPEMD-128", "hash": (new RIPEMD()), "type": "arrayBuffer", params: ["128"]},
|
||||
{"name": "RIPEMD-160", "hash": (new RIPEMD()), "type": "arrayBuffer", params: ["160"]},
|
||||
{"name": "RIPEMD-256", "hash": (new RIPEMD()), "type": "arrayBuffer", params: ["256"]},
|
||||
{"name": "RIPEMD-320", "hash": (new RIPEMD()), "type": "arrayBuffer", params: ["320"]},
|
||||
{"name": "HAS-160", "hash": (new HAS160()), "type": "arrayBuffer", params: []},
|
||||
{"name": "Whirlpool-0", "hash": (new Whirlpool()), "type": "arrayBuffer", params: ["Whirlpool-0"]},
|
||||
{"name": "Whirlpool-T", "hash": (new Whirlpool()), "type": "arrayBuffer", params: ["Whirlpool-T"]},
|
||||
{"name": "Whirlpool", "hash": (new Whirlpool()), "type": "arrayBuffer", params: ["Whirlpool"]},
|
||||
{"name": "BLAKE2b-128", "hash": (new BLAKE2b), "type": "arrayBuffer", params: ["128","Hex", {string: "", option: "UTF8"}]},
|
||||
{"name": "BLAKE2b-160", "hash": (new BLAKE2b), "type": "arrayBuffer", params: ["160","Hex", {string: "", option: "UTF8"}]},
|
||||
{"name": "BLAKE2b-256", "hash": (new BLAKE2b), "type": "arrayBuffer", params: ["256","Hex", {string: "", option: "UTF8"}]},
|
||||
{"name": "BLAKE2b-384", "hash": (new BLAKE2b), "type": "arrayBuffer", params: ["384","Hex", {string: "", option: "UTF8"}]},
|
||||
{"name": "BLAKE2b-512", "hash": (new BLAKE2b), "type": "arrayBuffer", params: ["512","Hex", {string: "", option: "UTF8"}]},
|
||||
{"name": "BLAKE2s-128", "hash": (new BLAKE2s), "type": "arrayBuffer", params: ["128","Hex", {string: "", option: "UTF8"}]},
|
||||
{"name": "BLAKE2s-160", "hash": (new BLAKE2s), "type": "arrayBuffer", params: ["160","Hex", {string: "", option: "UTF8"}]},
|
||||
{"name": "BLAKE2s-256", "hash": (new BLAKE2s), "type": "arrayBuffer", params: ["256","Hex", {string: "", option: "UTF8"}]},
|
||||
{"name": "Streebog-256", "hash": (new Streebog), "type": "arrayBuffer", params: ["256"]},
|
||||
{"name": "Streebog-512", "hash": (new Streebog), "type": "arrayBuffer", params: ["512"]},
|
||||
{"name": "GOST", "hash": (new GOSTHash), "type": "arrayBuffer", params: ["D-A"]},
|
||||
{"name": "SSDEEP", "hash": (new SSDEEP()), "type": "str"},
|
||||
{"name": "CTPH", "hash": (new CTPH()), "type": "str"}
|
||||
];
|
||||
this.checksums = [
|
||||
{"name": "Fletcher-8: ", "checksum": (new Fletcher8Checksum), "type": "byteArray", "params": []},
|
||||
{"name": "Fletcher-16: ", "checksum": (new Fletcher16Checksum), "type": "byteArray", "params": []},
|
||||
{"name": "Fletcher-32: ", "checksum": (new Fletcher32Checksum), "type": "byteArray", "params": []},
|
||||
{"name": "Fletcher-64: ", "checksum": (new Fletcher64Checksum), "type": "byteArray", "params": []},
|
||||
{"name": "Adler-32: ", "checksum": (new Adler32Checksum), "type": "byteArray", "params": []},
|
||||
{"name": "CRC-8: ", "checksum": (new CRC8Checksum), "type": "arrayBuffer", "params": ["CRC-8"]},
|
||||
{"name": "CRC-16: ", "checksum": (new CRC16Checksum), "type": "arrayBuffer", "params": []},
|
||||
{"name": "CRC-32: ", "checksum": (new CRC32Checksum), "type": "arrayBuffer", "params": []}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,51 +126,37 @@ class GenerateAllHashes extends Operation {
|
|||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const length = args[0];
|
||||
const names = args[1];
|
||||
|
||||
const arrayBuffer = input,
|
||||
str = Utils.arrayBufferToStr(arrayBuffer, false),
|
||||
byteArray = new Uint8Array(arrayBuffer),
|
||||
output = "MD2: " + (new MD2()).run(arrayBuffer, []) +
|
||||
"\nMD4: " + (new MD4()).run(arrayBuffer, []) +
|
||||
"\nMD5: " + (new MD5()).run(arrayBuffer, []) +
|
||||
"\nMD6: " + (new MD6()).run(str, []) +
|
||||
"\nSHA0: " + (new SHA0()).run(arrayBuffer, []) +
|
||||
"\nSHA1: " + (new SHA1()).run(arrayBuffer, []) +
|
||||
"\nSHA2 224: " + (new SHA2()).run(arrayBuffer, ["224"]) +
|
||||
"\nSHA2 256: " + (new SHA2()).run(arrayBuffer, ["256"]) +
|
||||
"\nSHA2 384: " + (new SHA2()).run(arrayBuffer, ["384"]) +
|
||||
"\nSHA2 512: " + (new SHA2()).run(arrayBuffer, ["512"]) +
|
||||
"\nSHA3 224: " + (new SHA3()).run(arrayBuffer, ["224"]) +
|
||||
"\nSHA3 256: " + (new SHA3()).run(arrayBuffer, ["256"]) +
|
||||
"\nSHA3 384: " + (new SHA3()).run(arrayBuffer, ["384"]) +
|
||||
"\nSHA3 512: " + (new SHA3()).run(arrayBuffer, ["512"]) +
|
||||
"\nKeccak 224: " + (new Keccak()).run(arrayBuffer, ["224"]) +
|
||||
"\nKeccak 256: " + (new Keccak()).run(arrayBuffer, ["256"]) +
|
||||
"\nKeccak 384: " + (new Keccak()).run(arrayBuffer, ["384"]) +
|
||||
"\nKeccak 512: " + (new Keccak()).run(arrayBuffer, ["512"]) +
|
||||
"\nShake 128: " + (new Shake()).run(arrayBuffer, ["128", 256]) +
|
||||
"\nShake 256: " + (new Shake()).run(arrayBuffer, ["256", 512]) +
|
||||
"\nRIPEMD-128: " + (new RIPEMD()).run(arrayBuffer, ["128"]) +
|
||||
"\nRIPEMD-160: " + (new RIPEMD()).run(arrayBuffer, ["160"]) +
|
||||
"\nRIPEMD-256: " + (new RIPEMD()).run(arrayBuffer, ["256"]) +
|
||||
"\nRIPEMD-320: " + (new RIPEMD()).run(arrayBuffer, ["320"]) +
|
||||
"\nHAS-160: " + (new HAS160()).run(arrayBuffer, []) +
|
||||
"\nWhirlpool-0: " + (new Whirlpool()).run(arrayBuffer, ["Whirlpool-0"]) +
|
||||
"\nWhirlpool-T: " + (new Whirlpool()).run(arrayBuffer, ["Whirlpool-T"]) +
|
||||
"\nWhirlpool: " + (new Whirlpool()).run(arrayBuffer, ["Whirlpool"]) +
|
||||
"\nBLAKE2b-128: " + (new BLAKE2b).run(arrayBuffer, ["128", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2b-160: " + (new BLAKE2b).run(arrayBuffer, ["160", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2b-256: " + (new BLAKE2b).run(arrayBuffer, ["256", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2b-384: " + (new BLAKE2b).run(arrayBuffer, ["384", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2b-512: " + (new BLAKE2b).run(arrayBuffer, ["512", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2s-128: " + (new BLAKE2s).run(arrayBuffer, ["128", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2s-160: " + (new BLAKE2s).run(arrayBuffer, ["160", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nBLAKE2s-256: " + (new BLAKE2s).run(arrayBuffer, ["256", "Hex", {string: "", option: "UTF8"}]) +
|
||||
"\nStreebog-256: " + (new Streebog).run(arrayBuffer, ["256"]) +
|
||||
"\nStreebog-512: " + (new Streebog).run(arrayBuffer, ["512"]) +
|
||||
"\nGOST: " + (new GOSTHash).run(arrayBuffer, ["D-A"]) +
|
||||
"\nSSDEEP: " + (new SSDEEP()).run(str) +
|
||||
"\nCTPH: " + (new CTPH()).run(str) +
|
||||
"\n\nChecksums:" +
|
||||
byteArray = new Uint8Array(arrayBuffer);
|
||||
|
||||
var value, output = "";
|
||||
// iterate over each of the hashes
|
||||
this.hashes.forEach(function (hash) {
|
||||
// calculate the hash value
|
||||
if (hash.type == "arrayBuffer") {
|
||||
value = hash.hash.run(arrayBuffer, hash.params);
|
||||
} else if (hash.type == "str") {
|
||||
if ("params" in hash) {
|
||||
value = hash.hash.run(str, hash.params);
|
||||
} else {
|
||||
value = hash.hash.run(str);
|
||||
}
|
||||
}
|
||||
// output the values base on the args: length & names
|
||||
if (length == "All" || value.length === parseInt(length)) {
|
||||
if (names) {
|
||||
output += hash.name + ":" + " ".repeat(13-hash.name.length);
|
||||
}
|
||||
output += value + "\n";
|
||||
}
|
||||
});
|
||||
|
||||
if (length == "All") {
|
||||
output += "\nChecksums:" +
|
||||
"\nFletcher-8: " + (new Fletcher8Checksum).run(byteArray, []) +
|
||||
"\nFletcher-16: " + (new Fletcher16Checksum).run(byteArray, []) +
|
||||
"\nFletcher-32: " + (new Fletcher32Checksum).run(byteArray, []) +
|
||||
|
@ -113,6 +165,7 @@ class GenerateAllHashes extends Operation {
|
|||
"\nCRC-8: " + (new CRC8Checksum).run(arrayBuffer, ["CRC-8"]) +
|
||||
"\nCRC-16: " + (new CRC16Checksum).run(arrayBuffer, []) +
|
||||
"\nCRC-32: " + (new CRC32Checksum).run(arrayBuffer, []);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue