summaryrefslogtreecommitdiff
path: root/toxcore/onion_client.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_client.c
parent7122d2e862e028a730478d88cd61557fbed16ebf (diff)
Wrap all sodium/nacl functions in crypto_core.c.
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r--toxcore/onion_client.c106
1 files changed, 53 insertions, 53 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index c03036ac..6ef22314 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -55,7 +55,7 @@ int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t
55 55
56 onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].ip_port = ip_port; 56 onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].ip_port = ip_port;
57 memcpy(onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].public_key, public_key, 57 memcpy(onion_c->path_nodes_bs[onion_c->path_nodes_index_bs % MAX_PATH_NODES].public_key, public_key,
58 crypto_box_PUBLICKEYBYTES); 58 CRYPTO_PUBLIC_KEY_SIZE);
59 59
60 uint16_t last = onion_c->path_nodes_index_bs; 60 uint16_t last = onion_c->path_nodes_index_bs;
61 ++onion_c->path_nodes_index_bs; 61 ++onion_c->path_nodes_index_bs;
@@ -88,7 +88,7 @@ static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uin
88 88
89 onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].ip_port = ip_port; 89 onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].ip_port = ip_port;
90 memcpy(onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].public_key, public_key, 90 memcpy(onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].public_key, public_key,
91 crypto_box_PUBLICKEYBYTES); 91 CRYPTO_PUBLIC_KEY_SIZE);
92 92
93 uint16_t last = onion_c->path_nodes_index; 93 uint16_t last = onion_c->path_nodes_index;
94 ++onion_c->path_nodes_index; 94 ++onion_c->path_nodes_index;
@@ -376,11 +376,11 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Pa
376static int new_sendback(Onion_Client *onion_c, uint32_t num, const uint8_t *public_key, IP_Port ip_port, 376static int new_sendback(Onion_Client *onion_c, uint32_t num, const uint8_t *public_key, IP_Port ip_port,
377 uint32_t path_num, uint64_t *sendback) 377 uint32_t path_num, uint64_t *sendback)
378{ 378{
379 uint8_t data[sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port) + sizeof(uint32_t)]; 379 uint8_t data[sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port) + sizeof(uint32_t)];
380 memcpy(data, &num, sizeof(uint32_t)); 380 memcpy(data, &num, sizeof(uint32_t));
381 memcpy(data + sizeof(uint32_t), public_key, crypto_box_PUBLICKEYBYTES); 381 memcpy(data + sizeof(uint32_t), public_key, CRYPTO_PUBLIC_KEY_SIZE);
382 memcpy(data + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES, &ip_port, sizeof(IP_Port)); 382 memcpy(data + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE, &ip_port, sizeof(IP_Port));
383 memcpy(data + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port), &path_num, sizeof(uint32_t)); 383 memcpy(data + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port), &path_num, sizeof(uint32_t));
384 *sendback = ping_array_add(&onion_c->announce_ping_array, data, sizeof(data)); 384 *sendback = ping_array_add(&onion_c->announce_ping_array, data, sizeof(data));
385 385
386 if (*sendback == 0) { 386 if (*sendback == 0) {
@@ -394,7 +394,7 @@ static int new_sendback(Onion_Client *onion_c, uint32_t num, const uint8_t *publ
394 * ip contained in it in ret_ip_port 394 * ip contained in it in ret_ip_port
395 * 395 *
396 * sendback is the sendback ONION_ANNOUNCE_SENDBACK_DATA_LENGTH big 396 * sendback is the sendback ONION_ANNOUNCE_SENDBACK_DATA_LENGTH big
397 * ret_pubkey must be at least crypto_box_PUBLICKEYBYTES big 397 * ret_pubkey must be at least CRYPTO_PUBLIC_KEY_SIZE big
398 * ret_ip_port must be at least 1 big 398 * ret_ip_port must be at least 1 big
399 * 399 *
400 * return ~0 on failure 400 * return ~0 on failure
@@ -405,15 +405,15 @@ static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, u
405{ 405{
406 uint64_t sback; 406 uint64_t sback;
407 memcpy(&sback, sendback, sizeof(uint64_t)); 407 memcpy(&sback, sendback, sizeof(uint64_t));
408 uint8_t data[sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port) + sizeof(uint32_t)]; 408 uint8_t data[sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port) + sizeof(uint32_t)];
409 409
410 if (ping_array_check(data, sizeof(data), &onion_c->announce_ping_array, sback) != sizeof(data)) { 410 if (ping_array_check(data, sizeof(data), &onion_c->announce_ping_array, sback) != sizeof(data)) {
411 return ~0; 411 return ~0;
412 } 412 }
413 413
414 memcpy(ret_pubkey, data + sizeof(uint32_t), crypto_box_PUBLICKEYBYTES); 414 memcpy(ret_pubkey, data + sizeof(uint32_t), CRYPTO_PUBLIC_KEY_SIZE);
415 memcpy(ret_ip_port, data + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES, sizeof(IP_Port)); 415 memcpy(ret_ip_port, data + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE, sizeof(IP_Port));
416 memcpy(path_num, data + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port), sizeof(uint32_t)); 416 memcpy(path_num, data + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port), sizeof(uint32_t));
417 417
418 uint32_t num; 418 uint32_t num;
419 memcpy(&num, data, sizeof(uint32_t)); 419 memcpy(&num, data, sizeof(uint32_t));
@@ -469,7 +469,7 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_
469 return send_onion_packet_tcp_udp(onion_c, &path, dest, request, len); 469 return send_onion_packet_tcp_udp(onion_c, &path, dest, request, len);
470} 470}
471 471
472static uint8_t cmp_public_key[crypto_box_PUBLICKEYBYTES]; 472static uint8_t cmp_public_key[CRYPTO_PUBLIC_KEY_SIZE];
473static int cmp_entry(const void *a, const void *b) 473static int cmp_entry(const void *a, const void *b)
474{ 474{
475 Onion_Node entry1, entry2; 475 Onion_Node entry1, entry2;
@@ -532,7 +532,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
532 list_length = MAX_ONION_CLIENTS; 532 list_length = MAX_ONION_CLIENTS;
533 } 533 }
534 534
535 memcpy(cmp_public_key, reference_id, crypto_box_PUBLICKEYBYTES); 535 memcpy(cmp_public_key, reference_id, CRYPTO_PUBLIC_KEY_SIZE);
536 qsort(list_nodes, list_length, sizeof(Onion_Node), cmp_entry); 536 qsort(list_nodes, list_length, sizeof(Onion_Node), cmp_entry);
537 537
538 int index = -1, stored = 0; 538 int index = -1, stored = 0;
@@ -555,14 +555,14 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
555 return 0; 555 return 0;
556 } 556 }
557 557
558 memcpy(list_nodes[index].public_key, public_key, crypto_box_PUBLICKEYBYTES); 558 memcpy(list_nodes[index].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE);
559 list_nodes[index].ip_port = ip_port; 559 list_nodes[index].ip_port = ip_port;
560 560
561 // TODO(irungentoo): remove this and find a better source of nodes to use for paths. 561 // TODO(irungentoo): remove this and find a better source of nodes to use for paths.
562 onion_add_path_node(onion_c, ip_port, public_key); 562 onion_add_path_node(onion_c, ip_port, public_key);
563 563
564 if (is_stored == 1) { 564 if (is_stored == 1) {
565 memcpy(list_nodes[index].data_public_key, pingid_or_key, crypto_box_PUBLICKEYBYTES); 565 memcpy(list_nodes[index].data_public_key, pingid_or_key, CRYPTO_PUBLIC_KEY_SIZE);
566 } else { 566 } else {
567 memcpy(list_nodes[index].ping_id, pingid_or_key, ONION_PING_ID_SIZE); 567 memcpy(list_nodes[index].ping_id, pingid_or_key, ONION_PING_ID_SIZE);
568 } 568 }
@@ -590,7 +590,7 @@ static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, co
590 } 590 }
591 } 591 }
592 592
593 memcpy(last_pinged[*last_pinged_index % MAX_STORED_PINGED_NODES].public_key, public_key, crypto_box_PUBLICKEYBYTES); 593 memcpy(last_pinged[*last_pinged_index % MAX_STORED_PINGED_NODES].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE);
594 last_pinged[*last_pinged_index % MAX_STORED_PINGED_NODES].timestamp = unix_time(); 594 last_pinged[*last_pinged_index % MAX_STORED_PINGED_NODES].timestamp = unix_time();
595 ++*last_pinged_index; 595 ++*last_pinged_index;
596 return 1; 596 return 1;
@@ -670,7 +670,7 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t
670 670
671 uint16_t len_nodes = length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE; 671 uint16_t len_nodes = length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE;
672 672
673 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; 673 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
674 IP_Port ip_port; 674 IP_Port ip_port;
675 uint32_t path_num; 675 uint32_t path_num;
676 uint32_t num = check_sendback(onion_c, packet + 1, public_key, &ip_port, &path_num); 676 uint32_t num = check_sendback(onion_c, packet + 1, public_key, &ip_port, &path_num);
@@ -684,8 +684,8 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t
684 684
685 if (num == 0) { 685 if (num == 0) {
686 len = decrypt_data(public_key, onion_c->c->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, 686 len = decrypt_data(public_key, onion_c->c->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
687 packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES, 687 packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE,
688 length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES), plain); 688 length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain);
689 } else { 689 } else {
690 if (onion_c->friends_list[num - 1].status == 0) { 690 if (onion_c->friends_list[num - 1].status == 0) {
691 return 1; 691 return 1;
@@ -693,8 +693,8 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t
693 693
694 len = decrypt_data(public_key, onion_c->friends_list[num - 1].temp_secret_key, 694 len = decrypt_data(public_key, onion_c->friends_list[num - 1].temp_secret_key,
695 packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, 695 packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
696 packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES, 696 packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE,
697 length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES), plain); 697 length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain);
698 } 698 }
699 699
700 if ((uint32_t)len != sizeof(plain)) { 700 if ((uint32_t)len != sizeof(plain)) {
@@ -738,17 +738,17 @@ static int handle_data_response(void *object, IP_Port source, const uint8_t *pac
738 } 738 }
739 739
740 uint8_t temp_plain[length - ONION_DATA_RESPONSE_MIN_SIZE]; 740 uint8_t temp_plain[length - ONION_DATA_RESPONSE_MIN_SIZE];
741 int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion_c->temp_secret_key, packet + 1, 741 int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, onion_c->temp_secret_key, packet + 1,
742 packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, 742 packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE,
743 length - (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES), temp_plain); 743 length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE), temp_plain);
744 744
745 if ((uint32_t)len != sizeof(temp_plain)) { 745 if ((uint32_t)len != sizeof(temp_plain)) {
746 return 1; 746 return 1;
747 } 747 }
748 748
749 uint8_t plain[sizeof(temp_plain) - DATA_IN_RESPONSE_MIN_SIZE]; 749 uint8_t plain[sizeof(temp_plain) - DATA_IN_RESPONSE_MIN_SIZE];
750 len = decrypt_data(temp_plain, onion_c->c->self_secret_key, packet + 1, temp_plain + crypto_box_PUBLICKEYBYTES, 750 len = decrypt_data(temp_plain, onion_c->c->self_secret_key, packet + 1, temp_plain + CRYPTO_PUBLIC_KEY_SIZE,
751 sizeof(temp_plain) - crypto_box_PUBLICKEYBYTES, plain); 751 sizeof(temp_plain) - CRYPTO_PUBLIC_KEY_SIZE, plain);
752 752
753 if ((uint32_t)len != sizeof(plain)) { 753 if ((uint32_t)len != sizeof(plain)) {
754 return 1; 754 return 1;
@@ -762,7 +762,7 @@ static int handle_data_response(void *object, IP_Port source, const uint8_t *pac
762 sizeof(plain), userdata); 762 sizeof(plain), userdata);
763} 763}
764 764
765#define DHTPK_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES) 765#define DHTPK_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE)
766#define DHTPK_DATA_MAX_LENGTH (DHTPK_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) 766#define DHTPK_DATA_MAX_LENGTH (DHTPK_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES)
767static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length, 767static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length,
768 void *userdata) 768 void *userdata)
@@ -805,7 +805,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con
805 805
806 if (len_nodes != 0) { 806 if (len_nodes != 0) {
807 Node_format nodes[MAX_SENT_NODES]; 807 Node_format nodes[MAX_SENT_NODES];
808 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, data + 1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES, 808 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, data + 1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE,
809 len_nodes, 1); 809 len_nodes, 1);
810 810
811 if (num_nodes <= 0) { 811 if (num_nodes <= 0) {
@@ -894,15 +894,15 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data,
894 return -1; 894 return -1;
895 } 895 }
896 896
897 uint8_t nonce[crypto_box_NONCEBYTES]; 897 uint8_t nonce[CRYPTO_NONCE_SIZE];
898 random_nonce(nonce); 898 random_nonce(nonce);
899 899
900 uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length]; 900 uint8_t packet[DATA_IN_RESPONSE_MIN_SIZE + length];
901 memcpy(packet, onion_c->c->self_public_key, crypto_box_PUBLICKEYBYTES); 901 memcpy(packet, onion_c->c->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
902 int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, 902 int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data,
903 length, packet + crypto_box_PUBLICKEYBYTES); 903 length, packet + CRYPTO_PUBLIC_KEY_SIZE);
904 904
905 if ((uint32_t)len + crypto_box_PUBLICKEYBYTES != sizeof(packet)) { 905 if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE != sizeof(packet)) {
906 return -1; 906 return -1;
907 } 907 }
908 908
@@ -948,16 +948,16 @@ static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uin
948 return -1; 948 return -1;
949 } 949 }
950 950
951 uint8_t nonce[crypto_box_NONCEBYTES]; 951 uint8_t nonce[CRYPTO_NONCE_SIZE];
952 random_nonce(nonce); 952 random_nonce(nonce);
953 953
954 uint8_t temp[DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES + length]; 954 uint8_t temp[DATA_IN_RESPONSE_MIN_SIZE + CRYPTO_NONCE_SIZE + length];
955 memcpy(temp, onion_c->c->self_public_key, crypto_box_PUBLICKEYBYTES); 955 memcpy(temp, onion_c->c->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
956 memcpy(temp + crypto_box_PUBLICKEYBYTES, nonce, crypto_box_NONCEBYTES); 956 memcpy(temp + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE);
957 int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data, 957 int len = encrypt_data(onion_c->friends_list[friend_num].real_public_key, onion_c->c->self_secret_key, nonce, data,
958 length, temp + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES); 958 length, temp + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE);
959 959
960 if ((uint32_t)len + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES != sizeof(temp)) { 960 if ((uint32_t)len + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE != sizeof(temp)) {
961 return -1; 961 return -1;
962 } 962 }
963 963
@@ -977,20 +977,20 @@ static int handle_dht_dhtpk(void *object, IP_Port source, const uint8_t *source_
977{ 977{
978 Onion_Client *onion_c = (Onion_Client *)object; 978 Onion_Client *onion_c = (Onion_Client *)object;
979 979
980 if (length < DHTPK_DATA_MIN_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES) { 980 if (length < DHTPK_DATA_MIN_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + CRYPTO_NONCE_SIZE) {
981 return 1; 981 return 1;
982 } 982 }
983 983
984 if (length > DHTPK_DATA_MAX_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES) { 984 if (length > DHTPK_DATA_MAX_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + CRYPTO_NONCE_SIZE) {
985 return 1; 985 return 1;
986 } 986 }
987 987
988 uint8_t plain[DHTPK_DATA_MAX_LENGTH]; 988 uint8_t plain[DHTPK_DATA_MAX_LENGTH];
989 int len = decrypt_data(packet, onion_c->c->self_secret_key, packet + crypto_box_PUBLICKEYBYTES, 989 int len = decrypt_data(packet, onion_c->c->self_secret_key, packet + CRYPTO_PUBLIC_KEY_SIZE,
990 packet + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, 990 packet + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE,
991 length - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES), plain); 991 length - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE), plain);
992 992
993 if (len != length - (DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES)) { 993 if (len != length - (DATA_IN_RESPONSE_MIN_SIZE + CRYPTO_NONCE_SIZE)) {
994 return 1; 994 return 1;
995 } 995 }
996 996
@@ -1020,7 +1020,7 @@ static int send_dhtpk_announce(Onion_Client *onion_c, uint16_t friend_num, uint8
1020 uint64_t no_replay = unix_time(); 1020 uint64_t no_replay = unix_time();
1021 host_to_net((uint8_t *)&no_replay, sizeof(no_replay)); 1021 host_to_net((uint8_t *)&no_replay, sizeof(no_replay));
1022 memcpy(data + 1, &no_replay, sizeof(no_replay)); 1022 memcpy(data + 1, &no_replay, sizeof(no_replay));
1023 memcpy(data + 1 + sizeof(uint64_t), onion_c->dht->self_public_key, crypto_box_PUBLICKEYBYTES); 1023 memcpy(data + 1 + sizeof(uint64_t), onion_c->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
1024 Node_format nodes[MAX_SENT_NODES]; 1024 Node_format nodes[MAX_SENT_NODES];
1025 uint16_t num_relays = copy_connected_tcp_relays(onion_c->c, nodes, (MAX_SENT_NODES / 2)); 1025 uint16_t num_relays = copy_connected_tcp_relays(onion_c->c, nodes, (MAX_SENT_NODES / 2));
1026 uint16_t num_nodes = closelist_nodes(onion_c->dht, &nodes[num_relays], MAX_SENT_NODES - num_relays); 1026 uint16_t num_nodes = closelist_nodes(onion_c->dht, &nodes[num_relays], MAX_SENT_NODES - num_relays);
@@ -1135,8 +1135,8 @@ int onion_addfriend(Onion_Client *onion_c, const uint8_t *public_key)
1135 } 1135 }
1136 1136
1137 onion_c->friends_list[index].status = 1; 1137 onion_c->friends_list[index].status = 1;
1138 memcpy(onion_c->friends_list[index].real_public_key, public_key, crypto_box_PUBLICKEYBYTES); 1138 memcpy(onion_c->friends_list[index].real_public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE);
1139 crypto_box_keypair(onion_c->friends_list[index].temp_public_key, onion_c->friends_list[index].temp_secret_key); 1139 crypto_new_keypair(onion_c->friends_list[index].temp_public_key, onion_c->friends_list[index].temp_secret_key);
1140 return index; 1140 return index;
1141} 1141}
1142 1142
@@ -1154,7 +1154,7 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num)
1154 //if (onion_c->friends_list[friend_num].know_dht_public_key) 1154 //if (onion_c->friends_list[friend_num].know_dht_public_key)
1155 // DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, 0); 1155 // DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, 0);
1156 1156
1157 sodium_memzero(&(onion_c->friends_list[friend_num]), sizeof(Onion_Friend)); 1157 crypto_memzero(&(onion_c->friends_list[friend_num]), sizeof(Onion_Friend));
1158 unsigned int i; 1158 unsigned int i;
1159 1159
1160 for (i = onion_c->num_friends; i != 0; --i) { 1160 for (i = onion_c->num_friends; i != 0; --i) {
@@ -1238,7 +1238,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
1238 1238
1239 onion_c->friends_list[friend_num].last_seen = unix_time(); 1239 onion_c->friends_list[friend_num].last_seen = unix_time();
1240 onion_c->friends_list[friend_num].know_dht_public_key = 1; 1240 onion_c->friends_list[friend_num].know_dht_public_key = 1;
1241 memcpy(onion_c->friends_list[friend_num].dht_public_key, dht_key, crypto_box_PUBLICKEYBYTES); 1241 memcpy(onion_c->friends_list[friend_num].dht_public_key, dht_key, CRYPTO_PUBLIC_KEY_SIZE);
1242 1242
1243 return 0; 1243 return 0;
1244} 1244}
@@ -1262,7 +1262,7 @@ unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_
1262 return 0; 1262 return 0;
1263 } 1263 }
1264 1264
1265 memcpy(dht_key, onion_c->friends_list[friend_num].dht_public_key, crypto_box_PUBLICKEYBYTES); 1265 memcpy(dht_key, onion_c->friends_list[friend_num].dht_public_key, CRYPTO_PUBLIC_KEY_SIZE);
1266 return 1; 1266 return 1;
1267} 1267}
1268 1268
@@ -1275,7 +1275,7 @@ unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_
1275 */ 1275 */
1276int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port) 1276int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port)
1277{ 1277{
1278 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES]; 1278 uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE];
1279 1279
1280 if (onion_getfriend_DHT_pubkey(onion_c, friend_num, dht_public_key) == 0) { 1280 if (onion_getfriend_DHT_pubkey(onion_c, friend_num, dht_public_key) == 0) {
1281 return -1; 1281 return -1;
@@ -1620,7 +1620,7 @@ Onion_Client *new_onion_client(Net_Crypto *c)
1620 onion_c->net = c->dht->net; 1620 onion_c->net = c->dht->net;
1621 onion_c->c = c; 1621 onion_c->c = c;
1622 new_symmetric_key(onion_c->secret_symmetric_key); 1622 new_symmetric_key(onion_c->secret_symmetric_key);
1623 crypto_box_keypair(onion_c->temp_public_key, onion_c->temp_secret_key); 1623 crypto_new_keypair(onion_c->temp_public_key, onion_c->temp_secret_key);
1624 networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c); 1624 networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c);
1625 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); 1625 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c);
1626 oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, &handle_dhtpk_announce, onion_c); 1626 oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, &handle_dhtpk_announce, onion_c);
@@ -1643,7 +1643,7 @@ void kill_onion_client(Onion_Client *onion_c)
1643 oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, NULL, NULL); 1643 oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, NULL, NULL);
1644 cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, NULL, NULL); 1644 cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, NULL, NULL);
1645 set_onion_packet_tcp_connection_callback(onion_c->c->tcp_c, NULL, NULL); 1645 set_onion_packet_tcp_connection_callback(onion_c->c->tcp_c, NULL, NULL);
1646 sodium_memzero(onion_c, sizeof(Onion_Client)); 1646 crypto_memzero(onion_c, sizeof(Onion_Client));
1647 free(onion_c); 1647 free(onion_c);
1648} 1648}
1649 1649