@@ -215,22 +215,18 @@ module SHA1 =
215215 else k60to79
216216
217217
218- type chan = SHABytes of byte []
219- type sha_instream =
220- { stream: chan ;
218+ type SHAStream =
219+ { stream: byte [];
221220 mutable pos: int ;
222221 mutable eof: bool ; }
223222
224- let rot_left32 x n = ( x <<< n) ||| ( x >>>& ( 32 - n))
223+ let rotLeft32 x n = ( x <<< n) ||| ( x >>>& ( 32 - n))
225224
226- let inline sha_eof sha = sha.eof
227-
228- (* padding and length (in bits!) recorded at end *)
229- let sha_after_eof sha =
225+
226+ // padding and length (in bits!) recorded at end
227+ let shaAfterEof sha =
230228 let n = sha.pos
231- let len =
232- ( match sha.stream with
233- | SHABytes s -> s.Length)
229+ let len = sha.stream.Length
234230 if n = len then 0x80
235231 else
236232 let padded_len = ((( len + 9 + 63 ) / 64 ) * 64 ) - 8
@@ -245,22 +241,21 @@ module SHA1 =
245241 elif ( n &&& 63 ) = 63 then ( sha.eof <- true ; int32 ( int64 len * int64 8 ) &&& 0xff )
246242 else 0x0
247243
248- let sha_read8 sha =
249- let b =
250- match sha.stream with
251- | SHABytes s -> if sha.pos >= s.Length then sha_ after_ eof sha else int32 s.[ sha.pos]
252- sha.pos <- sha.pos + 1 ;
244+ let shaRead8 sha =
245+ let s = sha.stream
246+ let b = if sha.pos >= s.Length then shaAfterEof sha else int32 s.[ sha.pos]
247+ sha.pos <- sha.pos + 1
253248 b
254249
255- let sha_read32 sha =
256- let b0 = sha _ read8 sha
257- let b1 = sha _ read8 sha
258- let b2 = sha _ read8 sha
259- let b3 = sha _ read8 sha
250+ let shaRead32 sha =
251+ let b0 = shaRead8 sha
252+ let b1 = shaRead8 sha
253+ let b2 = shaRead8 sha
254+ let b3 = shaRead8 sha
260255 let res = ( b0 <<< 24 ) ||| ( b1 <<< 16 ) ||| ( b2 <<< 8 ) ||| b3
261256 res
262257
263- let sha1_hash sha =
258+ let sha1Hash sha =
264259 let mutable h0 = 0x67452301
265260 let mutable h1 = 0xEFCDAB89
266261 let mutable h2 = 0x98BADCFE
@@ -272,21 +267,21 @@ module SHA1 =
272267 let mutable d = 0
273268 let mutable e = 0
274269 let w = Array.create 80 0x00
275- while ( not ( sha _ eof sha) ) do
270+ while ( not sha.eof ) do
276271 for i = 0 to 15 do
277- w.[ i] <- sha _ read32 sha
272+ w.[ i] <- shaRead32 sha
278273 for t = 16 to 79 do
279- w.[ t] <- rot _ left32 ( w.[ t-3 ] ^^^ w.[ t-8 ] ^^^ w.[ t-14 ] ^^^ w.[ t-16 ]) 1
274+ w.[ t] <- rotLeft32 ( w.[ t-3 ] ^^^ w.[ t-8 ] ^^^ w.[ t-14 ] ^^^ w.[ t-16 ]) 1
280275 a <- h0
281276 b <- h1
282277 c <- h2
283278 d <- h3
284279 e <- h4
285280 for t = 0 to 79 do
286- let temp = ( rot _ left32 a 5 ) + f( t, b, c, d) + e + w.[ t] + k( t)
281+ let temp = ( rotLeft32 a 5 ) + f( t, b, c, d) + e + w.[ t] + k( t)
287282 e <- d
288283 d <- c
289- c <- rot _ left32 b 30
284+ c <- rotLeft32 b 30
290285 b <- a
291286 a <- temp
292287 h0 <- h0 + a
@@ -297,7 +292,7 @@ module SHA1 =
297292 h0, h1, h2, h3, h4
298293
299294 let sha1HashBytes s =
300- let ( _h0 , _h1 , _h2 , h3 , h4 ) = sha1 _ hash { stream = SHABytes s; pos = 0 ; eof = false } // the result of the SHA algorithm is stored in registers 3 and 4
295+ let ( _h0 , _h1 , _h2 , h3 , h4 ) = sha1Hash { stream = s; pos = 0 ; eof = false } // the result of the SHA algorithm is stored in registers 3 and 4
301296 Array.map byte [| b0 h4; b1 h4; b2 h4; b3 h4; b0 h3; b1 h3; b2 h3; b3 h3; |]
302297
303298
0 commit comments