1
1
import { o1jsHash , nodeHash , generateRandomInput } from './test-utils' ;
2
2
import { bytesToHex , concatBytes } from '@noble/hashes/utils' ;
3
3
import { sha256 as nobleHashUint } from '@noble/hashes/sha256' ;
4
- import { sha256O1js , SHA256 } from './sha256' ;
4
+ import { sha256O1js } from './sha256' ;
5
+ import { SHA256 } from './sha256-class' ;
5
6
import * as crypto from 'crypto' ;
6
7
import { Bytes } from 'o1js' ;
7
8
@@ -130,7 +131,7 @@ describe('Testing o1js SHA256 hash function against to node-js implementation',
130
131
}
131
132
} ) ;
132
133
133
- // !This test takes an extremely long time to finish
134
+ // !This test takes extremely long time to finish
134
135
test . skip ( 'should have passing sliding window tests - 4096' , ( ) => {
135
136
const testWindow4096 = new Array < string > ( 4096 ) ;
136
137
for ( let i = 0 ; i < testWindow4096 . length ; i ++ )
@@ -142,12 +143,12 @@ describe('Testing o1js SHA256 hash function against to node-js implementation',
142
143
}
143
144
} ) ;
144
145
145
- // ===============================================================
146
-
147
- // This test aims to destruct an input into seperate 32-bit blocks and then compare the digest of the full input against recursive updates of the 32-bit blocks
148
- // It has the same concept of the sliding window test but on sequential update of destruced message blocks.
149
- //TODO: This test requires update method for the hash function.
150
- test . only ( 'should pass sliding window tests - 3/256' , ( ) => {
146
+ /*
147
+ This test aims to destruct an input into seperate 32-bit blocks and then compare the digest of the full input against recursive updates of the 32-bit blocks
148
+ It has the same concept of the sliding window test 4096 but on sequential update of destruced message blocks.
149
+ ! This test takes around 1.5 hours to finish
150
+ */
151
+ test . skip ( 'should pass sliding window tests - 3/256' , ( ) => {
151
152
let BUF_768 = new Uint8Array ( 256 * 3 ) ;
152
153
153
154
// Fill with random data
@@ -167,46 +168,9 @@ describe('Testing o1js SHA256 hash function against to node-js implementation',
167
168
let b3Bytes = Bytes . from ( b3 ) ;
168
169
169
170
expect ( concatBytes ( b1 , b2 , b3 ) ) . toStrictEqual ( BUF_768 ) ;
170
- // expect(nobleHashUint.create().update(b1).update(b2).update(b3).digest()).toStrictEqual(fnH);
171
- expect ( new SHA256 ( ) . update ( b1Bytes ) . update ( b2Bytes ) . digest ( ) . toHex ( ) )
172
- . toEqual ( bytesToHex ( nobleHashUint . create ( ) . update ( b1 ) . update ( b2 ) . digest ( ) ) )
173
- // expect(new SHA256().update(b1Bytes).update(b2Bytes).update(b3Bytes).digest().toHex()).toStrictEqual(digest768.toHex());
171
+ expect ( new SHA256 ( ) . update ( b1Bytes ) . update ( b2Bytes ) . update ( b3Bytes ) . digest ( ) . toHex ( ) )
172
+ . toEqual ( digest768 . toHex ( ) ) ;
174
173
}
175
174
}
176
175
} ) ;
177
-
178
- // ===============================================================
179
- let BUF_768 = new Uint8Array ( 256 * 3 ) ;
180
- // Fill with random data
181
- for ( let i = 0 ; i < ( 256 * 3 ) / 32 ; i ++ )
182
- BUF_768 . set ( crypto . createHash ( 'sha256' ) . update ( new Uint8Array ( i ) ) . digest ( ) , i * 32 ) ;
183
- // ===============================================================
184
-
185
- test . skip ( `Partial: sha256` , ( ) => {
186
- const fnH = nobleHashUint ( BUF_768 ) ;
187
- for ( let i = 0 ; i < 256 ; i ++ ) {
188
- let b1 = BUF_768 . subarray ( 0 , i ) ;
189
- for ( let j = 0 ; j < 256 ; j ++ ) {
190
- let b2 = BUF_768 . subarray ( i , i + j ) ;
191
- let b3 = BUF_768 . subarray ( i + j ) ;
192
- expect ( concatBytes ( b1 , b2 , b3 ) ) . toStrictEqual ( BUF_768 ) ;
193
- expect ( nobleHashUint . create ( ) . update ( b1 ) . update ( b2 ) . update ( b3 ) . digest ( ) ) . toStrictEqual ( fnH ) ;
194
- }
195
- }
196
- } ) ;
197
-
198
- // Same as before, but creates copy of each slice, which changes dataoffset of typed array
199
- // Catched bug in blake2
200
- test . skip ( `Partial (copy): sha256 partial` , ( ) => {
201
- const fnH = nobleHashUint ( BUF_768 ) ;
202
- for ( let i = 0 ; i < 256 ; i ++ ) {
203
- let b1 = BUF_768 . subarray ( 0 , i ) . slice ( ) ;
204
- for ( let j = 0 ; j < 256 ; j ++ ) {
205
- let b2 = BUF_768 . subarray ( i , i + j ) . slice ( ) ;
206
- let b3 = BUF_768 . subarray ( i + j ) . slice ( ) ;
207
- expect ( concatBytes ( b1 , b2 , b3 ) ) . toStrictEqual ( BUF_768 ) ;
208
- expect ( nobleHashUint . create ( ) . update ( b1 ) . update ( b2 ) . update ( b3 ) . digest ( ) ) . toStrictEqual ( fnH ) ;
209
- }
210
- }
211
- } ) ;
212
176
} ) ;
0 commit comments