Add parameter validation for BLAKE3 operation

This commit is contained in:
GCHQDeveloper581 2026-06-21 15:13:39 +00:00
parent bfc41f2534
commit 84df3c4fc7
No known key found for this signature in database
GPG Key ID: 6222E059A3DF595C
2 changed files with 44 additions and 2 deletions

View File

@ -30,7 +30,11 @@ class BLAKE3 extends Operation {
this.args = [ this.args = [
{ {
"name": "Size (bytes)", "name": "Size (bytes)",
"type": "number" "type": "number",
"value": 16,
"min": 1,
"max": 65535, // arbitrary limit to prevent resource exhaustion
"integer": true,
}, { }, {
"name": "Key", "name": "Key",
"type": "string", "type": "string",

View File

@ -69,5 +69,43 @@ TestRegister.addTests([
{ "op": "BLAKE3", { "op": "BLAKE3",
"args": [16390, "ThiskeyisexactlythirtytwoBytesLo"] } "args": [16390, "ThiskeyisexactlythirtytwoBytesLo"] }
] ]
},
// test vectors from https://github.com/BLAKE3-team/BLAKE3/blob/master/test_vectors/test_vectors.json
{
name: "BLAKE3: Std test vector - 0 bytes input, plain hash",
input: "",
expectedOutput: "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262e00f03e7b69af26b7faaf09fcd333050338ddfe085b8cc869ca98b206c08243a26f5487789e8f660afe6c99ef9e0c52b92e7393024a80459cf91f476f9ffdbda7001c22e159b402631f277ca96f2defdf1078282314e763699a31c5363165421cce14d",
recipeConfig: [
{
"op": "BLAKE3",
"args": [131, ""]
} }
]
},
{
name: "BLAKE3: Std test vector - 0 bytes input, keyed hash",
input: "",
expectedOutput: "92b2b75604ed3c761f9d6f62392c8a9227ad0ea3f09573e783f1498a4ed60d26b18171a2f22a4b94822c701f107153dba24918c4bae4d2945c20ece13387627d3b73cbf97b797d5e59948c7ef788f54372df45e45e4293c7dc18c1d41144a9758be58960856be1eabbe22c2653190de560ca3b2ac4aa692a9210694254c371e851bc8f",
recipeConfig: [
{
"op": "BLAKE3",
"args": [131, "whats the Elvish word for friend"]
}
]
},
{
name: "BLAKE3: Std test vector - 7 bytes input, keyed hash",
input: "0001020304050607",
expectedOutput: "be2f5495c61cba1bb348a34948c004045e3bd4dae8f0fe82bf44d0da245a060048eb5e68ce6dea1eb0229e144f578b3aa7e9f4f85febd135df8525e6fe40c6f0340d13dd09b255ccd5112a94238f2be3c0b5b7ecde06580426a93e0708555a265305abf86d874e34b4995b788e37a823491f25127a502fe0704baa6bfdf04e76c13276",
recipeConfig: [
{
"op": "From Hex",
args: [],
},
{
"op": "BLAKE3",
"args": [131, "whats the Elvish word for friend"]
}
]
},
]); ]);