Skip to content

Commit f92238b

Browse files
authored
Merge pull request #2023 from xumptex/feature/add-BLAKE3
2 parents 2b1ceef + bd8906f commit f92238b

File tree

6 files changed

+122
-0
lines changed

6 files changed

+122
-0
lines changed

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"file-saver": "^2.0.5",
133133
"flat": "^6.0.1",
134134
"geodesy": "1.1.3",
135+
"hash-wasm": "^4.12.0",
135136
"highlight.js": "^11.9.0",
136137
"ieee754": "^1.2.1",
137138
"jimp": "^0.22.12",

src/core/config/Categories.json

+1
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@
425425
"Snefru",
426426
"BLAKE2b",
427427
"BLAKE2s",
428+
"BLAKE3",
428429
"GOST Hash",
429430
"Streebog",
430431
"SSDEEP",

src/core/operations/BLAKE3.mjs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @author xumptex [xumptex@outlook.fr]
3+
* @copyright Crown Copyright 2025
4+
* @license Apache-2.0
5+
*/
6+
7+
import Operation from "../Operation.mjs";
8+
import OperationError from "../errors/OperationError.mjs";
9+
import { blake3 } from "hash-wasm";
10+
/**
11+
* BLAKE3 operation
12+
*/
13+
class BLAKE3 extends Operation {
14+
15+
/**
16+
* BLAKE3 constructor
17+
*/
18+
constructor() {
19+
super();
20+
21+
this.name = "BLAKE3";
22+
this.module = "Hashing";
23+
this.description = "Hashes the input using BLAKE3 (UTF-8 encoded), with an optional key (also UTF-8), and outputs the result in hexadecimal format.";
24+
this.infoURL = "https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE3";
25+
this.inputType = "string";
26+
this.outputType = "string";
27+
this.args = [
28+
{
29+
"name": "Size (bytes)",
30+
"type": "number"
31+
}, {
32+
"name": "Key",
33+
"type": "string",
34+
"value": ""
35+
}
36+
];
37+
}
38+
39+
/**
40+
* @param {string} input
41+
* @param {Object[]} args
42+
* @returns {string}
43+
*/
44+
run(input, args) {
45+
const key = args[1];
46+
const size = args[0];
47+
// Check if the user want a key hash or not
48+
if (key === "") {
49+
return blake3(input, size*8);
50+
} if (key.length !== 32) {
51+
throw new OperationError("The key must be exactly 32 bytes long");
52+
}
53+
return blake3(input, size*8, key);
54+
}
55+
56+
}
57+
58+
export default BLAKE3;

tests/operations/index.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import "./tests/BCD.mjs";
2929
import "./tests/BitwiseOp.mjs";
3030
import "./tests/BLAKE2b.mjs";
3131
import "./tests/BLAKE2s.mjs";
32+
import "./tests/BLAKE3.mjs";
3233
import "./tests/Bombe.mjs";
3334
import "./tests/BSON.mjs";
3435
import "./tests/ByteRepr.mjs";

tests/operations/tests/BLAKE3.mjs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* BLAKE3 tests.
3+
* @author xumptex [xumptex@outlook.fr]
4+
* @copyright Crown Copyright 2025
5+
* @license Apache-2.0
6+
*/
7+
import TestRegister from "../../lib/TestRegister.mjs";
8+
9+
TestRegister.addTests([
10+
{
11+
name: "BLAKE3: 8 - Hello world",
12+
input: "Hello world",
13+
expectedOutput: "e7e6fb7d2869d109",
14+
recipeConfig: [
15+
{ "op": "BLAKE3",
16+
"args": [8, ""] }
17+
]
18+
},
19+
{
20+
name: "BLAKE3: 16 - Hello world 2",
21+
input: "Hello world 2",
22+
expectedOutput: "2a3df5fe5f0d3fcdd995fc203c7f7c52",
23+
recipeConfig: [
24+
{ "op": "BLAKE3",
25+
"args": [16, ""] }
26+
]
27+
},
28+
{
29+
name: "BLAKE3: 32 - Hello world",
30+
input: "Hello world",
31+
expectedOutput: "e7e6fb7d2869d109b62cdb1227208d4016cdaa0af6603d95223c6a698137d945",
32+
recipeConfig: [
33+
{ "op": "BLAKE3",
34+
"args": [32, ""] }
35+
]
36+
},
37+
{
38+
name: "BLAKE3: Key Test",
39+
input: "Hello world",
40+
expectedOutput: "59dd23ac9d025690",
41+
recipeConfig: [
42+
{ "op": "BLAKE3",
43+
"args": [8, "ThiskeyisexactlythirtytwoBytesLo"] }
44+
]
45+
},
46+
{
47+
name: "BLAKE3: Key Test 2",
48+
input: "Hello world",
49+
expectedOutput: "c8302c9634c1da42",
50+
recipeConfig: [
51+
{ "op": "BLAKE3",
52+
"args": [8, "ThiskeyisexactlythirtytwoByteslo"] }
53+
]
54+
}
55+
]);

0 commit comments

Comments
 (0)