diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-12-19 02:47:42 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-12-22 10:26:59 +0000 |
commit | ce29c8e7ec91d95167b2dea3aee9fd1ae1aac254 (patch) | |
tree | a288df55c44e8edf816e6abbde19a70faef73394 /toxcore/DHT.c | |
parent | 7122d2e862e028a730478d88cd61557fbed16ebf (diff) |
Wrap all sodium/nacl functions in crypto_core.c.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 186 |
1 files changed, 93 insertions, 93 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 5185353e..e31405fd 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -68,7 +68,7 @@ int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2) | |||
68 | size_t i; | 68 | size_t i; |
69 | uint8_t distance1, distance2; | 69 | uint8_t distance1, distance2; |
70 | 70 | ||
71 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { | 71 | for (i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; ++i) { |
72 | 72 | ||
73 | distance1 = pk[i] ^ pk1[i]; | 73 | distance1 = pk[i] ^ pk1[i]; |
74 | distance2 = pk[i] ^ pk2[i]; | 74 | distance2 = pk[i] ^ pk2[i]; |
@@ -91,7 +91,7 @@ static unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2) | |||
91 | { | 91 | { |
92 | unsigned int i, j = 0; | 92 | unsigned int i, j = 0; |
93 | 93 | ||
94 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { | 94 | for (i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; ++i) { |
95 | if (pk1[i] == pk2[i]) { | 95 | if (pk1[i] == pk2[i]) { |
96 | continue; | 96 | continue; |
97 | } | 97 | } |
@@ -123,7 +123,7 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t | |||
123 | 123 | ||
124 | if (shared_keys->keys[index].stored) { | 124 | if (shared_keys->keys[index].stored) { |
125 | if (public_key_cmp(public_key, shared_keys->keys[index].public_key) == 0) { | 125 | if (public_key_cmp(public_key, shared_keys->keys[index].public_key) == 0) { |
126 | memcpy(shared_key, shared_keys->keys[index].shared_key, crypto_box_BEFORENMBYTES); | 126 | memcpy(shared_key, shared_keys->keys[index].shared_key, CRYPTO_SHARED_KEY_SIZE); |
127 | ++shared_keys->keys[index].times_requested; | 127 | ++shared_keys->keys[index].times_requested; |
128 | shared_keys->keys[index].time_last_requested = unix_time(); | 128 | shared_keys->keys[index].time_last_requested = unix_time(); |
129 | return; | 129 | return; |
@@ -151,8 +151,8 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t | |||
151 | if (num != (uint32_t)~0) { | 151 | if (num != (uint32_t)~0) { |
152 | shared_keys->keys[curr].stored = 1; | 152 | shared_keys->keys[curr].stored = 1; |
153 | shared_keys->keys[curr].times_requested = 1; | 153 | shared_keys->keys[curr].times_requested = 1; |
154 | memcpy(shared_keys->keys[curr].public_key, public_key, crypto_box_PUBLICKEYBYTES); | 154 | memcpy(shared_keys->keys[curr].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
155 | memcpy(shared_keys->keys[curr].shared_key, shared_key, crypto_box_BEFORENMBYTES); | 155 | memcpy(shared_keys->keys[curr].shared_key, shared_key, CRYPTO_SHARED_KEY_SIZE); |
156 | shared_keys->keys[curr].time_last_requested = unix_time(); | 156 | shared_keys->keys[curr].time_last_requested = unix_time(); |
157 | } | 157 | } |
158 | } | 158 | } |
@@ -190,28 +190,28 @@ int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_ke | |||
190 | return -1; | 190 | return -1; |
191 | } | 191 | } |
192 | 192 | ||
193 | if (MAX_CRYPTO_REQUEST_SIZE < length + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + | 193 | if (MAX_CRYPTO_REQUEST_SIZE < length + 1 + CRYPTO_PUBLIC_KEY_SIZE * 2 + CRYPTO_NONCE_SIZE + 1 + |
194 | crypto_box_MACBYTES) { | 194 | CRYPTO_MAC_SIZE) { |
195 | return -1; | 195 | return -1; |
196 | } | 196 | } |
197 | 197 | ||
198 | uint8_t *nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2; | 198 | uint8_t *nonce = packet + 1 + CRYPTO_PUBLIC_KEY_SIZE * 2; |
199 | random_nonce(nonce); | 199 | random_nonce(nonce); |
200 | uint8_t temp[MAX_CRYPTO_REQUEST_SIZE]; // TODO(irungentoo): sodium_memzero before exit function | 200 | uint8_t temp[MAX_CRYPTO_REQUEST_SIZE]; // TODO(irungentoo): sodium_memzero before exit function |
201 | memcpy(temp + 1, data, length); | 201 | memcpy(temp + 1, data, length); |
202 | temp[0] = request_id; | 202 | temp[0] = request_id; |
203 | int len = encrypt_data(recv_public_key, send_secret_key, nonce, temp, length + 1, | 203 | int len = encrypt_data(recv_public_key, send_secret_key, nonce, temp, length + 1, |
204 | 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + packet); | 204 | 1 + CRYPTO_PUBLIC_KEY_SIZE * 2 + CRYPTO_NONCE_SIZE + packet); |
205 | 205 | ||
206 | if (len == -1) { | 206 | if (len == -1) { |
207 | return -1; | 207 | return -1; |
208 | } | 208 | } |
209 | 209 | ||
210 | packet[0] = NET_PACKET_CRYPTO; | 210 | packet[0] = NET_PACKET_CRYPTO; |
211 | memcpy(packet + 1, recv_public_key, crypto_box_PUBLICKEYBYTES); | 211 | memcpy(packet + 1, recv_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
212 | memcpy(packet + 1 + crypto_box_PUBLICKEYBYTES, send_public_key, crypto_box_PUBLICKEYBYTES); | 212 | memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, send_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
213 | 213 | ||
214 | return len + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES; | 214 | return len + 1 + CRYPTO_PUBLIC_KEY_SIZE * 2 + CRYPTO_NONCE_SIZE; |
215 | } | 215 | } |
216 | 216 | ||
217 | /* Puts the senders public key in the request in public_key, the data from the request | 217 | /* Puts the senders public key in the request in public_key, the data from the request |
@@ -227,7 +227,7 @@ int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_ke | |||
227 | return -1; | 227 | return -1; |
228 | } | 228 | } |
229 | 229 | ||
230 | if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES || | 230 | if (length <= CRYPTO_PUBLIC_KEY_SIZE * 2 + CRYPTO_NONCE_SIZE + 1 + CRYPTO_MAC_SIZE || |
231 | length > MAX_CRYPTO_REQUEST_SIZE) { | 231 | length > MAX_CRYPTO_REQUEST_SIZE) { |
232 | return -1; | 232 | return -1; |
233 | } | 233 | } |
@@ -236,12 +236,12 @@ int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_ke | |||
236 | return -1; | 236 | return -1; |
237 | } | 237 | } |
238 | 238 | ||
239 | memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES); | 239 | memcpy(public_key, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, CRYPTO_PUBLIC_KEY_SIZE); |
240 | const uint8_t *nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2; | 240 | const uint8_t *nonce = packet + 1 + CRYPTO_PUBLIC_KEY_SIZE * 2; |
241 | uint8_t temp[MAX_CRYPTO_REQUEST_SIZE]; // TODO(irungentoo): sodium_memzero before exit function | 241 | uint8_t temp[MAX_CRYPTO_REQUEST_SIZE]; // TODO(irungentoo): sodium_memzero before exit function |
242 | int len1 = decrypt_data(public_key, self_secret_key, nonce, | 242 | int len1 = decrypt_data(public_key, self_secret_key, nonce, |
243 | packet + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES, | 243 | packet + 1 + CRYPTO_PUBLIC_KEY_SIZE * 2 + CRYPTO_NONCE_SIZE, |
244 | length - (crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1), temp); | 244 | length - (CRYPTO_PUBLIC_KEY_SIZE * 2 + CRYPTO_NONCE_SIZE + 1), temp); |
245 | 245 | ||
246 | if (len1 == -1 || len1 == 0) { | 246 | if (len1 == -1 || len1 == 0) { |
247 | return -1; | 247 | return -1; |
@@ -277,8 +277,8 @@ int to_host_family(IP *ip) | |||
277 | return -1; | 277 | return -1; |
278 | } | 278 | } |
279 | 279 | ||
280 | #define PACKED_NODE_SIZE_IP4 (1 + SIZE_IP4 + sizeof(uint16_t) + crypto_box_PUBLICKEYBYTES) | 280 | #define PACKED_NODE_SIZE_IP4 (1 + SIZE_IP4 + sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE) |
281 | #define PACKED_NODE_SIZE_IP6 (1 + SIZE_IP6 + sizeof(uint16_t) + crypto_box_PUBLICKEYBYTES) | 281 | #define PACKED_NODE_SIZE_IP6 (1 + SIZE_IP6 + sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE) |
282 | 282 | ||
283 | /* Return packet size of packed node with ip_family on success. | 283 | /* Return packet size of packed node with ip_family on success. |
284 | * Return -1 on failure. | 284 | * Return -1 on failure. |
@@ -365,11 +365,11 @@ static int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port) | |||
365 | return -1; | 365 | return -1; |
366 | } | 366 | } |
367 | 367 | ||
368 | static int DHT_create_packet(const uint8_t public_key[crypto_box_PUBLICKEYBYTES], | 368 | static int DHT_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], |
369 | const uint8_t *shared_key, const uint8_t type, uint8_t *plain, size_t plain_length, uint8_t *packet) | 369 | const uint8_t *shared_key, const uint8_t type, uint8_t *plain, size_t plain_length, uint8_t *packet) |
370 | { | 370 | { |
371 | uint8_t encrypted[plain_length + crypto_box_MACBYTES]; | 371 | uint8_t encrypted[plain_length + CRYPTO_MAC_SIZE]; |
372 | uint8_t nonce[crypto_box_NONCEBYTES]; | 372 | uint8_t nonce[CRYPTO_NONCE_SIZE]; |
373 | 373 | ||
374 | random_nonce(nonce); | 374 | random_nonce(nonce); |
375 | 375 | ||
@@ -381,11 +381,11 @@ static int DHT_create_packet(const uint8_t public_key[crypto_box_PUBLICKEYBYTES] | |||
381 | } | 381 | } |
382 | 382 | ||
383 | packet[0] = type; | 383 | packet[0] = type; |
384 | memcpy(packet + 1, public_key, crypto_box_PUBLICKEYBYTES); | 384 | memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
385 | memcpy(packet + 1 + crypto_box_PUBLICKEYBYTES, nonce, crypto_box_NONCEBYTES); | 385 | memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE); |
386 | memcpy(packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, encrypted, encrypted_length); | 386 | memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, encrypted, encrypted_length); |
387 | 387 | ||
388 | return 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + encrypted_length; | 388 | return 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + encrypted_length; |
389 | } | 389 | } |
390 | 390 | ||
391 | /* Unpack IP_Port structure from data of max size length into ip_port. | 391 | /* Unpack IP_Port structure from data of max size length into ip_port. |
@@ -473,14 +473,14 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_ | |||
473 | 473 | ||
474 | packed_length += ipp_size; | 474 | packed_length += ipp_size; |
475 | 475 | ||
476 | if (packed_length + crypto_box_PUBLICKEYBYTES > length) { | 476 | if (packed_length + CRYPTO_PUBLIC_KEY_SIZE > length) { |
477 | return -1; | 477 | return -1; |
478 | } | 478 | } |
479 | 479 | ||
480 | memcpy(data + packed_length, nodes[i].public_key, crypto_box_PUBLICKEYBYTES); | 480 | memcpy(data + packed_length, nodes[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
481 | packed_length += crypto_box_PUBLICKEYBYTES; | 481 | packed_length += CRYPTO_PUBLIC_KEY_SIZE; |
482 | 482 | ||
483 | uint32_t increment = ipp_size + crypto_box_PUBLICKEYBYTES; | 483 | uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE; |
484 | assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6); | 484 | assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6); |
485 | } | 485 | } |
486 | 486 | ||
@@ -508,15 +508,15 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed | |||
508 | 508 | ||
509 | len_processed += ipp_size; | 509 | len_processed += ipp_size; |
510 | 510 | ||
511 | if (len_processed + crypto_box_PUBLICKEYBYTES > length) { | 511 | if (len_processed + CRYPTO_PUBLIC_KEY_SIZE > length) { |
512 | return -1; | 512 | return -1; |
513 | } | 513 | } |
514 | 514 | ||
515 | memcpy(nodes[num].public_key, data + len_processed, crypto_box_PUBLICKEYBYTES); | 515 | memcpy(nodes[num].public_key, data + len_processed, CRYPTO_PUBLIC_KEY_SIZE); |
516 | len_processed += crypto_box_PUBLICKEYBYTES; | 516 | len_processed += CRYPTO_PUBLIC_KEY_SIZE; |
517 | ++num; | 517 | ++num; |
518 | 518 | ||
519 | uint32_t increment = ipp_size + crypto_box_PUBLICKEYBYTES; | 519 | uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE; |
520 | assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6); | 520 | assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6); |
521 | } | 521 | } |
522 | 522 | ||
@@ -589,7 +589,7 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le | |||
589 | if ((ip_port.ip.family == AF_INET) && ipport_equal(&list[i].assoc4.ip_port, &ip_port)) { | 589 | if ((ip_port.ip.family == AF_INET) && ipport_equal(&list[i].assoc4.ip_port, &ip_port)) { |
590 | /* Initialize client timestamp. */ | 590 | /* Initialize client timestamp. */ |
591 | list[i].assoc4.timestamp = temp_time; | 591 | list[i].assoc4.timestamp = temp_time; |
592 | memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES); | 592 | memcpy(list[i].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
593 | 593 | ||
594 | LOGGER_DEBUG(log, "coipil[%u]: switching public_key (ipv4)", i); | 594 | LOGGER_DEBUG(log, "coipil[%u]: switching public_key (ipv4)", i); |
595 | 595 | ||
@@ -601,7 +601,7 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le | |||
601 | if ((ip_port.ip.family == AF_INET6) && ipport_equal(&list[i].assoc6.ip_port, &ip_port)) { | 601 | if ((ip_port.ip.family == AF_INET6) && ipport_equal(&list[i].assoc6.ip_port, &ip_port)) { |
602 | /* Initialize client timestamp. */ | 602 | /* Initialize client timestamp. */ |
603 | list[i].assoc6.timestamp = temp_time; | 603 | list[i].assoc6.timestamp = temp_time; |
604 | memcpy(list[i].public_key, public_key, crypto_box_PUBLICKEYBYTES); | 604 | memcpy(list[i].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
605 | 605 | ||
606 | LOGGER_DEBUG(log, "coipil[%u]: switching public_key (ipv6)", i); | 606 | LOGGER_DEBUG(log, "coipil[%u]: switching public_key (ipv6)", i); |
607 | 607 | ||
@@ -653,16 +653,16 @@ static int friend_number(const DHT *dht, const uint8_t *public_key) | |||
653 | bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port, | 653 | bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port, |
654 | const uint8_t *cmp_pk) | 654 | const uint8_t *cmp_pk) |
655 | { | 655 | { |
656 | uint8_t pk_bak[crypto_box_PUBLICKEYBYTES]; | 656 | uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE]; |
657 | IP_Port ip_port_bak; | 657 | IP_Port ip_port_bak; |
658 | 658 | ||
659 | unsigned int i; | 659 | unsigned int i; |
660 | 660 | ||
661 | for (i = 0; i < length; ++i) { | 661 | for (i = 0; i < length; ++i) { |
662 | if (id_closest(cmp_pk, nodes_list[i].public_key, pk) == 2) { | 662 | if (id_closest(cmp_pk, nodes_list[i].public_key, pk) == 2) { |
663 | memcpy(pk_bak, nodes_list[i].public_key, crypto_box_PUBLICKEYBYTES); | 663 | memcpy(pk_bak, nodes_list[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
664 | ip_port_bak = nodes_list[i].ip_port; | 664 | ip_port_bak = nodes_list[i].ip_port; |
665 | memcpy(nodes_list[i].public_key, pk, crypto_box_PUBLICKEYBYTES); | 665 | memcpy(nodes_list[i].public_key, pk, CRYPTO_PUBLIC_KEY_SIZE); |
666 | nodes_list[i].ip_port = ip_port; | 666 | nodes_list[i].ip_port = ip_port; |
667 | 667 | ||
668 | if (i != (length - 1)) { | 668 | if (i != (length - 1)) { |
@@ -742,7 +742,7 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_ | |||
742 | if (num_nodes < MAX_SENT_NODES) { | 742 | if (num_nodes < MAX_SENT_NODES) { |
743 | memcpy(nodes_list[num_nodes].public_key, | 743 | memcpy(nodes_list[num_nodes].public_key, |
744 | client->public_key, | 744 | client->public_key, |
745 | crypto_box_PUBLICKEYBYTES); | 745 | CRYPTO_PUBLIC_KEY_SIZE); |
746 | 746 | ||
747 | nodes_list[num_nodes].ip_port = ipptp->ip_port; | 747 | nodes_list[num_nodes].ip_port = ipptp->ip_port; |
748 | num_nodes++; | 748 | num_nodes++; |
@@ -796,7 +796,7 @@ int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *node | |||
796 | return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family, is_LAN, want_good); | 796 | return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family, is_LAN, want_good); |
797 | } | 797 | } |
798 | 798 | ||
799 | static uint8_t cmp_public_key[crypto_box_PUBLICKEYBYTES]; | 799 | static uint8_t cmp_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
800 | static int cmp_dht_entry(const void *a, const void *b) | 800 | static int cmp_dht_entry(const void *a, const void *b) |
801 | { | 801 | { |
802 | Client_data entry1, entry2; | 802 | Client_data entry1, entry2; |
@@ -862,7 +862,7 @@ static unsigned int store_node_ok(const Client_data *client, const uint8_t *publ | |||
862 | 862 | ||
863 | static void sort_client_list(Client_data *list, unsigned int length, const uint8_t *comp_public_key) | 863 | static void sort_client_list(Client_data *list, unsigned int length, const uint8_t *comp_public_key) |
864 | { | 864 | { |
865 | memcpy(cmp_public_key, comp_public_key, crypto_box_PUBLICKEYBYTES); | 865 | memcpy(cmp_public_key, comp_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
866 | qsort(list, length, sizeof(Client_data), cmp_dht_entry); | 866 | qsort(list, length, sizeof(Client_data), cmp_dht_entry); |
867 | } | 867 | } |
868 | 868 | ||
@@ -1018,7 +1018,7 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_k | |||
1018 | 1018 | ||
1019 | if (ret && !client_in_nodelist(dht->to_bootstrap, dht->num_to_bootstrap, public_key)) { | 1019 | if (ret && !client_in_nodelist(dht->to_bootstrap, dht->num_to_bootstrap, public_key)) { |
1020 | if (dht->num_to_bootstrap < MAX_CLOSE_TO_BOOTSTRAP_NODES) { | 1020 | if (dht->num_to_bootstrap < MAX_CLOSE_TO_BOOTSTRAP_NODES) { |
1021 | memcpy(dht->to_bootstrap[dht->num_to_bootstrap].public_key, public_key, crypto_box_PUBLICKEYBYTES); | 1021 | memcpy(dht->to_bootstrap[dht->num_to_bootstrap].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
1022 | dht->to_bootstrap[dht->num_to_bootstrap].ip_port = ip_port; | 1022 | dht->to_bootstrap[dht->num_to_bootstrap].ip_port = ip_port; |
1023 | ++dht->num_to_bootstrap; | 1023 | ++dht->num_to_bootstrap; |
1024 | } else { | 1024 | } else { |
@@ -1045,7 +1045,7 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_k | |||
1045 | if (store_ok && !client_in_nodelist(dht_friend->to_bootstrap, dht_friend->num_to_bootstrap, public_key) | 1045 | if (store_ok && !client_in_nodelist(dht_friend->to_bootstrap, dht_friend->num_to_bootstrap, public_key) |
1046 | && !is_pk_in_client_list(dht_friend->client_list, MAX_FRIEND_CLIENTS, public_key, ip_port)) { | 1046 | && !is_pk_in_client_list(dht_friend->client_list, MAX_FRIEND_CLIENTS, public_key, ip_port)) { |
1047 | if (dht_friend->num_to_bootstrap < MAX_SENT_NODES) { | 1047 | if (dht_friend->num_to_bootstrap < MAX_SENT_NODES) { |
1048 | memcpy(dht_friend->to_bootstrap[dht_friend->num_to_bootstrap].public_key, public_key, crypto_box_PUBLICKEYBYTES); | 1048 | memcpy(dht_friend->to_bootstrap[dht_friend->num_to_bootstrap].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
1049 | dht_friend->to_bootstrap[dht_friend->num_to_bootstrap].ip_port = ip_port; | 1049 | dht_friend->to_bootstrap[dht_friend->num_to_bootstrap].ip_port = ip_port; |
1050 | ++dht_friend->num_to_bootstrap; | 1050 | ++dht_friend->num_to_bootstrap; |
1051 | } else { | 1051 | } else { |
@@ -1195,7 +1195,7 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const | |||
1195 | uint8_t plain_message[sizeof(Node_format) * 2] = {0}; | 1195 | uint8_t plain_message[sizeof(Node_format) * 2] = {0}; |
1196 | 1196 | ||
1197 | Node_format receiver; | 1197 | Node_format receiver; |
1198 | memcpy(receiver.public_key, public_key, crypto_box_PUBLICKEYBYTES); | 1198 | memcpy(receiver.public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
1199 | receiver.ip_port = ip_port; | 1199 | receiver.ip_port = ip_port; |
1200 | memcpy(plain_message, &receiver, sizeof(receiver)); | 1200 | memcpy(plain_message, &receiver, sizeof(receiver)); |
1201 | 1201 | ||
@@ -1212,13 +1212,13 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const | |||
1212 | return -1; | 1212 | return -1; |
1213 | } | 1213 | } |
1214 | 1214 | ||
1215 | uint8_t plain[crypto_box_PUBLICKEYBYTES + sizeof(ping_id)]; | 1215 | uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + sizeof(ping_id)]; |
1216 | uint8_t data[1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + sizeof(plain) + crypto_box_MACBYTES]; | 1216 | uint8_t data[1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + sizeof(plain) + CRYPTO_MAC_SIZE]; |
1217 | 1217 | ||
1218 | memcpy(plain, client_id, crypto_box_PUBLICKEYBYTES); | 1218 | memcpy(plain, client_id, CRYPTO_PUBLIC_KEY_SIZE); |
1219 | memcpy(plain + crypto_box_PUBLICKEYBYTES, &ping_id, sizeof(ping_id)); | 1219 | memcpy(plain + CRYPTO_PUBLIC_KEY_SIZE, &ping_id, sizeof(ping_id)); |
1220 | 1220 | ||
1221 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 1221 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; |
1222 | DHT_get_shared_key_sent(dht, shared_key, public_key); | 1222 | DHT_get_shared_key_sent(dht, shared_key, public_key); |
1223 | 1223 | ||
1224 | int len = DHT_create_packet(dht->self_public_key, shared_key, NET_PACKET_GET_NODES, | 1224 | int len = DHT_create_packet(dht->self_public_key, shared_key, NET_PACKET_GET_NODES, |
@@ -1264,8 +1264,8 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public | |||
1264 | plain[0] = num_nodes; | 1264 | plain[0] = num_nodes; |
1265 | memcpy(plain + 1 + nodes_length, sendback_data, length); | 1265 | memcpy(plain + 1 + nodes_length, sendback_data, length); |
1266 | 1266 | ||
1267 | uint8_t data[1 + nodes_length + length + 1 + crypto_box_PUBLICKEYBYTES | 1267 | uint8_t data[1 + nodes_length + length + 1 + CRYPTO_PUBLIC_KEY_SIZE |
1268 | + crypto_box_NONCEBYTES + crypto_box_MACBYTES]; | 1268 | + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE]; |
1269 | 1269 | ||
1270 | int len = DHT_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6, | 1270 | int len = DHT_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6, |
1271 | plain, 1 + nodes_length + length, data); | 1271 | plain, 1 + nodes_length + length, data); |
@@ -1279,8 +1279,8 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public | |||
1279 | 1279 | ||
1280 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 1280 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
1281 | { | 1281 | { |
1282 | if (length != (1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof( | 1282 | if (length != (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + sizeof( |
1283 | uint64_t) + crypto_box_MACBYTES)) { | 1283 | uint64_t) + CRYPTO_MAC_SIZE)) { |
1284 | return 1; | 1284 | return 1; |
1285 | } | 1285 | } |
1286 | 1286 | ||
@@ -1291,21 +1291,21 @@ static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, | |||
1291 | return 1; | 1291 | return 1; |
1292 | } | 1292 | } |
1293 | 1293 | ||
1294 | uint8_t plain[crypto_box_PUBLICKEYBYTES + sizeof(uint64_t)]; | 1294 | uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t)]; |
1295 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 1295 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; |
1296 | 1296 | ||
1297 | DHT_get_shared_key_recv(dht, shared_key, packet + 1); | 1297 | DHT_get_shared_key_recv(dht, shared_key, packet + 1); |
1298 | int len = decrypt_data_symmetric(shared_key, | 1298 | int len = decrypt_data_symmetric(shared_key, |
1299 | packet + 1 + crypto_box_PUBLICKEYBYTES, | 1299 | packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, |
1300 | packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, | 1300 | packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, |
1301 | crypto_box_PUBLICKEYBYTES + sizeof(uint64_t) + crypto_box_MACBYTES, | 1301 | CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t) + CRYPTO_MAC_SIZE, |
1302 | plain); | 1302 | plain); |
1303 | 1303 | ||
1304 | if (len != crypto_box_PUBLICKEYBYTES + sizeof(uint64_t)) { | 1304 | if (len != CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t)) { |
1305 | return 1; | 1305 | return 1; |
1306 | } | 1306 | } |
1307 | 1307 | ||
1308 | sendnodes_ipv6(dht, source, packet + 1, plain, plain + crypto_box_PUBLICKEYBYTES, sizeof(uint64_t), shared_key); | 1308 | sendnodes_ipv6(dht, source, packet + 1, plain, plain + CRYPTO_PUBLIC_KEY_SIZE, sizeof(uint64_t), shared_key); |
1309 | 1309 | ||
1310 | add_to_ping(dht->ping, packet + 1, source); | 1310 | add_to_ping(dht->ping, packet + 1, source); |
1311 | 1311 | ||
@@ -1344,7 +1344,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa | |||
1344 | Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out) | 1344 | Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out) |
1345 | { | 1345 | { |
1346 | DHT *dht = (DHT *)object; | 1346 | DHT *dht = (DHT *)object; |
1347 | uint32_t cid_size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + 1 + sizeof(uint64_t) + crypto_box_MACBYTES; | 1347 | uint32_t cid_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + 1 + sizeof(uint64_t) + CRYPTO_MAC_SIZE; |
1348 | 1348 | ||
1349 | if (length < cid_size) { /* too short */ | 1349 | if (length < cid_size) { /* too short */ |
1350 | return 1; | 1350 | return 1; |
@@ -1361,13 +1361,13 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa | |||
1361 | } | 1361 | } |
1362 | 1362 | ||
1363 | uint8_t plain[1 + data_size + sizeof(uint64_t)]; | 1363 | uint8_t plain[1 + data_size + sizeof(uint64_t)]; |
1364 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 1364 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; |
1365 | DHT_get_shared_key_sent(dht, shared_key, packet + 1); | 1365 | DHT_get_shared_key_sent(dht, shared_key, packet + 1); |
1366 | int len = decrypt_data_symmetric( | 1366 | int len = decrypt_data_symmetric( |
1367 | shared_key, | 1367 | shared_key, |
1368 | packet + 1 + crypto_box_PUBLICKEYBYTES, | 1368 | packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, |
1369 | packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, | 1369 | packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, |
1370 | 1 + data_size + sizeof(uint64_t) + crypto_box_MACBYTES, | 1370 | 1 + data_size + sizeof(uint64_t) + CRYPTO_MAC_SIZE, |
1371 | plain); | 1371 | plain); |
1372 | 1372 | ||
1373 | if ((unsigned int)len != sizeof(plain)) { | 1373 | if ((unsigned int)len != sizeof(plain)) { |
@@ -1477,7 +1477,7 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void | |||
1477 | dht->friends_list = temp; | 1477 | dht->friends_list = temp; |
1478 | DHT_Friend *dht_friend = &dht->friends_list[dht->num_friends]; | 1478 | DHT_Friend *dht_friend = &dht->friends_list[dht->num_friends]; |
1479 | memset(dht_friend, 0, sizeof(DHT_Friend)); | 1479 | memset(dht_friend, 0, sizeof(DHT_Friend)); |
1480 | memcpy(dht_friend->public_key, public_key, crypto_box_PUBLICKEYBYTES); | 1480 | memcpy(dht_friend->public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
1481 | 1481 | ||
1482 | dht_friend->nat.NATping_id = random_64b(); | 1482 | dht_friend->nat.NATping_id = random_64b(); |
1483 | ++dht->num_friends; | 1483 | ++dht->num_friends; |
@@ -2216,10 +2216,10 @@ static int send_hardening_req(DHT *dht, Node_format *sendto, uint8_t type, uint8 | |||
2216 | /* Send a get node hardening request */ | 2216 | /* Send a get node hardening request */ |
2217 | static int send_hardening_getnode_req(DHT *dht, Node_format *dest, Node_format *node_totest, uint8_t *search_id) | 2217 | static int send_hardening_getnode_req(DHT *dht, Node_format *dest, Node_format *node_totest, uint8_t *search_id) |
2218 | { | 2218 | { |
2219 | uint8_t data[sizeof(Node_format) + crypto_box_PUBLICKEYBYTES]; | 2219 | uint8_t data[sizeof(Node_format) + CRYPTO_PUBLIC_KEY_SIZE]; |
2220 | memcpy(data, node_totest, sizeof(Node_format)); | 2220 | memcpy(data, node_totest, sizeof(Node_format)); |
2221 | memcpy(data + sizeof(Node_format), search_id, crypto_box_PUBLICKEYBYTES); | 2221 | memcpy(data + sizeof(Node_format), search_id, CRYPTO_PUBLIC_KEY_SIZE); |
2222 | return send_hardening_req(dht, dest, CHECK_TYPE_GETNODE_REQ, data, sizeof(Node_format) + crypto_box_PUBLICKEYBYTES); | 2222 | return send_hardening_req(dht, dest, CHECK_TYPE_GETNODE_REQ, data, sizeof(Node_format) + CRYPTO_PUBLIC_KEY_SIZE); |
2223 | } | 2223 | } |
2224 | #endif | 2224 | #endif |
2225 | 2225 | ||
@@ -2232,10 +2232,10 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, | |||
2232 | } | 2232 | } |
2233 | 2233 | ||
2234 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; | 2234 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; |
2235 | uint8_t data[1 + crypto_box_PUBLICKEYBYTES + nodes_data_length]; | 2235 | uint8_t data[1 + CRYPTO_PUBLIC_KEY_SIZE + nodes_data_length]; |
2236 | data[0] = CHECK_TYPE_GETNODE_RES; | 2236 | data[0] = CHECK_TYPE_GETNODE_RES; |
2237 | memcpy(data + 1, queried_client_id, crypto_box_PUBLICKEYBYTES); | 2237 | memcpy(data + 1, queried_client_id, CRYPTO_PUBLIC_KEY_SIZE); |
2238 | memcpy(data + 1 + crypto_box_PUBLICKEYBYTES, nodes_data, nodes_data_length); | 2238 | memcpy(data + 1 + CRYPTO_PUBLIC_KEY_SIZE, nodes_data, nodes_data_length); |
2239 | int len = create_request(dht->self_public_key, dht->self_secret_key, packet, sendto->public_key, data, | 2239 | int len = create_request(dht->self_public_key, dht->self_secret_key, packet, sendto->public_key, data, |
2240 | sizeof(data), CRYPTO_PACKET_HARDENING); | 2240 | sizeof(data), CRYPTO_PACKET_HARDENING); |
2241 | 2241 | ||
@@ -2317,7 +2317,7 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_ | |||
2317 | 2317 | ||
2318 | Node_format node, tocheck_node; | 2318 | Node_format node, tocheck_node; |
2319 | node.ip_port = source; | 2319 | node.ip_port = source; |
2320 | memcpy(node.public_key, source_pubkey, crypto_box_PUBLICKEYBYTES); | 2320 | memcpy(node.public_key, source_pubkey, CRYPTO_PUBLIC_KEY_SIZE); |
2321 | memcpy(&tocheck_node, packet + 1, sizeof(Node_format)); | 2321 | memcpy(&tocheck_node, packet + 1, sizeof(Node_format)); |
2322 | 2322 | ||
2323 | if (getnodes(dht, tocheck_node.ip_port, tocheck_node.public_key, packet + 1 + sizeof(Node_format), &node) == -1) { | 2323 | if (getnodes(dht, tocheck_node.ip_port, tocheck_node.public_key, packet + 1 + sizeof(Node_format), &node) == -1) { |
@@ -2328,17 +2328,17 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_ | |||
2328 | } | 2328 | } |
2329 | 2329 | ||
2330 | case CHECK_TYPE_GETNODE_RES: { | 2330 | case CHECK_TYPE_GETNODE_RES: { |
2331 | if (length <= crypto_box_PUBLICKEYBYTES + 1) { | 2331 | if (length <= CRYPTO_PUBLIC_KEY_SIZE + 1) { |
2332 | return 1; | 2332 | return 1; |
2333 | } | 2333 | } |
2334 | 2334 | ||
2335 | if (length > 1 + crypto_box_PUBLICKEYBYTES + sizeof(Node_format) * MAX_SENT_NODES) { | 2335 | if (length > 1 + CRYPTO_PUBLIC_KEY_SIZE + sizeof(Node_format) * MAX_SENT_NODES) { |
2336 | return 1; | 2336 | return 1; |
2337 | } | 2337 | } |
2338 | 2338 | ||
2339 | uint16_t length_nodes = length - 1 - crypto_box_PUBLICKEYBYTES; | 2339 | uint16_t length_nodes = length - 1 - CRYPTO_PUBLIC_KEY_SIZE; |
2340 | Node_format nodes[MAX_SENT_NODES]; | 2340 | Node_format nodes[MAX_SENT_NODES]; |
2341 | int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, packet + 1 + crypto_box_PUBLICKEYBYTES, length_nodes, 0); | 2341 | int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, length_nodes, 0); |
2342 | 2342 | ||
2343 | /* TODO(irungentoo): MAX_SENT_NODES nodes should be returned at all times | 2343 | /* TODO(irungentoo): MAX_SENT_NODES nodes should be returned at all times |
2344 | (right now we have a small network size so it could cause problems for testing and etc..) */ | 2344 | (right now we have a small network size so it could cause problems for testing and etc..) */ |
@@ -2380,10 +2380,10 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_ | |||
2380 | */ | 2380 | */ |
2381 | static Node_format random_node(DHT *dht, sa_family_t sa_family) | 2381 | static Node_format random_node(DHT *dht, sa_family_t sa_family) |
2382 | { | 2382 | { |
2383 | uint8_t id[crypto_box_PUBLICKEYBYTES]; | 2383 | uint8_t id[CRYPTO_PUBLIC_KEY_SIZE]; |
2384 | uint32_t i; | 2384 | uint32_t i; |
2385 | 2385 | ||
2386 | for (i = 0; i < crypto_box_PUBLICKEYBYTES / 4; ++i) { /* populate the id with pseudorandom bytes.*/ | 2386 | for (i = 0; i < CRYPTO_PUBLIC_KEY_SIZE / 4; ++i) { /* populate the id with pseudorandom bytes.*/ |
2387 | uint32_t t = rand(); | 2387 | uint32_t t = rand(); |
2388 | memcpy(id + i * sizeof(t), &t, sizeof(t)); | 2388 | memcpy(id + i * sizeof(t), &t, sizeof(t)); |
2389 | } | 2389 | } |
@@ -2430,7 +2430,7 @@ static uint16_t list_nodes(Client_data *list, unsigned int length, Node_format * | |||
2430 | } | 2430 | } |
2431 | 2431 | ||
2432 | if (assoc != NULL) { | 2432 | if (assoc != NULL) { |
2433 | memcpy(nodes[count].public_key, list[i - 1].public_key, crypto_box_PUBLICKEYBYTES); | 2433 | memcpy(nodes[count].public_key, list[i - 1].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
2434 | nodes[count].ip_port = assoc->ip_port; | 2434 | nodes[count].ip_port = assoc->ip_port; |
2435 | ++count; | 2435 | ++count; |
2436 | 2436 | ||
@@ -2513,11 +2513,11 @@ static void do_hardening(DHT *dht) | |||
2513 | 2513 | ||
2514 | Node_format to_test; | 2514 | Node_format to_test; |
2515 | to_test.ip_port = cur_iptspng->ip_port; | 2515 | to_test.ip_port = cur_iptspng->ip_port; |
2516 | memcpy(to_test.public_key, public_key, crypto_box_PUBLICKEYBYTES); | 2516 | memcpy(to_test.public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
2517 | 2517 | ||
2518 | // TODO(irungentoo): The search id should maybe not be ours? | 2518 | // TODO(irungentoo): The search id should maybe not be ours? |
2519 | if (send_hardening_getnode_req(dht, &rand_node, &to_test, dht->self_public_key) > 0) { | 2519 | if (send_hardening_getnode_req(dht, &rand_node, &to_test, dht->self_public_key) > 0) { |
2520 | memcpy(cur_iptspng->hardening.send_nodes_pingedid, rand_node.public_key, crypto_box_PUBLICKEYBYTES); | 2520 | memcpy(cur_iptspng->hardening.send_nodes_pingedid, rand_node.public_key, CRYPTO_PUBLIC_KEY_SIZE); |
2521 | cur_iptspng->hardening.send_nodes_timestamp = unix_time(); | 2521 | cur_iptspng->hardening.send_nodes_timestamp = unix_time(); |
2522 | } | 2522 | } |
2523 | } | 2523 | } |
@@ -2545,13 +2545,13 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack | |||
2545 | DHT *dht = (DHT *)object; | 2545 | DHT *dht = (DHT *)object; |
2546 | 2546 | ||
2547 | if (packet[0] == NET_PACKET_CRYPTO) { | 2547 | if (packet[0] == NET_PACKET_CRYPTO) { |
2548 | if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES || | 2548 | if (length <= CRYPTO_PUBLIC_KEY_SIZE * 2 + CRYPTO_NONCE_SIZE + 1 + CRYPTO_MAC_SIZE || |
2549 | length > MAX_CRYPTO_REQUEST_SIZE + crypto_box_MACBYTES) { | 2549 | length > MAX_CRYPTO_REQUEST_SIZE + CRYPTO_MAC_SIZE) { |
2550 | return 1; | 2550 | return 1; |
2551 | } | 2551 | } |
2552 | 2552 | ||
2553 | if (public_key_cmp(packet + 1, dht->self_public_key) == 0) { // Check if request is for us. | 2553 | if (public_key_cmp(packet + 1, dht->self_public_key) == 0) { // Check if request is for us. |
2554 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | 2554 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
2555 | uint8_t data[MAX_CRYPTO_REQUEST_SIZE]; | 2555 | uint8_t data[MAX_CRYPTO_REQUEST_SIZE]; |
2556 | uint8_t number; | 2556 | uint8_t number; |
2557 | int len = handle_request(dht->self_public_key, dht->self_secret_key, public_key, data, &number, packet, length); | 2557 | int len = handle_request(dht->self_public_key, dht->self_secret_key, public_key, data, &number, packet, length); |
@@ -2615,15 +2615,15 @@ DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled) | |||
2615 | cryptopacket_registerhandler(dht, CRYPTO_PACKET_HARDENING, &handle_hardening, dht); | 2615 | cryptopacket_registerhandler(dht, CRYPTO_PACKET_HARDENING, &handle_hardening, dht); |
2616 | 2616 | ||
2617 | new_symmetric_key(dht->secret_symmetric_key); | 2617 | new_symmetric_key(dht->secret_symmetric_key); |
2618 | crypto_box_keypair(dht->self_public_key, dht->self_secret_key); | 2618 | crypto_new_keypair(dht->self_public_key, dht->self_secret_key); |
2619 | 2619 | ||
2620 | ping_array_init(&dht->dht_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); | 2620 | ping_array_init(&dht->dht_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); |
2621 | ping_array_init(&dht->dht_harden_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); | 2621 | ping_array_init(&dht->dht_harden_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); |
2622 | uint32_t i; | 2622 | uint32_t i; |
2623 | 2623 | ||
2624 | for (i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { | 2624 | for (i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { |
2625 | uint8_t random_key_bytes[crypto_box_PUBLICKEYBYTES]; | 2625 | uint8_t random_key_bytes[CRYPTO_PUBLIC_KEY_SIZE]; |
2626 | randombytes(random_key_bytes, sizeof(random_key_bytes)); | 2626 | random_bytes(random_key_bytes, sizeof(random_key_bytes)); |
2627 | 2627 | ||
2628 | if (DHT_addfriend(dht, random_key_bytes, 0, 0, 0, 0) != 0) { | 2628 | if (DHT_addfriend(dht, random_key_bytes, 0, 0, 0, 0) != 0) { |
2629 | kill_DHT(dht); | 2629 | kill_DHT(dht); |
@@ -2730,13 +2730,13 @@ void DHT_save(DHT *dht, uint8_t *data) | |||
2730 | 2730 | ||
2731 | for (num = 0, i = 0; i < LCLIENT_LIST; ++i) { | 2731 | for (num = 0, i = 0; i < LCLIENT_LIST; ++i) { |
2732 | if (dht->close_clientlist[i].assoc4.timestamp != 0) { | 2732 | if (dht->close_clientlist[i].assoc4.timestamp != 0) { |
2733 | memcpy(clients[num].public_key, dht->close_clientlist[i].public_key, crypto_box_PUBLICKEYBYTES); | 2733 | memcpy(clients[num].public_key, dht->close_clientlist[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
2734 | clients[num].ip_port = dht->close_clientlist[i].assoc4.ip_port; | 2734 | clients[num].ip_port = dht->close_clientlist[i].assoc4.ip_port; |
2735 | ++num; | 2735 | ++num; |
2736 | } | 2736 | } |
2737 | 2737 | ||
2738 | if (dht->close_clientlist[i].assoc6.timestamp != 0) { | 2738 | if (dht->close_clientlist[i].assoc6.timestamp != 0) { |
2739 | memcpy(clients[num].public_key, dht->close_clientlist[i].public_key, crypto_box_PUBLICKEYBYTES); | 2739 | memcpy(clients[num].public_key, dht->close_clientlist[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
2740 | clients[num].ip_port = dht->close_clientlist[i].assoc6.ip_port; | 2740 | clients[num].ip_port = dht->close_clientlist[i].assoc6.ip_port; |
2741 | ++num; | 2741 | ++num; |
2742 | } | 2742 | } |
@@ -2747,13 +2747,13 @@ void DHT_save(DHT *dht, uint8_t *data) | |||
2747 | 2747 | ||
2748 | for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { | 2748 | for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { |
2749 | if (fr->client_list[j].assoc4.timestamp != 0) { | 2749 | if (fr->client_list[j].assoc4.timestamp != 0) { |
2750 | memcpy(clients[num].public_key, fr->client_list[j].public_key, crypto_box_PUBLICKEYBYTES); | 2750 | memcpy(clients[num].public_key, fr->client_list[j].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
2751 | clients[num].ip_port = fr->client_list[j].assoc4.ip_port; | 2751 | clients[num].ip_port = fr->client_list[j].assoc4.ip_port; |
2752 | ++num; | 2752 | ++num; |
2753 | } | 2753 | } |
2754 | 2754 | ||
2755 | if (fr->client_list[j].assoc6.timestamp != 0) { | 2755 | if (fr->client_list[j].assoc6.timestamp != 0) { |
2756 | memcpy(clients[num].public_key, fr->client_list[j].public_key, crypto_box_PUBLICKEYBYTES); | 2756 | memcpy(clients[num].public_key, fr->client_list[j].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
2757 | clients[num].ip_port = fr->client_list[j].assoc6.ip_port; | 2757 | clients[num].ip_port = fr->client_list[j].assoc6.ip_port; |
2758 | ++num; | 2758 | ++num; |
2759 | } | 2759 | } |