This repository was archived by the owner on Jan 20, 2025. It is now read-only.
File tree 6 files changed +8
-8
lines changed
6 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { expect, test } from "vitest";
2
2
import { sha1 } from "./sha1.js" ;
3
3
4
4
test ( "sha256()" , async ( ) => {
5
- const randomValues = crypto . getRandomValues ( new Uint8Array ( 100 ) ) ;
5
+ const randomValues = crypto . getRandomValues ( new Uint8Array ( 200 ) ) ;
6
6
for ( let i = 0 ; i < randomValues . byteLength + 1 ; i ++ ) {
7
7
const data = randomValues . slice ( 0 , i ) ;
8
8
const result = sha1 ( data ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { expect, test } from "vitest";
2
2
import { sha256 } from "./sha256.js" ;
3
3
4
4
test ( "sha256()" , async ( ) => {
5
- const randomValues = crypto . getRandomValues ( new Uint8Array ( 100 ) ) ;
5
+ const randomValues = crypto . getRandomValues ( new Uint8Array ( 200 ) ) ;
6
6
for ( let i = 0 ; i < randomValues . byteLength + 1 ; i ++ ) {
7
7
const data = randomValues . slice ( 0 , i ) ;
8
8
const result = sha256 ( data ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { expect, test } from "vitest";
2
2
import { sha384 } from "./sha384.js" ;
3
3
4
4
test ( "sha384()" , async ( ) => {
5
- const randomValues = crypto . getRandomValues ( new Uint8Array ( 100 ) ) ;
5
+ const randomValues = crypto . getRandomValues ( new Uint8Array ( 200 ) ) ;
6
6
for ( let i = 0 ; i < randomValues . byteLength + 1 ; i ++ ) {
7
7
const data = randomValues . slice ( 0 , i ) ;
8
8
const result = sha384 ( data ) ;
Original file line number Diff line number Diff line change @@ -100,11 +100,11 @@ export function sha384(data: Uint8Array): Uint8Array {
100
100
] ) ;
101
101
102
102
const l = data . byteLength * 8 ;
103
- const targetLength = Math . ceil ( ( data . length + 1 + 8 ) / 128 ) * 128 ;
103
+ const targetLength = Math . ceil ( ( data . length + 1 + 16 ) / 128 ) * 128 ;
104
104
const buffer = new Uint8Array ( targetLength ) ;
105
105
buffer [ data . length ] = 0x80 ;
106
106
buffer . set ( data ) ;
107
- bigEndian . putUint32 ( buffer , l , targetLength - 4 ) ;
107
+ bigEndian . putUint64 ( buffer , BigInt ( l ) , targetLength - 8 ) ;
108
108
for ( let i = 0 ; i < buffer . length ; i += 128 ) {
109
109
for ( let t = 0 ; t < 16 ; t ++ ) {
110
110
w [ t ] =
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { expect, test } from "vitest";
2
2
import { sha512 } from "./sha512.js" ;
3
3
4
4
test ( "sha512()" , async ( ) => {
5
- const randomValues = crypto . getRandomValues ( new Uint8Array ( 100 ) ) ;
5
+ const randomValues = crypto . getRandomValues ( new Uint8Array ( 200 ) ) ;
6
6
for ( let i = 0 ; i < randomValues . byteLength + 1 ; i ++ ) {
7
7
const data = randomValues . slice ( 0 , i ) ;
8
8
const result = sha512 ( data ) ;
Original file line number Diff line number Diff line change @@ -100,11 +100,11 @@ export function sha512(data: Uint8Array): Uint8Array {
100
100
] ) ;
101
101
102
102
const l = data . byteLength * 8 ;
103
- const targetLength = Math . ceil ( ( data . length + 1 + 8 ) / 128 ) * 128 ;
103
+ const targetLength = Math . ceil ( ( data . length + 1 + 16 ) / 128 ) * 128 ;
104
104
const buffer = new Uint8Array ( targetLength ) ;
105
105
buffer [ data . length ] = 0x80 ;
106
106
buffer . set ( data ) ;
107
- bigEndian . putUint32 ( buffer , l , targetLength - 4 ) ;
107
+ bigEndian . putUint64 ( buffer , BigInt ( l ) , targetLength - 8 ) ;
108
108
for ( let i = 0 ; i < buffer . length ; i += 128 ) {
109
109
for ( let t = 0 ; t < 16 ; t ++ ) {
110
110
w [ t ] =
You can’t perform that action at this time.
0 commit comments