11 Commits
1 ... 7.0.1

5 changed files with 32 additions and 18 deletions

View File

@@ -5,9 +5,9 @@
(
(license "BSD")
(category cryptography)
(category crypt)
(needs message-digest-port srfi-4-utils)
(needs message-digest)
(test-depends test sha1 string-utils)

View File

@@ -1,4 +1,10 @@
(repo git "git://example.com/{egg-name}.git") ; optional
(repo git "git://github.com/ThomasHintz/chicken-scheme-{egg-name}.git") ; optional
(uri targz "http://example.com/{egg-name}/releases/{egg-name}-{egg-release}.tar.gz")
(uri targz "https://github.com/ThomasHintz/chicken-scheme-{egg-name}/tarball/{egg-release}")
(release "1")
(release "2")
(release "3")
(release "4")
(release "6")
(release "7")
(release "7.0.1")

View File

@@ -6,17 +6,25 @@
(hmac)
(import scheme chicken srfi-4 srfi-13)
(use srfi-4-utils message-digest-port)
(use message-digest-port)
; taken from example at http://wiki.call-cc.org/drupal-xml-rpc
(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)))
(set! key (blob->u8vector (string->blob key)))
(let ((ipad (blob->string (u8vector->blob (u8vector-map (lambda (v) (bitwise-xor v #x36)) key))))
(opad (blob->string (u8vector->blob (u8vector-map (lambda (v) (bitwise-xor v #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 (cut display (string-append opad (call-with-output-digest digest-primitive (cut display (string-append ipad message) <>) 'string)) <>) 'string))))
(call-with-output-digest
digest-primitive
(cut display
(string-append opad
(call-with-output-digest
digest-primitive
(cut display (string-append ipad message) <>)
'string))
<>)
'string)))))
)

View File

@@ -11,5 +11,5 @@
; Files to install for your extension:
'("hmac.o" "hmac.so" "hmac.import.so")
; Assoc list with properties for your extension:
'((version 1)
'((version 7.0.1)
(static "hmac.o"))) ;; for static linking

View File

@@ -3,7 +3,7 @@
; license: bsd
(use test)
(use sha1 string-utils)
(use sha1 string-utils hmac)
(test-group "HMAC"
(test "Short Key and Message"