Merge a08f57cc1574515694c4c71513eb1cb0f90b4e7c into 002ed911b1a39f303b70246ac0ebf455a91c6d0f

This commit is contained in:
Петушков А. 2026-07-07 06:35:35 +01:00 committed by GitHub
commit 6abe8088a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View File

@ -5,6 +5,7 @@
*/ */
import Operation from "../Operation.mjs"; import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import {runHash} from "../lib/Hash.mjs"; import {runHash} from "../lib/Hash.mjs";
/** /**
@ -30,7 +31,7 @@ class Snefru extends Operation {
type: "number", type: "number",
value: 128, value: 128,
min: 32, min: 32,
max: 480, max: 448,
step: 32 step: 32
}, },
{ {
@ -47,8 +48,14 @@ class Snefru extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const size = args[0];
if (!Number.isInteger(size) || size < 32 || size > 448 || size % 32 !== 0) {
throw new OperationError("Size must be a multiple of 32 between 32 and 448");
}
return runHash("snefru", input, { return runHash("snefru", input, {
length: args[0], length: size,
rounds: args[1] rounds: args[1]
}); });
} }

View File

@ -404,6 +404,28 @@ TestRegister.addTests([
} }
] ]
}, },
{
name: "Snefru rejects negative size",
input: "hello",
expectedOutput: "Size must be a multiple of 32 between 32 and 448",
recipeConfig: [
{
"op": "Snefru",
"args": [-32, "8"]
}
]
},
{
name: "Snefru rejects out-of-range size",
input: "hello",
expectedOutput: "Size must be a multiple of 32 between 32 and 448",
recipeConfig: [
{
"op": "Snefru",
"args": [480, "8"]
}
]
},
{ {
name: "SM3 256 64", name: "SM3 256 64",
input: "Hello, World!", input: "Hello, World!",