]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/checksums/hmac/hmac.factor
factor: trim using lists
[factor.git] / basis / checksums / hmac / hmac.factor
old mode 100755 (executable)
new mode 100644 (file)
index 9ec7824..2dcae86
@@ -1,30 +1,28 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays checksums combinators fry io io.binary
-io.encodings.binary io.files io.streams.byte-array kernel
-locals math math.vectors memoize sequences ;
+USING: accessors arrays checksums io.encodings.binary
+io.files io.streams.byte-array kernel math math.vectors
+sequences ;
 IN: checksums.hmac
 
 <PRIVATE
 
-: seq-bitxor ( seq seq -- seq ) [ bitxor ] 2map ;
+: opad ( checksum-state -- seq ) block-size>> 0x5c <array> ;
 
-: opad ( checksum-state -- seq ) block-size>> HEX: 5c <array> ;
-
-: ipad ( checksum-state -- seq ) block-size>> HEX: 36 <array> ;
+: ipad ( checksum-state -- seq ) block-size>> 0x36 <array> ;
 
 :: init-key ( checksum key checksum-state -- o i )
     checksum-state block-size>> key length <
     [ key checksum checksum-bytes ] [ key ] if
-    checksum-state block-size>> 0 pad-tail 
-    [ checksum-state opad seq-bitxor ]
-    [ checksum-state ipad seq-bitxor ] bi ;
+    checksum-state block-size>> 0 pad-tail
+    [ checksum-state opad vbitxor ]
+    [ checksum-state ipad vbitxor ] bi ;
 
 PRIVATE>
 
 :: hmac-stream ( stream key checksum -- value )
     checksum initialize-checksum-state :> checksum-state
-    checksum key checksum-state init-key :> Ki :> Ko
+    checksum key checksum-state init-key :> ( Ko Ki )
     checksum-state Ki add-checksum-bytes
     stream add-checksum-stream get-checksum
     checksum initialize-checksum-state