Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
fix sha384 and sha512
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed May 4, 2024
1 parent 3f62bb2 commit 18942a0
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/crypto/sha/sha1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha/sha256.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha/sha384.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/sha/sha384.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha/sha512.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/sha/sha512.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down

0 comments on commit 18942a0

Please sign in to comment.