Mercurial > dropbear
comparison libtomcrypt/tests/multi_test.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
2 * | |
3 * LibTomCrypt is a library that provides various cryptographic | |
4 * algorithms in a highly modular and flexible manner. | |
5 * | |
6 * The library is free for all purposes without any express | |
7 * guarantee it works. | |
8 */ | |
9 /* test the multi helpers... */ | |
10 #include <tomcrypt_test.h> | |
11 | |
12 int multi_test(void) | |
13 { | |
14 unsigned char key[32] = { 0 }; | |
15 unsigned char buf[2][MAXBLOCKSIZE]; | |
16 unsigned long len, len2; | |
17 | |
18 /* register algos */ | |
19 register_hash(&sha256_desc); | |
20 register_cipher(&aes_desc); | |
21 | |
22 /* HASH testing */ | |
23 len = sizeof(buf[0]); | |
24 hash_memory(find_hash("sha256"), (unsigned char*)"hello", 5, buf[0], &len); | |
25 len2 = sizeof(buf[0]); | |
26 hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"hello", 5, NULL); | |
27 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
28 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
29 return CRYPT_FAIL_TESTVECTOR; | |
30 } | |
31 len2 = sizeof(buf[0]); | |
32 hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL, 0); | |
33 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
34 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
35 return CRYPT_FAIL_TESTVECTOR; | |
36 } | |
37 len2 = sizeof(buf[0]); | |
38 hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); | |
39 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
40 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
41 return CRYPT_FAIL_TESTVECTOR; | |
42 } | |
43 | |
44 #ifdef LTC_HMAC | |
45 len = sizeof(buf[0]); | |
46 hmac_memory(find_hash("sha256"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); | |
47 len2 = sizeof(buf[0]); | |
48 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL); | |
49 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
50 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
51 return CRYPT_FAIL_TESTVECTOR; | |
52 } | |
53 len2 = sizeof(buf[0]); | |
54 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); | |
55 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
56 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
57 return CRYPT_FAIL_TESTVECTOR; | |
58 } | |
59 len2 = sizeof(buf[0]); | |
60 hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); | |
61 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
62 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
63 return CRYPT_FAIL_TESTVECTOR; | |
64 } | |
65 #endif | |
66 | |
67 #ifdef LTC_OMAC | |
68 len = sizeof(buf[0]); | |
69 omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); | |
70 len2 = sizeof(buf[0]); | |
71 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL); | |
72 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
73 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
74 return CRYPT_FAIL_TESTVECTOR; | |
75 } | |
76 len2 = sizeof(buf[0]); | |
77 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); | |
78 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
79 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
80 return CRYPT_FAIL_TESTVECTOR; | |
81 } | |
82 len2 = sizeof(buf[0]); | |
83 omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); | |
84 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
85 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
86 return CRYPT_FAIL_TESTVECTOR; | |
87 } | |
88 #endif | |
89 | |
90 #ifdef LTC_PMAC | |
91 len = sizeof(buf[0]); | |
92 pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); | |
93 len2 = sizeof(buf[0]); | |
94 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL); | |
95 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
96 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
97 return CRYPT_FAIL_TESTVECTOR; | |
98 } | |
99 len2 = sizeof(buf[0]); | |
100 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); | |
101 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
102 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
103 return CRYPT_FAIL_TESTVECTOR; | |
104 } | |
105 len2 = sizeof(buf[0]); | |
106 pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); | |
107 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
108 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
109 return CRYPT_FAIL_TESTVECTOR; | |
110 } | |
111 #endif | |
112 | |
113 #ifdef LTC_XCBC | |
114 len = sizeof(buf[0]); | |
115 xcbc_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); | |
116 len2 = sizeof(buf[0]); | |
117 xcbc_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL); | |
118 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
119 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
120 return CRYPT_FAIL_TESTVECTOR; | |
121 } | |
122 len2 = sizeof(buf[0]); | |
123 xcbc_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); | |
124 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
125 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
126 return CRYPT_FAIL_TESTVECTOR; | |
127 } | |
128 len2 = sizeof(buf[0]); | |
129 xcbc_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); | |
130 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
131 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
132 return CRYPT_FAIL_TESTVECTOR; | |
133 } | |
134 #endif | |
135 | |
136 #ifdef LTC_F9 | |
137 len = sizeof(buf[0]); | |
138 f9_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len); | |
139 len2 = sizeof(buf[0]); | |
140 f9_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL); | |
141 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
142 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
143 return CRYPT_FAIL_TESTVECTOR; | |
144 } | |
145 len2 = sizeof(buf[0]); | |
146 f9_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); | |
147 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
148 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
149 return CRYPT_FAIL_TESTVECTOR; | |
150 } | |
151 len2 = sizeof(buf[0]); | |
152 f9_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); | |
153 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
154 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
155 return CRYPT_FAIL_TESTVECTOR; | |
156 } | |
157 #endif | |
158 | |
159 #ifdef LTC_PELICAN | |
160 /* TODO: there is no pelican_memory_multi(..) */ | |
161 #endif | |
162 | |
163 #ifdef LTC_POLY1305 | |
164 len = sizeof(buf[0]); | |
165 poly1305_memory(key, 32, (unsigned char*)"hello", 5, buf[0], &len); | |
166 len2 = sizeof(buf[0]); | |
167 poly1305_memory_multi(key, 32, buf[1], &len2, (unsigned char*)"hello", 5, NULL); | |
168 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
169 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
170 return CRYPT_FAIL_TESTVECTOR; | |
171 } | |
172 len2 = sizeof(buf[0]); | |
173 poly1305_memory_multi(key, 32, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); | |
174 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
175 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
176 return CRYPT_FAIL_TESTVECTOR; | |
177 } | |
178 len2 = sizeof(buf[0]); | |
179 poly1305_memory_multi(key, 32, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); | |
180 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
181 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
182 return CRYPT_FAIL_TESTVECTOR; | |
183 } | |
184 #endif | |
185 | |
186 #ifdef LTC_BLAKE2SMAC | |
187 len = 32; | |
188 blake2smac_memory(key, 16, (unsigned char*)"hello", 5, buf[0], &len); | |
189 len2 = 32; | |
190 blake2smac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL); | |
191 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
192 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
193 return CRYPT_FAIL_TESTVECTOR; | |
194 } | |
195 len2 = 32; | |
196 blake2smac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); | |
197 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
198 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
199 return CRYPT_FAIL_TESTVECTOR; | |
200 } | |
201 len2 = 32; | |
202 blake2smac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); | |
203 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
204 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
205 return CRYPT_FAIL_TESTVECTOR; | |
206 } | |
207 #endif | |
208 | |
209 #ifdef LTC_BLAKE2BMAC | |
210 len = 64; | |
211 blake2bmac_memory(key, 16, (unsigned char*)"hello", 5, buf[0], &len); | |
212 len2 = 64; | |
213 blake2bmac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL); | |
214 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
215 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
216 return CRYPT_FAIL_TESTVECTOR; | |
217 } | |
218 len2 = 64; | |
219 blake2bmac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL); | |
220 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
221 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
222 return CRYPT_FAIL_TESTVECTOR; | |
223 } | |
224 len2 = 64; | |
225 blake2bmac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL); | |
226 if (len != len2 || memcmp(buf[0], buf[1], len)) { | |
227 printf("Failed: %d %lu %lu\n", __LINE__, len, len2); | |
228 return CRYPT_FAIL_TESTVECTOR; | |
229 } | |
230 #endif | |
231 | |
232 return CRYPT_OK; | |
233 } | |
234 | |
235 /* ref: $Format:%D$ */ | |
236 /* git commit: $Format:%H$ */ | |
237 /* commit time: $Format:%ai$ */ |