trying to speed up md5
parent
6fd71439d6
commit
2067553f3e
|
@ -4,7 +4,6 @@ USING: kernel io strings sequences namespaces math parser ;
|
|||
: w+ ( int -- int ) + HEX: ffffffff bitand ; inline
|
||||
: nth-int ( string n -- int ) 2 shift dup 4 + rot <slice> le> ; inline
|
||||
: nth-int-be ( string n -- int ) 2 shift dup 4 + rot <slice> be> ; inline
|
||||
: float-sin ( int -- int ) sin abs 4294967296 * >bignum ; inline
|
||||
: update ( num var -- ) [ w+ ] change ; inline
|
||||
|
||||
: update-old-new ( old new -- )
|
||||
|
@ -13,8 +12,8 @@ USING: kernel io strings sequences namespaces math parser ;
|
|||
: calculate-pad-length ( length -- pad-length )
|
||||
dup 56 < 55 119 ? swap - ;
|
||||
|
||||
! pad 0x80 then 00 til 8 bytes left, then 64bit length in bits
|
||||
: preprocess-plaintext ( string big-endian? -- padded-string )
|
||||
#! pad 0x80 then 00 til 8 bytes left, then 64bit length in bits
|
||||
>r >sbuf r> over [
|
||||
HEX: 80 ,
|
||||
dup length HEX: 3f bitand calculate-pad-length 0 <string> %
|
||||
|
|
|
@ -10,6 +10,12 @@ SYMBOL: old-b
|
|||
SYMBOL: old-c
|
||||
SYMBOL: old-d
|
||||
|
||||
: calculate-sin ( int -- int )
|
||||
sin abs 4294967296 * >bignum ; inline
|
||||
|
||||
SYMBOL: md5-sin-table
|
||||
65 [ calculate-sin ] map md5-sin-table set-global
|
||||
|
||||
: initialize-md5 ( -- )
|
||||
HEX: 67452301 dup a set old-a set
|
||||
HEX: efcdab89 dup b set old-b set
|
||||
|
@ -31,7 +37,7 @@ SYMBOL: old-d
|
|||
|
||||
: (ABCD) ( s i x vars result -- )
|
||||
#! bits to shift, input to float-sin, x, func
|
||||
swap >r w+ swap float-sin w+ r> dup first >r swap r> update
|
||||
swap >r w+ swap md5-sin-table get nth w+ r> dup first >r swap r> update
|
||||
dup first get rot 32 bitroll over second get w+ swap first set ;
|
||||
|
||||
: ABCD { a b c d } swap (F) (ABCD) ; inline
|
||||
|
|
Loading…
Reference in New Issue