Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/operations/BLAKE3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class BLAKE3 extends Operation {
this.args = [
{
"name": "Size (bytes)",
"type": "number"
"type": "number",
"value": 16,
"min": 1,
"max": 65535, // arbitrary limit to prevent resource exhaustion
"integer": true,
}, {
"name": "Key",
"type": "string",
Expand Down
5 changes: 4 additions & 1 deletion src/core/operations/BitShiftLeft.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class BitShiftLeft extends Operation {
{
"name": "Amount",
"type": "number",
"value": 1
"value": 1,
"min": 0,
"max": 7,
"integer": true,
}
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/operations/PseudoRandomNumberGenerator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class PseudoRandomNumberGenerator extends Operation {
{
"name": "Number of bytes",
"type": "number",
"value": 32
"value": 32,
"min": 1
},
{
"name": "Output as",
Expand Down
8 changes: 4 additions & 4 deletions src/core/operations/ToBase.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class ToBase extends Operation {
{
"name": "Radix",
"type": "number",
"value": 36
"value": 36,
"min": 2,
"max": 36,
"integer": true,
}
];
}
Expand All @@ -43,9 +46,6 @@ class ToBase extends Operation {
throw new OperationError("Error: Input must be a number");
}
const radix = args[0];
if (radix < 2 || radix > 36) {
throw new OperationError("Error: Radix argument must be between 2 and 36");
}
return input.toString(radix);
}

Expand Down
5 changes: 4 additions & 1 deletion src/core/operations/ToBinary.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class ToBinary extends Operation {
{
"name": "Byte Length",
"type": "number",
"value": 8
"value": 8,
"min": 1,
"max": 256, // arbitrary - significantly larger than word size for any known machine ("640k ought to be enough for anybody")
Comment thread
C85297 marked this conversation as resolved.
"integer": true
}
];
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/operations/XORBruteForce.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class XORBruteForce extends Operation {
{
"name": "Key length",
"type": "number",
"value": 1
"value": 1,
"min": 1,
"max": 2,
"integer": true
},
{
"name": "Sample length",
Expand Down
4 changes: 2 additions & 2 deletions src/core/operations/XORChecksum.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Operation from "../Operation.mjs";
import Utils from "../Utils.mjs";
import { toHex } from "../lib/Hex.mjs";
import OperationError from "../errors/OperationError.mjs";
import OperationError from "../errors/OperationError.mjs";

/**
* XOR Checksum operation
Expand Down Expand Up @@ -43,7 +43,7 @@ class XORChecksum extends Operation {
run(input, args) {
const blocksize = args[0];


if (!Number.isInteger(blocksize) || blocksize <= 0) {
throw new OperationError("Blocksize must be a positive integer.");
}
Expand Down
40 changes: 39 additions & 1 deletion tests/operations/tests/BLAKE3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,43 @@ TestRegister.addTests([
{ "op": "BLAKE3",
"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"]
}
]
},
]);
Loading