diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 44 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 8 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 2 | ||||
-rw-r--r-- | toxcore/network.h | 1 | ||||
-rw-r--r-- | toxcore/ping.c | 14 |
5 files changed, 39 insertions, 30 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index ee51f16c..bce726c8 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -131,6 +131,7 @@ static int client_in_list(Client_data *list, uint32_t length, uint8_t *client_id | |||
131 | uint64_t temp_time = unix_time(); | 131 | uint64_t temp_time = unix_time(); |
132 | 132 | ||
133 | for (i = 0; i < length; i++) | 133 | for (i = 0; i < length; i++) |
134 | |||
134 | /* Dead nodes are considered dead (not in the list)*/ | 135 | /* Dead nodes are considered dead (not in the list)*/ |
135 | if (!is_timeout(temp_time, list[i].assoc4.timestamp, KILL_NODE_TIMEOUT) || | 136 | if (!is_timeout(temp_time, list[i].assoc4.timestamp, KILL_NODE_TIMEOUT) || |
136 | !is_timeout(temp_time, list[i].assoc6.timestamp, KILL_NODE_TIMEOUT)) | 137 | !is_timeout(temp_time, list[i].assoc6.timestamp, KILL_NODE_TIMEOUT)) |
@@ -289,6 +290,7 @@ static void get_close_nodes_inner(DHT *dht, uint8_t *client_id, Node_format *nod | |||
289 | continue; | 290 | continue; |
290 | 291 | ||
291 | IPPTsPng *ipptp = NULL; | 292 | IPPTsPng *ipptp = NULL; |
293 | |||
292 | if (sa_family == AF_INET) | 294 | if (sa_family == AF_INET) |
293 | ipptp = &client->assoc4; | 295 | ipptp = &client->assoc4; |
294 | else | 296 | else |
@@ -640,9 +642,9 @@ static int getnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cli | |||
640 | if (ping_id == 0) | 642 | if (ping_id == 0) |
641 | return -1; | 643 | return -1; |
642 | 644 | ||
643 | uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + CLIENT_ID_SIZE + ENCRYPTION_PADDING]; | 645 | uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + CLIENT_ID_SIZE + crypto_box_MACBYTES]; |
644 | uint8_t plain[sizeof(ping_id) + CLIENT_ID_SIZE]; | 646 | uint8_t plain[sizeof(ping_id) + CLIENT_ID_SIZE]; |
645 | uint8_t encrypt[sizeof(ping_id) + CLIENT_ID_SIZE + ENCRYPTION_PADDING]; | 647 | uint8_t encrypt[sizeof(ping_id) + CLIENT_ID_SIZE + crypto_box_MACBYTES]; |
646 | uint8_t nonce[crypto_box_NONCEBYTES]; | 648 | uint8_t nonce[crypto_box_NONCEBYTES]; |
647 | new_nonce(nonce); | 649 | new_nonce(nonce); |
648 | 650 | ||
@@ -656,7 +658,7 @@ static int getnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cli | |||
656 | sizeof(ping_id) + CLIENT_ID_SIZE, | 658 | sizeof(ping_id) + CLIENT_ID_SIZE, |
657 | encrypt ); | 659 | encrypt ); |
658 | 660 | ||
659 | if (len != sizeof(ping_id) + CLIENT_ID_SIZE + ENCRYPTION_PADDING) | 661 | if (len != sizeof(ping_id) + CLIENT_ID_SIZE + crypto_box_MACBYTES) |
660 | return -1; | 662 | return -1; |
661 | 663 | ||
662 | data[0] = NET_PACKET_GET_NODES; | 664 | data[0] = NET_PACKET_GET_NODES; |
@@ -667,6 +669,8 @@ static int getnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cli | |||
667 | return sendpacket(dht->c->lossless_udp->net, ip_port, data, sizeof(data)); | 669 | return sendpacket(dht->c->lossless_udp->net, ip_port, data, sizeof(data)); |
668 | } | 670 | } |
669 | 671 | ||
672 | #define NODES_ENCRYPTED_MESSAGE_LENGTH (sizeof(Node_format) + crypto_secretbox_MACBYTES) | ||
673 | |||
670 | /* Send a send nodes response. */ | 674 | /* Send a send nodes response. */ |
671 | /* because of BINARY compatibility, the Node_format MUST BE Node4_format, | 675 | /* because of BINARY compatibility, the Node_format MUST BE Node4_format, |
672 | * IPv6 nodes are sent in a different message */ | 676 | * IPv6 nodes are sent in a different message */ |
@@ -678,7 +682,7 @@ static int sendnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cl | |||
678 | 682 | ||
679 | size_t Node4_format_size = sizeof(Node4_format); | 683 | size_t Node4_format_size = sizeof(Node4_format); |
680 | uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) | 684 | uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) |
681 | + Node4_format_size * MAX_SENT_NODES + ENCRYPTION_PADDING]; | 685 | + Node4_format_size * MAX_SENT_NODES + crypto_box_MACBYTES]; |
682 | 686 | ||
683 | Node_format nodes_list[MAX_SENT_NODES]; | 687 | Node_format nodes_list[MAX_SENT_NODES]; |
684 | int num_nodes = get_close_nodes(dht, client_id, nodes_list, AF_INET, LAN_ip(ip_port.ip) == 0); | 688 | int num_nodes = get_close_nodes(dht, client_id, nodes_list, AF_INET, LAN_ip(ip_port.ip) == 0); |
@@ -687,7 +691,7 @@ static int sendnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cl | |||
687 | return 0; | 691 | return 0; |
688 | 692 | ||
689 | uint8_t plain[sizeof(ping_id) + Node4_format_size * MAX_SENT_NODES]; | 693 | uint8_t plain[sizeof(ping_id) + Node4_format_size * MAX_SENT_NODES]; |
690 | uint8_t encrypt[sizeof(ping_id) + Node4_format_size * MAX_SENT_NODES + ENCRYPTION_PADDING]; | 694 | uint8_t encrypt[sizeof(ping_id) + Node4_format_size * MAX_SENT_NODES + crypto_box_MACBYTES]; |
691 | uint8_t nonce[crypto_box_NONCEBYTES]; | 695 | uint8_t nonce[crypto_box_NONCEBYTES]; |
692 | new_nonce(nonce); | 696 | new_nonce(nonce); |
693 | 697 | ||
@@ -728,7 +732,7 @@ static int sendnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cl | |||
728 | if (len == -1) | 732 | if (len == -1) |
729 | return -1; | 733 | return -1; |
730 | 734 | ||
731 | if ((unsigned int)len != sizeof(ping_id) + num_nodes * Node4_format_size + ENCRYPTION_PADDING) | 735 | if ((unsigned int)len != sizeof(ping_id) + num_nodes * Node4_format_size + crypto_box_MACBYTES) |
732 | return -1; | 736 | return -1; |
733 | 737 | ||
734 | data[0] = NET_PACKET_SEND_NODES; | 738 | data[0] = NET_PACKET_SEND_NODES; |
@@ -748,7 +752,7 @@ static int sendnodes_ipv6(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_ | |||
748 | 752 | ||
749 | size_t Node_format_size = sizeof(Node_format); | 753 | size_t Node_format_size = sizeof(Node_format); |
750 | uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) | 754 | uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) |
751 | + Node_format_size * MAX_SENT_NODES + ENCRYPTION_PADDING]; | 755 | + Node_format_size * MAX_SENT_NODES + crypto_box_MACBYTES]; |
752 | 756 | ||
753 | Node_format nodes_list[MAX_SENT_NODES]; | 757 | Node_format nodes_list[MAX_SENT_NODES]; |
754 | int num_nodes = get_close_nodes(dht, client_id, nodes_list, AF_INET6, LAN_ip(ip_port.ip) == 0); | 758 | int num_nodes = get_close_nodes(dht, client_id, nodes_list, AF_INET6, LAN_ip(ip_port.ip) == 0); |
@@ -757,7 +761,7 @@ static int sendnodes_ipv6(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_ | |||
757 | return 0; | 761 | return 0; |
758 | 762 | ||
759 | uint8_t plain[sizeof(ping_id) + Node_format_size * MAX_SENT_NODES]; | 763 | uint8_t plain[sizeof(ping_id) + Node_format_size * MAX_SENT_NODES]; |
760 | uint8_t encrypt[sizeof(ping_id) + Node_format_size * MAX_SENT_NODES + ENCRYPTION_PADDING]; | 764 | uint8_t encrypt[sizeof(ping_id) + Node_format_size * MAX_SENT_NODES + crypto_box_MACBYTES]; |
761 | uint8_t nonce[crypto_box_NONCEBYTES]; | 765 | uint8_t nonce[crypto_box_NONCEBYTES]; |
762 | new_nonce(nonce); | 766 | new_nonce(nonce); |
763 | 767 | ||
@@ -774,7 +778,7 @@ static int sendnodes_ipv6(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_ | |||
774 | if (len == -1) | 778 | if (len == -1) |
775 | return -1; | 779 | return -1; |
776 | 780 | ||
777 | if ((unsigned int)len != sizeof(ping_id) + num_nodes * Node_format_size + ENCRYPTION_PADDING) | 781 | if ((unsigned int)len != sizeof(ping_id) + num_nodes * Node_format_size + crypto_box_MACBYTES) |
778 | return -1; | 782 | return -1; |
779 | 783 | ||
780 | data[0] = NET_PACKET_SEND_NODES_IPV6; | 784 | data[0] = NET_PACKET_SEND_NODES_IPV6; |
@@ -791,7 +795,7 @@ static int handle_getnodes(void *object, IP_Port source, uint8_t *packet, uint32 | |||
791 | uint64_t ping_id; | 795 | uint64_t ping_id; |
792 | 796 | ||
793 | if (length != ( 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES | 797 | if (length != ( 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES |
794 | + sizeof(ping_id) + CLIENT_ID_SIZE + ENCRYPTION_PADDING )) | 798 | + sizeof(ping_id) + CLIENT_ID_SIZE + crypto_box_MACBYTES )) |
795 | return 1; | 799 | return 1; |
796 | 800 | ||
797 | /* Check if packet is from ourself. */ | 801 | /* Check if packet is from ourself. */ |
@@ -804,7 +808,7 @@ static int handle_getnodes(void *object, IP_Port source, uint8_t *packet, uint32 | |||
804 | dht->c->self_secret_key, | 808 | dht->c->self_secret_key, |
805 | packet + 1 + CLIENT_ID_SIZE, | 809 | packet + 1 + CLIENT_ID_SIZE, |
806 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, | 810 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, |
807 | sizeof(ping_id) + CLIENT_ID_SIZE + ENCRYPTION_PADDING, | 811 | sizeof(ping_id) + CLIENT_ID_SIZE + crypto_box_MACBYTES, |
808 | plain ); | 812 | plain ); |
809 | 813 | ||
810 | if (len != sizeof(ping_id) + CLIENT_ID_SIZE) | 814 | if (len != sizeof(ping_id) + CLIENT_ID_SIZE) |
@@ -826,7 +830,7 @@ static int handle_sendnodes(void *object, IP_Port source, uint8_t *packet, uint3 | |||
826 | DHT *dht = object; | 830 | DHT *dht = object; |
827 | uint64_t ping_id; | 831 | uint64_t ping_id; |
828 | uint32_t cid_size = 1 + CLIENT_ID_SIZE; | 832 | uint32_t cid_size = 1 + CLIENT_ID_SIZE; |
829 | cid_size += crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING; | 833 | cid_size += crypto_box_NONCEBYTES + sizeof(ping_id) + crypto_box_MACBYTES; |
830 | 834 | ||
831 | size_t Node4_format_size = sizeof(Node4_format); | 835 | size_t Node4_format_size = sizeof(Node4_format); |
832 | 836 | ||
@@ -843,7 +847,7 @@ static int handle_sendnodes(void *object, IP_Port source, uint8_t *packet, uint3 | |||
843 | dht->c->self_secret_key, | 847 | dht->c->self_secret_key, |
844 | packet + 1 + CLIENT_ID_SIZE, | 848 | packet + 1 + CLIENT_ID_SIZE, |
845 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, | 849 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, |
846 | sizeof(ping_id) + num_nodes * Node4_format_size + ENCRYPTION_PADDING, plain ); | 850 | sizeof(ping_id) + num_nodes * Node4_format_size + crypto_box_MACBYTES, plain ); |
847 | 851 | ||
848 | if ((unsigned int)len != sizeof(ping_id) + num_nodes * Node4_format_size) | 852 | if ((unsigned int)len != sizeof(ping_id) + num_nodes * Node4_format_size) |
849 | return 1; | 853 | return 1; |
@@ -888,7 +892,7 @@ static int handle_sendnodes_ipv6(void *object, IP_Port source, uint8_t *packet, | |||
888 | DHT *dht = object; | 892 | DHT *dht = object; |
889 | uint64_t ping_id; | 893 | uint64_t ping_id; |
890 | uint32_t cid_size = 1 + CLIENT_ID_SIZE; | 894 | uint32_t cid_size = 1 + CLIENT_ID_SIZE; |
891 | cid_size += crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING; | 895 | cid_size += crypto_box_NONCEBYTES + sizeof(ping_id) + crypto_box_MACBYTES; |
892 | 896 | ||
893 | size_t Node_format_size = sizeof(Node_format); | 897 | size_t Node_format_size = sizeof(Node_format); |
894 | 898 | ||
@@ -905,7 +909,7 @@ static int handle_sendnodes_ipv6(void *object, IP_Port source, uint8_t *packet, | |||
905 | dht->c->self_secret_key, | 909 | dht->c->self_secret_key, |
906 | packet + 1 + CLIENT_ID_SIZE, | 910 | packet + 1 + CLIENT_ID_SIZE, |
907 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, | 911 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, |
908 | sizeof(ping_id) + num_nodes * Node_format_size + ENCRYPTION_PADDING, plain ); | 912 | sizeof(ping_id) + num_nodes * Node_format_size + crypto_box_MACBYTES, plain ); |
909 | 913 | ||
910 | if ((unsigned int)len != sizeof(ping_id) + num_nodes * Node_format_size) | 914 | if ((unsigned int)len != sizeof(ping_id) + num_nodes * Node_format_size) |
911 | return 1; | 915 | return 1; |
@@ -1193,14 +1197,16 @@ static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num) | |||
1193 | connected = 0; | 1197 | connected = 0; |
1194 | 1198 | ||
1195 | /* If ip is not zero and node is good. */ | 1199 | /* If ip is not zero and node is good. */ |
1196 | if (ip_isset(&client->assoc4.ret_ip_port.ip) && !is_timeout(temp_time, client->assoc4.ret_timestamp, BAD_NODE_TIMEOUT)) { | 1200 | if (ip_isset(&client->assoc4.ret_ip_port.ip) |
1201 | && !is_timeout(temp_time, client->assoc4.ret_timestamp, BAD_NODE_TIMEOUT)) { | ||
1197 | ipv4s[num_ipv4s] = client->assoc4.ret_ip_port; | 1202 | ipv4s[num_ipv4s] = client->assoc4.ret_ip_port; |
1198 | ++num_ipv4s; | 1203 | ++num_ipv4s; |
1199 | 1204 | ||
1200 | connected = 1; | 1205 | connected = 1; |
1201 | } | 1206 | } |
1202 | 1207 | ||
1203 | if (ip_isset(&client->assoc6.ret_ip_port.ip) && !is_timeout(temp_time, client->assoc6.ret_timestamp, BAD_NODE_TIMEOUT)) { | 1208 | if (ip_isset(&client->assoc6.ret_ip_port.ip) |
1209 | && !is_timeout(temp_time, client->assoc6.ret_timestamp, BAD_NODE_TIMEOUT)) { | ||
1204 | ipv6s[num_ipv6s] = client->assoc6.ret_ip_port; | 1210 | ipv6s[num_ipv6s] = client->assoc6.ret_ip_port; |
1205 | ++num_ipv6s; | 1211 | ++num_ipv6s; |
1206 | 1212 | ||
@@ -1213,12 +1219,15 @@ static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num) | |||
1213 | 1219 | ||
1214 | #ifdef FRIEND_IPLIST_PAD | 1220 | #ifdef FRIEND_IPLIST_PAD |
1215 | memcpy(ip_portlist, ipv6s, num_ipv6s * sizeof(IP_Port)); | 1221 | memcpy(ip_portlist, ipv6s, num_ipv6s * sizeof(IP_Port)); |
1222 | |||
1216 | if (num_ipv6s == MAX_FRIEND_CLIENTS) | 1223 | if (num_ipv6s == MAX_FRIEND_CLIENTS) |
1217 | return MAX_FRIEND_CLIENTS; | 1224 | return MAX_FRIEND_CLIENTS; |
1218 | 1225 | ||
1219 | int num_ipv4s_used = MAX_FRIEND_CLIENTS - num_ipv6s; | 1226 | int num_ipv4s_used = MAX_FRIEND_CLIENTS - num_ipv6s; |
1227 | |||
1220 | if (num_ipv4s_used > num_ipv4s) | 1228 | if (num_ipv4s_used > num_ipv4s) |
1221 | num_ipv4s_used = num_ipv4s; | 1229 | num_ipv4s_used = num_ipv4s; |
1230 | |||
1222 | memcpy(&ip_portlist[num_ipv6s], ipv4s, num_ipv4s_used * sizeof(IP_Port)); | 1231 | memcpy(&ip_portlist[num_ipv6s], ipv4s, num_ipv4s_used * sizeof(IP_Port)); |
1223 | return num_ipv6s + num_ipv4s_used; | 1232 | return num_ipv6s + num_ipv4s_used; |
1224 | 1233 | ||
@@ -1825,6 +1834,7 @@ static int dht_load_state_callback(void *outer, uint8_t *data, uint32_t length, | |||
1825 | break; | 1834 | break; |
1826 | 1835 | ||
1827 | #ifdef DEBUG | 1836 | #ifdef DEBUG |
1837 | |||
1828 | default: | 1838 | default: |
1829 | fprintf(stderr, "Load state (DHT): contains unrecognized part (len %u, type %u)\n", | 1839 | fprintf(stderr, "Load state (DHT): contains unrecognized part (len %u, type %u)\n", |
1830 | length, type); | 1840 | length, type); |
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index a9aa77f9..3c16f0ac 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -247,7 +247,7 @@ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uin | |||
247 | int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key, | 247 | int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t *packet, uint8_t *recv_public_key, |
248 | uint8_t *data, uint32_t length, uint8_t request_id) | 248 | uint8_t *data, uint32_t length, uint8_t request_id) |
249 | { | 249 | { |
250 | if (MAX_DATA_SIZE < length + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING) | 250 | if (MAX_DATA_SIZE < length + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES) |
251 | return -1; | 251 | return -1; |
252 | 252 | ||
253 | uint8_t nonce[crypto_box_NONCEBYTES]; | 253 | uint8_t nonce[crypto_box_NONCEBYTES]; |
@@ -278,7 +278,7 @@ int create_request(uint8_t *send_public_key, uint8_t *send_secret_key, uint8_t * | |||
278 | int handle_request(uint8_t *self_public_key, uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data, | 278 | int handle_request(uint8_t *self_public_key, uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data, |
279 | uint8_t *request_id, uint8_t *packet, uint16_t length) | 279 | uint8_t *request_id, uint8_t *packet, uint16_t length) |
280 | { | 280 | { |
281 | if (length > crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING && | 281 | if (length > crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES && |
282 | length <= MAX_DATA_SIZE) { | 282 | length <= MAX_DATA_SIZE) { |
283 | if (memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) { | 283 | if (memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) { |
284 | memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES); | 284 | memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES); |
@@ -313,8 +313,8 @@ static int cryptopacket_handle(void *object, IP_Port source, uint8_t *packet, ui | |||
313 | DHT *dht = object; | 313 | DHT *dht = object; |
314 | 314 | ||
315 | if (packet[0] == NET_PACKET_CRYPTO) { | 315 | if (packet[0] == NET_PACKET_CRYPTO) { |
316 | if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + ENCRYPTION_PADDING || | 316 | if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES || |
317 | length > MAX_DATA_SIZE + ENCRYPTION_PADDING) | 317 | length > MAX_DATA_SIZE + crypto_box_MACBYTES) |
318 | return 1; | 318 | return 1; |
319 | 319 | ||
320 | if (memcmp(packet + 1, dht->c->self_public_key, crypto_box_PUBLICKEYBYTES) == 0) { // Check if request is for us. | 320 | if (memcmp(packet + 1, dht->c->self_public_key, crypto_box_PUBLICKEYBYTES) == 0) { // Check if request is for us. |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 0de66e98..3ec70c21 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -77,8 +77,6 @@ typedef struct { | |||
77 | 77 | ||
78 | #include "DHT.h" | 78 | #include "DHT.h" |
79 | 79 | ||
80 | #define ENCRYPTION_PADDING (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) | ||
81 | |||
82 | /* return zero if the buffer contains only zeros. */ | 80 | /* return zero if the buffer contains only zeros. */ |
83 | uint8_t crypto_iszero(uint8_t *buffer, uint32_t blen); | 81 | uint8_t crypto_iszero(uint8_t *buffer, uint32_t blen); |
84 | 82 | ||
diff --git a/toxcore/network.h b/toxcore/network.h index 1253c07e..0b76a574 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -70,6 +70,7 @@ typedef int sock_t; | |||
70 | #include <crypto_box.h> | 70 | #include <crypto_box.h> |
71 | #include <randombytes.h> | 71 | #include <randombytes.h> |
72 | #define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) | 72 | #define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) |
73 | #define crypto_secretbox_MACBYTES (crypto_secretbox_ZEROBYTES - crypto_secretbox_BOXZEROBYTES) | ||
73 | #endif | 74 | #endif |
74 | 75 | ||
75 | #ifndef IPV6_ADD_MEMBERSHIP | 76 | #ifndef IPV6_ADD_MEMBERSHIP |
diff --git a/toxcore/ping.c b/toxcore/ping.c index 2d0a4545..5fd34972 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * This file is donated to the Tox Project. | 4 | * This file is donated to the Tox Project. |
5 | * Copyright 2013 plutooo | 5 | * Copyright 2013 plutooo |
6 | * | 6 | * |
7 | * Copyright (C) 2013 Tox project All Rights Reserved. | 7 | * Copyright (C) 2013 Tox project All Rights Reserved. |
8 | * | 8 | * |
9 | * This file is part of Tox. | 9 | * This file is part of Tox. |
@@ -20,7 +20,7 @@ | |||
20 | * | 20 | * |
21 | * You should have received a copy of the GNU General Public License | 21 | * You should have received a copy of the GNU General Public License |
22 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | 22 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. |
23 | * | 23 | * |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #ifdef HAVE_CONFIG_H | 26 | #ifdef HAVE_CONFIG_H |
@@ -132,7 +132,7 @@ static bool is_pinging(PING *ping, IP_Port ipp, uint64_t ping_id) // O(n) TOD | |||
132 | return false; | 132 | return false; |
133 | } | 133 | } |
134 | 134 | ||
135 | #define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(uint64_t) + ENCRYPTION_PADDING) | 135 | #define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(uint64_t) + crypto_box_MACBYTES) |
136 | 136 | ||
137 | int send_ping_request(PING *ping, IP_Port ipp, uint8_t *client_id) | 137 | int send_ping_request(PING *ping, IP_Port ipp, uint8_t *client_id) |
138 | { | 138 | { |
@@ -157,7 +157,7 @@ int send_ping_request(PING *ping, IP_Port ipp, uint8_t *client_id) | |||
157 | (uint8_t *) &ping_id, sizeof(ping_id), | 157 | (uint8_t *) &ping_id, sizeof(ping_id), |
158 | pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES); | 158 | pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES); |
159 | 159 | ||
160 | if (rc != sizeof(ping_id) + ENCRYPTION_PADDING) | 160 | if (rc != sizeof(ping_id) + crypto_box_MACBYTES) |
161 | return 1; | 161 | return 1; |
162 | 162 | ||
163 | return sendpacket(ping->c->lossless_udp->net, ipp, pk, sizeof(pk)); | 163 | return sendpacket(ping->c->lossless_udp->net, ipp, pk, sizeof(pk)); |
@@ -182,7 +182,7 @@ static int send_ping_response(PING *ping, IP_Port ipp, uint8_t *client_id, uint6 | |||
182 | (uint8_t *) &ping_id, sizeof(ping_id), | 182 | (uint8_t *) &ping_id, sizeof(ping_id), |
183 | pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES); | 183 | pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES); |
184 | 184 | ||
185 | if (rc != sizeof(ping_id) + ENCRYPTION_PADDING) | 185 | if (rc != sizeof(ping_id) + crypto_box_MACBYTES) |
186 | return 1; | 186 | return 1; |
187 | 187 | ||
188 | return sendpacket(ping->c->lossless_udp->net, ipp, pk, sizeof(pk)); | 188 | return sendpacket(ping->c->lossless_udp->net, ipp, pk, sizeof(pk)); |
@@ -207,7 +207,7 @@ static int handle_ping_request(void *_dht, IP_Port source, uint8_t *packet, uint | |||
207 | ping->c->self_secret_key, | 207 | ping->c->self_secret_key, |
208 | packet + 1 + CLIENT_ID_SIZE, | 208 | packet + 1 + CLIENT_ID_SIZE, |
209 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, | 209 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, |
210 | sizeof(ping_id) + ENCRYPTION_PADDING, | 210 | sizeof(ping_id) + crypto_box_MACBYTES, |
211 | (uint8_t *) &ping_id); | 211 | (uint8_t *) &ping_id); |
212 | 212 | ||
213 | if (rc != sizeof(ping_id)) | 213 | if (rc != sizeof(ping_id)) |
@@ -239,7 +239,7 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin | |||
239 | ping->c->self_secret_key, | 239 | ping->c->self_secret_key, |
240 | packet + 1 + CLIENT_ID_SIZE, | 240 | packet + 1 + CLIENT_ID_SIZE, |
241 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, | 241 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, |
242 | sizeof(ping_id) + ENCRYPTION_PADDING, | 242 | sizeof(ping_id) + crypto_box_MACBYTES, |
243 | (uint8_t *) &ping_id); | 243 | (uint8_t *) &ping_id); |
244 | 244 | ||
245 | if (rc != sizeof(ping_id)) | 245 | if (rc != sizeof(ping_id)) |