diff --git a/src/core/config/scripts/fixCryptoApiImports.mjs b/src/core/config/scripts/fixCryptoApiImports.mjs index f4b7c76750..008913c4e5 100644 --- a/src/core/config/scripts/fixCryptoApiImports.mjs +++ b/src/core/config/scripts/fixCryptoApiImports.mjs @@ -35,7 +35,7 @@ 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; @@ -43,6 +43,16 @@ function walk(dir) { } ); + // 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"); } diff --git a/src/core/operations/SHA2.mjs b/src/core/operations/SHA2.mjs index 9844070def..52d56a2fc0 100644 --- a/src/core/operations/SHA2.mjs +++ b/src/core/operations/SHA2.mjs @@ -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.

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.

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"; @@ -70,8 +70,8 @@ class SHA2 extends Operation { { name: "Rounds", // For SHA512 variants type: "number", - value: 160, - min: 32 + value: 80, + min: 16 } ]; } diff --git a/tests/operations/tests/Hash.mjs b/tests/operations/tests/Hash.mjs index ba50293446..9bcecdedaf 100644 --- a/tests/operations/tests/Hash.mjs +++ b/tests/operations/tests/Hash.mjs @@ -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!",