Skip to content
Open
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
12 changes: 11 additions & 1 deletion src/core/config/scripts/fixCryptoApiImports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ function walk(dir) {
const content = readFileSync(fullPath, "utf8");

// Add .mjs to imports if not present
const updated = content.replace(
let updated = content.replace(
/from "(\.[^"]*)";/g,
(match, p1) => {
if (p1.endsWith(".mjs")) return match;
return `from "${p1}.mjs";`;
}
);

// Patch sha512.mjs default rounds and loop step logic
if (entry.name === "sha512.mjs") {
updated = updated
.replace("options.rounds = options.rounds || 160;", "options.rounds = options.rounds || 80;")
.replace("for (let i = 0; i < this.options.rounds; i += 2) {", "for (let i = 0; i < this.options.rounds * 2; i += 2) {")
.replace("this.W = new Array(160);", "this.W = new Array(this.options.rounds * 2);")
.replace("options.rounds=160", "options.rounds=80")
.replace("(Must be greater than 32)", "(Must be greater than 16)");
}

if (updated !== content) {
writeFileSync(fullPath, updated, "utf8");
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/operations/SHA2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SHA2 extends Operation {

this.name = "SHA2";
this.module = "Crypto";
this.description = "The SHA-2 (Secure Hash Algorithm 2) hash functions were designed by the NSA. SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA224, SHA256, SHA384, SHA512.<br><br><ul><li>SHA-512 operates on 64-bit words.</li><li>SHA-256 operates on 32-bit words.</li><li>SHA-384 is largely identical to SHA-512 but is truncated to 384 bits.</li><li>SHA-224 is largely identical to SHA-256 but is truncated to 224 bits.</li><li>SHA-512/224 and SHA-512/256 are truncated versions of SHA-512, but the initial values are generated using the method described in Federal Information Processing Standards (FIPS) PUB 180-4.</li></ul> The message digest algorithm for SHA256 variants consists, by default, of 64 rounds, and for SHA512 variants, it is, by default, 160.";
this.description = "The SHA-2 (Secure Hash Algorithm 2) hash functions were designed by the NSA. SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA224, SHA256, SHA384, SHA512.<br><br><ul><li>SHA-512 operates on 64-bit words.</li><li>SHA-256 operates on 32-bit words.</li><li>SHA-384 is largely identical to SHA-512 but is truncated to 384 bits.</li><li>SHA-224 is largely identical to SHA-256 but is truncated to 224 bits.</li><li>SHA-512/224 and SHA-512/256 are truncated versions of SHA-512, but the initial values are generated using the method described in Federal Information Processing Standards (FIPS) PUB 180-4.</li></ul> The message digest algorithm for SHA256 variants consists, by default, of 64 rounds, and for SHA512 variants, it is, by default, 80.";
this.infoURL = "https://wikipedia.org/wiki/SHA-2";
this.inputType = "ArrayBuffer";
this.outputType = "string";
Expand Down Expand Up @@ -70,8 +70,8 @@ class SHA2 extends Operation {
{
name: "Rounds", // For SHA512 variants
type: "number",
value: 160,
min: 32
value: 80,
min: 16
}
];
}
Expand Down
11 changes: 11 additions & 0 deletions tests/operations/tests/Hash.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ TestRegister.addTests([
}
]
},
{
name: "SHA2 512 with 80 rounds",
input: "Hello, World!",
expectedOutput: "374d794a95cdcfd8b35993185fef9ba368f160d8daf432d08ba9f1ed1e5abe6cc69291e0fa2fe0006a52570ef18c19def4e617c33ce52ef0a6e5fbe318cb0387",
recipeConfig: [
{
"op": "SHA2",
"args": ["512", null, 80]
}
]
},
{
name: "SHA2 512/224",
input: "Hello, World!",
Expand Down