Use the RFC2202 test vectors

master
LemonBoy 7 years ago
parent e7fd2b3cc6
commit d7634f2773

@ -5,7 +5,7 @@
(module hmac (module hmac
(hmac hmac-primitive) (hmac hmac-primitive)
(import scheme chicken lolevel srfi-13) (import scheme chicken srfi-13)
(use message-digest-basic message-digest-item message-digest-update-item) (use message-digest-basic message-digest-item message-digest-update-item)
(define (hmac-primitive key digest-primitive) (define (hmac-primitive key digest-primitive)

@ -5,25 +5,30 @@
(use test) (use test)
(use sha1 string-utils hmac) (use sha1 string-utils hmac)
(test-group "HMAC" (test-group "RFC2202 test vectors"
(test "Short Key and Message" (define (testv key msg expected)
"64608bd9aa157cdfbca795bf9a727fc191a50b66" (test "Vector" expected (string->hex ((hmac key (sha1-primitive)) msg))))
(string->hex ((hmac "hi" (sha1-primitive) 64) "food is good")))
(test "Long Key, Short Message" (testv (make-string 20 (integer->char #x0b))
"511387216297726a7947c6006f5be89711662b1f" "Hi There"
(string->hex ((hmac "hi my name is the big bad wolf" (sha1-primitive) 64) "hi"))) "b617318655057264e28bc0b6fb378c8ef146be00")
(testv "Jefe"
(test "Short Key, Long Message (Longer than blocksize)" "what do ya want for nothing?"
"73dc948bab4e0c65b1e5d18ae3694a39a4788bee" "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79")
(string->hex ((hmac "key" (sha1-primitive) 64) "this is a really long message that is going to being run through this hmac test to make sure that it works correctly."))) (testv "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19"
(make-string 50 (integer->char #xcd))
(test "Larger Blocksize" "4c9007f4026250c6bc8414f9bf50c86c2d7235da")
"3dbf833dc1e13c88f0366efaa2ec7d89399c5c1a" (testv (make-string 20 (integer->char #xaa))
(string->hex ((hmac "key key key" (sha1-primitive) 256) "hi what is your name?"))) (make-string 50 (integer->char #xdd))
"125d7342b9ac11cd91a39af48aa17b4f63f175d3")
(test "Smaller Blocksize" (testv (make-string 20 (integer->char #x0c))
"dd9547893c27d1af459601bb571c6da8941ac00c" "Test With Truncation"
(string->hex ((hmac "key key key" (sha1-primitive) 16) "hi what is your name?")))) "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04")
(testv (make-string 80 (integer->char #xaa))
"Test Using Larger Than Block-Size Key - Hash Key First"
"aa4ae5e15272d00e95705637ce8a3b55ed402112")
(testv (make-string 80 (integer->char #xaa))
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
"e8e99d0f45237d786d6bbaa7965c7808bbff1a91"))
(test-exit) (test-exit)
Loading…
Cancel
Save