Don't destructively modifiy args.
This commit is contained in:
27
hmac.scm
27
hmac.scm
@@ -9,21 +9,22 @@
|
|||||||
(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_))
|
||||||
(lambda (message)
|
(opad (string-map (lambda (c) (integer->char (bitwise-xor (char->integer c) #x5c))) key_)))
|
||||||
(call-with-output-digest
|
(lambda (message)
|
||||||
digest-primitive
|
(call-with-output-digest
|
||||||
(cut display
|
digest-primitive
|
||||||
(string-append opad
|
(cut display
|
||||||
(call-with-output-digest
|
(string-append opad
|
||||||
|
(call-with-output-digest
|
||||||
digest-primitive
|
digest-primitive
|
||||||
(cut display (string-append ipad message) <>)
|
(cut display (string-append ipad message) <>)
|
||||||
'string))
|
'string))
|
||||||
<>)
|
<>)
|
||||||
'string))))
|
'string)))))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user