diff options
author | irungentoo <irungentoo@gmail.com> | 2014-11-25 15:31:46 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-11-25 15:31:46 -0500 |
commit | 89f2436fac93491d9830bcf7a41ff49ea7721104 (patch) | |
tree | fd4b838a4086dece4a2625f5d2758b890e118a69 | |
parent | 28ffa035cb9e19ffed73255b9cde9657da57b79b (diff) |
Astyle autotests.
-rw-r--r-- | auto_tests/dht_test.c | 72 | ||||
-rw-r--r-- | auto_tests/encryptsave_test.c | 35 | ||||
-rw-r--r-- | auto_tests/tox_test.c | 5 |
3 files changed, 71 insertions, 41 deletions
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 6d7e70ad..3e90fb1c 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c | |||
@@ -45,6 +45,7 @@ void mark_good(IPPTsPng *ipptp) | |||
45 | void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6) | 45 | void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6) |
46 | { | 46 | { |
47 | uint32_t i; | 47 | uint32_t i; |
48 | |||
48 | for (i = 0; i < length; ++i) { | 49 | for (i = 0; i < length; ++i) { |
49 | if (ipv6) | 50 | if (ipv6) |
50 | mark_good(&list[i].assoc6); | 51 | mark_good(&list[i].assoc6); |
@@ -58,18 +59,22 @@ void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6) | |||
58 | uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *client_id) | 59 | uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *client_id) |
59 | { | 60 | { |
60 | uint32_t i; | 61 | uint32_t i; |
62 | |||
61 | for (i = 0; i < length; ++i) | 63 | for (i = 0; i < length; ++i) |
62 | if (id_closest(comp_client_id, client_id, list[i].client_id) == 1) | 64 | if (id_closest(comp_client_id, client_id, list[i].client_id) == 1) |
63 | return 0; | 65 | return 0; |
66 | |||
64 | return 1; | 67 | return 1; |
65 | } | 68 | } |
66 | 69 | ||
67 | int client_in_list(Client_data *list, uint32_t length, const uint8_t *client_id) | 70 | int client_in_list(Client_data *list, uint32_t length, const uint8_t *client_id) |
68 | { | 71 | { |
69 | int i; | 72 | int i; |
73 | |||
70 | for (i = 0; i < (int)length; ++i) | 74 | for (i = 0; i < (int)length; ++i) |
71 | if (id_equal(client_id, list[i].client_id)) | 75 | if (id_equal(client_id, list[i].client_id)) |
72 | return i; | 76 | return i; |
77 | |||
73 | return -1; | 78 | return -1; |
74 | } | 79 | } |
75 | 80 | ||
@@ -93,7 +98,8 @@ void test_addto_lists_update(DHT *dht, | |||
93 | // it is possible to have ip_port duplicates in the list, so ip_port @ found not always equal to ip_port @ test | 98 | // it is possible to have ip_port duplicates in the list, so ip_port @ found not always equal to ip_port @ test |
94 | found = client_in_list(list, length, test_id); | 99 | found = client_in_list(list, length, test_id); |
95 | ck_assert_msg(found >= 0, "Client id is not in the list"); | 100 | ck_assert_msg(found >= 0, "Client id is not in the list"); |
96 | ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[found].assoc6.ip_port : &list[found].assoc4.ip_port), "Client IP_Port is incorrect"); | 101 | ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[found].assoc6.ip_port : &list[found].assoc4.ip_port), |
102 | "Client IP_Port is incorrect"); | ||
97 | 103 | ||
98 | // check ip_port update for existing id | 104 | // check ip_port update for existing id |
99 | test = rand() % length; | 105 | test = rand() % length; |
@@ -104,7 +110,8 @@ void test_addto_lists_update(DHT *dht, | |||
104 | ck_assert_msg(used >= 1, "Wrong number of added clients"); | 110 | ck_assert_msg(used >= 1, "Wrong number of added clients"); |
105 | // it is not possible to have id duplicates in the list, so id @ found must be equal id @ test | 111 | // it is not possible to have id duplicates in the list, so id @ found must be equal id @ test |
106 | ck_assert_msg(client_in_list(list, length, test_id) == test, "Client id is not in the list"); | 112 | ck_assert_msg(client_in_list(list, length, test_id) == test, "Client id is not in the list"); |
107 | ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[test].assoc6.ip_port : &list[test].assoc4.ip_port), "Client IP_Port is incorrect"); | 113 | ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[test].assoc6.ip_port : &list[test].assoc4.ip_port), |
114 | "Client IP_Port is incorrect"); | ||
108 | 115 | ||
109 | // check ip_port update for existing id and ip_port (... port ... id ...) | 116 | // check ip_port update for existing id and ip_port (... port ... id ...) |
110 | test1 = rand() % (length / 2); | 117 | test1 = rand() % (length / 2); |
@@ -112,11 +119,15 @@ void test_addto_lists_update(DHT *dht, | |||
112 | 119 | ||
113 | ipport_copy(&test_ipp, ipv6 ? &list[test1].assoc6.ip_port : &list[test1].assoc4.ip_port); | 120 | ipport_copy(&test_ipp, ipv6 ? &list[test1].assoc6.ip_port : &list[test1].assoc4.ip_port); |
114 | id_copy(test_id, list[test2].client_id); | 121 | id_copy(test_id, list[test2].client_id); |
115 | if (ipv6) list[test2].assoc6.ip_port.port = -1; else list[test2].assoc4.ip_port.port = -1; | 122 | |
123 | if (ipv6) list[test2].assoc6.ip_port.port = -1; | ||
124 | else list[test2].assoc4.ip_port.port = -1; | ||
125 | |||
116 | used = addto_lists(dht, test_ipp, test_id); | 126 | used = addto_lists(dht, test_ipp, test_id); |
117 | ck_assert_msg(used >= 1, "Wrong number of added clients"); | 127 | ck_assert_msg(used >= 1, "Wrong number of added clients"); |
118 | ck_assert_msg(client_in_list(list, length, test_id) == test2, "Client id is not in the list"); | 128 | ck_assert_msg(client_in_list(list, length, test_id) == test2, "Client id is not in the list"); |
119 | ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[test2].assoc6.ip_port : &list[test2].assoc4.ip_port), "Client IP_Port is incorrect"); | 129 | ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[test2].assoc6.ip_port : &list[test2].assoc4.ip_port), |
130 | "Client IP_Port is incorrect"); | ||
120 | 131 | ||
121 | // check ip_port update for existing id and ip_port (... id ... port ...) | 132 | // check ip_port update for existing id and ip_port (... id ... port ...) |
122 | test1 = rand() % (length / 2); | 133 | test1 = rand() % (length / 2); |
@@ -124,11 +135,15 @@ void test_addto_lists_update(DHT *dht, | |||
124 | 135 | ||
125 | ipport_copy(&test_ipp, ipv6 ? &list[test2].assoc6.ip_port : &list[test2].assoc4.ip_port); | 136 | ipport_copy(&test_ipp, ipv6 ? &list[test2].assoc6.ip_port : &list[test2].assoc4.ip_port); |
126 | id_copy(test_id, list[test1].client_id); | 137 | id_copy(test_id, list[test1].client_id); |
127 | if (ipv6) list[test1].assoc6.ip_port.port = -1; else list[test1].assoc4.ip_port.port = -1; | 138 | |
139 | if (ipv6) list[test1].assoc6.ip_port.port = -1; | ||
140 | else list[test1].assoc4.ip_port.port = -1; | ||
141 | |||
128 | used = addto_lists(dht, test_ipp, test_id); | 142 | used = addto_lists(dht, test_ipp, test_id); |
129 | ck_assert_msg(used >= 1, "Wrong number of added clients"); | 143 | ck_assert_msg(used >= 1, "Wrong number of added clients"); |
130 | ck_assert_msg(client_in_list(list, length, test_id) == test1, "Client id is not in the list"); | 144 | ck_assert_msg(client_in_list(list, length, test_id) == test1, "Client id is not in the list"); |
131 | ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[test1].assoc6.ip_port : &list[test1].assoc4.ip_port), "Client IP_Port is incorrect"); | 145 | ck_assert_msg(ipport_equal(&test_ipp, ipv6 ? &list[test1].assoc6.ip_port : &list[test1].assoc4.ip_port), |
146 | "Client IP_Port is incorrect"); | ||
132 | } | 147 | } |
133 | 148 | ||
134 | void test_addto_lists_bad(DHT *dht, | 149 | void test_addto_lists_bad(DHT *dht, |
@@ -149,9 +164,9 @@ void test_addto_lists_bad(DHT *dht, | |||
149 | test3 = rand() % (length / 3) + 2 * length / 3; | 164 | test3 = rand() % (length / 3) + 2 * length / 3; |
150 | ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen"); | 165 | ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen"); |
151 | 166 | ||
152 | id_copy((uint8_t*)&test_id1, list[test1].client_id); | 167 | id_copy((uint8_t *)&test_id1, list[test1].client_id); |
153 | id_copy((uint8_t*)&test_id2, list[test2].client_id); | 168 | id_copy((uint8_t *)&test_id2, list[test2].client_id); |
154 | id_copy((uint8_t*)&test_id3, list[test3].client_id); | 169 | id_copy((uint8_t *)&test_id3, list[test3].client_id); |
155 | 170 | ||
156 | // mark nodes as "bad" | 171 | // mark nodes as "bad" |
157 | if (ipv6) { | 172 | if (ipv6) { |
@@ -193,9 +208,9 @@ void test_addto_lists_possible_bad(DHT *dht, | |||
193 | test3 = rand() % (length / 3) + 2 * length / 3; | 208 | test3 = rand() % (length / 3) + 2 * length / 3; |
194 | ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen"); | 209 | ck_assert_msg(!(test1 == test2 || test1 == test3 || test2 == test3), "Wrong test indices are chosen"); |
195 | 210 | ||
196 | id_copy((uint8_t*)&test_id1, list[test1].client_id); | 211 | id_copy((uint8_t *)&test_id1, list[test1].client_id); |
197 | id_copy((uint8_t*)&test_id2, list[test2].client_id); | 212 | id_copy((uint8_t *)&test_id2, list[test2].client_id); |
198 | id_copy((uint8_t*)&test_id3, list[test3].client_id); | 213 | id_copy((uint8_t *)&test_id3, list[test3].client_id); |
199 | 214 | ||
200 | // mark nodes as "possibly bad" | 215 | // mark nodes as "possibly bad" |
201 | if (ipv6) { | 216 | if (ipv6) { |
@@ -221,14 +236,20 @@ void test_addto_lists_possible_bad(DHT *dht, | |||
221 | ck_assert_msg(inlist_id1 + inlist_id2 + inlist_id3 == 2, "Wrong client removed"); | 236 | ck_assert_msg(inlist_id1 + inlist_id2 + inlist_id3 == 2, "Wrong client removed"); |
222 | 237 | ||
223 | if (!inlist_id1) { | 238 | if (!inlist_id1) { |
224 | ck_assert_msg(id_closest(comp_client_id, test_id2, test_id1) == 1, "Id has been removed but is closer to than another one"); | 239 | ck_assert_msg(id_closest(comp_client_id, test_id2, test_id1) == 1, |
225 | ck_assert_msg(id_closest(comp_client_id, test_id3, test_id1) == 1, "Id has been removed but is closer to than another one"); | 240 | "Id has been removed but is closer to than another one"); |
241 | ck_assert_msg(id_closest(comp_client_id, test_id3, test_id1) == 1, | ||
242 | "Id has been removed but is closer to than another one"); | ||
226 | } else if (!inlist_id2) { | 243 | } else if (!inlist_id2) { |
227 | ck_assert_msg(id_closest(comp_client_id, test_id1, test_id2) == 1, "Id has been removed but is closer to than another one"); | 244 | ck_assert_msg(id_closest(comp_client_id, test_id1, test_id2) == 1, |
228 | ck_assert_msg(id_closest(comp_client_id, test_id3, test_id2) == 1, "Id has been removed but is closer to than another one"); | 245 | "Id has been removed but is closer to than another one"); |
246 | ck_assert_msg(id_closest(comp_client_id, test_id3, test_id2) == 1, | ||
247 | "Id has been removed but is closer to than another one"); | ||
229 | } else if (!inlist_id3) { | 248 | } else if (!inlist_id3) { |
230 | ck_assert_msg(id_closest(comp_client_id, test_id1, test_id3) == 1, "Id has been removed but is closer to than another one"); | 249 | ck_assert_msg(id_closest(comp_client_id, test_id1, test_id3) == 1, |
231 | ck_assert_msg(id_closest(comp_client_id, test_id2, test_id3) == 1, "Id has been removed but is closer to than another one"); | 250 | "Id has been removed but is closer to than another one"); |
251 | ck_assert_msg(id_closest(comp_client_id, test_id2, test_id3) == 1, | ||
252 | "Id has been removed but is closer to than another one"); | ||
232 | } | 253 | } |
233 | } | 254 | } |
234 | 255 | ||
@@ -247,6 +268,7 @@ void test_addto_lists_good(DHT *dht, | |||
247 | do { | 268 | do { |
248 | randombytes(client_id, sizeof(client_id)); | 269 | randombytes(client_id, sizeof(client_id)); |
249 | } while (is_furthest(comp_client_id, list, length, client_id)); | 270 | } while (is_furthest(comp_client_id, list, length, client_id)); |
271 | |||
250 | ip_port->port += 1; | 272 | ip_port->port += 1; |
251 | addto_lists(dht, *ip_port, client_id); | 273 | addto_lists(dht, *ip_port, client_id); |
252 | ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Good client id is not in the list"); | 274 | ck_assert_msg(client_in_list(list, length, client_id) >= 0, "Good client id is not in the list"); |
@@ -263,10 +285,10 @@ void test_addto_lists_good(DHT *dht, | |||
263 | 285 | ||
264 | void test_addto_lists(IP ip) | 286 | void test_addto_lists(IP ip) |
265 | { | 287 | { |
266 | Networking_Core* net = new_networking(ip, TOX_PORT_DEFAULT); | 288 | Networking_Core *net = new_networking(ip, TOX_PORT_DEFAULT); |
267 | ck_assert_msg(net != 0, "Failed to create Networking_Core"); | 289 | ck_assert_msg(net != 0, "Failed to create Networking_Core"); |
268 | 290 | ||
269 | DHT* dht = new_DHT(net); | 291 | DHT *dht = new_DHT(net); |
270 | ck_assert_msg(dht != 0, "Failed to create DHT"); | 292 | ck_assert_msg(dht != 0, "Failed to create DHT"); |
271 | 293 | ||
272 | IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT }; | 294 | IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT }; |
@@ -296,23 +318,29 @@ void test_addto_lists(IP ip) | |||
296 | /*check: Current behavior if there are two clients with the same id is | 318 | /*check: Current behavior if there are two clients with the same id is |
297 | * to replace the first ip by the second. */ | 319 | * to replace the first ip by the second. */ |
298 | test_addto_lists_update(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port); | 320 | test_addto_lists_update(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port); |
321 | |||
299 | for (i = 0; i < dht->num_friends; ++i) | 322 | for (i = 0; i < dht->num_friends; ++i) |
300 | test_addto_lists_update(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port); | 323 | test_addto_lists_update(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port); |
301 | 324 | ||
302 | // check "bad" entries | 325 | // check "bad" entries |
303 | test_addto_lists_bad(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port); | 326 | test_addto_lists_bad(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port); |
327 | |||
304 | for (i = 0; i < dht->num_friends; ++i) | 328 | for (i = 0; i < dht->num_friends; ++i) |
305 | test_addto_lists_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port); | 329 | test_addto_lists_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port); |
306 | 330 | ||
307 | // check "possibly bad" entries | 331 | // check "possibly bad" entries |
308 | test_addto_lists_possible_bad(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key); | 332 | test_addto_lists_possible_bad(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key); |
333 | |||
309 | for (i = 0; i < dht->num_friends; ++i) | 334 | for (i = 0; i < dht->num_friends; ++i) |
310 | test_addto_lists_possible_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, dht->friends_list[i].client_id); | 335 | test_addto_lists_possible_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, |
336 | dht->friends_list[i].client_id); | ||
311 | 337 | ||
312 | // check "good" entries | 338 | // check "good" entries |
313 | test_addto_lists_good(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key); | 339 | test_addto_lists_good(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key); |
340 | |||
314 | for (i = 0; i < dht->num_friends; ++i) | 341 | for (i = 0; i < dht->num_friends; ++i) |
315 | test_addto_lists_good(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, dht->friends_list[i].client_id); | 342 | test_addto_lists_good(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, |
343 | dht->friends_list[i].client_id); | ||
316 | 344 | ||
317 | kill_DHT(dht); | 345 | kill_DHT(dht); |
318 | kill_networking(net); | 346 | kill_networking(net); |
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 3045fbfa..aa5bef3f 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -20,12 +20,12 @@ | |||
20 | #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h" /* sodium_memzero */ | 20 | #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h" /* sodium_memzero */ |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | unsigned char salt[32] = {0xB1,0xC2,0x09,0xEE,0x50,0x6C,0xF0,0x20,0xC4,0xD6,0xEB,0xC0,0x44,0x51,0x3B,0x60,0x4B,0x39,0x4A,0xCF,0x09,0x53,0x4F,0xEA,0x08,0x41,0xFA,0xCA,0x66,0xD2,0x68,0x7F}; | 23 | unsigned char salt[32] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F}; |
24 | unsigned char known_key[crypto_box_BEFORENMBYTES] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8}; | 24 | unsigned char known_key[crypto_box_BEFORENMBYTES] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8}; |
25 | char* pw = "hunter2"; | 25 | char *pw = "hunter2"; |
26 | unsigned int pwlen = 7; | 26 | unsigned int pwlen = 7; |
27 | 27 | ||
28 | unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1}; | 28 | unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1}; |
29 | // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat | 29 | // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat |
30 | 30 | ||
31 | /* cause I'm shameless */ | 31 | /* cause I'm shameless */ |
@@ -49,7 +49,7 @@ START_TEST(test_known_kdf) | |||
49 | salt, | 49 | salt, |
50 | crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8, | 50 | crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8, |
51 | crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE); | 51 | crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE); |
52 | ck_assert_msg(memcmp(out, known_key, crypto_box_BEFORENMBYTES) == 0, "derived key is wrong"); | 52 | ck_assert_msg(memcmp(out, known_key, crypto_box_BEFORENMBYTES) == 0, "derived key is wrong"); |
53 | } | 53 | } |
54 | END_TEST | 54 | END_TEST |
55 | 55 | ||
@@ -82,13 +82,14 @@ START_TEST(test_save_friend) | |||
82 | size = tox_encrypted_size(tox3); | 82 | size = tox_encrypted_size(tox3); |
83 | uint8_t data2[size]; | 83 | uint8_t data2[size]; |
84 | uint8_t key[32 + crypto_box_BEFORENMBYTES]; | 84 | uint8_t key[32 + crypto_box_BEFORENMBYTES]; |
85 | memcpy(key, salt, 32); memcpy(key+32, known_key2, crypto_box_BEFORENMBYTES); | 85 | memcpy(key, salt, 32); |
86 | memcpy(key + 32, known_key2, crypto_box_BEFORENMBYTES); | ||
86 | test = tox_encrypted_key_save(tox3, data2, key); | 87 | test = tox_encrypted_key_save(tox3, data2, key); |
87 | ck_assert_msg(test == 0, "failed to encrypted save the second"); | 88 | ck_assert_msg(test == 0, "failed to encrypted save the second"); |
88 | ck_assert_msg(tox_is_save_encrypted(data2) == 1, "magic number the second missing"); | 89 | ck_assert_msg(tox_is_save_encrypted(data2) == 1, "magic number the second missing"); |
89 | 90 | ||
90 | // first test tox_encrypted_key_load | 91 | // first test tox_encrypted_key_load |
91 | Tox* tox4 = tox_new(0); | 92 | Tox *tox4 = tox_new(0); |
92 | test = tox_encrypted_key_load(tox4, data2, size, key); | 93 | test = tox_encrypted_key_load(tox4, data2, size, key); |
93 | ck_assert_msg(test == 0, "failed to encrypted load the second"); | 94 | ck_assert_msg(test == 0, "failed to encrypted load the second"); |
94 | uint8_t address4[TOX_CLIENT_ID_SIZE]; | 95 | uint8_t address4[TOX_CLIENT_ID_SIZE]; |
@@ -106,7 +107,7 @@ START_TEST(test_save_friend) | |||
106 | 107 | ||
107 | // and now with the code in use (I only bothered with manually to debug this, and it seems a waste | 108 | // and now with the code in use (I only bothered with manually to debug this, and it seems a waste |
108 | // to remove the manual check now that it's there) | 109 | // to remove the manual check now that it's there) |
109 | Tox* tox5 = tox_new(0); | 110 | Tox *tox5 = tox_new(0); |
110 | test = tox_encrypted_load(tox5, data2, size, pw, pwlen); | 111 | test = tox_encrypted_load(tox5, data2, size, pw, pwlen); |
111 | ck_assert_msg(test == 0, "failed to encrypted load the third"); | 112 | ck_assert_msg(test == 0, "failed to encrypted load the third"); |
112 | uint8_t address5[TOX_CLIENT_ID_SIZE]; | 113 | uint8_t address5[TOX_CLIENT_ID_SIZE]; |
@@ -120,29 +121,29 @@ START_TEST(test_keys) | |||
120 | { | 121 | { |
121 | uint8_t key[tox_pass_key_length()]; | 122 | uint8_t key[tox_pass_key_length()]; |
122 | tox_derive_key_from_pass("123qweasdzxc", 12, key); | 123 | tox_derive_key_from_pass("123qweasdzxc", 12, key); |
123 | uint8_t* string = "No Patrick, mayonnaise is not an instrument."; // 44 | 124 | uint8_t *string = "No Patrick, mayonnaise is not an instrument."; // 44 |
124 | 125 | ||
125 | uint8_t encrypted[44+tox_pass_encryption_extra_length()]; | 126 | uint8_t encrypted[44 + tox_pass_encryption_extra_length()]; |
126 | int sz = tox_pass_key_encrypt(string, 44, key, encrypted); | 127 | int sz = tox_pass_key_encrypt(string, 44, key, encrypted); |
127 | 128 | ||
128 | uint8_t encrypted2[44+tox_pass_encryption_extra_length()]; | 129 | uint8_t encrypted2[44 + tox_pass_encryption_extra_length()]; |
129 | int sz2 = tox_pass_encrypt(string, 44, "123qweasdzxc", 12, encrypted2); | 130 | int sz2 = tox_pass_encrypt(string, 44, "123qweasdzxc", 12, encrypted2); |
130 | 131 | ||
131 | ck_assert_msg(sz == sz2, "an encryption failed"); | 132 | ck_assert_msg(sz == sz2, "an encryption failed"); |
132 | 133 | ||
133 | uint8_t out1[44+tox_pass_encryption_extra_length()]; | 134 | uint8_t out1[44 + tox_pass_encryption_extra_length()]; |
134 | uint8_t out2[44+tox_pass_encryption_extra_length()]; | 135 | uint8_t out2[44 + tox_pass_encryption_extra_length()]; |
135 | 136 | ||
136 | sz = tox_pass_key_decrypt(encrypted, 44+tox_pass_encryption_extra_length(), key, out1); | 137 | 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(sz == 44, "sz isn't right"); |
138 | ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 1 failed"); | 139 | ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 1 failed"); |
139 | 140 | ||
140 | sz2 = tox_pass_decrypt(encrypted2, 44+tox_pass_encryption_extra_length(), "123qweasdzxc", 12, out2); | 141 | 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(sz2 == 44, "sz2 isn't right"); |
142 | ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed"); | 143 | ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed"); |
143 | 144 | ||
144 | // test that pass_decrypt can decrypt things from pass_key_encrypt | 145 | // 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 | 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(sz == 44, "sz isn't right"); |
147 | ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed"); | 148 | ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed"); |
148 | 149 | ||
@@ -154,7 +155,7 @@ START_TEST(test_keys) | |||
154 | } | 155 | } |
155 | END_TEST | 156 | END_TEST |
156 | 157 | ||
157 | Suite * encryptsave_suite(void) | 158 | Suite *encryptsave_suite(void) |
158 | { | 159 | { |
159 | Suite *s = suite_create("encryptsave"); | 160 | Suite *s = suite_create("encryptsave"); |
160 | 161 | ||
@@ -169,7 +170,7 @@ int main(int argc, char *argv[]) | |||
169 | { | 170 | { |
170 | srand((unsigned int) time(NULL)); | 171 | srand((unsigned int) time(NULL)); |
171 | 172 | ||
172 | Suite * encryptsave = encryptsave_suite(); | 173 | Suite *encryptsave = encryptsave_suite(); |
173 | SRunner *test_runner = srunner_create(encryptsave); | 174 | SRunner *test_runner = srunner_create(encryptsave); |
174 | 175 | ||
175 | int number_failed = 0; | 176 | int number_failed = 0; |
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 6d837661..65ce304c 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -79,10 +79,11 @@ int handle_custom_packet(void *object, const uint8_t *data, uint32_t len) | |||
79 | 79 | ||
80 | uint8_t f_data[len]; | 80 | uint8_t f_data[len]; |
81 | memset(f_data, number, len); | 81 | memset(f_data, number, len); |
82 | |||
82 | if (memcmp(f_data, data, len) == 0) { | 83 | if (memcmp(f_data, data, len) == 0) { |
83 | ++custom_packet; | 84 | ++custom_packet; |
84 | } else { | 85 | } else { |
85 | printf("Custom packet fail. %u\n",number ); | 86 | printf("Custom packet fail. %u\n", number ); |
86 | } | 87 | } |
87 | 88 | ||
88 | return 0; | 89 | return 0; |
@@ -277,7 +278,7 @@ START_TEST(test_few_clients) | |||
277 | 278 | ||
278 | c_sleep(50); | 279 | c_sleep(50); |
279 | } | 280 | } |
280 | 281 | ||
281 | packet_number = 200; | 282 | packet_number = 200; |
282 | ret = tox_lossy_packet_registerhandler(tox3, 0, packet_number, handle_custom_packet, &packet_number); | 283 | ret = tox_lossy_packet_registerhandler(tox3, 0, packet_number, handle_custom_packet, &packet_number); |
283 | ck_assert_msg(ret == 0, "tox_lossy_packet_registerhandler fail %i", ret); | 284 | ck_assert_msg(ret == 0, "tox_lossy_packet_registerhandler fail %i", ret); |