@@ -198,15 +198,15 @@ let b3 n = ((n >>> 24) &&& 0xFF)
198198module SHA1 =
199199let inline (>>>&) ( x : int ) ( y : int ) = int32( uint32 x>>> y)
200200let f ( t , b , c , d ) =
201- if t< 20 then ( b&&& c) ||| ((~~~ b) &&& d) else
202- if t< 40 then b^^^ c^^^ delse
203- if t< 60 then ( b&&& c) ||| ( b&&& d) ||| ( c&&& d) else
204- b^^^ c^^^ d
201+ if t< 20 then ( b&&& c) ||| ((~~~ b) &&& d)
202+ elif t< 40 then b^^^ c^^^ d
203+ elif t< 60 then ( b&&& c) ||| ( b&&& d) ||| ( c&&& d)
204+ else b^^^ c^^^ d
205205
206- let k0to19 = 0x5A827999
207- let k20to39 = 0x6ED9EBA1
208- let k40to59 = 0x8F1BBCDC
209- let k60to79 = 0xCA62C1D6
206+ let [<Literal>] k0to19 = 0x5A827999
207+ let [<Literal>] k20to39 = 0x6ED9EBA1
208+ let [<Literal>] k40to59 = 0x8F1BBCDC
209+ let [<Literal>] k60to79 = 0xCA62C1D6
210210
211211let k t =
212212if t< 20 then k0to19
@@ -223,7 +223,7 @@ module SHA1 =
223223
224224let rot_left32 x n = ( x<<< n) ||| ( x>>>& ( 32 - n))
225225
226- let sha_eof sha = sha.eof
226+ letinline sha_eof sha = sha.eof
227227
228228(* padding and length (in bits!) recorded at end*)
229229let sha_after_eof sha =
@@ -260,43 +260,41 @@ module SHA1 =
260260let res = ( b0<<< 24 ) ||| ( b1<<< 16 ) ||| ( b2<<< 8 ) ||| b3
261261 res
262262
263-
264263let sha1_hash sha =
265- let h0 = ref 0x67452301
266- let h1 = ref 0xEFCDAB89
267- let h2 = ref 0x98BADCFE
268- let h3 = ref 0x10325476
269- let h4 = ref 0xC3D2E1F0
270- let a = ref 0
271- let b = ref 0
272- let c = ref 0
273- let d = ref 0
274- let e = ref 0
264+ letmutable h0 = 0x67452301
265+ letmutable h1 = 0xEFCDAB89
266+ letmutable h2 = 0x98BADCFE
267+ letmutable h3 = 0x10325476
268+ letmutable h4 = 0xC3D2E1F0
269+ letmutable a = 0
270+ letmutable b = 0
271+ letmutable c = 0
272+ letmutable d = 0
273+ letmutable e = 0
275274let w = Array.create80 0x00
276275while ( not ( sha_ eof sha)) do
277- for i= 0 to 15 do
278- w.[ i] <- sha_ read32 sha
279- for t= 16 to 79 do
280- w.[ t] <- rot_ left32( w.[ t-3 ] ^^^ w.[ t-8 ] ^^^ w.[ t-14 ] ^^^ w.[ t-16 ]) 1 ;
281- a:= ! h0;
282- b:= ! h1;
283- c:= ! h2;
284- d:= ! h3;
285- e:= ! h4;
286- for t= 0 to 79 do
287- let temp = ( rot_ left32! a5 ) + f( t,! b,! c,! d) + ! e+ w.[ t] + k( t)
288- e:= ! d;
289- d:= ! c;
290- c:= rot_ left32! b30 ;
291- b:= ! a;
292- a:= temp;
293- h0:= ! h0+ ! a;
294- h1:= ! h1+ ! b;
295- h2:= ! h2+ ! c;
296- h3:= ! h3+ ! d;
297- h4:= ! h4+ ! e
298- done ;
299- (! h0,! h1,! h2,! h3,! h4)
276+ for i= 0 to 15 do
277+ w.[ i] <- sha_ read32 sha
278+ for t= 16 to 79 do
279+ w.[ t] <- rot_ left32( w.[ t-3 ] ^^^ w.[ t-8 ] ^^^ w.[ t-14 ] ^^^ w.[ t-16 ]) 1
280+ a<- h0
281+ b<- h1
282+ c<- h2
283+ d<- h3
284+ e<- h4
285+ for t= 0 to 79 do
286+ let temp = ( rot_ left32 a5 ) + f( t, b, c, d) + e+ w.[ t] + k( t)
287+ e<- d
288+ d<- c
289+ c<- rot_ left32 b30
290+ b<- a
291+ a<- temp
292+ h0<- h0+ a
293+ h1<- h1+ b
294+ h2<- h2+ c
295+ h3<- h3+ d
296+ h4<- h4+ e
297+ h0, h1, h2, h3, h4
300298
301299let sha1HashBytes s =
302300let ( _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