]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/sanitizer_common/TestCases/NetBSD/rmd160.cc
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / sanitizer_common / TestCases / NetBSD / rmd160.cc
1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
2
3 #include <assert.h>
4 #include <rmd160.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 void test1() {
10   RMD160_CTX ctx;
11   uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
12   uint8_t digest[RMD160_DIGEST_LENGTH];
13
14   RMD160Init(&ctx);
15   RMD160Update(&ctx, entropy, __arraycount(entropy));
16   RMD160Final(digest, &ctx);
17
18   printf("test1: '");
19   for (size_t i = 0; i < __arraycount(digest); i++)
20     printf("%02x", digest[i]);
21   printf("'\n");
22 }
23
24 void test2() {
25   RMD160_CTX ctx;
26   uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
27   char digest[RMD160_DIGEST_STRING_LENGTH];
28
29   RMD160Init(&ctx);
30   RMD160Update(&ctx, entropy, __arraycount(entropy));
31   char *p = RMD160End(&ctx, digest);
32   assert(p == digest);
33
34   printf("test2: '%s'\n", digest);
35 }
36
37 void test3() {
38   RMD160_CTX ctx;
39   uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
40
41   RMD160Init(&ctx);
42   RMD160Update(&ctx, entropy, __arraycount(entropy));
43   char *p = RMD160End(&ctx, NULL);
44   assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1);
45
46   printf("test3: '%s'\n", p);
47
48   free(p);
49 }
50
51 void test4() {
52   char digest[RMD160_DIGEST_STRING_LENGTH];
53
54   char *p = RMD160File("/etc/fstab", digest);
55   assert(p == digest);
56
57   printf("test4: '%s'\n", p);
58 }
59
60 void test5() {
61   char *p = RMD160File("/etc/fstab", NULL);
62   assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1);
63
64   printf("test5: '%s'\n", p);
65
66   free(p);
67 }
68
69 void test6() {
70   char digest[RMD160_DIGEST_STRING_LENGTH];
71
72   char *p = RMD160FileChunk("/etc/fstab", digest, 10, 20);
73   assert(p == digest);
74
75   printf("test6: '%s'\n", p);
76 }
77
78 void test7() {
79   char *p = RMD160FileChunk("/etc/fstab", NULL, 10, 20);
80   assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1);
81
82   printf("test7: '%s'\n", p);
83
84   free(p);
85 }
86
87 void test8() {
88   uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
89   char digest[RMD160_DIGEST_STRING_LENGTH];
90
91   char *p = RMD160Data(entropy, __arraycount(entropy), digest);
92   assert(p == digest);
93
94   printf("test8: '%s'\n", p);
95 }
96
97 void test9() {
98   uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
99
100   char *p = RMD160Data(entropy, __arraycount(entropy), NULL);
101   assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1);
102
103   printf("test9: '%s'\n", p);
104
105   free(p);
106 }
107
108 int main(void) {
109   printf("RMD160\n");
110
111   test1();
112   test2();
113   test3();
114   test4();
115   test5();
116   test6();
117   test7();
118   test8();
119   test9();
120
121   // CHECK: RMD160
122   // CHECK: test1: '2787e5a006365df6e8e799315b669dc34866783c'
123   // CHECK: test2: '2787e5a006365df6e8e799315b669dc34866783c'
124   // CHECK: test3: '2787e5a006365df6e8e799315b669dc34866783c'
125   // CHECK: test4: '{{.*}}'
126   // CHECK: test5: '{{.*}}'
127   // CHECK: test6: '{{.*}}'
128   // CHECK: test7: '{{.*}}'
129   // CHECK: test8: '2787e5a006365df6e8e799315b669dc34866783c'
130   // CHECK: test9: '2787e5a006365df6e8e799315b669dc34866783c'
131
132   return 0;
133 }