/work/auto_tests/crypto_test.c
Line | Count | Source |
1 | | #include <stdint.h> |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | |
5 | | #include "../toxcore/crypto_core.h" |
6 | | #include "../toxcore/net_crypto.h" |
7 | | #include "../toxcore/os_memory.h" |
8 | | #include "../toxcore/os_random.h" |
9 | | #include "check_compat.h" |
10 | | |
11 | | static void rand_bytes(const Random *rng, uint8_t *b, size_t blen) |
12 | 206 | { |
13 | 12.4k | for (size_t i = 0; i < blen; i++) { |
14 | 12.2k | b[i] = random_u08(rng); |
15 | 12.2k | } |
16 | 206 | } |
17 | | |
18 | | // These test vectors are from libsodium's test suite |
19 | | |
20 | | static const uint8_t alicesk[32] = { |
21 | | 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, |
22 | | 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45, |
23 | | 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a, |
24 | | 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a |
25 | | }; |
26 | | |
27 | | static const uint8_t bobpk[32] = { |
28 | | 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, |
29 | | 0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37, |
30 | | 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78, 0x67, 0x4d, |
31 | | 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f |
32 | | }; |
33 | | |
34 | | static const uint8_t test_nonce[24] = { |
35 | | 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73, |
36 | | 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6, |
37 | | 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 |
38 | | }; |
39 | | |
40 | | static const uint8_t test_m[131] = { |
41 | | 0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5, |
42 | | 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b, |
43 | | 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4, |
44 | | 0x4b, 0x66, 0x84, 0x9b, 0x64, 0x24, 0x4f, 0xfc, |
45 | | 0xe5, 0xec, 0xba, 0xaf, 0x33, 0xbd, 0x75, 0x1a, |
46 | | 0x1a, 0xc7, 0x28, 0xd4, 0x5e, 0x6c, 0x61, 0x29, |
47 | | 0x6c, 0xdc, 0x3c, 0x01, 0x23, 0x35, 0x61, 0xf4, |
48 | | 0x1d, 0xb6, 0x6c, 0xce, 0x31, 0x4a, 0xdb, 0x31, |
49 | | 0x0e, 0x3b, 0xe8, 0x25, 0x0c, 0x46, 0xf0, 0x6d, |
50 | | 0xce, 0xea, 0x3a, 0x7f, 0xa1, 0x34, 0x80, 0x57, |
51 | | 0xe2, 0xf6, 0x55, 0x6a, 0xd6, 0xb1, 0x31, 0x8a, |
52 | | 0x02, 0x4a, 0x83, 0x8f, 0x21, 0xaf, 0x1f, 0xde, |
53 | | 0x04, 0x89, 0x77, 0xeb, 0x48, 0xf5, 0x9f, 0xfd, |
54 | | 0x49, 0x24, 0xca, 0x1c, 0x60, 0x90, 0x2e, 0x52, |
55 | | 0xf0, 0xa0, 0x89, 0xbc, 0x76, 0x89, 0x70, 0x40, |
56 | | 0xe0, 0x82, 0xf9, 0x37, 0x76, 0x38, 0x48, 0x64, |
57 | | 0x5e, 0x07, 0x05 |
58 | | }; |
59 | | |
60 | | static const uint8_t test_c[147] = { |
61 | | 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, |
62 | | 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9, |
63 | | 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, |
64 | | 0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, 0x76, 0xce, |
65 | | 0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4, |
66 | | 0x47, 0x6f, 0xb8, 0xc5, 0x31, 0xa1, 0x18, 0x6a, |
67 | | 0xc0, 0xdf, 0xc1, 0x7c, 0x98, 0xdc, 0xe8, 0x7b, |
68 | | 0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72, |
69 | | 0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, 0x8f, 0xe2, |
70 | | 0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38, |
71 | | 0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a, |
72 | | 0xb9, 0x32, 0x16, 0x45, 0x48, 0xe5, 0x26, 0xae, |
73 | | 0x90, 0x22, 0x43, 0x68, 0x51, 0x7a, 0xcf, 0xea, |
74 | | 0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda, |
75 | | 0x99, 0x83, 0x2b, 0x61, 0xca, 0x01, 0xb6, 0xde, |
76 | | 0x56, 0x24, 0x4a, 0x9e, 0x88, 0xd5, 0xf9, 0xb3, |
77 | | 0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6, |
78 | | 0x59, 0x9b, 0x1f, 0x65, 0x4c, 0xb4, 0x5a, 0x74, |
79 | | 0xe3, 0x55, 0xa5 |
80 | | }; |
81 | | |
82 | | static void test_known(void) |
83 | 1 | { |
84 | 1 | const Memory *mem = os_memory(); |
85 | 1 | ck_assert(mem != nullptr); |
86 | | |
87 | 1 | uint8_t c[147]; |
88 | 1 | uint8_t m[131]; |
89 | | |
90 | 1 | ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(uint8_t), |
91 | 1 | "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext"); |
92 | 1 | ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); |
93 | 1 | ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); |
94 | | |
95 | 1 | const uint16_t clen = encrypt_data(mem, bobpk, alicesk, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c); |
96 | | |
97 | 1 | ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector"); |
98 | 1 | ck_assert_msg(clen == sizeof(c) / sizeof(uint8_t), "wrong ciphertext length"); |
99 | | |
100 | 1 | const uint16_t mlen = decrypt_data(mem, bobpk, alicesk, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m); |
101 | | |
102 | 1 | ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector"); |
103 | 1 | ck_assert_msg(mlen == sizeof(m) / sizeof(uint8_t), "wrong plaintext length"); |
104 | 1 | } |
105 | | |
106 | | static void test_fast_known(void) |
107 | 1 | { |
108 | 1 | const Memory *mem = os_memory(); |
109 | 1 | ck_assert(mem != nullptr); |
110 | | |
111 | 1 | uint8_t k[CRYPTO_SHARED_KEY_SIZE]; |
112 | 1 | uint8_t c[147]; |
113 | 1 | uint8_t m[131]; |
114 | | |
115 | 1 | encrypt_precompute(bobpk, alicesk, k); |
116 | | |
117 | 1 | ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(uint8_t), |
118 | 1 | "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext"); |
119 | 1 | ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); |
120 | 1 | ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); |
121 | | |
122 | 1 | const uint16_t clen = encrypt_data_symmetric(mem, k, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c); |
123 | | |
124 | 1 | ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector"); |
125 | 1 | ck_assert_msg(clen == sizeof(c) / sizeof(uint8_t), "wrong ciphertext length"); |
126 | | |
127 | 1 | const uint16_t mlen = decrypt_data_symmetric(mem, k, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m); |
128 | | |
129 | 1 | ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector"); |
130 | 1 | ck_assert_msg(mlen == sizeof(m) / sizeof(uint8_t), "wrong plaintext length"); |
131 | 1 | } |
132 | | |
133 | | static void test_endtoend(void) |
134 | 1 | { |
135 | 1 | const Memory *mem = os_memory(); |
136 | 1 | ck_assert(mem != nullptr); |
137 | 1 | const Random *rng = os_random(); |
138 | 1 | ck_assert(rng != nullptr); |
139 | | |
140 | | // Test 100 random messages and keypairs |
141 | 101 | for (uint8_t testno = 0; testno < 100; testno++) { |
142 | 100 | uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE]; |
143 | 100 | uint8_t sk1[CRYPTO_SECRET_KEY_SIZE]; |
144 | 100 | uint8_t pk2[CRYPTO_PUBLIC_KEY_SIZE]; |
145 | 100 | uint8_t sk2[CRYPTO_SECRET_KEY_SIZE]; |
146 | 100 | uint8_t k1[CRYPTO_SHARED_KEY_SIZE]; |
147 | 100 | uint8_t k2[CRYPTO_SHARED_KEY_SIZE]; |
148 | | |
149 | 100 | uint8_t n[CRYPTO_NONCE_SIZE]; |
150 | | |
151 | 100 | enum { M_SIZE = 50 }; |
152 | 100 | uint8_t m[M_SIZE]; |
153 | 100 | uint8_t c1[sizeof(m) + CRYPTO_MAC_SIZE]; |
154 | 100 | uint8_t c2[sizeof(m) + CRYPTO_MAC_SIZE]; |
155 | 100 | uint8_t c3[sizeof(m) + CRYPTO_MAC_SIZE]; |
156 | 100 | uint8_t c4[sizeof(m) + CRYPTO_MAC_SIZE]; |
157 | 100 | uint8_t m1[sizeof(m)]; |
158 | 100 | uint8_t m2[sizeof(m)]; |
159 | 100 | uint8_t m3[sizeof(m)]; |
160 | 100 | uint8_t m4[sizeof(m)]; |
161 | | |
162 | | //Generate random message (random length from 10 to 50) |
163 | 100 | const uint16_t mlen = (random_u32(rng) % (M_SIZE - 10)) + 10; |
164 | 100 | rand_bytes(rng, m, mlen); |
165 | 100 | rand_bytes(rng, n, CRYPTO_NONCE_SIZE); |
166 | | |
167 | | //Generate keypairs |
168 | 100 | crypto_new_keypair(rng, pk1, sk1); |
169 | 100 | crypto_new_keypair(rng, pk2, sk2); |
170 | | |
171 | | //Precompute shared keys |
172 | 100 | encrypt_precompute(pk2, sk1, k1); |
173 | 100 | encrypt_precompute(pk1, sk2, k2); |
174 | | |
175 | 100 | ck_assert_msg(memcmp(k1, k2, CRYPTO_SHARED_KEY_SIZE) == 0, "encrypt_precompute: bad"); |
176 | | |
177 | | //Encrypt all four ways |
178 | 100 | const uint16_t c1len = encrypt_data(mem, pk2, sk1, n, m, mlen, c1); |
179 | 100 | const uint16_t c2len = encrypt_data(mem, pk1, sk2, n, m, mlen, c2); |
180 | 100 | const uint16_t c3len = encrypt_data_symmetric(mem, k1, n, m, mlen, c3); |
181 | 100 | const uint16_t c4len = encrypt_data_symmetric(mem, k2, n, m, mlen, c4); |
182 | | |
183 | 100 | ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ"); |
184 | 100 | ck_assert_msg(c1len == mlen + (uint16_t)CRYPTO_MAC_SIZE, "wrong cyphertext length"); |
185 | 100 | ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0 |
186 | 100 | && memcmp(c1, c4, c1len) == 0, "crypertexts differ"); |
187 | | |
188 | | //Decrypt all four ways |
189 | 100 | const uint16_t m1len = decrypt_data(mem, pk2, sk1, n, c1, c1len, m1); |
190 | 100 | const uint16_t m2len = decrypt_data(mem, pk1, sk2, n, c1, c1len, m2); |
191 | 100 | const uint16_t m3len = decrypt_data_symmetric(mem, k1, n, c1, c1len, m3); |
192 | 100 | const uint16_t m4len = decrypt_data_symmetric(mem, k2, n, c1, c1len, m4); |
193 | | |
194 | 100 | ck_assert_msg(m1len == m2len && m1len == m3len && m1len == m4len, "decrypted text lengths differ"); |
195 | 100 | ck_assert_msg(m1len == mlen, "wrong decrypted text length"); |
196 | 100 | ck_assert_msg(memcmp(m1, m2, mlen) == 0 && memcmp(m1, m3, mlen) == 0 |
197 | 100 | && memcmp(m1, m4, mlen) == 0, "decrypted texts differ"); |
198 | 100 | ck_assert_msg(memcmp(m1, m, mlen) == 0, "wrong decrypted text"); |
199 | 100 | } |
200 | 1 | } |
201 | | |
202 | | static void test_large_data(void) |
203 | 1 | { |
204 | 1 | const Memory *mem = os_memory(); |
205 | 1 | ck_assert(mem != nullptr); |
206 | 1 | const Random *rng = os_random(); |
207 | 1 | ck_assert(rng != nullptr); |
208 | 1 | uint8_t k[CRYPTO_SHARED_KEY_SIZE]; |
209 | 1 | uint8_t n[CRYPTO_NONCE_SIZE]; |
210 | | |
211 | 1 | const size_t m1_size = MAX_CRYPTO_PACKET_SIZE - CRYPTO_MAC_SIZE; |
212 | 1 | uint8_t *m1 = (uint8_t *)malloc(m1_size); |
213 | 1 | uint8_t *c1 = (uint8_t *)malloc(m1_size + CRYPTO_MAC_SIZE); |
214 | 1 | uint8_t *m1prime = (uint8_t *)malloc(m1_size); |
215 | | |
216 | 1 | const size_t m2_size = MAX_CRYPTO_PACKET_SIZE - CRYPTO_MAC_SIZE; |
217 | 1 | uint8_t *m2 = (uint8_t *)malloc(m2_size); |
218 | 1 | uint8_t *c2 = (uint8_t *)malloc(m2_size + CRYPTO_MAC_SIZE); |
219 | | |
220 | 1 | ck_assert(m1 != nullptr && c1 != nullptr && m1prime != nullptr && m2 != nullptr && c2 != nullptr); |
221 | | |
222 | | //Generate random messages |
223 | 1 | rand_bytes(rng, m1, m1_size); |
224 | 1 | rand_bytes(rng, m2, m2_size); |
225 | 1 | rand_bytes(rng, n, CRYPTO_NONCE_SIZE); |
226 | | |
227 | | //Generate key |
228 | 1 | rand_bytes(rng, k, CRYPTO_SHARED_KEY_SIZE); |
229 | | |
230 | 1 | const uint16_t c1len = encrypt_data_symmetric(mem, k, n, m1, m1_size, c1); |
231 | 1 | const uint16_t c2len = encrypt_data_symmetric(mem, k, n, m2, m2_size, c2); |
232 | | |
233 | 1 | ck_assert_msg(c1len == m1_size + CRYPTO_MAC_SIZE, "could not encrypt"); |
234 | 1 | ck_assert_msg(c2len == m2_size + CRYPTO_MAC_SIZE, "could not encrypt"); |
235 | | |
236 | 1 | const uint16_t m1plen = decrypt_data_symmetric(mem, k, n, c1, c1len, m1prime); |
237 | | |
238 | 1 | ck_assert_msg(m1plen == m1_size, "decrypted text lengths differ"); |
239 | 1 | ck_assert_msg(memcmp(m1prime, m1, m1_size) == 0, "decrypted texts differ"); |
240 | | |
241 | 1 | free(c2); |
242 | 1 | free(m2); |
243 | 1 | free(m1prime); |
244 | 1 | free(c1); |
245 | 1 | free(m1); |
246 | 1 | } |
247 | | |
248 | | static void test_large_data_symmetric(void) |
249 | 1 | { |
250 | 1 | const Memory *mem = os_memory(); |
251 | 1 | ck_assert(mem != nullptr); |
252 | 1 | const Random *rng = os_random(); |
253 | 1 | ck_assert(rng != nullptr); |
254 | 1 | uint8_t k[CRYPTO_SYMMETRIC_KEY_SIZE]; |
255 | | |
256 | 1 | uint8_t n[CRYPTO_NONCE_SIZE]; |
257 | | |
258 | 1 | const size_t m1_size = 16 * 16 * 16; |
259 | 1 | uint8_t *m1 = (uint8_t *)malloc(m1_size); |
260 | 1 | uint8_t *c1 = (uint8_t *)malloc(m1_size + CRYPTO_MAC_SIZE); |
261 | 1 | uint8_t *m1prime = (uint8_t *)malloc(m1_size); |
262 | | |
263 | 1 | ck_assert(m1 != nullptr && c1 != nullptr && m1prime != nullptr); |
264 | | |
265 | | //Generate random messages |
266 | 1 | rand_bytes(rng, m1, m1_size); |
267 | 1 | rand_bytes(rng, n, CRYPTO_NONCE_SIZE); |
268 | | |
269 | | //Generate key |
270 | 1 | new_symmetric_key(rng, k); |
271 | | |
272 | 1 | const uint16_t c1len = encrypt_data_symmetric(mem, k, n, m1, m1_size, c1); |
273 | 1 | ck_assert_msg(c1len == m1_size + CRYPTO_MAC_SIZE, "could not encrypt data"); |
274 | | |
275 | 1 | const uint16_t m1plen = decrypt_data_symmetric(mem, k, n, c1, c1len, m1prime); |
276 | | |
277 | 1 | ck_assert_msg(m1plen == m1_size, "decrypted text lengths differ"); |
278 | 1 | ck_assert_msg(memcmp(m1prime, m1, m1_size) == 0, "decrypted texts differ"); |
279 | | |
280 | 1 | free(m1prime); |
281 | 1 | free(c1); |
282 | 1 | free(m1); |
283 | 1 | } |
284 | | |
285 | | static void test_very_large_data(void) |
286 | 1 | { |
287 | 1 | const Memory *mem = os_memory(); |
288 | 1 | ck_assert(mem != nullptr); |
289 | 1 | const Random *rng = os_random(); |
290 | 1 | ck_assert(rng != nullptr); |
291 | | |
292 | 1 | const uint8_t nonce[CRYPTO_NONCE_SIZE] = {0}; |
293 | 1 | uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE]; |
294 | 1 | uint8_t sk[CRYPTO_SECRET_KEY_SIZE]; |
295 | 1 | crypto_new_keypair(rng, pk, sk); |
296 | | |
297 | | // 100 MiB of data (all zeroes, doesn't matter what's inside). |
298 | 1 | const uint32_t plain_size = 100 * 1024 * 1024; |
299 | 1 | uint8_t *plain = (uint8_t *)malloc(plain_size); |
300 | 1 | uint8_t *encrypted = (uint8_t *)malloc(plain_size + CRYPTO_MAC_SIZE); |
301 | | |
302 | 1 | ck_assert(plain != nullptr); |
303 | 1 | ck_assert(encrypted != nullptr); |
304 | | |
305 | 1 | memset(plain, 0, plain_size); |
306 | | |
307 | 1 | encrypt_data(mem, pk, sk, nonce, plain, plain_size, encrypted); |
308 | | |
309 | 1 | free(encrypted); |
310 | 1 | free(plain); |
311 | 1 | } |
312 | | |
313 | | static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) |
314 | 524k | { |
315 | 524k | uint32_t num1 = 0; |
316 | 524k | memcpy(&num1, nonce + (CRYPTO_NONCE_SIZE - sizeof(num1)), sizeof(num1)); |
317 | 524k | num1 = net_ntohl(num1); |
318 | 524k | uint32_t num2 = num + num1; |
319 | | |
320 | 524k | if (num2 < num1) { |
321 | 131k | for (uint16_t i = CRYPTO_NONCE_SIZE - sizeof(num1); i != 0; --i) { |
322 | 131k | ++nonce[i - 1]; |
323 | | |
324 | 131k | if (nonce[i - 1] != 0) { |
325 | 131k | break; |
326 | 131k | } |
327 | 131k | } |
328 | 131k | } |
329 | | |
330 | 524k | num2 = net_htonl(num2); |
331 | 524k | memcpy(nonce + (CRYPTO_NONCE_SIZE - sizeof(num2)), &num2, sizeof(num2)); |
332 | 524k | } |
333 | | |
334 | | static void test_increment_nonce(void) |
335 | 1 | { |
336 | 1 | const Random *rng = os_random(); |
337 | 1 | ck_assert(rng != nullptr); |
338 | | |
339 | 1 | uint8_t n[CRYPTO_NONCE_SIZE]; |
340 | | |
341 | 25 | for (uint32_t i = 0; i < CRYPTO_NONCE_SIZE; ++i) { |
342 | 24 | n[i] = random_u08(rng); |
343 | 24 | } |
344 | | |
345 | 1 | uint8_t n1[CRYPTO_NONCE_SIZE]; |
346 | | |
347 | 1 | memcpy(n1, n, CRYPTO_NONCE_SIZE); |
348 | | |
349 | 262k | for (uint32_t i = 0; i < (1 << 18); ++i) { |
350 | 262k | increment_nonce_number_cmp(n, 1); |
351 | 262k | increment_nonce(n1); |
352 | 262k | ck_assert_msg(memcmp(n, n1, CRYPTO_NONCE_SIZE) == 0, "Bad increment_nonce function"); |
353 | 262k | } |
354 | | |
355 | 262k | for (uint32_t i = 0; i < (1 << 18); ++i) { |
356 | 262k | const uint32_t r = random_u32(rng); |
357 | 262k | increment_nonce_number_cmp(n, r); |
358 | 262k | increment_nonce_number(n1, r); |
359 | 262k | ck_assert_msg(memcmp(n, n1, CRYPTO_NONCE_SIZE) == 0, "Bad increment_nonce_number function"); |
360 | 262k | } |
361 | 1 | } |
362 | | |
363 | | static void test_memzero(void) |
364 | 1 | { |
365 | 1 | uint8_t src[sizeof(test_c)]; |
366 | 1 | memcpy(src, test_c, sizeof(test_c)); |
367 | | |
368 | 1 | crypto_memzero(src, sizeof(src)); |
369 | | |
370 | 148 | for (size_t i = 0; i < sizeof(src); i++) { |
371 | 147 | ck_assert_msg(src[i] == 0, "Memory is not zeroed"); |
372 | 147 | } |
373 | 1 | } |
374 | | |
375 | | int main(void) |
376 | 84 | { |
377 | 84 | setvbuf(stdout, nullptr, _IONBF, 0); |
378 | | |
379 | 84 | test_known(); |
380 | 84 | test_fast_known(); |
381 | 84 | test_endtoend(); /* waiting up to 15 seconds */ |
382 | 84 | test_large_data(); |
383 | 84 | test_large_data_symmetric(); |
384 | 84 | test_very_large_data(); |
385 | 84 | test_increment_nonce(); |
386 | 84 | test_memzero(); |
387 | | |
388 | 84 | return 0; |
389 | 84 | } |