]> git.ozlabs.org Git - ccan/blob - ccan/crypto/ripemd160/test/run-types.c
crypto/ripemd160: new module.
[ccan] / ccan / crypto / ripemd160 / test / run-types.c
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>
5
6 static unsigned char arr[] = {
7         0x12,
8 #if HAVE_BIG_ENDIAN
9         /* u16 */
10         0x12, 0x34,
11         /* u32 */
12         0x12, 0x34, 0x56, 0x78,
13         /* u64 */
14         0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
15 #else
16         /* u16 */
17         0x34, 0x12,
18         /* u32 */
19         0x78, 0x56, 0x34, 0x12,
20         /* u64 */
21         0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
22 #endif
23         /* le16 */
24         0x34, 0x12,
25         /* le32 */
26         0x78, 0x56, 0x34, 0x12,
27         /* le64 */
28         0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
29         /* be16 */
30         0x12, 0x34,
31         /* be32 */
32         0x12, 0x34, 0x56, 0x78,
33         /* be64 */
34         0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
35 };
36
37 int main(void)
38 {
39         struct ripemd160 h, expected;
40         struct ripemd160_ctx ctx;
41
42         /* This is how many tests you plan to run */
43         plan_tests(1);
44
45         ripemd160_init(&ctx);
46         ripemd160_u8(&ctx, 0x12);
47         ripemd160_u16(&ctx, 0x1234);
48         ripemd160_u32(&ctx, 0x12345678);
49         ripemd160_u64(&ctx, 0x123456789abcdef0ULL);
50         ripemd160_le16(&ctx, 0x1234);
51         ripemd160_le32(&ctx, 0x12345678);
52         ripemd160_le64(&ctx, 0x123456789abcdef0ULL);
53         ripemd160_be16(&ctx, 0x1234);
54         ripemd160_be32(&ctx, 0x12345678);
55         ripemd160_be64(&ctx, 0x123456789abcdef0ULL);
56         ripemd160_done(&ctx, &h);
57
58         ripemd160(&expected, arr, sizeof(arr));
59         ok1(memcmp(&h, &expected, sizeof(h)) == 0);
60
61         /* This exits depending on whether all tests passed */
62         return exit_status();
63 }