diff --git a/src/core/operations/BLAKE3.mjs b/src/core/operations/BLAKE3.mjs index a22eb0b8..8002a277 100644 --- a/src/core/operations/BLAKE3.mjs +++ b/src/core/operations/BLAKE3.mjs @@ -51,6 +51,11 @@ class BLAKE3 extends Operation { run(input, args) { const key = args[1]; const size = args[0]; + + if (!Number.isInteger(size) || size < 0) { + throw new OperationError("Size must be a non-negative integer"); + } + const opts = { dkLen: size }; const inputBytes = new Uint8Array(Utils.strToArrayBuffer(input)); if (key !== "") { diff --git a/tests/operations/tests/BLAKE3.mjs b/tests/operations/tests/BLAKE3.mjs index e15144b2..92504ca9 100644 --- a/tests/operations/tests/BLAKE3.mjs +++ b/tests/operations/tests/BLAKE3.mjs @@ -34,6 +34,24 @@ TestRegister.addTests([ "args": [32, ""] } ] }, + { + name: "BLAKE3: negative size", + input: "hello", + expectedOutput: "Size must be a non-negative integer", + recipeConfig: [ + { "op": "BLAKE3", + "args": [-6, ""] } + ] + }, + { + name: "BLAKE3: fractional size", + input: "hello", + expectedOutput: "Size must be a non-negative integer", + recipeConfig: [ + { "op": "BLAKE3", + "args": [1.2, ""] } + ] + }, { name: "BLAKE3: Key Test", input: "Hello world",