mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Removed a useless define.
This commit is contained in:
parent
4d28630d49
commit
6cb8ff4d65
|
@ -18,7 +18,7 @@
|
|||
START_TEST(test_basics)
|
||||
{
|
||||
/* TODO: real test */
|
||||
uint8_t id[CLIENT_ID_SIZE];
|
||||
uint8_t id[crypto_box_PUBLICKEYBYTES];
|
||||
Assoc *assoc = new_Assoc_default(id);
|
||||
ck_assert_msg(assoc != NULL, "failed to create default assoc");
|
||||
|
||||
|
@ -63,19 +63,19 @@ START_TEST(test_fillup)
|
|||
{
|
||||
/* TODO: real test */
|
||||
int i, j;
|
||||
uint8_t id[CLIENT_ID_SIZE];
|
||||
uint8_t id[crypto_box_PUBLICKEYBYTES];
|
||||
//uint32_t a = current_time();
|
||||
uint32_t a = 2710106197;
|
||||
srand(a);
|
||||
|
||||
for (i = 0; i < CLIENT_ID_SIZE; ++i) {
|
||||
for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
|
||||
id[i] = rand();
|
||||
}
|
||||
|
||||
Assoc *assoc = new_Assoc(6, 15, id);
|
||||
ck_assert_msg(assoc != NULL, "failed to create default assoc");
|
||||
struct entry {
|
||||
uint8_t id[CLIENT_ID_SIZE];
|
||||
uint8_t id[crypto_box_PUBLICKEYBYTES];
|
||||
IPPTs ippts_send;
|
||||
IP_Port ipp_recv;
|
||||
};
|
||||
|
@ -85,7 +85,7 @@ START_TEST(test_fillup)
|
|||
|
||||
for (j = 0; j < 128; ++j) {
|
||||
|
||||
for (i = 0; i < CLIENT_ID_SIZE; ++i) {
|
||||
for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
|
||||
entries[j].id[i] = rand();
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ START_TEST(test_fillup)
|
|||
entries[j].ipp_recv = ipp;
|
||||
|
||||
if (j % 16 == 0) {
|
||||
memcpy(entries[j].id, id, CLIENT_ID_SIZE - 30);
|
||||
memcpy(entries[j].id, id, crypto_box_PUBLICKEYBYTES - 30);
|
||||
memcpy(&closest[j / 16], &entries[j], sizeof(struct entry));
|
||||
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ void test_addto_lists_update(DHT *dht,
|
|||
{
|
||||
int used, test, test1, test2, found;
|
||||
IP_Port test_ipp;
|
||||
uint8_t test_id[CLIENT_ID_SIZE];
|
||||
uint8_t test_id[crypto_box_PUBLICKEYBYTES];
|
||||
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
||||
|
||||
// check id update for existing ip_port
|
||||
|
@ -153,7 +153,7 @@ void test_addto_lists_bad(DHT *dht,
|
|||
{
|
||||
// check "bad" clients replacement
|
||||
int used, test1, test2, test3;
|
||||
uint8_t public_key[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
|
||||
uint8_t public_key[crypto_box_PUBLICKEYBYTES], test_id1[crypto_box_PUBLICKEYBYTES], test_id2[crypto_box_PUBLICKEYBYTES], test_id3[crypto_box_PUBLICKEYBYTES];
|
||||
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
||||
|
||||
randombytes(public_key, sizeof(public_key));
|
||||
|
@ -196,7 +196,7 @@ void test_addto_lists_possible_bad(DHT *dht,
|
|||
{
|
||||
// check "possibly bad" clients replacement
|
||||
int used, test1, test2, test3;
|
||||
uint8_t public_key[CLIENT_ID_SIZE], test_id1[CLIENT_ID_SIZE], test_id2[CLIENT_ID_SIZE], test_id3[CLIENT_ID_SIZE];
|
||||
uint8_t public_key[crypto_box_PUBLICKEYBYTES], test_id1[crypto_box_PUBLICKEYBYTES], test_id2[crypto_box_PUBLICKEYBYTES], test_id3[crypto_box_PUBLICKEYBYTES];
|
||||
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
||||
|
||||
randombytes(public_key, sizeof(public_key));
|
||||
|
@ -258,7 +258,7 @@ void test_addto_lists_good(DHT *dht,
|
|||
IP_Port *ip_port,
|
||||
const uint8_t *comp_client_id)
|
||||
{
|
||||
uint8_t public_key[CLIENT_ID_SIZE];
|
||||
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
|
||||
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
|
||||
|
||||
mark_all_good(list, length, ipv6);
|
||||
|
@ -291,7 +291,7 @@ void test_addto_lists(IP ip)
|
|||
ck_assert_msg(dht != 0, "Failed to create DHT");
|
||||
|
||||
IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT };
|
||||
uint8_t public_key[CLIENT_ID_SIZE];
|
||||
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
|
||||
int i, used;
|
||||
|
||||
// check lists filling
|
||||
|
|
|
@ -52,13 +52,13 @@
|
|||
|
||||
#define PORT 33445
|
||||
|
||||
uint8_t zeroes_cid[CLIENT_ID_SIZE];
|
||||
uint8_t zeroes_cid[crypto_box_PUBLICKEYBYTES];
|
||||
|
||||
void print_client_id(uint8_t *public_key)
|
||||
{
|
||||
uint32_t j;
|
||||
|
||||
for (j = 0; j < CLIENT_ID_SIZE; j++) {
|
||||
for (j = 0; j < crypto_box_PUBLICKEYBYTES; j++) {
|
||||
printf("%02hhX", public_key[j]);
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ void print_clientlist(DHT *dht)
|
|||
for (i = 0; i < LCLIENT_LIST; i++) {
|
||||
Client_data *client = &dht->close_clientlist[i];
|
||||
|
||||
if (memcmp(client->public_key, zeroes_cid, CLIENT_ID_SIZE) == 0)
|
||||
if (memcmp(client->public_key, zeroes_cid, crypto_box_PUBLICKEYBYTES) == 0)
|
||||
continue;
|
||||
|
||||
printf("ClientID: ");
|
||||
|
@ -139,7 +139,7 @@ void print_friendlist(DHT *dht)
|
|||
for (i = 0; i < MAX_FRIEND_CLIENTS; i++) {
|
||||
Client_data *client = &dht->friends_list[k].client_list[i];
|
||||
|
||||
if (memcmp(client->public_key, zeroes_cid, CLIENT_ID_SIZE) == 0)
|
||||
if (memcmp(client->public_key, zeroes_cid, crypto_box_PUBLICKEYBYTES) == 0)
|
||||
continue;
|
||||
|
||||
printf("ClientID: ");
|
||||
|
|
|
@ -919,7 +919,7 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const
|
|||
uint8_t plain_message[sizeof(Node_format) * 2] = {0};
|
||||
|
||||
Node_format receiver;
|
||||
memcpy(receiver.public_key, public_key, CLIENT_ID_SIZE);
|
||||
memcpy(receiver.public_key, public_key, crypto_box_PUBLICKEYBYTES);
|
||||
receiver.ip_port = ip_port;
|
||||
memcpy(plain_message, &receiver, sizeof(receiver));
|
||||
|
||||
|
@ -935,12 +935,12 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const
|
|||
if (ping_id == 0)
|
||||
return -1;
|
||||
|
||||
uint8_t plain[CLIENT_ID_SIZE + sizeof(ping_id)];
|
||||
uint8_t plain[crypto_box_PUBLICKEYBYTES + sizeof(ping_id)];
|
||||
uint8_t encrypt[sizeof(plain) + crypto_box_MACBYTES];
|
||||
uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(encrypt)];
|
||||
uint8_t data[1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + sizeof(encrypt)];
|
||||
|
||||
memcpy(plain, client_id, CLIENT_ID_SIZE);
|
||||
memcpy(plain + CLIENT_ID_SIZE, &ping_id, sizeof(ping_id));
|
||||
memcpy(plain, client_id, crypto_box_PUBLICKEYBYTES);
|
||||
memcpy(plain + crypto_box_PUBLICKEYBYTES, &ping_id, sizeof(ping_id));
|
||||
|
||||
uint8_t shared_key[crypto_box_BEFORENMBYTES];
|
||||
DHT_get_shared_key_sent(dht, shared_key, public_key);
|
||||
|
@ -958,9 +958,9 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const
|
|||
return -1;
|
||||
|
||||
data[0] = NET_PACKET_GET_NODES;
|
||||
memcpy(data + 1, dht->self_public_key, CLIENT_ID_SIZE);
|
||||
memcpy(data + 1 + CLIENT_ID_SIZE, nonce, crypto_box_NONCEBYTES);
|
||||
memcpy(data + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, encrypt, len);
|
||||
memcpy(data + 1, dht->self_public_key, crypto_box_PUBLICKEYBYTES);
|
||||
memcpy(data + 1 + crypto_box_PUBLICKEYBYTES, nonce, crypto_box_NONCEBYTES);
|
||||
memcpy(data + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, encrypt, len);
|
||||
|
||||
return sendpacket(dht->net, ip_port, data, sizeof(data));
|
||||
}
|
||||
|
@ -977,7 +977,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
|
|||
return -1;
|
||||
|
||||
size_t Node_format_size = sizeof(Node_format);
|
||||
uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES
|
||||
uint8_t data[1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES
|
||||
+ Node_format_size * MAX_SENT_NODES + length + crypto_box_MACBYTES];
|
||||
|
||||
Node_format nodes_list[MAX_SENT_NODES];
|
||||
|
@ -1008,16 +1008,17 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
|
|||
return -1;
|
||||
|
||||
data[0] = NET_PACKET_SEND_NODES_IPV6;
|
||||
memcpy(data + 1, dht->self_public_key, CLIENT_ID_SIZE);
|
||||
memcpy(data + 1 + CLIENT_ID_SIZE, nonce, crypto_box_NONCEBYTES);
|
||||
memcpy(data + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, encrypt, len);
|
||||
memcpy(data + 1, dht->self_public_key, crypto_box_PUBLICKEYBYTES);
|
||||
memcpy(data + 1 + crypto_box_PUBLICKEYBYTES, nonce, crypto_box_NONCEBYTES);
|
||||
memcpy(data + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES, encrypt, len);
|
||||
|
||||
return sendpacket(dht->net, ip_port, data, 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + len);
|
||||
return sendpacket(dht->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + len);
|
||||
}
|
||||
|
||||
static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
|
||||
{
|
||||
if (length != (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + sizeof(uint64_t) + crypto_box_MACBYTES))
|
||||
if (length != (1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof(
|
||||
uint64_t) + crypto_box_MACBYTES))
|
||||
return 1;
|
||||
|
||||
DHT *dht = object;
|
||||
|
@ -1026,20 +1027,20 @@ static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet,
|
|||
if (id_equal(packet + 1, dht->self_public_key))
|
||||
return 1;
|
||||
|
||||
uint8_t plain[CLIENT_ID_SIZE + sizeof(uint64_t)];
|
||||
uint8_t plain[crypto_box_PUBLICKEYBYTES + sizeof(uint64_t)];
|
||||
uint8_t shared_key[crypto_box_BEFORENMBYTES];
|
||||
|
||||
DHT_get_shared_key_recv(dht, shared_key, packet + 1);
|
||||
int len = decrypt_data_symmetric( shared_key,
|
||||
packet + 1 + CLIENT_ID_SIZE,
|
||||
packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES,
|
||||
CLIENT_ID_SIZE + sizeof(uint64_t) + crypto_box_MACBYTES,
|
||||
packet + 1 + crypto_box_PUBLICKEYBYTES,
|
||||
packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES,
|
||||
crypto_box_PUBLICKEYBYTES + sizeof(uint64_t) + crypto_box_MACBYTES,
|
||||
plain );
|
||||
|
||||
if (len != CLIENT_ID_SIZE + sizeof(uint64_t))
|
||||
if (len != crypto_box_PUBLICKEYBYTES + sizeof(uint64_t))
|
||||
return 1;
|
||||
|
||||
sendnodes_ipv6(dht, source, packet + 1, plain, plain + CLIENT_ID_SIZE, sizeof(uint64_t), shared_key);
|
||||
sendnodes_ipv6(dht, source, packet + 1, plain, plain + crypto_box_PUBLICKEYBYTES, sizeof(uint64_t), shared_key);
|
||||
|
||||
add_to_ping(dht->ping, packet + 1, source);
|
||||
|
||||
|
@ -1077,7 +1078,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
|
|||
Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out)
|
||||
{
|
||||
DHT *dht = object;
|
||||
uint32_t cid_size = 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + 1 + sizeof(uint64_t) + crypto_box_MACBYTES;
|
||||
uint32_t cid_size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + 1 + sizeof(uint64_t) + crypto_box_MACBYTES;
|
||||
|
||||
if (length <= cid_size) /* too short */
|
||||
return 1;
|
||||
|
@ -1095,8 +1096,8 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
|
|||
DHT_get_shared_key_sent(dht, shared_key, packet + 1);
|
||||
int len = decrypt_data_symmetric(
|
||||
shared_key,
|
||||
packet + 1 + CLIENT_ID_SIZE,
|
||||
packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES,
|
||||
packet + 1 + crypto_box_PUBLICKEYBYTES,
|
||||
packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES,
|
||||
1 + data_size + sizeof(uint64_t) + crypto_box_MACBYTES,
|
||||
plain);
|
||||
|
||||
|
@ -1197,7 +1198,7 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void
|
|||
dht->friends_list = temp;
|
||||
DHT_Friend *friend = &dht->friends_list[dht->num_friends];
|
||||
memset(friend, 0, sizeof(DHT_Friend));
|
||||
memcpy(friend->public_key, public_key, CLIENT_ID_SIZE);
|
||||
memcpy(friend->public_key, public_key, crypto_box_PUBLICKEYBYTES);
|
||||
|
||||
friend->nat.NATping_id = random_64b();
|
||||
++dht->num_friends;
|
||||
|
@ -1893,10 +1894,10 @@ static int send_hardening_req(DHT *dht, Node_format *sendto, uint8_t type, uint8
|
|||
/* Send a get node hardening request */
|
||||
static int send_hardening_getnode_req(DHT *dht, Node_format *dest, Node_format *node_totest, uint8_t *search_id)
|
||||
{
|
||||
uint8_t data[sizeof(Node_format) + CLIENT_ID_SIZE];
|
||||
uint8_t data[sizeof(Node_format) + crypto_box_PUBLICKEYBYTES];
|
||||
memcpy(data, node_totest, sizeof(Node_format));
|
||||
memcpy(data + sizeof(Node_format), search_id, CLIENT_ID_SIZE);
|
||||
return send_hardening_req(dht, dest, CHECK_TYPE_GETNODE_REQ, data, sizeof(Node_format) + CLIENT_ID_SIZE);
|
||||
memcpy(data + sizeof(Node_format), search_id, crypto_box_PUBLICKEYBYTES);
|
||||
return send_hardening_req(dht, dest, CHECK_TYPE_GETNODE_REQ, data, sizeof(Node_format) + crypto_box_PUBLICKEYBYTES);
|
||||
}
|
||||
|
||||
/* Send a get node hardening response */
|
||||
|
@ -1907,10 +1908,10 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto,
|
|||
return -1;
|
||||
|
||||
uint8_t packet[MAX_CRYPTO_REQUEST_SIZE];
|
||||
uint8_t data[1 + CLIENT_ID_SIZE + nodes_data_length];
|
||||
uint8_t data[1 + crypto_box_PUBLICKEYBYTES + nodes_data_length];
|
||||
data[0] = CHECK_TYPE_GETNODE_RES;
|
||||
memcpy(data + 1, queried_client_id, CLIENT_ID_SIZE);
|
||||
memcpy(data + 1 + CLIENT_ID_SIZE, nodes_data, nodes_data_length);
|
||||
memcpy(data + 1, queried_client_id, crypto_box_PUBLICKEYBYTES);
|
||||
memcpy(data + 1 + crypto_box_PUBLICKEYBYTES, nodes_data, nodes_data_length);
|
||||
int len = create_request(dht->self_public_key, dht->self_secret_key, packet, sendto->public_key, data,
|
||||
sizeof(data), CRYPTO_PACKET_HARDENING);
|
||||
|
||||
|
@ -1926,7 +1927,7 @@ static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, sa_
|
|||
uint32_t i;
|
||||
|
||||
for (i = 0; i < LCLIENT_LIST; ++i) {
|
||||
if (memcmp(dht->close_clientlist[i].public_key, public_key, CLIENT_ID_SIZE) != 0)
|
||||
if (memcmp(dht->close_clientlist[i].public_key, public_key, crypto_box_PUBLICKEYBYTES) != 0)
|
||||
continue;
|
||||
|
||||
if (sa_family == AF_INET)
|
||||
|
@ -1996,15 +1997,15 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
|
|||
}
|
||||
|
||||
case CHECK_TYPE_GETNODE_RES: {
|
||||
if (length <= CLIENT_ID_SIZE + 1)
|
||||
if (length <= crypto_box_PUBLICKEYBYTES + 1)
|
||||
return 1;
|
||||
|
||||
if (length > 1 + CLIENT_ID_SIZE + sizeof(Node_format) * MAX_SENT_NODES)
|
||||
if (length > 1 + crypto_box_PUBLICKEYBYTES + sizeof(Node_format) * MAX_SENT_NODES)
|
||||
return 1;
|
||||
|
||||
uint16_t length_nodes = length - 1 - CLIENT_ID_SIZE;
|
||||
uint16_t length_nodes = length - 1 - crypto_box_PUBLICKEYBYTES;
|
||||
Node_format nodes[MAX_SENT_NODES];
|
||||
int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, packet + 1 + CLIENT_ID_SIZE, length_nodes, 0);
|
||||
int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, packet + 1 + crypto_box_PUBLICKEYBYTES, length_nodes, 0);
|
||||
|
||||
/* TODO: MAX_SENT_NODES nodes should be returned at all times
|
||||
(right now we have a small network size so it could cause problems for testing and etc..) */
|
||||
|
@ -2023,7 +2024,7 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
|
|||
if (is_timeout(temp->hardening.send_nodes_timestamp, HARDENING_INTERVAL))
|
||||
return 1;
|
||||
|
||||
if (memcmp(temp->hardening.send_nodes_pingedid, source_pubkey, CLIENT_ID_SIZE) != 0)
|
||||
if (memcmp(temp->hardening.send_nodes_pingedid, source_pubkey, crypto_box_PUBLICKEYBYTES) != 0)
|
||||
return 1;
|
||||
|
||||
/* If Nodes look good and the request checks out */
|
||||
|
@ -2040,10 +2041,10 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
|
|||
*/
|
||||
Node_format random_node(DHT *dht, sa_family_t sa_family)
|
||||
{
|
||||
uint8_t id[CLIENT_ID_SIZE];
|
||||
uint8_t id[crypto_box_PUBLICKEYBYTES];
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < CLIENT_ID_SIZE / 4; ++i) { /* populate the id with pseudorandom bytes.*/
|
||||
for (i = 0; i < crypto_box_PUBLICKEYBYTES / 4; ++i) { /* populate the id with pseudorandom bytes.*/
|
||||
uint32_t t = rand();
|
||||
memcpy(id + i * sizeof(t), &t, sizeof(t));
|
||||
}
|
||||
|
@ -2086,7 +2087,7 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num)
|
|||
}
|
||||
|
||||
if (assoc != NULL) {
|
||||
memcpy(nodes[count].public_key, list[i - 1].public_key, CLIENT_ID_SIZE);
|
||||
memcpy(nodes[count].public_key, list[i - 1].public_key, crypto_box_PUBLICKEYBYTES);
|
||||
nodes[count].ip_port = assoc->ip_port;
|
||||
++count;
|
||||
|
||||
|
@ -2230,7 +2231,7 @@ DHT *new_DHT(Networking_Core *net)
|
|||
uint32_t i;
|
||||
|
||||
for (i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) {
|
||||
uint8_t random_key_bytes[CLIENT_ID_SIZE];
|
||||
uint8_t random_key_bytes[crypto_box_PUBLICKEYBYTES];
|
||||
randombytes(random_key_bytes, sizeof(random_key_bytes));
|
||||
DHT_addfriend(dht, random_key_bytes, 0, 0, 0, 0);
|
||||
}
|
||||
|
|
|
@ -28,9 +28,6 @@
|
|||
#include "network.h"
|
||||
#include "ping_array.h"
|
||||
|
||||
/* Size of the client_id in bytes. */
|
||||
#define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES
|
||||
|
||||
/* Maximum number of clients stored per friend. */
|
||||
#define MAX_FRIEND_CLIENTS 8
|
||||
|
||||
|
@ -79,17 +76,17 @@ typedef struct {
|
|||
uint8_t routes_requests_ok;
|
||||
/* Time which we last checked this.*/
|
||||
uint64_t routes_requests_timestamp;
|
||||
uint8_t routes_requests_pingedid[CLIENT_ID_SIZE];
|
||||
uint8_t routes_requests_pingedid[crypto_box_PUBLICKEYBYTES];
|
||||
/* Node sends correct send_node (true (1) or false/didn't check (0)) */
|
||||
uint8_t send_nodes_ok;
|
||||
/* Time which we last checked this.*/
|
||||
uint64_t send_nodes_timestamp;
|
||||
uint8_t send_nodes_pingedid[CLIENT_ID_SIZE];
|
||||
uint8_t send_nodes_pingedid[crypto_box_PUBLICKEYBYTES];
|
||||
/* Node can be used to test other nodes (true (1) or false/didn't check (0)) */
|
||||
uint8_t testing_requests;
|
||||
/* Time which we last checked this.*/
|
||||
uint64_t testing_timestamp;
|
||||
uint8_t testing_pingedid[CLIENT_ID_SIZE];
|
||||
uint8_t testing_pingedid[crypto_box_PUBLICKEYBYTES];
|
||||
} Hardening;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -87,7 +87,7 @@ typedef struct candidates_bucket {
|
|||
|
||||
struct Assoc {
|
||||
hash_t self_hash; /* hash of self_client_id */
|
||||
uint8_t self_client_id[CLIENT_ID_SIZE]; /* don't store entries for this */
|
||||
uint8_t self_client_id[crypto_box_PUBLICKEYBYTES]; /* don't store entries for this */
|
||||
|
||||
/* association centralization: clients not in use */
|
||||
size_t candidates_bucket_bits;
|
||||
|
@ -101,7 +101,7 @@ struct Assoc {
|
|||
/* HELPER FUNCTIONS */
|
||||
/*****************************************************************************/
|
||||
|
||||
/* the complete distance would be CLIENT_ID_SIZE long...
|
||||
/* the complete distance would be crypto_box_PUBLICKEYBYTES long...
|
||||
* returns DISTANCE_INDEX_DISTANCE_BITS valid bits */
|
||||
static uint64_t id_distance(const Assoc *assoc, void *callback_data, const uint8_t *id_ref, const uint8_t *id_test)
|
||||
{
|
||||
|
@ -200,7 +200,7 @@ static hash_t id_hash(const Assoc *assoc, const uint8_t *id)
|
|||
{
|
||||
uint32_t i, res = 0x19a64e82;
|
||||
|
||||
for (i = 0; i < CLIENT_ID_SIZE; i++)
|
||||
for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++)
|
||||
res = ((res << 1) ^ id[i]) + (res >> 31);
|
||||
|
||||
/* can't have zero as hash, a) marks an unused spot,
|
||||
|
@ -976,11 +976,11 @@ void kill_Assoc(Assoc *assoc)
|
|||
|
||||
#ifdef LOGGING
|
||||
|
||||
static char buffer[CLIENT_ID_SIZE * 2 + 1];
|
||||
static char buffer[crypto_box_PUBLICKEYBYTES * 2 + 1];
|
||||
static char *idpart2str(uint8_t *id, size_t len)
|
||||
{
|
||||
if (len > CLIENT_ID_SIZE)
|
||||
len = CLIENT_ID_SIZE;
|
||||
if (len > crypto_box_PUBLICKEYBYTES)
|
||||
len = crypto_box_PUBLICKEYBYTES;
|
||||
|
||||
size_t i;
|
||||
|
||||
|
|
|
@ -55,8 +55,8 @@ struct PING {
|
|||
|
||||
|
||||
#define PING_PLAIN_SIZE (1 + sizeof(uint64_t))
|
||||
#define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + PING_PLAIN_SIZE + crypto_box_MACBYTES)
|
||||
#define PING_DATA_SIZE (CLIENT_ID_SIZE + sizeof(IP_Port))
|
||||
#define DHT_PING_SIZE (1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + PING_PLAIN_SIZE + crypto_box_MACBYTES)
|
||||
#define PING_DATA_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(IP_Port))
|
||||
|
||||
int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *public_key)
|
||||
{
|
||||
|
@ -74,7 +74,7 @@ int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *public_key)
|
|||
// Generate random ping_id.
|
||||
uint8_t data[PING_DATA_SIZE];
|
||||
id_copy(data, public_key);
|
||||
memcpy(data + CLIENT_ID_SIZE, &ipp, sizeof(IP_Port));
|
||||
memcpy(data + crypto_box_PUBLICKEYBYTES, &ipp, sizeof(IP_Port));
|
||||
ping_id = ping_array_add(&ping->ping_array, data, sizeof(data));
|
||||
|
||||
if (ping_id == 0)
|
||||
|
@ -86,13 +86,13 @@ int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *public_key)
|
|||
|
||||
pk[0] = NET_PACKET_PING_REQUEST;
|
||||
id_copy(pk + 1, ping->dht->self_public_key); // Our pubkey
|
||||
new_nonce(pk + 1 + CLIENT_ID_SIZE); // Generate new nonce
|
||||
new_nonce(pk + 1 + crypto_box_PUBLICKEYBYTES); // Generate new nonce
|
||||
|
||||
|
||||
rc = encrypt_data_symmetric(shared_key,
|
||||
pk + 1 + CLIENT_ID_SIZE,
|
||||
pk + 1 + crypto_box_PUBLICKEYBYTES,
|
||||
ping_plain, sizeof(ping_plain),
|
||||
pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES);
|
||||
pk + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES);
|
||||
|
||||
if (rc != PING_PLAIN_SIZE + crypto_box_MACBYTES)
|
||||
return 1;
|
||||
|
@ -115,13 +115,13 @@ static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *public_key
|
|||
|
||||
pk[0] = NET_PACKET_PING_RESPONSE;
|
||||
id_copy(pk + 1, ping->dht->self_public_key); // Our pubkey
|
||||
new_nonce(pk + 1 + CLIENT_ID_SIZE); // Generate new nonce
|
||||
new_nonce(pk + 1 + crypto_box_PUBLICKEYBYTES); // Generate new nonce
|
||||
|
||||
// Encrypt ping_id using recipient privkey
|
||||
rc = encrypt_data_symmetric(shared_encryption_key,
|
||||
pk + 1 + CLIENT_ID_SIZE,
|
||||
pk + 1 + crypto_box_PUBLICKEYBYTES,
|
||||
ping_plain, sizeof(ping_plain),
|
||||
pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES );
|
||||
pk + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES );
|
||||
|
||||
if (rc != PING_PLAIN_SIZE + crypto_box_MACBYTES)
|
||||
return 1;
|
||||
|
@ -148,8 +148,8 @@ static int handle_ping_request(void *_dht, IP_Port source, const uint8_t *packet
|
|||
// Decrypt ping_id
|
||||
DHT_get_shared_key_recv(dht, shared_key, packet + 1);
|
||||
rc = decrypt_data_symmetric(shared_key,
|
||||
packet + 1 + CLIENT_ID_SIZE,
|
||||
packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES,
|
||||
packet + 1 + crypto_box_PUBLICKEYBYTES,
|
||||
packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES,
|
||||
PING_PLAIN_SIZE + crypto_box_MACBYTES,
|
||||
ping_plain );
|
||||
|
||||
|
@ -189,8 +189,8 @@ static int handle_ping_response(void *_dht, IP_Port source, const uint8_t *packe
|
|||
uint8_t ping_plain[PING_PLAIN_SIZE];
|
||||
// Decrypt ping_id
|
||||
rc = decrypt_data_symmetric(shared_key,
|
||||
packet + 1 + CLIENT_ID_SIZE,
|
||||
packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES,
|
||||
packet + 1 + crypto_box_PUBLICKEYBYTES,
|
||||
packet + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES,
|
||||
PING_PLAIN_SIZE + crypto_box_MACBYTES,
|
||||
ping_plain);
|
||||
|
||||
|
@ -211,7 +211,7 @@ static int handle_ping_response(void *_dht, IP_Port source, const uint8_t *packe
|
|||
return 1;
|
||||
|
||||
IP_Port ipp;
|
||||
memcpy(&ipp, data + CLIENT_ID_SIZE, sizeof(IP_Port));
|
||||
memcpy(&ipp, data + crypto_box_PUBLICKEYBYTES, sizeof(IP_Port));
|
||||
|
||||
if (!ipport_equal(&ipp, &source))
|
||||
return 1;
|
||||
|
@ -269,12 +269,12 @@ int add_to_ping(PING *ping, const uint8_t *public_key, IP_Port ip_port)
|
|||
|
||||
for (i = 0; i < MAX_TO_PING; ++i) {
|
||||
if (!ip_isset(&ping->to_ping[i].ip_port.ip)) {
|
||||
memcpy(ping->to_ping[i].public_key, public_key, CLIENT_ID_SIZE);
|
||||
memcpy(ping->to_ping[i].public_key, public_key, crypto_box_PUBLICKEYBYTES);
|
||||
ipport_copy(&ping->to_ping[i].ip_port, &ip_port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (memcmp(ping->to_ping[i].public_key, public_key, CLIENT_ID_SIZE) == 0) {
|
||||
if (memcmp(ping->to_ping[i].public_key, public_key, crypto_box_PUBLICKEYBYTES) == 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ int add_to_ping(PING *ping, const uint8_t *public_key, IP_Port ip_port)
|
|||
|
||||
for (i = 0; i < MAX_TO_PING; ++i) {
|
||||
if (id_closest(ping->dht->self_public_key, ping->to_ping[(i + r) % MAX_TO_PING].public_key, public_key) == 2) {
|
||||
memcpy(ping->to_ping[(i + r) % MAX_TO_PING].public_key, public_key, CLIENT_ID_SIZE);
|
||||
memcpy(ping->to_ping[(i + r) % MAX_TO_PING].public_key, public_key, crypto_box_PUBLICKEYBYTES);
|
||||
ipport_copy(&ping->to_ping[(i + r) % MAX_TO_PING].ip_port, &ip_port);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
/* for CLIENT_ID_SIZE */
|
||||
#include "DHT.h"
|
||||
/* for crypto_box_PUBLICKEYBYTES */
|
||||
#include "crypto_core.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
|
@ -60,13 +60,13 @@ int is_timeout(uint64_t timestamp, uint64_t timeout)
|
|||
/* id functions */
|
||||
bool id_equal(const uint8_t *dest, const uint8_t *src)
|
||||
{
|
||||
return memcmp(dest, src, CLIENT_ID_SIZE) == 0;
|
||||
return memcmp(dest, src, crypto_box_PUBLICKEYBYTES) == 0;
|
||||
}
|
||||
|
||||
uint32_t id_copy(uint8_t *dest, const uint8_t *src)
|
||||
{
|
||||
memcpy(dest, src, CLIENT_ID_SIZE);
|
||||
return CLIENT_ID_SIZE;
|
||||
memcpy(dest, src, crypto_box_PUBLICKEYBYTES);
|
||||
return crypto_box_PUBLICKEYBYTES;
|
||||
}
|
||||
|
||||
void host_to_net(uint8_t *num, uint16_t numbytes)
|
||||
|
|
Loading…
Reference in New Issue
Block a user