summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/crypto_test.c31
-rw-r--r--auto_tests/messenger_test.c22
2 files changed, 53 insertions, 0 deletions
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c
index 806ea7b8..95cdefcd 100644
--- a/auto_tests/crypto_test.c
+++ b/auto_tests/crypto_test.c
@@ -246,6 +246,36 @@ START_TEST(test_large_data)
246} 246}
247END_TEST 247END_TEST
248 248
249START_TEST(test_large_data_symmetric)
250{
251 unsigned char k[crypto_secretbox_KEYBYTES];
252
253 unsigned char n[crypto_secretbox_NONCEBYTES];
254
255 unsigned char m1[16 * 16 * 16];
256 unsigned char c1[sizeof(m1) + crypto_box_MACBYTES];
257 unsigned char m1prime[sizeof(m1)];
258
259 int c1len;
260 int m1plen;
261
262 //Generate random messages
263 rand_bytes(m1, sizeof(m1));
264 rand_bytes(n, crypto_box_NONCEBYTES);
265
266 //Generate key
267 new_symmetric_key(k);
268
269 c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1);
270 ck_assert_msg(c1len == sizeof(m1) + crypto_box_MACBYTES, "could not encrypt data");
271
272 m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime);
273
274 ck_assert_msg(m1plen == sizeof(m1), "decrypted text lengths differ");
275 ck_assert_msg(memcmp(m1prime, m1, sizeof(m1)) == 0, "decrypted texts differ");
276}
277END_TEST
278
249#define DEFTESTCASE(NAME) \ 279#define DEFTESTCASE(NAME) \
250 TCase *NAME = tcase_create(#NAME); \ 280 TCase *NAME = tcase_create(#NAME); \
251 tcase_add_test(NAME, test_##NAME); \ 281 tcase_add_test(NAME, test_##NAME); \
@@ -263,6 +293,7 @@ Suite *crypto_suite(void)
263 DEFTESTCASE(fast_known); 293 DEFTESTCASE(fast_known);
264 DEFTESTCASE_SLOW(endtoend, 15); /* waiting up to 15 seconds */ 294 DEFTESTCASE_SLOW(endtoend, 15); /* waiting up to 15 seconds */
265 DEFTESTCASE(large_data); 295 DEFTESTCASE(large_data);
296 DEFTESTCASE(large_data_symmetric);
266 297
267 return s; 298 return s;
268} 299}
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index cfbc4967..5c8e242e 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -310,6 +310,27 @@ START_TEST(test_messenger_state_saveloadsave)
310} 310}
311END_TEST 311END_TEST
312 312
313START_TEST(test_messenger_state_saveload_encrypted)
314{
315 uint8_t addr[FRIEND_ADDRESS_SIZE];
316 getaddress(m, addr);
317 Messenger *m_temp = new_messenger(TOX_ENABLE_IPV6_DEFAULT);
318
319 size_t size = messenger_size_encrypted(m);
320 uint8_t buffer[size];
321 messenger_save_encrypted(m, buffer, "Gentoo", sizeof("Gentoo"));
322
323 ck_assert_msg(messenger_load_encrypted(m_temp, buffer, size, "Ubuntu", sizeof("Ubuntu")) == -1,
324 "Bad password didn't make the function fail.");
325 ck_assert_msg(messenger_load_encrypted(m_temp, buffer, size, "Gentoo", sizeof("Gentoo")) == 0,
326 "Good password didn't make the function succeed.");
327 uint8_t addr1[FRIEND_ADDRESS_SIZE];
328 getaddress(m_temp, addr1);
329 ck_assert_msg(memcmp(addr1, addr, FRIEND_ADDRESS_SIZE) == 0, "Didn't load messenger successfully");
330 kill_messenger(m_temp);
331}
332END_TEST
333
313#define DEFTESTCASE(NAME) \ 334#define DEFTESTCASE(NAME) \
314 TCase *tc_##NAME = tcase_create(#NAME); \ 335 TCase *tc_##NAME = tcase_create(#NAME); \
315 tcase_add_test(tc_##NAME, test_##NAME); \ 336 tcase_add_test(tc_##NAME, test_##NAME); \
@@ -321,6 +342,7 @@ Suite *messenger_suite(void)
321 342
322 DEFTESTCASE(dht_state_saveloadsave); 343 DEFTESTCASE(dht_state_saveloadsave);
323 DEFTESTCASE(messenger_state_saveloadsave); 344 DEFTESTCASE(messenger_state_saveloadsave);
345 DEFTESTCASE(messenger_state_saveload_encrypted);
324 346
325 DEFTESTCASE(getself_name); 347 DEFTESTCASE(getself_name);
326 DEFTESTCASE(m_get_userstatus_size); 348 DEFTESTCASE(m_get_userstatus_size);