source: project/release/5/ripemd/trunk/tests/ripemd-test.scm @ 35929

Last change on this file since 35929 was 35929, checked in by Kon Lovett, 2 years ago

full test, curr prim

File size: 3.4 KB
Line 
1;;;; ripemd-test.scm  -*- Scheme -*-
2;;;; Kon Lovett, Jul '18
3
4(import test)
5
6(test-begin "Ripemd")
7
8;;;
9
10(import ripemd)
11
12;;
13
14(import message-digest-primitive)
15
16(test-group "Ripemd128 Primitive"
17  (let ((ripemd128 (ripemd128-primitive)))
18    (test-assert (message-digest-primitive? ripemd128))
19    (test 'ripemd128 (message-digest-primitive-name ripemd128))
20    ;FIXME this is an impl detail that shouldn't be tested
21    (test-assert (not (equal? (message-digest-primitive-update ripemd128) (message-digest-primitive-raw-update ripemd128)))) )
22)
23
24(test-group "Ripemd160 Primitive"
25  (let ((ripemd160 (ripemd160-primitive)))
26    (test-assert (message-digest-primitive? ripemd160))
27    (test 'ripemd160 (message-digest-primitive-name ripemd160))
28    ;FIXME this is an impl detail that shouldn't be tested
29    (test-assert (not (equal? (message-digest-primitive-update ripemd160) (message-digest-primitive-raw-update ripemd160)))) )
30)
31
32(import
33  (chicken blob)
34  (srfi 13)
35  message-digest-item
36  message-digest-byte-vector)
37
38(define (ripemd128-digest obj)
39  (message-digest-object (ripemd128-primitive) obj 'hex) )
40
41(define (ripemd160-digest obj)
42  (message-digest-object (ripemd160-primitive) obj 'hex) )
43
44(test-group "128 bits"
45  (test "cdf26213a150dc3ecb610f18f6b38b46" (ripemd128-digest ""))
46  (test "86be7afa339d0fc7cfc785e72f578d33" (ripemd128-digest "a"))
47  (test "c14a12199c66e4ba84636b0f69144c77" (ripemd128-digest "abc"))
48  (test "9e327b3d6e523062afc1132d7df9d1b8" (ripemd128-digest "message digest"))
49  (test "fd2aa607f71dc8f510714922b371834e" (ripemd128-digest "abcdefghijklmnopqrstuvwxyz"))
50  (test "a1aa0689d0fafa2ddc22e88b49133a06" (ripemd128-digest "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))
51  (test "d1e959eb179c911faea4624c60c5c702" (ripemd128-digest "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"))
52  (test "3f45ef194732c2dbb2c4a2c769795fa3" (ripemd128-digest "12345678901234567890123456789012345678901234567890123456789012345678901234567890"))
53)
54
55(test-group "160 bits"
56        ;See http://www.cosic.esat.kuleuven.be/nessie/
57        (test-group "NESSIE Strings"
58                (test "S1.0" "9c1185a5c5e9fc54612808977ee8f548b2258d31" (message-digest-string (ripemd160-primitive) ""))
59                (test "S1.1" "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe" (message-digest-string (ripemd160-primitive) "a"))
60                (test "S1.2" "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc" (message-digest-string (ripemd160-primitive) "abc"))
61                (test "S1.3" "5d0689ef49d2fae572b881b123a85ffa21595f36" (message-digest-string (ripemd160-primitive) "message digest"))
62                (test "S1.4" "f71c27109c692c1b56bbdceb5b9d2865b3708dbc" (message-digest-string (ripemd160-primitive) "abcdefghijklmnopqrstuvwxyz"))
63                (test "S1.5" "12a053384a9c0c88e405a06c27dcf49ada62eb2b" (message-digest-string (ripemd160-primitive) "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))
64                (test "S1.6" "b0e20b6e3116640286ed3a87a5713079b21f5189" (message-digest-string (ripemd160-primitive) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"))
65                (let ((tstr "1234567890"))
66                        (test "S1.7" "9b752e45573d4b39f4dbd3323cab82bf63326bfb" (message-digest-string (ripemd160-primitive) (xsubstring tstr 0 (* 8 (string-length tstr))))) )
67        )
68
69        (test-group "byte-vector"
70                (test "9c1185a5c5e9fc54612808977ee8f548b2258d31" (ripemd160-digest (string->blob "")))
71                (test "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe" (ripemd160-digest (string->blob "a")))
72        )
73)
74
75;;;
76
77(test-end "Ripemd")
78
79(test-exit)
Note: See TracBrowser for help on using the repository browser.