Don't destructively modifiy args.

master
Thomas Hintz 11 years ago
parent d759083e9d
commit a0a1bab4c1

@ -9,11 +9,12 @@
(use message-digest-port)
(define (hmac key digest-primitive #!optional (block-size 64))
(when (> (string-length key) block-size)
(set! key (call-with-output-digest digest-primitive (cut display key <>) 'string)))
(set! key (string-pad-right key block-size (integer->char 0)))
(let ((ipad (string-map (lambda (c) (integer->char (bitwise-xor (char->integer c) #x36))) key))
(opad (string-map (lambda (c) (integer->char (bitwise-xor (char->integer c) #x5c))) key)))
(let ((key_ key))
(when (> (string-length key_) block-size)
(set! key_ (call-with-output-digest digest-primitive (cut display key_ <>) 'string)))
(set! key_ (string-pad-right key_ block-size (integer->char 0)))
(let ((ipad (string-map (lambda (c) (integer->char (bitwise-xor (char->integer c) #x36))) key_))
(opad (string-map (lambda (c) (integer->char (bitwise-xor (char->integer c) #x5c))) key_)))
(lambda (message)
(call-with-output-digest
digest-primitive
@ -24,6 +25,6 @@
(cut display (string-append ipad message) <>)
'string))
<>)
'string))))
'string)))))
)

Loading…
Cancel
Save