mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 06:55:08 -04:00
Merge bd8906f46b
into 7c8be12d52
This commit is contained in:
commit
50727b3c4e
6 changed files with 122 additions and 0 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -46,6 +46,7 @@
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"flat": "^6.0.1",
|
"flat": "^6.0.1",
|
||||||
"geodesy": "1.1.3",
|
"geodesy": "1.1.3",
|
||||||
|
"hash-wasm": "^4.12.0",
|
||||||
"highlight.js": "^11.9.0",
|
"highlight.js": "^11.9.0",
|
||||||
"ieee754": "^1.2.1",
|
"ieee754": "^1.2.1",
|
||||||
"jimp": "^0.22.12",
|
"jimp": "^0.22.12",
|
||||||
|
@ -10940,6 +10941,11 @@
|
||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/hash-wasm": {
|
||||||
|
"version": "4.12.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/hash-wasm/-/hash-wasm-4.12.0.tgz",
|
||||||
|
"integrity": "sha512-+/2B2rYLb48I/evdOIhP+K/DD2ca2fgBjp6O+GBEnCDk2e4rpeXIK8GvIyRPjTezgmWn9gmKwkQjjx6BtqDHVQ=="
|
||||||
|
},
|
||||||
"node_modules/hash.js": {
|
"node_modules/hash.js": {
|
||||||
"version": "1.1.7",
|
"version": "1.1.7",
|
||||||
"resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz",
|
||||||
|
|
|
@ -132,6 +132,7 @@
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"flat": "^6.0.1",
|
"flat": "^6.0.1",
|
||||||
"geodesy": "1.1.3",
|
"geodesy": "1.1.3",
|
||||||
|
"hash-wasm": "^4.12.0",
|
||||||
"highlight.js": "^11.9.0",
|
"highlight.js": "^11.9.0",
|
||||||
"ieee754": "^1.2.1",
|
"ieee754": "^1.2.1",
|
||||||
"jimp": "^0.22.12",
|
"jimp": "^0.22.12",
|
||||||
|
|
|
@ -422,6 +422,7 @@
|
||||||
"Snefru",
|
"Snefru",
|
||||||
"BLAKE2b",
|
"BLAKE2b",
|
||||||
"BLAKE2s",
|
"BLAKE2s",
|
||||||
|
"BLAKE3",
|
||||||
"GOST Hash",
|
"GOST Hash",
|
||||||
"Streebog",
|
"Streebog",
|
||||||
"SSDEEP",
|
"SSDEEP",
|
||||||
|
|
58
src/core/operations/BLAKE3.mjs
Normal file
58
src/core/operations/BLAKE3.mjs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* @author xumptex [xumptex@outlook.fr]
|
||||||
|
* @copyright Crown Copyright 2025
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
import { blake3 } from "hash-wasm";
|
||||||
|
/**
|
||||||
|
* BLAKE3 operation
|
||||||
|
*/
|
||||||
|
class BLAKE3 extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BLAKE3 constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "BLAKE3";
|
||||||
|
this.module = "Hashing";
|
||||||
|
this.description = "Hashes the input using BLAKE3 (UTF-8 encoded), with an optional key (also UTF-8), and outputs the result in hexadecimal format.";
|
||||||
|
this.infoURL = "https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
"name": "Size (bytes)",
|
||||||
|
"type": "number"
|
||||||
|
}, {
|
||||||
|
"name": "Key",
|
||||||
|
"type": "string",
|
||||||
|
"value": ""
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const key = args[1];
|
||||||
|
const size = args[0];
|
||||||
|
// Check if the user want a key hash or not
|
||||||
|
if (key === "") {
|
||||||
|
return blake3(input, size*8);
|
||||||
|
} if (key.length !== 32) {
|
||||||
|
throw new OperationError("The key must be exactly 32 bytes long");
|
||||||
|
}
|
||||||
|
return blake3(input, size*8, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BLAKE3;
|
|
@ -31,6 +31,7 @@ import "./tests/BCD.mjs";
|
||||||
import "./tests/BitwiseOp.mjs";
|
import "./tests/BitwiseOp.mjs";
|
||||||
import "./tests/BLAKE2b.mjs";
|
import "./tests/BLAKE2b.mjs";
|
||||||
import "./tests/BLAKE2s.mjs";
|
import "./tests/BLAKE2s.mjs";
|
||||||
|
import "./tests/BLAKE3.mjs";
|
||||||
import "./tests/Bombe.mjs";
|
import "./tests/Bombe.mjs";
|
||||||
import "./tests/BSON.mjs";
|
import "./tests/BSON.mjs";
|
||||||
import "./tests/ByteRepr.mjs";
|
import "./tests/ByteRepr.mjs";
|
||||||
|
|
55
tests/operations/tests/BLAKE3.mjs
Normal file
55
tests/operations/tests/BLAKE3.mjs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/**
|
||||||
|
* BLAKE3 tests.
|
||||||
|
* @author xumptex [xumptex@outlook.fr]
|
||||||
|
* @copyright Crown Copyright 2025
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "BLAKE3: 8 - Hello world",
|
||||||
|
input: "Hello world",
|
||||||
|
expectedOutput: "e7e6fb7d2869d109",
|
||||||
|
recipeConfig: [
|
||||||
|
{ "op": "BLAKE3",
|
||||||
|
"args": [8, ""] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "BLAKE3: 16 - Hello world 2",
|
||||||
|
input: "Hello world 2",
|
||||||
|
expectedOutput: "2a3df5fe5f0d3fcdd995fc203c7f7c52",
|
||||||
|
recipeConfig: [
|
||||||
|
{ "op": "BLAKE3",
|
||||||
|
"args": [16, ""] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "BLAKE3: 32 - Hello world",
|
||||||
|
input: "Hello world",
|
||||||
|
expectedOutput: "e7e6fb7d2869d109b62cdb1227208d4016cdaa0af6603d95223c6a698137d945",
|
||||||
|
recipeConfig: [
|
||||||
|
{ "op": "BLAKE3",
|
||||||
|
"args": [32, ""] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "BLAKE3: Key Test",
|
||||||
|
input: "Hello world",
|
||||||
|
expectedOutput: "59dd23ac9d025690",
|
||||||
|
recipeConfig: [
|
||||||
|
{ "op": "BLAKE3",
|
||||||
|
"args": [8, "ThiskeyisexactlythirtytwoBytesLo"] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "BLAKE3: Key Test 2",
|
||||||
|
input: "Hello world",
|
||||||
|
expectedOutput: "c8302c9634c1da42",
|
||||||
|
recipeConfig: [
|
||||||
|
{ "op": "BLAKE3",
|
||||||
|
"args": [8, "ThiskeyisexactlythirtytwoByteslo"] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]);
|
Loading…
Add table
Add a link
Reference in a new issue