summaryrefslogtreecommitdiff
path: root/toxcore/onion.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-12-19 02:47:42 +0000
committeriphydf <iphydf@users.noreply.github.com>2016-12-22 10:26:59 +0000
commitce29c8e7ec91d95167b2dea3aee9fd1ae1aac254 (patch)
treea288df55c44e8edf816e6abbde19a70faef73394 /toxcore/onion.c
parent7122d2e862e028a730478d88cd61557fbed16ebf (diff)
Wrap all sodium/nacl functions in crypto_core.c.
Diffstat (limited to 'toxcore/onion.c')
-rw-r--r--toxcore/onion.c144
1 files changed, 72 insertions, 72 deletions
diff --git a/toxcore/onion.c b/toxcore/onion.c
index 06ff719b..07908f2e 100644
--- a/toxcore/onion.c
+++ b/toxcore/onion.c
@@ -122,26 +122,26 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n
122 } 122 }
123 123
124 encrypt_precompute(nodes[0].public_key, dht->self_secret_key, new_path->shared_key1); 124 encrypt_precompute(nodes[0].public_key, dht->self_secret_key, new_path->shared_key1);
125 memcpy(new_path->public_key1, dht->self_public_key, crypto_box_PUBLICKEYBYTES); 125 memcpy(new_path->public_key1, dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
126 126
127 uint8_t random_public_key[crypto_box_PUBLICKEYBYTES]; 127 uint8_t random_public_key[CRYPTO_PUBLIC_KEY_SIZE];
128 uint8_t random_secret_key[crypto_box_SECRETKEYBYTES]; 128 uint8_t random_secret_key[CRYPTO_SECRET_KEY_SIZE];
129 129
130 crypto_box_keypair(random_public_key, random_secret_key); 130 crypto_new_keypair(random_public_key, random_secret_key);
131 encrypt_precompute(nodes[1].public_key, random_secret_key, new_path->shared_key2); 131 encrypt_precompute(nodes[1].public_key, random_secret_key, new_path->shared_key2);
132 memcpy(new_path->public_key2, random_public_key, crypto_box_PUBLICKEYBYTES); 132 memcpy(new_path->public_key2, random_public_key, CRYPTO_PUBLIC_KEY_SIZE);
133 133
134 crypto_box_keypair(random_public_key, random_secret_key); 134 crypto_new_keypair(random_public_key, random_secret_key);
135 encrypt_precompute(nodes[2].public_key, random_secret_key, new_path->shared_key3); 135 encrypt_precompute(nodes[2].public_key, random_secret_key, new_path->shared_key3);
136 memcpy(new_path->public_key3, random_public_key, crypto_box_PUBLICKEYBYTES); 136 memcpy(new_path->public_key3, random_public_key, CRYPTO_PUBLIC_KEY_SIZE);
137 137
138 new_path->ip_port1 = nodes[0].ip_port; 138 new_path->ip_port1 = nodes[0].ip_port;
139 new_path->ip_port2 = nodes[1].ip_port; 139 new_path->ip_port2 = nodes[1].ip_port;
140 new_path->ip_port3 = nodes[2].ip_port; 140 new_path->ip_port3 = nodes[2].ip_port;
141 141
142 memcpy(new_path->node_public_key1, nodes[0].public_key, crypto_box_PUBLICKEYBYTES); 142 memcpy(new_path->node_public_key1, nodes[0].public_key, CRYPTO_PUBLIC_KEY_SIZE);
143 memcpy(new_path->node_public_key2, nodes[1].public_key, crypto_box_PUBLICKEYBYTES); 143 memcpy(new_path->node_public_key2, nodes[1].public_key, CRYPTO_PUBLIC_KEY_SIZE);
144 memcpy(new_path->node_public_key3, nodes[2].public_key, crypto_box_PUBLICKEYBYTES); 144 memcpy(new_path->node_public_key3, nodes[2].public_key, CRYPTO_PUBLIC_KEY_SIZE);
145 145
146 return 0; 146 return 0;
147} 147}
@@ -161,9 +161,9 @@ int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_
161 nodes[1].ip_port = path->ip_port2; 161 nodes[1].ip_port = path->ip_port2;
162 nodes[2].ip_port = path->ip_port3; 162 nodes[2].ip_port = path->ip_port3;
163 163
164 memcpy(nodes[0].public_key, path->node_public_key1, crypto_box_PUBLICKEYBYTES); 164 memcpy(nodes[0].public_key, path->node_public_key1, CRYPTO_PUBLIC_KEY_SIZE);
165 memcpy(nodes[1].public_key, path->node_public_key2, crypto_box_PUBLICKEYBYTES); 165 memcpy(nodes[1].public_key, path->node_public_key2, CRYPTO_PUBLIC_KEY_SIZE);
166 memcpy(nodes[2].public_key, path->node_public_key3, crypto_box_PUBLICKEYBYTES); 166 memcpy(nodes[2].public_key, path->node_public_key3, CRYPTO_PUBLIC_KEY_SIZE);
167 return 0; 167 return 0;
168} 168}
169 169
@@ -188,42 +188,42 @@ int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion
188 ipport_pack(step1, &dest); 188 ipport_pack(step1, &dest);
189 memcpy(step1 + SIZE_IPPORT, data, length); 189 memcpy(step1 + SIZE_IPPORT, data, length);
190 190
191 uint8_t nonce[crypto_box_NONCEBYTES]; 191 uint8_t nonce[CRYPTO_NONCE_SIZE];
192 random_nonce(nonce); 192 random_nonce(nonce);
193 193
194 uint8_t step2[SIZE_IPPORT + SEND_BASE + length]; 194 uint8_t step2[SIZE_IPPORT + SEND_BASE + length];
195 ipport_pack(step2, &path->ip_port3); 195 ipport_pack(step2, &path->ip_port3);
196 memcpy(step2 + SIZE_IPPORT, path->public_key3, crypto_box_PUBLICKEYBYTES); 196 memcpy(step2 + SIZE_IPPORT, path->public_key3, CRYPTO_PUBLIC_KEY_SIZE);
197 197
198 int len = encrypt_data_symmetric(path->shared_key3, nonce, step1, sizeof(step1), 198 int len = encrypt_data_symmetric(path->shared_key3, nonce, step1, sizeof(step1),
199 step2 + SIZE_IPPORT + crypto_box_PUBLICKEYBYTES); 199 step2 + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE);
200 200
201 if (len != SIZE_IPPORT + length + crypto_box_MACBYTES) { 201 if (len != SIZE_IPPORT + length + CRYPTO_MAC_SIZE) {
202 return -1; 202 return -1;
203 } 203 }
204 204
205 uint8_t step3[SIZE_IPPORT + SEND_BASE * 2 + length]; 205 uint8_t step3[SIZE_IPPORT + SEND_BASE * 2 + length];
206 ipport_pack(step3, &path->ip_port2); 206 ipport_pack(step3, &path->ip_port2);
207 memcpy(step3 + SIZE_IPPORT, path->public_key2, crypto_box_PUBLICKEYBYTES); 207 memcpy(step3 + SIZE_IPPORT, path->public_key2, CRYPTO_PUBLIC_KEY_SIZE);
208 len = encrypt_data_symmetric(path->shared_key2, nonce, step2, sizeof(step2), 208 len = encrypt_data_symmetric(path->shared_key2, nonce, step2, sizeof(step2),
209 step3 + SIZE_IPPORT + crypto_box_PUBLICKEYBYTES); 209 step3 + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE);
210 210
211 if (len != SIZE_IPPORT + SEND_BASE + length + crypto_box_MACBYTES) { 211 if (len != SIZE_IPPORT + SEND_BASE + length + CRYPTO_MAC_SIZE) {
212 return -1; 212 return -1;
213 } 213 }
214 214
215 packet[0] = NET_PACKET_ONION_SEND_INITIAL; 215 packet[0] = NET_PACKET_ONION_SEND_INITIAL;
216 memcpy(packet + 1, nonce, crypto_box_NONCEBYTES); 216 memcpy(packet + 1, nonce, CRYPTO_NONCE_SIZE);
217 memcpy(packet + 1 + crypto_box_NONCEBYTES, path->public_key1, crypto_box_PUBLICKEYBYTES); 217 memcpy(packet + 1 + CRYPTO_NONCE_SIZE, path->public_key1, CRYPTO_PUBLIC_KEY_SIZE);
218 218
219 len = encrypt_data_symmetric(path->shared_key1, nonce, step3, sizeof(step3), 219 len = encrypt_data_symmetric(path->shared_key1, nonce, step3, sizeof(step3),
220 packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES); 220 packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE);
221 221
222 if (len != SIZE_IPPORT + SEND_BASE * 2 + length + crypto_box_MACBYTES) { 222 if (len != SIZE_IPPORT + SEND_BASE * 2 + length + CRYPTO_MAC_SIZE) {
223 return -1; 223 return -1;
224 } 224 }
225 225
226 return 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + len; 226 return 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + len;
227} 227}
228 228
229/* Create a onion packet to be sent over tcp. 229/* Create a onion packet to be sent over tcp.
@@ -238,7 +238,7 @@ int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion
238int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest, 238int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest,
239 const uint8_t *data, uint16_t length) 239 const uint8_t *data, uint16_t length)
240{ 240{
241 if (crypto_box_NONCEBYTES + SIZE_IPPORT + SEND_BASE * 2 + length > max_packet_length || length == 0) { 241 if (CRYPTO_NONCE_SIZE + SIZE_IPPORT + SEND_BASE * 2 + length > max_packet_length || length == 0) {
242 return -1; 242 return -1;
243 } 243 }
244 244
@@ -247,32 +247,32 @@ int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const O
247 ipport_pack(step1, &dest); 247 ipport_pack(step1, &dest);
248 memcpy(step1 + SIZE_IPPORT, data, length); 248 memcpy(step1 + SIZE_IPPORT, data, length);
249 249
250 uint8_t nonce[crypto_box_NONCEBYTES]; 250 uint8_t nonce[CRYPTO_NONCE_SIZE];
251 random_nonce(nonce); 251 random_nonce(nonce);
252 252
253 uint8_t step2[SIZE_IPPORT + SEND_BASE + length]; 253 uint8_t step2[SIZE_IPPORT + SEND_BASE + length];
254 ipport_pack(step2, &path->ip_port3); 254 ipport_pack(step2, &path->ip_port3);
255 memcpy(step2 + SIZE_IPPORT, path->public_key3, crypto_box_PUBLICKEYBYTES); 255 memcpy(step2 + SIZE_IPPORT, path->public_key3, CRYPTO_PUBLIC_KEY_SIZE);
256 256
257 int len = encrypt_data_symmetric(path->shared_key3, nonce, step1, sizeof(step1), 257 int len = encrypt_data_symmetric(path->shared_key3, nonce, step1, sizeof(step1),
258 step2 + SIZE_IPPORT + crypto_box_PUBLICKEYBYTES); 258 step2 + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE);
259 259
260 if (len != SIZE_IPPORT + length + crypto_box_MACBYTES) { 260 if (len != SIZE_IPPORT + length + CRYPTO_MAC_SIZE) {
261 return -1; 261 return -1;
262 } 262 }
263 263
264 ipport_pack(packet + crypto_box_NONCEBYTES, &path->ip_port2); 264 ipport_pack(packet + CRYPTO_NONCE_SIZE, &path->ip_port2);
265 memcpy(packet + crypto_box_NONCEBYTES + SIZE_IPPORT, path->public_key2, crypto_box_PUBLICKEYBYTES); 265 memcpy(packet + CRYPTO_NONCE_SIZE + SIZE_IPPORT, path->public_key2, CRYPTO_PUBLIC_KEY_SIZE);
266 len = encrypt_data_symmetric(path->shared_key2, nonce, step2, sizeof(step2), 266 len = encrypt_data_symmetric(path->shared_key2, nonce, step2, sizeof(step2),
267 packet + crypto_box_NONCEBYTES + SIZE_IPPORT + crypto_box_PUBLICKEYBYTES); 267 packet + CRYPTO_NONCE_SIZE + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE);
268 268
269 if (len != SIZE_IPPORT + SEND_BASE + length + crypto_box_MACBYTES) { 269 if (len != SIZE_IPPORT + SEND_BASE + length + CRYPTO_MAC_SIZE) {
270 return -1; 270 return -1;
271 } 271 }
272 272
273 memcpy(packet, nonce, crypto_box_NONCEBYTES); 273 memcpy(packet, nonce, CRYPTO_NONCE_SIZE);
274 274
275 return crypto_box_NONCEBYTES + SIZE_IPPORT + crypto_box_PUBLICKEYBYTES + len; 275 return CRYPTO_NONCE_SIZE + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE + len;
276} 276}
277 277
278/* Create and send a onion packet. 278/* Create and send a onion packet.
@@ -338,12 +338,12 @@ static int handle_send_initial(void *object, IP_Port source, const uint8_t *pack
338 change_symmetric_key(onion); 338 change_symmetric_key(onion);
339 339
340 uint8_t plain[ONION_MAX_PACKET_SIZE]; 340 uint8_t plain[ONION_MAX_PACKET_SIZE];
341 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 341 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
342 get_shared_key(&onion->shared_keys_1, shared_key, onion->dht->self_secret_key, packet + 1 + crypto_box_NONCEBYTES); 342 get_shared_key(&onion->shared_keys_1, shared_key, onion->dht->self_secret_key, packet + 1 + CRYPTO_NONCE_SIZE);
343 int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, 343 int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE,
344 length - (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES), plain); 344 length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE), plain);
345 345
346 if (len != length - (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)) { 346 if (len != length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)) {
347 return 1; 347 return 1;
348 } 348 }
349 349
@@ -352,7 +352,7 @@ static int handle_send_initial(void *object, IP_Port source, const uint8_t *pack
352 352
353int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port source, const uint8_t *nonce) 353int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port source, const uint8_t *nonce)
354{ 354{
355 if (len > ONION_MAX_PACKET_SIZE + SIZE_IPPORT - (1 + crypto_box_NONCEBYTES + ONION_RETURN_1)) { 355 if (len > ONION_MAX_PACKET_SIZE + SIZE_IPPORT - (1 + CRYPTO_NONCE_SIZE + ONION_RETURN_1)) {
356 return 1; 356 return 1;
357 } 357 }
358 358
@@ -371,19 +371,19 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port
371 371
372 uint8_t data[ONION_MAX_PACKET_SIZE]; 372 uint8_t data[ONION_MAX_PACKET_SIZE];
373 data[0] = NET_PACKET_ONION_SEND_1; 373 data[0] = NET_PACKET_ONION_SEND_1;
374 memcpy(data + 1, nonce, crypto_box_NONCEBYTES); 374 memcpy(data + 1, nonce, CRYPTO_NONCE_SIZE);
375 memcpy(data + 1 + crypto_box_NONCEBYTES, plain + SIZE_IPPORT, len - SIZE_IPPORT); 375 memcpy(data + 1 + CRYPTO_NONCE_SIZE, plain + SIZE_IPPORT, len - SIZE_IPPORT);
376 uint16_t data_len = 1 + crypto_box_NONCEBYTES + (len - SIZE_IPPORT); 376 uint16_t data_len = 1 + CRYPTO_NONCE_SIZE + (len - SIZE_IPPORT);
377 uint8_t *ret_part = data + data_len; 377 uint8_t *ret_part = data + data_len;
378 random_nonce(ret_part); 378 random_nonce(ret_part);
379 len = encrypt_data_symmetric(onion->secret_symmetric_key, ret_part, ip_port, SIZE_IPPORT, 379 len = encrypt_data_symmetric(onion->secret_symmetric_key, ret_part, ip_port, SIZE_IPPORT,
380 ret_part + crypto_box_NONCEBYTES); 380 ret_part + CRYPTO_NONCE_SIZE);
381 381
382 if (len != SIZE_IPPORT + crypto_box_MACBYTES) { 382 if (len != SIZE_IPPORT + CRYPTO_MAC_SIZE) {
383 return 1; 383 return 1;
384 } 384 }
385 385
386 data_len += crypto_box_NONCEBYTES + len; 386 data_len += CRYPTO_NONCE_SIZE + len;
387 387
388 if ((uint32_t)sendpacket(onion->net, send_to, data, data_len) != data_len) { 388 if ((uint32_t)sendpacket(onion->net, send_to, data, data_len) != data_len) {
389 return 1; 389 return 1;
@@ -407,12 +407,12 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui
407 change_symmetric_key(onion); 407 change_symmetric_key(onion);
408 408
409 uint8_t plain[ONION_MAX_PACKET_SIZE]; 409 uint8_t plain[ONION_MAX_PACKET_SIZE];
410 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 410 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
411 get_shared_key(&onion->shared_keys_2, shared_key, onion->dht->self_secret_key, packet + 1 + crypto_box_NONCEBYTES); 411 get_shared_key(&onion->shared_keys_2, shared_key, onion->dht->self_secret_key, packet + 1 + CRYPTO_NONCE_SIZE);
412 int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, 412 int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE,
413 length - (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + RETURN_1), plain); 413 length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_1), plain);
414 414
415 if (len != length - (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + RETURN_1 + crypto_box_MACBYTES)) { 415 if (len != length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_1 + CRYPTO_MAC_SIZE)) {
416 return 1; 416 return 1;
417 } 417 }
418 418
@@ -424,22 +424,22 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui
424 424
425 uint8_t data[ONION_MAX_PACKET_SIZE]; 425 uint8_t data[ONION_MAX_PACKET_SIZE];
426 data[0] = NET_PACKET_ONION_SEND_2; 426 data[0] = NET_PACKET_ONION_SEND_2;
427 memcpy(data + 1, packet + 1, crypto_box_NONCEBYTES); 427 memcpy(data + 1, packet + 1, CRYPTO_NONCE_SIZE);
428 memcpy(data + 1 + crypto_box_NONCEBYTES, plain + SIZE_IPPORT, len - SIZE_IPPORT); 428 memcpy(data + 1 + CRYPTO_NONCE_SIZE, plain + SIZE_IPPORT, len - SIZE_IPPORT);
429 uint16_t data_len = 1 + crypto_box_NONCEBYTES + (len - SIZE_IPPORT); 429 uint16_t data_len = 1 + CRYPTO_NONCE_SIZE + (len - SIZE_IPPORT);
430 uint8_t *ret_part = data + data_len; 430 uint8_t *ret_part = data + data_len;
431 random_nonce(ret_part); 431 random_nonce(ret_part);
432 uint8_t ret_data[RETURN_1 + SIZE_IPPORT]; 432 uint8_t ret_data[RETURN_1 + SIZE_IPPORT];
433 ipport_pack(ret_data, &source); 433 ipport_pack(ret_data, &source);
434 memcpy(ret_data + SIZE_IPPORT, packet + (length - RETURN_1), RETURN_1); 434 memcpy(ret_data + SIZE_IPPORT, packet + (length - RETURN_1), RETURN_1);
435 len = encrypt_data_symmetric(onion->secret_symmetric_key, ret_part, ret_data, sizeof(ret_data), 435 len = encrypt_data_symmetric(onion->secret_symmetric_key, ret_part, ret_data, sizeof(ret_data),
436 ret_part + crypto_box_NONCEBYTES); 436 ret_part + CRYPTO_NONCE_SIZE);
437 437
438 if (len != RETURN_2 - crypto_box_NONCEBYTES) { 438 if (len != RETURN_2 - CRYPTO_NONCE_SIZE) {
439 return 1; 439 return 1;
440 } 440 }
441 441
442 data_len += crypto_box_NONCEBYTES + len; 442 data_len += CRYPTO_NONCE_SIZE + len;
443 443
444 if ((uint32_t)sendpacket(onion->net, send_to, data, data_len) != data_len) { 444 if ((uint32_t)sendpacket(onion->net, send_to, data, data_len) != data_len) {
445 return 1; 445 return 1;
@@ -463,12 +463,12 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui
463 change_symmetric_key(onion); 463 change_symmetric_key(onion);
464 464
465 uint8_t plain[ONION_MAX_PACKET_SIZE]; 465 uint8_t plain[ONION_MAX_PACKET_SIZE];
466 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 466 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
467 get_shared_key(&onion->shared_keys_3, shared_key, onion->dht->self_secret_key, packet + 1 + crypto_box_NONCEBYTES); 467 get_shared_key(&onion->shared_keys_3, shared_key, onion->dht->self_secret_key, packet + 1 + CRYPTO_NONCE_SIZE);
468 int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, 468 int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE,
469 length - (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + RETURN_2), plain); 469 length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_2), plain);
470 470
471 if (len != length - (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + RETURN_2 + crypto_box_MACBYTES)) { 471 if (len != length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_2 + CRYPTO_MAC_SIZE)) {
472 return 1; 472 return 1;
473 } 473 }
474 474
@@ -487,9 +487,9 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui
487 ipport_pack(ret_data, &source); 487 ipport_pack(ret_data, &source);
488 memcpy(ret_data + SIZE_IPPORT, packet + (length - RETURN_2), RETURN_2); 488 memcpy(ret_data + SIZE_IPPORT, packet + (length - RETURN_2), RETURN_2);
489 len = encrypt_data_symmetric(onion->secret_symmetric_key, ret_part, ret_data, sizeof(ret_data), 489 len = encrypt_data_symmetric(onion->secret_symmetric_key, ret_part, ret_data, sizeof(ret_data),
490 ret_part + crypto_box_NONCEBYTES); 490 ret_part + CRYPTO_NONCE_SIZE);
491 491
492 if (len != RETURN_3 - crypto_box_NONCEBYTES) { 492 if (len != RETURN_3 - CRYPTO_NONCE_SIZE) {
493 return 1; 493 return 1;
494 } 494 }
495 495
@@ -518,8 +518,8 @@ static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, ui
518 change_symmetric_key(onion); 518 change_symmetric_key(onion);
519 519
520 uint8_t plain[SIZE_IPPORT + RETURN_2]; 520 uint8_t plain[SIZE_IPPORT + RETURN_2];
521 int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES, 521 int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE,
522 SIZE_IPPORT + RETURN_2 + crypto_box_MACBYTES, plain); 522 SIZE_IPPORT + RETURN_2 + CRYPTO_MAC_SIZE, plain);
523 523
524 if ((uint32_t)len != sizeof(plain)) { 524 if ((uint32_t)len != sizeof(plain)) {
525 return 1; 525 return 1;
@@ -559,8 +559,8 @@ static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, ui
559 change_symmetric_key(onion); 559 change_symmetric_key(onion);
560 560
561 uint8_t plain[SIZE_IPPORT + RETURN_1]; 561 uint8_t plain[SIZE_IPPORT + RETURN_1];
562 int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES, 562 int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE,
563 SIZE_IPPORT + RETURN_1 + crypto_box_MACBYTES, plain); 563 SIZE_IPPORT + RETURN_1 + CRYPTO_MAC_SIZE, plain);
564 564
565 if ((uint32_t)len != sizeof(plain)) { 565 if ((uint32_t)len != sizeof(plain)) {
566 return 1; 566 return 1;
@@ -600,8 +600,8 @@ static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, ui
600 change_symmetric_key(onion); 600 change_symmetric_key(onion);
601 601
602 uint8_t plain[SIZE_IPPORT]; 602 uint8_t plain[SIZE_IPPORT];
603 int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES, 603 int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE,
604 SIZE_IPPORT + crypto_box_MACBYTES, plain); 604 SIZE_IPPORT + CRYPTO_MAC_SIZE, plain);
605 605
606 if ((uint32_t)len != SIZE_IPPORT) { 606 if ((uint32_t)len != SIZE_IPPORT) {
607 return 1; 607 return 1;