diff options
author | dubslow <bunslow@gmail.com> | 2014-10-17 09:19:27 -0500 |
---|---|---|
committer | dubslow <bunslow@gmail.com> | 2014-10-17 09:23:21 -0500 |
commit | ff1d4faa744138946d12f98d21fcc10f33db10bd (patch) | |
tree | 93faf62d44ff27a462df29006de9f52ef59ce1ef /auto_tests/encryptsave_test.c | |
parent | ca38ee8bc75e2792d8e44c48f96f86925a76ad84 (diff) |
add new test cases, cleanup astray printf
Diffstat (limited to 'auto_tests/encryptsave_test.c')
-rw-r--r-- | auto_tests/encryptsave_test.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index b335cbe1..85952392 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -116,12 +116,45 @@ START_TEST(test_save_friend) | |||
116 | } | 116 | } |
117 | END_TEST | 117 | END_TEST |
118 | 118 | ||
119 | START_TEST(test_keys) | ||
120 | { | ||
121 | uint8_t key[tox_pass_key_length()]; | ||
122 | tox_derive_key_from_pass("123qweasdzxc", 12, key); | ||
123 | uint8_t* string = "No Patrick, mayonnaise is not an instrument."; // 44 | ||
124 | |||
125 | uint8_t encrypted[44+tox_pass_encryption_extra_length()]; | ||
126 | int sz = tox_pass_key_encrypt(string, 44, key, encrypted); | ||
127 | |||
128 | uint8_t encrypted2[44+tox_pass_encryption_extra_length()]; | ||
129 | int sz2 = tox_pass_encrypt(string, 44, "123qweasdzxc", 12, encrypted2); | ||
130 | |||
131 | ck_assert_msg(sz == sz2, "an encryption failed"); | ||
132 | |||
133 | uint8_t out1[44+tox_pass_encryption_extra_length()]; | ||
134 | uint8_t out2[44+tox_pass_encryption_extra_length()]; | ||
135 | |||
136 | sz = tox_pass_key_decrypt(encrypted, 44+tox_pass_encryption_extra_length(), key, out1); | ||
137 | ck_assert_msg(sz == 44, "sz isn't right"); | ||
138 | ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 1 failed"); | ||
139 | |||
140 | sz2 = tox_pass_decrypt(encrypted2, 44+tox_pass_encryption_extra_length(), "123qweasdzxc", 12, out2); | ||
141 | ck_assert_msg(sz2 == 44, "sz2 isn't right"); | ||
142 | ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed"); | ||
143 | |||
144 | // test that pass_decrypt can decrypt things from pass_key_encrypt | ||
145 | sz = tox_pass_decrypt(encrypted, 44+tox_pass_encryption_extra_length(), "123qweasdzxc", 12, out1); | ||
146 | ck_assert_msg(sz == 44, "sz isn't right"); | ||
147 | ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed"); | ||
148 | } | ||
149 | END_TEST | ||
150 | |||
119 | Suite * encryptsave_suite(void) | 151 | Suite * encryptsave_suite(void) |
120 | { | 152 | { |
121 | Suite *s = suite_create("encryptsave"); | 153 | Suite *s = suite_create("encryptsave"); |
122 | 154 | ||
123 | DEFTESTCASE_SLOW(known_kdf, 60); /* is 5-10 seconds on my computer, but is directly dependent on CPU */ | 155 | DEFTESTCASE_SLOW(known_kdf, 60); /* is 5-10 seconds on my computer, but is directly dependent on CPU */ |
124 | DEFTESTCASE(save_friend); | 156 | DEFTESTCASE(save_friend); |
157 | DEFTESTCASE(keys); | ||
125 | 158 | ||
126 | return s; | 159 | return s; |
127 | } | 160 | } |