Don't destructively modifiy args.

master
Thomas Hintz 11 years ago
parent d759083e9d
commit a0a1bab4c1

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

Loading…
Cancel
Save