;;;; tiger-hash-test.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 (import test) (test-begin "Tiger Hash") ;;; (import tiger-hash) (import (only (srfi 13) xsubstring)) (import message-digest-byte-vector message-digest-primitive) ;; (test-group "Tiger192 Primitive" (let ((tiger192 (tiger192-primitive))) (test-assert (message-digest-primitive? tiger192)) (test 'tiger192 (message-digest-primitive-name tiger192)) ;FIXME this is an impl detail that shouldn't be tested (test-assert (not (equal? (message-digest-primitive-update tiger192) (message-digest-primitive-raw-update tiger192)))) ) ) ;; ;See http://www.cosic.esat.kuleuven.be/nessie/ (test-group "NESSIE Strings" (test "S1.0" "3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3" (message-digest-string (tiger192-primitive) "")) (test "S1.1" "77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809" (message-digest-string (tiger192-primitive) "a")) (test "S1.2" "2aab1484e8c158f2bfb8c5ff41b57a525129131c957b5f93" (message-digest-string (tiger192-primitive) "abc")) (test "S1.3" "d981f8cb78201a950dcf3048751e441c517fca1aa55a29f6" (message-digest-string (tiger192-primitive) "message digest")) (test "S1.4" "1714a472eee57d30040412bfcc55032a0b11602ff37beee9" (message-digest-string (tiger192-primitive) "abcdefghijklmnopqrstuvwxyz")) (test "S1.5" "0f7bf9a19b9c58f2b7610df7e84f0ac3a71c631e7b53f78e" (message-digest-string (tiger192-primitive) "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")) (test "S1.6" "8dcea680a17583ee502ba38a3c368651890ffbccdc49a8cc" (message-digest-string (tiger192-primitive) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")) (let ((tstr "1234567890")) (test "S1.7" "1c14795529fd9f207a958f84c52f11e887fa0cabdfd91bfd" (message-digest-string (tiger192-primitive) (xsubstring tstr 0 (* 8 (string-length tstr))))) ) ) (test-group "Any Old Strings" (test "S0.1" "6d12a41e72e644f017b6f0e2f7b44c6285f06dd5d2c5b075" (message-digest-string (tiger192-primitive) "The quick brown fox jumps over the lazy dog")) (test "S0.2" "a8f04b0f7201a0d728101c9d26525b31764a3493fcd8458f" (message-digest-string (tiger192-primitive) "The quick brown fox jumps over the lazy cog")) ;(test "S1" "24f0130c63ac933216166e76b1bb925ff373de2d49584e7a" (message-digest-string (tiger192-primitive) "")) ;(test "S2" "f258c1e88414ab2a527ab541ffc5b8bf935f7b951c132951" (message-digest-string (tiger192-primitive) "abc")) ;(test "S3" "9f00f599072300dd276abb38c8eb6dec37790c116f9d2bdf" (message-digest-string (tiger192-primitive) "Tiger")) ;(test "S4" "87fb2a9083851cf7470d2cf810e6df9eb586445034a5a386" (message-digest-string (tiger192-primitive) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-")) ;(test "S5" "467db80863ebce488df1cd1261655de957896565975f9197" (message-digest-string (tiger192-primitive) "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789")) ;(test "S6" "0c410a042968868a1671da5a3fd29a725ec1e457d3cdb303" (message-digest-string (tiger192-primitive) "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham")) ;(test "S7" "00b83eb4e53440c576ac6aaee0a7485825fd15e70a59ffe4" (message-digest-string (tiger192-primitive) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-")) ) ;; #| ;when interested (import (chicken irregex) (chicken io)) (define (decode-nessie-format nam msg hsh) `((,(irregex-match-substring nam 1) . ,(irregex-match-substring nam 2)) ,(irregex-match-substring msg 1) ,(irregex-match-substring hsh 1)) ) (define (read-line-match rx port) (let ((lin (read-line port))) (and (not (eof-object? lin)) (and-let* ((mch (irregex-match rx lin))) mch)) ) ) (define nam-patt (irregex '(: bos (* space) "Set" (+ space) ($ (+ num)) #\, (+ space) "vector#" (* space) ($ (+ num)) #\: eos))) (define msg-patt (irregex '(: bos (* space) "message=" ($ (* any)) eos))) (define hsh-patt (irregex '(: bos (* space) "hash=" ($ (+ xdigit)) eos))) (define test-data (let ((dat (open-input-file "test-vectors-nessie-format.dat"))) (let loop ((ls '())) (if (eof-object? (peek-char dat)) (begin (close-input-port dat) ls) (let ((nam (read-line-match nam-patt dat))) (if (not nam) (loop ls) (let* ((msg (read-line-match msg-patt dat)) (hsh (read-line-match hsh-patt dat)) ) (if (not (and nam msg hsh)) (loop ls) (loop (cons (decode-nessie-format nam msg hsh) ls)) ) ) ) ) ) ) ) ) (let () (import (chicken pretty-print)) (pp test-data) ) |# ;;; (test-end "Tiger Hash") (test-exit)