1 #include <ccan/crypto/ripemd160/ripemd160.h>
2 /* Include the C files directly. */
3 #include <ccan/crypto/ripemd160/ripemd160.c>
4 #include <ccan/tap/tap.h>
13 /* Test vectors from: http://homes.esat.kuleuven.be/~bosselae/ripemd160.html */
14 static struct test tests[] = {
16 { CPU_TO_BE32(0x9c1185a5), CPU_TO_BE32(0xc5e9fc54),
17 CPU_TO_BE32(0x61280897), CPU_TO_BE32(0x7ee8f548),
18 CPU_TO_BE32(0xb2258d31) } },
20 { CPU_TO_BE32(0x8eb208f7), CPU_TO_BE32(0xe05d987a),
21 CPU_TO_BE32(0x9b044a8e), CPU_TO_BE32(0x98c6b087),
22 CPU_TO_BE32(0xf15a0bfc) } },
23 { "message digest", 1,
24 { CPU_TO_BE32(0x5d0689ef), CPU_TO_BE32(0x49d2fae5),
25 CPU_TO_BE32(0x72b881b1), CPU_TO_BE32(0x23a85ffa),
26 CPU_TO_BE32(0x21595f36) } },
27 { "abcdefghijklmnopqrstuvwxyz", 1,
28 { CPU_TO_BE32(0xf71c2710), CPU_TO_BE32(0x9c692c1b),
29 CPU_TO_BE32(0x56bbdceb), CPU_TO_BE32(0x5b9d2865),
30 CPU_TO_BE32(0xb3708dbc) } },
31 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
32 { CPU_TO_BE32(0x12a05338), CPU_TO_BE32(0x4a9c0c88),
33 CPU_TO_BE32(0xe405a06c), CPU_TO_BE32(0x27dcf49a),
34 CPU_TO_BE32(0xda62eb2b) } },
35 { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 1,
36 { CPU_TO_BE32(0xb0e20b6e), CPU_TO_BE32(0x31166402),
37 CPU_TO_BE32(0x86ed3a87), CPU_TO_BE32(0xa5713079),
38 CPU_TO_BE32(0xb21f5189) } },
40 { CPU_TO_BE32(0x9b752e45), CPU_TO_BE32(0x573d4b39),
41 CPU_TO_BE32(0xf4dbd332), CPU_TO_BE32(0x3cab82bf),
42 CPU_TO_BE32(0x63326bfb) } },
44 { CPU_TO_BE32(0x52783243), CPU_TO_BE32(0xc1697bdb),
45 CPU_TO_BE32(0xe16d37f9), CPU_TO_BE32(0x7f68f083),
46 CPU_TO_BE32(0x25dc1528) } }
49 static bool do_test(const struct test *t, bool single)
54 if (t->repetitions != 1)
56 ripemd160(&h, t->test, strlen(t->test));
58 struct ripemd160_ctx ctx = RIPEMD160_INIT;
61 for (i = 0; i < t->repetitions; i++)
62 ripemd160_update(&ctx, t->test, strlen(t->test));
63 ripemd160_done(&ctx, &h);
66 return memcmp(&h.u, t->result, sizeof(t->result)) == 0;
73 /* This is how many tests you plan to run */
74 plan_tests(sizeof(tests) / sizeof(struct test) * 2);
76 for (i = 0; i < sizeof(tests) / sizeof(struct test); i++)
77 ok1(do_test(&tests[i], false));
79 for (i = 0; i < sizeof(tests) / sizeof(struct test); i++)
80 ok1(do_test(&tests[i], true));
82 /* This exits depending on whether all tests passed */