diff --git a/src/crypto/sha/sha1.test.ts b/src/crypto/sha/sha1.test.ts index 0a5b6e5..106ae2c 100644 --- a/src/crypto/sha/sha1.test.ts +++ b/src/crypto/sha/sha1.test.ts @@ -2,7 +2,7 @@ import { expect, test } from "vitest"; import { sha1 } from "./sha1.js"; test("sha256()", async () => { - const randomValues = crypto.getRandomValues(new Uint8Array(100)); + const randomValues = crypto.getRandomValues(new Uint8Array(200)); for (let i = 0; i < randomValues.byteLength + 1; i++) { const data = randomValues.slice(0, i); const result = sha1(data); diff --git a/src/crypto/sha/sha256.test.ts b/src/crypto/sha/sha256.test.ts index 2363562..4dc3660 100644 --- a/src/crypto/sha/sha256.test.ts +++ b/src/crypto/sha/sha256.test.ts @@ -2,7 +2,7 @@ import { expect, test } from "vitest"; import { sha256 } from "./sha256.js"; test("sha256()", async () => { - const randomValues = crypto.getRandomValues(new Uint8Array(100)); + const randomValues = crypto.getRandomValues(new Uint8Array(200)); for (let i = 0; i < randomValues.byteLength + 1; i++) { const data = randomValues.slice(0, i); const result = sha256(data); diff --git a/src/crypto/sha/sha384.test.ts b/src/crypto/sha/sha384.test.ts index 07f4ec8..90260c5 100644 --- a/src/crypto/sha/sha384.test.ts +++ b/src/crypto/sha/sha384.test.ts @@ -2,7 +2,7 @@ import { expect, test } from "vitest"; import { sha384 } from "./sha384.js"; test("sha384()", async () => { - const randomValues = crypto.getRandomValues(new Uint8Array(100)); + const randomValues = crypto.getRandomValues(new Uint8Array(200)); for (let i = 0; i < randomValues.byteLength + 1; i++) { const data = randomValues.slice(0, i); const result = sha384(data); diff --git a/src/crypto/sha/sha384.ts b/src/crypto/sha/sha384.ts index 80ed7dd..34a16af 100644 --- a/src/crypto/sha/sha384.ts +++ b/src/crypto/sha/sha384.ts @@ -100,11 +100,11 @@ export function sha384(data: Uint8Array): Uint8Array { ]); const l = data.byteLength * 8; - const targetLength = Math.ceil((data.length + 1 + 8) / 128) * 128; + const targetLength = Math.ceil((data.length + 1 + 16) / 128) * 128; const buffer = new Uint8Array(targetLength); buffer[data.length] = 0x80; buffer.set(data); - bigEndian.putUint32(buffer, l, targetLength - 4); + bigEndian.putUint64(buffer, BigInt(l), targetLength - 8); for (let i = 0; i < buffer.length; i += 128) { for (let t = 0; t < 16; t++) { w[t] = diff --git a/src/crypto/sha/sha512.test.ts b/src/crypto/sha/sha512.test.ts index 1431042..d1e5650 100644 --- a/src/crypto/sha/sha512.test.ts +++ b/src/crypto/sha/sha512.test.ts @@ -2,7 +2,7 @@ import { expect, test } from "vitest"; import { sha512 } from "./sha512.js"; test("sha512()", async () => { - const randomValues = crypto.getRandomValues(new Uint8Array(100)); + const randomValues = crypto.getRandomValues(new Uint8Array(200)); for (let i = 0; i < randomValues.byteLength + 1; i++) { const data = randomValues.slice(0, i); const result = sha512(data); diff --git a/src/crypto/sha/sha512.ts b/src/crypto/sha/sha512.ts index 30e9b45..9c54059 100644 --- a/src/crypto/sha/sha512.ts +++ b/src/crypto/sha/sha512.ts @@ -100,11 +100,11 @@ export function sha512(data: Uint8Array): Uint8Array { ]); const l = data.byteLength * 8; - const targetLength = Math.ceil((data.length + 1 + 8) / 128) * 128; + const targetLength = Math.ceil((data.length + 1 + 16) / 128) * 128; const buffer = new Uint8Array(targetLength); buffer[data.length] = 0x80; buffer.set(data); - bigEndian.putUint32(buffer, l, targetLength - 4); + bigEndian.putUint64(buffer, BigInt(l), targetLength - 8); for (let i = 0; i < buffer.length; i += 128) { for (let t = 0; t < 16; t++) { w[t] =