diff options
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/TCP_test.c | 190 | ||||
-rw-r--r-- | auto_tests/crypto_test.c | 88 | ||||
-rw-r--r-- | auto_tests/dht_test.c | 90 | ||||
-rw-r--r-- | auto_tests/encryptsave_test.c | 10 | ||||
-rw-r--r-- | auto_tests/onion_test.c | 62 |
5 files changed, 225 insertions, 215 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index 4fdb8a88..d9013378 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -29,9 +29,9 @@ static uint16_t ports[NUM_PORTS] = {1234, 33445, 25643}; | |||
29 | 29 | ||
30 | START_TEST(test_basic) | 30 | START_TEST(test_basic) |
31 | { | 31 | { |
32 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | 32 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
33 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | 33 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
34 | crypto_box_keypair(self_public_key, self_secret_key); | 34 | crypto_new_keypair(self_public_key, self_secret_key); |
35 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); | 35 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); |
36 | ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); | 36 | ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); |
37 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); | 37 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); |
@@ -45,23 +45,23 @@ START_TEST(test_basic) | |||
45 | int ret = connect(sock, (struct sockaddr *)&addr6_loopback, sizeof(addr6_loopback)); | 45 | int ret = connect(sock, (struct sockaddr *)&addr6_loopback, sizeof(addr6_loopback)); |
46 | ck_assert_msg(ret == 0, "Failed to connect to TCP relay server"); | 46 | ck_assert_msg(ret == 0, "Failed to connect to TCP relay server"); |
47 | 47 | ||
48 | uint8_t f_public_key[crypto_box_PUBLICKEYBYTES]; | 48 | uint8_t f_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
49 | uint8_t f_secret_key[crypto_box_SECRETKEYBYTES]; | 49 | uint8_t f_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
50 | uint8_t f_nonce[crypto_box_NONCEBYTES]; | 50 | uint8_t f_nonce[CRYPTO_NONCE_SIZE]; |
51 | crypto_box_keypair(f_public_key, f_secret_key); | 51 | crypto_new_keypair(f_public_key, f_secret_key); |
52 | random_nonce(f_nonce); | 52 | random_nonce(f_nonce); |
53 | 53 | ||
54 | uint8_t t_secret_key[crypto_box_SECRETKEYBYTES]; | 54 | uint8_t t_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
55 | uint8_t handshake_plain[TCP_HANDSHAKE_PLAIN_SIZE]; | 55 | uint8_t handshake_plain[TCP_HANDSHAKE_PLAIN_SIZE]; |
56 | crypto_box_keypair(handshake_plain, t_secret_key); | 56 | crypto_new_keypair(handshake_plain, t_secret_key); |
57 | memcpy(handshake_plain + crypto_box_PUBLICKEYBYTES, f_nonce, crypto_box_NONCEBYTES); | 57 | memcpy(handshake_plain + CRYPTO_PUBLIC_KEY_SIZE, f_nonce, CRYPTO_NONCE_SIZE); |
58 | uint8_t handshake[TCP_CLIENT_HANDSHAKE_SIZE]; | 58 | uint8_t handshake[TCP_CLIENT_HANDSHAKE_SIZE]; |
59 | memcpy(handshake, f_public_key, crypto_box_PUBLICKEYBYTES); | 59 | memcpy(handshake, f_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
60 | random_nonce(handshake + crypto_box_PUBLICKEYBYTES); | 60 | random_nonce(handshake + CRYPTO_PUBLIC_KEY_SIZE); |
61 | 61 | ||
62 | ret = encrypt_data(self_public_key, f_secret_key, handshake + crypto_box_PUBLICKEYBYTES, handshake_plain, | 62 | ret = encrypt_data(self_public_key, f_secret_key, handshake + CRYPTO_PUBLIC_KEY_SIZE, handshake_plain, |
63 | TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES); | 63 | TCP_HANDSHAKE_PLAIN_SIZE, handshake + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); |
64 | ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES), | 64 | ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE), |
65 | "Encrypt failed."); | 65 | "Encrypt failed."); |
66 | ck_assert_msg(send(sock, (const char *)handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, | 66 | ck_assert_msg(send(sock, (const char *)handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, |
67 | "send Failed."); | 67 | "send Failed."); |
@@ -79,20 +79,20 @@ START_TEST(test_basic) | |||
79 | uint8_t response[TCP_SERVER_HANDSHAKE_SIZE]; | 79 | uint8_t response[TCP_SERVER_HANDSHAKE_SIZE]; |
80 | uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE]; | 80 | uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE]; |
81 | ck_assert_msg(recv(sock, (char *)response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed."); | 81 | ck_assert_msg(recv(sock, (char *)response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed."); |
82 | ret = decrypt_data(self_public_key, f_secret_key, response, response + crypto_box_NONCEBYTES, | 82 | ret = decrypt_data(self_public_key, f_secret_key, response, response + CRYPTO_NONCE_SIZE, |
83 | TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain); | 83 | TCP_SERVER_HANDSHAKE_SIZE - CRYPTO_NONCE_SIZE, response_plain); |
84 | ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed."); | 84 | ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed."); |
85 | uint8_t f_nonce_r[crypto_box_NONCEBYTES]; | 85 | uint8_t f_nonce_r[CRYPTO_NONCE_SIZE]; |
86 | uint8_t f_shared_key[crypto_box_BEFORENMBYTES]; | 86 | uint8_t f_shared_key[CRYPTO_SHARED_KEY_SIZE]; |
87 | encrypt_precompute(response_plain, t_secret_key, f_shared_key); | 87 | encrypt_precompute(response_plain, t_secret_key, f_shared_key); |
88 | memcpy(f_nonce_r, response_plain + crypto_box_BEFORENMBYTES, crypto_box_NONCEBYTES); | 88 | memcpy(f_nonce_r, response_plain + CRYPTO_SHARED_KEY_SIZE, CRYPTO_NONCE_SIZE); |
89 | 89 | ||
90 | uint8_t r_req_p[1 + crypto_box_PUBLICKEYBYTES] = {0}; | 90 | uint8_t r_req_p[1 + CRYPTO_PUBLIC_KEY_SIZE] = {0}; |
91 | memcpy(r_req_p + 1, f_public_key, crypto_box_PUBLICKEYBYTES); | 91 | memcpy(r_req_p + 1, f_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
92 | uint8_t r_req[2 + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES]; | 92 | uint8_t r_req[2 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE]; |
93 | uint16_t size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES; | 93 | uint16_t size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE; |
94 | size = htons(size); | 94 | size = htons(size); |
95 | encrypt_data_symmetric(f_shared_key, f_nonce, r_req_p, 1 + crypto_box_PUBLICKEYBYTES, r_req + 2); | 95 | encrypt_data_symmetric(f_shared_key, f_nonce, r_req_p, 1 + CRYPTO_PUBLIC_KEY_SIZE, r_req + 2); |
96 | increment_nonce(f_nonce); | 96 | increment_nonce(f_nonce); |
97 | memcpy(r_req, &size, 2); | 97 | memcpy(r_req, &size, 2); |
98 | uint32_t i; | 98 | uint32_t i; |
@@ -107,11 +107,11 @@ START_TEST(test_basic) | |||
107 | do_TCP_server(tcp_s); | 107 | do_TCP_server(tcp_s); |
108 | c_sleep(50); | 108 | c_sleep(50); |
109 | uint8_t packet_resp[4096]; | 109 | uint8_t packet_resp[4096]; |
110 | int recv_data_len = recv(sock, (char *)packet_resp, 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, 0); | 110 | int recv_data_len = recv(sock, (char *)packet_resp, 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE, 0); |
111 | ck_assert_msg(recv_data_len == 2 + 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, | 111 | ck_assert_msg(recv_data_len == 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE, |
112 | "recv Failed. %u", recv_data_len); | 112 | "recv Failed. %u", recv_data_len); |
113 | memcpy(&size, packet_resp, 2); | 113 | memcpy(&size, packet_resp, 2); |
114 | ck_assert_msg(ntohs(size) == 2 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES, "Wrong packet size."); | 114 | ck_assert_msg(ntohs(size) == 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE, "Wrong packet size."); |
115 | uint8_t packet_resp_plain[4096]; | 115 | uint8_t packet_resp_plain[4096]; |
116 | ret = decrypt_data_symmetric(f_shared_key, f_nonce_r, packet_resp + 2, recv_data_len - 2, packet_resp_plain); | 116 | ret = decrypt_data_symmetric(f_shared_key, f_nonce_r, packet_resp + 2, recv_data_len - 2, packet_resp_plain); |
117 | ck_assert_msg(ret != -1, "decryption failed"); | 117 | ck_assert_msg(ret != -1, "decryption failed"); |
@@ -125,10 +125,10 @@ END_TEST | |||
125 | 125 | ||
126 | struct sec_TCP_con { | 126 | struct sec_TCP_con { |
127 | sock_t sock; | 127 | sock_t sock; |
128 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | 128 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
129 | uint8_t recv_nonce[crypto_box_NONCEBYTES]; | 129 | uint8_t recv_nonce[CRYPTO_NONCE_SIZE]; |
130 | uint8_t sent_nonce[crypto_box_NONCEBYTES]; | 130 | uint8_t sent_nonce[CRYPTO_NONCE_SIZE]; |
131 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 131 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; |
132 | }; | 132 | }; |
133 | 133 | ||
134 | static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) | 134 | static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) |
@@ -143,21 +143,21 @@ static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) | |||
143 | int ret = connect(sock, (struct sockaddr *)&addr6_loopback, sizeof(addr6_loopback)); | 143 | int ret = connect(sock, (struct sockaddr *)&addr6_loopback, sizeof(addr6_loopback)); |
144 | ck_assert_msg(ret == 0, "Failed to connect to TCP relay server"); | 144 | ck_assert_msg(ret == 0, "Failed to connect to TCP relay server"); |
145 | 145 | ||
146 | uint8_t f_secret_key[crypto_box_SECRETKEYBYTES]; | 146 | uint8_t f_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
147 | crypto_box_keypair(sec_c->public_key, f_secret_key); | 147 | crypto_new_keypair(sec_c->public_key, f_secret_key); |
148 | random_nonce(sec_c->sent_nonce); | 148 | random_nonce(sec_c->sent_nonce); |
149 | 149 | ||
150 | uint8_t t_secret_key[crypto_box_SECRETKEYBYTES]; | 150 | uint8_t t_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
151 | uint8_t handshake_plain[TCP_HANDSHAKE_PLAIN_SIZE]; | 151 | uint8_t handshake_plain[TCP_HANDSHAKE_PLAIN_SIZE]; |
152 | crypto_box_keypair(handshake_plain, t_secret_key); | 152 | crypto_new_keypair(handshake_plain, t_secret_key); |
153 | memcpy(handshake_plain + crypto_box_PUBLICKEYBYTES, sec_c->sent_nonce, crypto_box_NONCEBYTES); | 153 | memcpy(handshake_plain + CRYPTO_PUBLIC_KEY_SIZE, sec_c->sent_nonce, CRYPTO_NONCE_SIZE); |
154 | uint8_t handshake[TCP_CLIENT_HANDSHAKE_SIZE]; | 154 | uint8_t handshake[TCP_CLIENT_HANDSHAKE_SIZE]; |
155 | memcpy(handshake, sec_c->public_key, crypto_box_PUBLICKEYBYTES); | 155 | memcpy(handshake, sec_c->public_key, CRYPTO_PUBLIC_KEY_SIZE); |
156 | random_nonce(handshake + crypto_box_PUBLICKEYBYTES); | 156 | random_nonce(handshake + CRYPTO_PUBLIC_KEY_SIZE); |
157 | 157 | ||
158 | ret = encrypt_data(tcp_server_public_key(tcp_s), f_secret_key, handshake + crypto_box_PUBLICKEYBYTES, handshake_plain, | 158 | ret = encrypt_data(tcp_server_public_key(tcp_s), f_secret_key, handshake + CRYPTO_PUBLIC_KEY_SIZE, handshake_plain, |
159 | TCP_HANDSHAKE_PLAIN_SIZE, handshake + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES); | 159 | TCP_HANDSHAKE_PLAIN_SIZE, handshake + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); |
160 | ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES), | 160 | ck_assert_msg(ret == TCP_CLIENT_HANDSHAKE_SIZE - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE), |
161 | "Encrypt failed."); | 161 | "Encrypt failed."); |
162 | ck_assert_msg(send(sock, (const char *)handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, | 162 | ck_assert_msg(send(sock, (const char *)handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1, 0) == TCP_CLIENT_HANDSHAKE_SIZE - 1, |
163 | "send Failed."); | 163 | "send Failed."); |
@@ -169,11 +169,11 @@ static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) | |||
169 | uint8_t response[TCP_SERVER_HANDSHAKE_SIZE]; | 169 | uint8_t response[TCP_SERVER_HANDSHAKE_SIZE]; |
170 | uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE]; | 170 | uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE]; |
171 | ck_assert_msg(recv(sock, (char *)response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed."); | 171 | ck_assert_msg(recv(sock, (char *)response, TCP_SERVER_HANDSHAKE_SIZE, 0) == TCP_SERVER_HANDSHAKE_SIZE, "recv Failed."); |
172 | ret = decrypt_data(tcp_server_public_key(tcp_s), f_secret_key, response, response + crypto_box_NONCEBYTES, | 172 | ret = decrypt_data(tcp_server_public_key(tcp_s), f_secret_key, response, response + CRYPTO_NONCE_SIZE, |
173 | TCP_SERVER_HANDSHAKE_SIZE - crypto_box_NONCEBYTES, response_plain); | 173 | TCP_SERVER_HANDSHAKE_SIZE - CRYPTO_NONCE_SIZE, response_plain); |
174 | ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed."); | 174 | ck_assert_msg(ret == TCP_HANDSHAKE_PLAIN_SIZE, "Decrypt Failed."); |
175 | encrypt_precompute(response_plain, t_secret_key, sec_c->shared_key); | 175 | encrypt_precompute(response_plain, t_secret_key, sec_c->shared_key); |
176 | memcpy(sec_c->recv_nonce, response_plain + crypto_box_BEFORENMBYTES, crypto_box_NONCEBYTES); | 176 | memcpy(sec_c->recv_nonce, response_plain + CRYPTO_SHARED_KEY_SIZE, CRYPTO_NONCE_SIZE); |
177 | sec_c->sock = sock; | 177 | sec_c->sock = sock; |
178 | return sec_c; | 178 | return sec_c; |
179 | } | 179 | } |
@@ -186,9 +186,9 @@ static void kill_TCP_con(struct sec_TCP_con *con) | |||
186 | 186 | ||
187 | static int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length) | 187 | static int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length) |
188 | { | 188 | { |
189 | uint8_t packet[sizeof(uint16_t) + length + crypto_box_MACBYTES]; | 189 | uint8_t packet[sizeof(uint16_t) + length + CRYPTO_MAC_SIZE]; |
190 | 190 | ||
191 | uint16_t c_length = htons(length + crypto_box_MACBYTES); | 191 | uint16_t c_length = htons(length + CRYPTO_MAC_SIZE); |
192 | memcpy(packet, &c_length, sizeof(uint16_t)); | 192 | memcpy(packet, &c_length, sizeof(uint16_t)); |
193 | int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t)); | 193 | int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t)); |
194 | 194 | ||
@@ -214,9 +214,9 @@ static int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t | |||
214 | 214 | ||
215 | START_TEST(test_some) | 215 | START_TEST(test_some) |
216 | { | 216 | { |
217 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | 217 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
218 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | 218 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
219 | crypto_box_keypair(self_public_key, self_secret_key); | 219 | crypto_new_keypair(self_public_key, self_secret_key); |
220 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); | 220 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); |
221 | ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); | 221 | ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); |
222 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); | 222 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); |
@@ -225,22 +225,22 @@ START_TEST(test_some) | |||
225 | struct sec_TCP_con *con2 = new_TCP_con(tcp_s); | 225 | struct sec_TCP_con *con2 = new_TCP_con(tcp_s); |
226 | struct sec_TCP_con *con3 = new_TCP_con(tcp_s); | 226 | struct sec_TCP_con *con3 = new_TCP_con(tcp_s); |
227 | 227 | ||
228 | uint8_t requ_p[1 + crypto_box_PUBLICKEYBYTES]; | 228 | uint8_t requ_p[1 + CRYPTO_PUBLIC_KEY_SIZE]; |
229 | requ_p[0] = 0; | 229 | requ_p[0] = 0; |
230 | memcpy(requ_p + 1, con3->public_key, crypto_box_PUBLICKEYBYTES); | 230 | memcpy(requ_p + 1, con3->public_key, CRYPTO_PUBLIC_KEY_SIZE); |
231 | write_packet_TCP_secure_connection(con1, requ_p, sizeof(requ_p)); | 231 | write_packet_TCP_secure_connection(con1, requ_p, sizeof(requ_p)); |
232 | memcpy(requ_p + 1, con1->public_key, crypto_box_PUBLICKEYBYTES); | 232 | memcpy(requ_p + 1, con1->public_key, CRYPTO_PUBLIC_KEY_SIZE); |
233 | write_packet_TCP_secure_connection(con3, requ_p, sizeof(requ_p)); | 233 | write_packet_TCP_secure_connection(con3, requ_p, sizeof(requ_p)); |
234 | do_TCP_server(tcp_s); | 234 | do_TCP_server(tcp_s); |
235 | c_sleep(50); | 235 | c_sleep(50); |
236 | uint8_t data[2048]; | 236 | uint8_t data[2048]; |
237 | int len = read_packet_sec_TCP(con1, data, 2 + 1 + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES); | 237 | int len = read_packet_sec_TCP(con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE); |
238 | ck_assert_msg(len == 1 + 1 + crypto_box_PUBLICKEYBYTES, "wrong len %u", len); | 238 | ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "wrong len %u", len); |
239 | ck_assert_msg(data[0] == 1, "wrong packet id %u", data[0]); | 239 | ck_assert_msg(data[0] == 1, "wrong packet id %u", data[0]); |
240 | ck_assert_msg(data[1] == 16, "connection not refused %u", data[1]); | 240 | ck_assert_msg(data[1] == 16, "connection not refused %u", data[1]); |
241 | ck_assert_msg(public_key_cmp(data + 2, con3->public_key) == 0, "key in packet wrong"); | 241 | ck_assert_msg(public_key_cmp(data + 2, con3->public_key) == 0, "key in packet wrong"); |
242 | len = read_packet_sec_TCP(con3, data, 2 + 1 + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES); | 242 | len = read_packet_sec_TCP(con3, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE); |
243 | ck_assert_msg(len == 1 + 1 + crypto_box_PUBLICKEYBYTES, "wrong len %u", len); | 243 | ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "wrong len %u", len); |
244 | ck_assert_msg(data[0] == 1, "wrong packet id %u", data[0]); | 244 | ck_assert_msg(data[0] == 1, "wrong packet id %u", data[0]); |
245 | ck_assert_msg(data[1] == 16, "connection not refused %u", data[1]); | 245 | ck_assert_msg(data[1] == 16, "connection not refused %u", data[1]); |
246 | ck_assert_msg(public_key_cmp(data + 2, con1->public_key) == 0, "key in packet wrong"); | 246 | ck_assert_msg(public_key_cmp(data + 2, con1->public_key) == 0, "key in packet wrong"); |
@@ -252,23 +252,23 @@ START_TEST(test_some) | |||
252 | c_sleep(50); | 252 | c_sleep(50); |
253 | do_TCP_server(tcp_s); | 253 | do_TCP_server(tcp_s); |
254 | c_sleep(50); | 254 | c_sleep(50); |
255 | len = read_packet_sec_TCP(con1, data, 2 + 2 + crypto_box_MACBYTES); | 255 | len = read_packet_sec_TCP(con1, data, 2 + 2 + CRYPTO_MAC_SIZE); |
256 | ck_assert_msg(len == 2, "wrong len %u", len); | 256 | ck_assert_msg(len == 2, "wrong len %u", len); |
257 | ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]); | 257 | ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]); |
258 | ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]); | 258 | ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]); |
259 | len = read_packet_sec_TCP(con3, data, 2 + 2 + crypto_box_MACBYTES); | 259 | len = read_packet_sec_TCP(con3, data, 2 + 2 + CRYPTO_MAC_SIZE); |
260 | ck_assert_msg(len == 2, "wrong len %u", len); | 260 | ck_assert_msg(len == 2, "wrong len %u", len); |
261 | ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]); | 261 | ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]); |
262 | ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]); | 262 | ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]); |
263 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES); | 263 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE); |
264 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); | 264 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); |
265 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], | 265 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], |
266 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); | 266 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); |
267 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES); | 267 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE); |
268 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); | 268 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); |
269 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], | 269 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], |
270 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); | 270 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); |
271 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES); | 271 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE); |
272 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); | 272 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); |
273 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], | 273 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], |
274 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); | 274 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); |
@@ -278,15 +278,15 @@ START_TEST(test_some) | |||
278 | c_sleep(50); | 278 | c_sleep(50); |
279 | do_TCP_server(tcp_s); | 279 | do_TCP_server(tcp_s); |
280 | c_sleep(50); | 280 | c_sleep(50); |
281 | len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES); | 281 | len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE); |
282 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); | 282 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); |
283 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], | 283 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], |
284 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); | 284 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); |
285 | len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES); | 285 | len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE); |
286 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); | 286 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); |
287 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], | 287 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], |
288 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); | 288 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); |
289 | len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + crypto_box_MACBYTES); | 289 | len = read_packet_sec_TCP(con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE); |
290 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); | 290 | ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); |
291 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], | 291 | ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1], |
292 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); | 292 | data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]); |
@@ -296,7 +296,7 @@ START_TEST(test_some) | |||
296 | c_sleep(50); | 296 | c_sleep(50); |
297 | do_TCP_server(tcp_s); | 297 | do_TCP_server(tcp_s); |
298 | c_sleep(50); | 298 | c_sleep(50); |
299 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(ping_packet) + crypto_box_MACBYTES); | 299 | len = read_packet_sec_TCP(con1, data, 2 + sizeof(ping_packet) + CRYPTO_MAC_SIZE); |
300 | ck_assert_msg(len == sizeof(ping_packet), "wrong len %u", len); | 300 | ck_assert_msg(len == sizeof(ping_packet), "wrong len %u", len); |
301 | ck_assert_msg(data[0] == 5, "wrong packet id %u", data[0]); | 301 | ck_assert_msg(data[0] == 5, "wrong packet id %u", data[0]); |
302 | ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data"); | 302 | ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data"); |
@@ -309,7 +309,7 @@ END_TEST | |||
309 | 309 | ||
310 | static int response_callback_good; | 310 | static int response_callback_good; |
311 | static uint8_t response_callback_connection_id; | 311 | static uint8_t response_callback_connection_id; |
312 | static uint8_t response_callback_public_key[crypto_box_PUBLICKEYBYTES]; | 312 | static uint8_t response_callback_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
313 | static int response_callback(void *object, uint8_t connection_id, const uint8_t *public_key) | 313 | static int response_callback(void *object, uint8_t connection_id, const uint8_t *public_key) |
314 | { | 314 | { |
315 | if (set_tcp_connection_number((TCP_Client_Connection *)((char *)object - 2), connection_id, 7) != 0) { | 315 | if (set_tcp_connection_number((TCP_Client_Connection *)((char *)object - 2), connection_id, 7) != 0) { |
@@ -317,7 +317,7 @@ static int response_callback(void *object, uint8_t connection_id, const uint8_t | |||
317 | } | 317 | } |
318 | 318 | ||
319 | response_callback_connection_id = connection_id; | 319 | response_callback_connection_id = connection_id; |
320 | memcpy(response_callback_public_key, public_key, crypto_box_PUBLICKEYBYTES); | 320 | memcpy(response_callback_public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
321 | response_callback_good++; | 321 | response_callback_good++; |
322 | return 0; | 322 | return 0; |
323 | } | 323 | } |
@@ -364,7 +364,7 @@ static int data_callback(void *object, uint32_t number, uint8_t connection_id, c | |||
364 | } | 364 | } |
365 | 365 | ||
366 | static int oob_data_callback_good; | 366 | static int oob_data_callback_good; |
367 | static uint8_t oob_pubkey[crypto_box_PUBLICKEYBYTES]; | 367 | static uint8_t oob_pubkey[CRYPTO_PUBLIC_KEY_SIZE]; |
368 | static int oob_data_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length, | 368 | static int oob_data_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length, |
369 | void *userdata) | 369 | void *userdata) |
370 | { | 370 | { |
@@ -391,16 +391,16 @@ static int oob_data_callback(void *object, const uint8_t *public_key, const uint | |||
391 | START_TEST(test_client) | 391 | START_TEST(test_client) |
392 | { | 392 | { |
393 | unix_time_update(); | 393 | unix_time_update(); |
394 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | 394 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
395 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | 395 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
396 | crypto_box_keypair(self_public_key, self_secret_key); | 396 | crypto_new_keypair(self_public_key, self_secret_key); |
397 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); | 397 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); |
398 | ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); | 398 | ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server"); |
399 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); | 399 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports"); |
400 | 400 | ||
401 | uint8_t f_public_key[crypto_box_PUBLICKEYBYTES]; | 401 | uint8_t f_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
402 | uint8_t f_secret_key[crypto_box_SECRETKEYBYTES]; | 402 | uint8_t f_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
403 | crypto_box_keypair(f_public_key, f_secret_key); | 403 | crypto_new_keypair(f_public_key, f_secret_key); |
404 | IP_Port ip_port_tcp_s; | 404 | IP_Port ip_port_tcp_s; |
405 | 405 | ||
406 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); | 406 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); |
@@ -430,9 +430,9 @@ START_TEST(test_client) | |||
430 | ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED, | 430 | ck_assert_msg(conn->status == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED, |
431 | conn->status); | 431 | conn->status); |
432 | 432 | ||
433 | uint8_t f2_public_key[crypto_box_PUBLICKEYBYTES]; | 433 | uint8_t f2_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
434 | uint8_t f2_secret_key[crypto_box_SECRETKEYBYTES]; | 434 | uint8_t f2_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
435 | crypto_box_keypair(f2_public_key, f2_secret_key); | 435 | crypto_new_keypair(f2_public_key, f2_secret_key); |
436 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); | 436 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); |
437 | TCP_Client_Connection *conn2 = new_TCP_connection(ip_port_tcp_s, self_public_key, f2_public_key, f2_secret_key, 0); | 437 | TCP_Client_Connection *conn2 = new_TCP_connection(ip_port_tcp_s, self_public_key, f2_public_key, f2_secret_key, 0); |
438 | routing_response_handler(conn, response_callback, (char *)conn + 2); | 438 | routing_response_handler(conn, response_callback, (char *)conn + 2); |
@@ -450,7 +450,7 @@ START_TEST(test_client) | |||
450 | do_TCP_connection(conn2, NULL); | 450 | do_TCP_connection(conn2, NULL); |
451 | c_sleep(50); | 451 | c_sleep(50); |
452 | uint8_t data[5] = {1, 2, 3, 4, 5}; | 452 | uint8_t data[5] = {1, 2, 3, 4, 5}; |
453 | memcpy(oob_pubkey, f2_public_key, crypto_box_PUBLICKEYBYTES); | 453 | memcpy(oob_pubkey, f2_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
454 | send_oob_packet(conn2, f_public_key, data, 5); | 454 | send_oob_packet(conn2, f_public_key, data, 5); |
455 | send_routing_request(conn, f2_public_key); | 455 | send_routing_request(conn, f2_public_key); |
456 | send_routing_request(conn2, f_public_key); | 456 | send_routing_request(conn2, f_public_key); |
@@ -492,13 +492,13 @@ END_TEST | |||
492 | START_TEST(test_client_invalid) | 492 | START_TEST(test_client_invalid) |
493 | { | 493 | { |
494 | unix_time_update(); | 494 | unix_time_update(); |
495 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | 495 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
496 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | 496 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
497 | crypto_box_keypair(self_public_key, self_secret_key); | 497 | crypto_new_keypair(self_public_key, self_secret_key); |
498 | 498 | ||
499 | uint8_t f_public_key[crypto_box_PUBLICKEYBYTES]; | 499 | uint8_t f_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
500 | uint8_t f_secret_key[crypto_box_SECRETKEYBYTES]; | 500 | uint8_t f_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
501 | crypto_box_keypair(f_public_key, f_secret_key); | 501 | crypto_new_keypair(f_public_key, f_secret_key); |
502 | IP_Port ip_port_tcp_s; | 502 | IP_Port ip_port_tcp_s; |
503 | 503 | ||
504 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); | 504 | ip_port_tcp_s.port = htons(ports[rand() % NUM_PORTS]); |
@@ -552,19 +552,19 @@ START_TEST(test_tcp_connection) | |||
552 | { | 552 | { |
553 | tcp_data_callback_called = 0; | 553 | tcp_data_callback_called = 0; |
554 | unix_time_update(); | 554 | unix_time_update(); |
555 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | 555 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
556 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | 556 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
557 | crypto_box_keypair(self_public_key, self_secret_key); | 557 | crypto_new_keypair(self_public_key, self_secret_key); |
558 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); | 558 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); |
559 | ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); | 559 | ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); |
560 | 560 | ||
561 | TCP_Proxy_Info proxy_info; | 561 | TCP_Proxy_Info proxy_info; |
562 | proxy_info.proxy_type = TCP_PROXY_NONE; | 562 | proxy_info.proxy_type = TCP_PROXY_NONE; |
563 | crypto_box_keypair(self_public_key, self_secret_key); | 563 | crypto_new_keypair(self_public_key, self_secret_key); |
564 | TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info); | 564 | TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info); |
565 | ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_1), self_public_key) == 0, "Wrong public key"); | 565 | ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_1), self_public_key) == 0, "Wrong public key"); |
566 | 566 | ||
567 | crypto_box_keypair(self_public_key, self_secret_key); | 567 | crypto_new_keypair(self_public_key, self_secret_key); |
568 | TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info); | 568 | TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info); |
569 | ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_2), self_public_key) == 0, "Wrong public key"); | 569 | ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_2), self_public_key) == 0, "Wrong public key"); |
570 | 570 | ||
@@ -661,19 +661,19 @@ START_TEST(test_tcp_connection2) | |||
661 | tcp_data_callback_called = 0; | 661 | tcp_data_callback_called = 0; |
662 | 662 | ||
663 | unix_time_update(); | 663 | unix_time_update(); |
664 | uint8_t self_public_key[crypto_box_PUBLICKEYBYTES]; | 664 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
665 | uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; | 665 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
666 | crypto_box_keypair(self_public_key, self_secret_key); | 666 | crypto_new_keypair(self_public_key, self_secret_key); |
667 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); | 667 | TCP_Server *tcp_s = new_TCP_server(1, NUM_PORTS, ports, self_secret_key, NULL); |
668 | ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); | 668 | ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); |
669 | 669 | ||
670 | TCP_Proxy_Info proxy_info; | 670 | TCP_Proxy_Info proxy_info; |
671 | proxy_info.proxy_type = TCP_PROXY_NONE; | 671 | proxy_info.proxy_type = TCP_PROXY_NONE; |
672 | crypto_box_keypair(self_public_key, self_secret_key); | 672 | crypto_new_keypair(self_public_key, self_secret_key); |
673 | TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info); | 673 | TCP_Connections *tc_1 = new_tcp_connections(self_secret_key, &proxy_info); |
674 | ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_1), self_public_key) == 0, "Wrong public key"); | 674 | ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_1), self_public_key) == 0, "Wrong public key"); |
675 | 675 | ||
676 | crypto_box_keypair(self_public_key, self_secret_key); | 676 | crypto_new_keypair(self_public_key, self_secret_key); |
677 | TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info); | 677 | TCP_Connections *tc_2 = new_tcp_connections(self_secret_key, &proxy_info); |
678 | ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_2), self_public_key) == 0, "Wrong public key"); | 678 | ck_assert_msg(public_key_cmp(tcp_connections_public_key(tc_2), self_public_key) == 0, "Wrong public key"); |
679 | 679 | ||
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index ce2101cc..c1003f80 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c | |||
@@ -91,8 +91,8 @@ START_TEST(test_known) | |||
91 | unsigned char m[131]; | 91 | unsigned char m[131]; |
92 | int clen, mlen; | 92 | int clen, mlen; |
93 | 93 | ||
94 | ck_assert_msg(sizeof(c) == sizeof(m) + crypto_box_MACBYTES * sizeof(unsigned char), | 94 | ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(unsigned char), |
95 | "cyphertext should be crypto_box_MACBYTES bytes longer than plaintext"); | 95 | "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext"); |
96 | ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); | 96 | ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); |
97 | ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); | 97 | ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); |
98 | 98 | ||
@@ -110,15 +110,15 @@ END_TEST | |||
110 | 110 | ||
111 | START_TEST(test_fast_known) | 111 | START_TEST(test_fast_known) |
112 | { | 112 | { |
113 | unsigned char k[crypto_box_BEFORENMBYTES]; | 113 | unsigned char k[CRYPTO_SHARED_KEY_SIZE]; |
114 | unsigned char c[147]; | 114 | unsigned char c[147]; |
115 | unsigned char m[131]; | 115 | unsigned char m[131]; |
116 | int clen, mlen; | 116 | int clen, mlen; |
117 | 117 | ||
118 | encrypt_precompute(bobpk, alicesk, k); | 118 | encrypt_precompute(bobpk, alicesk, k); |
119 | 119 | ||
120 | ck_assert_msg(sizeof(c) == sizeof(m) + crypto_box_MACBYTES * sizeof(unsigned char), | 120 | ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(unsigned char), |
121 | "cyphertext should be crypto_box_MACBYTES bytes longer than plaintext"); | 121 | "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext"); |
122 | ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); | 122 | ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); |
123 | ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); | 123 | ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); |
124 | 124 | ||
@@ -136,20 +136,20 @@ END_TEST | |||
136 | 136 | ||
137 | START_TEST(test_endtoend) | 137 | START_TEST(test_endtoend) |
138 | { | 138 | { |
139 | unsigned char pk1[crypto_box_PUBLICKEYBYTES]; | 139 | unsigned char pk1[CRYPTO_PUBLIC_KEY_SIZE]; |
140 | unsigned char sk1[crypto_box_SECRETKEYBYTES]; | 140 | unsigned char sk1[CRYPTO_SECRET_KEY_SIZE]; |
141 | unsigned char pk2[crypto_box_PUBLICKEYBYTES]; | 141 | unsigned char pk2[CRYPTO_PUBLIC_KEY_SIZE]; |
142 | unsigned char sk2[crypto_box_SECRETKEYBYTES]; | 142 | unsigned char sk2[CRYPTO_SECRET_KEY_SIZE]; |
143 | unsigned char k1[crypto_box_BEFORENMBYTES]; | 143 | unsigned char k1[CRYPTO_SHARED_KEY_SIZE]; |
144 | unsigned char k2[crypto_box_BEFORENMBYTES]; | 144 | unsigned char k2[CRYPTO_SHARED_KEY_SIZE]; |
145 | 145 | ||
146 | unsigned char n[crypto_box_NONCEBYTES]; | 146 | unsigned char n[CRYPTO_NONCE_SIZE]; |
147 | 147 | ||
148 | unsigned char m[500]; | 148 | unsigned char m[500]; |
149 | unsigned char c1[sizeof(m) + crypto_box_MACBYTES]; | 149 | unsigned char c1[sizeof(m) + CRYPTO_MAC_SIZE]; |
150 | unsigned char c2[sizeof(m) + crypto_box_MACBYTES]; | 150 | unsigned char c2[sizeof(m) + CRYPTO_MAC_SIZE]; |
151 | unsigned char c3[sizeof(m) + crypto_box_MACBYTES]; | 151 | unsigned char c3[sizeof(m) + CRYPTO_MAC_SIZE]; |
152 | unsigned char c4[sizeof(m) + crypto_box_MACBYTES]; | 152 | unsigned char c4[sizeof(m) + CRYPTO_MAC_SIZE]; |
153 | unsigned char m1[sizeof(m)]; | 153 | unsigned char m1[sizeof(m)]; |
154 | unsigned char m2[sizeof(m)]; | 154 | unsigned char m2[sizeof(m)]; |
155 | unsigned char m3[sizeof(m)]; | 155 | unsigned char m3[sizeof(m)]; |
@@ -166,17 +166,17 @@ START_TEST(test_endtoend) | |||
166 | //Generate random message (random length from 100 to 500) | 166 | //Generate random message (random length from 100 to 500) |
167 | mlen = (rand() % 400) + 100; | 167 | mlen = (rand() % 400) + 100; |
168 | rand_bytes(m, mlen); | 168 | rand_bytes(m, mlen); |
169 | rand_bytes(n, crypto_box_NONCEBYTES); | 169 | rand_bytes(n, CRYPTO_NONCE_SIZE); |
170 | 170 | ||
171 | //Generate keypairs | 171 | //Generate keypairs |
172 | crypto_box_keypair(pk1, sk1); | 172 | crypto_new_keypair(pk1, sk1); |
173 | crypto_box_keypair(pk2, sk2); | 173 | crypto_new_keypair(pk2, sk2); |
174 | 174 | ||
175 | //Precompute shared keys | 175 | //Precompute shared keys |
176 | encrypt_precompute(pk2, sk1, k1); | 176 | encrypt_precompute(pk2, sk1, k1); |
177 | encrypt_precompute(pk1, sk2, k2); | 177 | encrypt_precompute(pk1, sk2, k2); |
178 | 178 | ||
179 | ck_assert_msg(memcmp(k1, k2, crypto_box_BEFORENMBYTES) == 0, "encrypt_precompute: bad"); | 179 | ck_assert_msg(memcmp(k1, k2, CRYPTO_SHARED_KEY_SIZE) == 0, "encrypt_precompute: bad"); |
180 | 180 | ||
181 | //Encrypt all four ways | 181 | //Encrypt all four ways |
182 | c1len = encrypt_data(pk2, sk1, n, m, mlen, c1); | 182 | c1len = encrypt_data(pk2, sk1, n, m, mlen, c1); |
@@ -185,7 +185,7 @@ START_TEST(test_endtoend) | |||
185 | c4len = encrypt_data_symmetric(k2, n, m, mlen, c4); | 185 | c4len = encrypt_data_symmetric(k2, n, m, mlen, c4); |
186 | 186 | ||
187 | ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ"); | 187 | ck_assert_msg(c1len == c2len && c1len == c3len && c1len == c4len, "cyphertext lengths differ"); |
188 | ck_assert_msg(c1len == mlen + (int)crypto_box_MACBYTES, "wrong cyphertext length"); | 188 | ck_assert_msg(c1len == mlen + (int)CRYPTO_MAC_SIZE, "wrong cyphertext length"); |
189 | ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0 | 189 | ck_assert_msg(memcmp(c1, c2, c1len) == 0 && memcmp(c1, c3, c1len) == 0 |
190 | && memcmp(c1, c4, c1len) == 0, "crypertexts differ"); | 190 | && memcmp(c1, c4, c1len) == 0, "crypertexts differ"); |
191 | 191 | ||
@@ -206,16 +206,16 @@ END_TEST | |||
206 | 206 | ||
207 | START_TEST(test_large_data) | 207 | START_TEST(test_large_data) |
208 | { | 208 | { |
209 | unsigned char k[crypto_box_BEFORENMBYTES]; | 209 | unsigned char k[CRYPTO_SHARED_KEY_SIZE]; |
210 | 210 | ||
211 | unsigned char n[crypto_box_NONCEBYTES]; | 211 | unsigned char n[CRYPTO_NONCE_SIZE]; |
212 | 212 | ||
213 | unsigned char m1[MAX_CRYPTO_PACKET_SIZE - crypto_box_MACBYTES]; | 213 | unsigned char m1[MAX_CRYPTO_PACKET_SIZE - CRYPTO_MAC_SIZE]; |
214 | unsigned char c1[sizeof(m1) + crypto_box_MACBYTES]; | 214 | unsigned char c1[sizeof(m1) + CRYPTO_MAC_SIZE]; |
215 | unsigned char m1prime[sizeof(m1)]; | 215 | unsigned char m1prime[sizeof(m1)]; |
216 | 216 | ||
217 | unsigned char m2[MAX_CRYPTO_PACKET_SIZE]; | 217 | unsigned char m2[MAX_CRYPTO_PACKET_SIZE]; |
218 | unsigned char c2[sizeof(m2) + crypto_box_MACBYTES]; | 218 | unsigned char c2[sizeof(m2) + CRYPTO_MAC_SIZE]; |
219 | 219 | ||
220 | int c1len, c2len; | 220 | int c1len, c2len; |
221 | int m1plen; | 221 | int m1plen; |
@@ -223,16 +223,16 @@ START_TEST(test_large_data) | |||
223 | //Generate random messages | 223 | //Generate random messages |
224 | rand_bytes(m1, sizeof(m1)); | 224 | rand_bytes(m1, sizeof(m1)); |
225 | rand_bytes(m2, sizeof(m2)); | 225 | rand_bytes(m2, sizeof(m2)); |
226 | rand_bytes(n, crypto_box_NONCEBYTES); | 226 | rand_bytes(n, CRYPTO_NONCE_SIZE); |
227 | 227 | ||
228 | //Generate key | 228 | //Generate key |
229 | rand_bytes(k, crypto_box_BEFORENMBYTES); | 229 | rand_bytes(k, CRYPTO_SHARED_KEY_SIZE); |
230 | 230 | ||
231 | c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1); | 231 | c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1); |
232 | c2len = encrypt_data_symmetric(k, n, m2, sizeof(m2), c2); | 232 | c2len = encrypt_data_symmetric(k, n, m2, sizeof(m2), c2); |
233 | 233 | ||
234 | ck_assert_msg(c1len == sizeof(m1) + crypto_box_MACBYTES, "could not encrypt"); | 234 | ck_assert_msg(c1len == sizeof(m1) + CRYPTO_MAC_SIZE, "could not encrypt"); |
235 | ck_assert_msg(c2len == sizeof(m2) + crypto_box_MACBYTES, "could not encrypt"); | 235 | ck_assert_msg(c2len == sizeof(m2) + CRYPTO_MAC_SIZE, "could not encrypt"); |
236 | 236 | ||
237 | m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime); | 237 | m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime); |
238 | 238 | ||
@@ -243,12 +243,12 @@ END_TEST | |||
243 | 243 | ||
244 | START_TEST(test_large_data_symmetric) | 244 | START_TEST(test_large_data_symmetric) |
245 | { | 245 | { |
246 | unsigned char k[crypto_box_KEYBYTES]; | 246 | unsigned char k[CRYPTO_SYMMETRIC_KEY_SIZE]; |
247 | 247 | ||
248 | unsigned char n[crypto_box_NONCEBYTES]; | 248 | unsigned char n[CRYPTO_NONCE_SIZE]; |
249 | 249 | ||
250 | unsigned char m1[16 * 16 * 16]; | 250 | unsigned char m1[16 * 16 * 16]; |
251 | unsigned char c1[sizeof(m1) + crypto_box_MACBYTES]; | 251 | unsigned char c1[sizeof(m1) + CRYPTO_MAC_SIZE]; |
252 | unsigned char m1prime[sizeof(m1)]; | 252 | unsigned char m1prime[sizeof(m1)]; |
253 | 253 | ||
254 | int c1len; | 254 | int c1len; |
@@ -256,13 +256,13 @@ START_TEST(test_large_data_symmetric) | |||
256 | 256 | ||
257 | //Generate random messages | 257 | //Generate random messages |
258 | rand_bytes(m1, sizeof(m1)); | 258 | rand_bytes(m1, sizeof(m1)); |
259 | rand_bytes(n, crypto_box_NONCEBYTES); | 259 | rand_bytes(n, CRYPTO_NONCE_SIZE); |
260 | 260 | ||
261 | //Generate key | 261 | //Generate key |
262 | new_symmetric_key(k); | 262 | new_symmetric_key(k); |
263 | 263 | ||
264 | c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1); | 264 | c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1); |
265 | ck_assert_msg(c1len == sizeof(m1) + crypto_box_MACBYTES, "could not encrypt data"); | 265 | ck_assert_msg(c1len == sizeof(m1) + CRYPTO_MAC_SIZE, "could not encrypt data"); |
266 | 266 | ||
267 | m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime); | 267 | m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime); |
268 | 268 | ||
@@ -274,14 +274,14 @@ END_TEST | |||
274 | static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) | 274 | static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) |
275 | { | 275 | { |
276 | uint32_t num1, num2; | 276 | uint32_t num1, num2; |
277 | memcpy(&num1, nonce + (crypto_box_NONCEBYTES - sizeof(num1)), sizeof(num1)); | 277 | memcpy(&num1, nonce + (CRYPTO_NONCE_SIZE - sizeof(num1)), sizeof(num1)); |
278 | num1 = ntohl(num1); | 278 | num1 = ntohl(num1); |
279 | num2 = num + num1; | 279 | num2 = num + num1; |
280 | 280 | ||
281 | if (num2 < num1) { | 281 | if (num2 < num1) { |
282 | uint32_t i; | 282 | uint32_t i; |
283 | 283 | ||
284 | for (i = crypto_box_NONCEBYTES - sizeof(num1); i != 0; --i) { | 284 | for (i = CRYPTO_NONCE_SIZE - sizeof(num1); i != 0; --i) { |
285 | ++nonce[i - 1]; | 285 | ++nonce[i - 1]; |
286 | 286 | ||
287 | if (nonce[i - 1] != 0) { | 287 | if (nonce[i - 1] != 0) { |
@@ -291,34 +291,34 @@ static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) | |||
291 | } | 291 | } |
292 | 292 | ||
293 | num2 = htonl(num2); | 293 | num2 = htonl(num2); |
294 | memcpy(nonce + (crypto_box_NONCEBYTES - sizeof(num2)), &num2, sizeof(num2)); | 294 | memcpy(nonce + (CRYPTO_NONCE_SIZE - sizeof(num2)), &num2, sizeof(num2)); |
295 | } | 295 | } |
296 | 296 | ||
297 | START_TEST(test_increment_nonce) | 297 | START_TEST(test_increment_nonce) |
298 | { | 298 | { |
299 | long long unsigned int i; | 299 | long long unsigned int i; |
300 | 300 | ||
301 | uint8_t n[crypto_box_NONCEBYTES]; | 301 | uint8_t n[CRYPTO_NONCE_SIZE]; |
302 | 302 | ||
303 | for (i = 0; i < crypto_box_NONCEBYTES; ++i) { | 303 | for (i = 0; i < CRYPTO_NONCE_SIZE; ++i) { |
304 | n[i] = rand(); | 304 | n[i] = rand(); |
305 | } | 305 | } |
306 | 306 | ||
307 | uint8_t n1[crypto_box_NONCEBYTES]; | 307 | uint8_t n1[CRYPTO_NONCE_SIZE]; |
308 | 308 | ||
309 | memcpy(n1, n, crypto_box_NONCEBYTES); | 309 | memcpy(n1, n, CRYPTO_NONCE_SIZE); |
310 | 310 | ||
311 | for (i = 0; i < (1 << 18); ++i) { | 311 | for (i = 0; i < (1 << 18); ++i) { |
312 | increment_nonce_number_cmp(n, 1); | 312 | increment_nonce_number_cmp(n, 1); |
313 | increment_nonce(n1); | 313 | increment_nonce(n1); |
314 | ck_assert_msg(memcmp(n, n1, crypto_box_NONCEBYTES) == 0, "Bad increment_nonce function"); | 314 | ck_assert_msg(memcmp(n, n1, CRYPTO_NONCE_SIZE) == 0, "Bad increment_nonce function"); |
315 | } | 315 | } |
316 | 316 | ||
317 | for (i = 0; i < (1 << 18); ++i) { | 317 | for (i = 0; i < (1 << 18); ++i) { |
318 | uint32_t r = rand(); | 318 | uint32_t r = rand(); |
319 | increment_nonce_number_cmp(n, r); | 319 | increment_nonce_number_cmp(n, r); |
320 | increment_nonce_number(n1, r); | 320 | increment_nonce_number(n1, r); |
321 | ck_assert_msg(memcmp(n, n1, crypto_box_NONCEBYTES) == 0, "Bad increment_nonce_number function"); | 321 | ck_assert_msg(memcmp(n, n1, CRYPTO_NONCE_SIZE) == 0, "Bad increment_nonce_number function"); |
322 | } | 322 | } |
323 | } | 323 | } |
324 | END_TEST | 324 | END_TEST |
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 11406554..7734e64a 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c | |||
@@ -12,7 +12,8 @@ | |||
12 | 12 | ||
13 | 13 | ||
14 | // These tests currently fail. | 14 | // These tests currently fail. |
15 | #if 0 | 15 | static bool enable_broken_tests = false; |
16 | |||
16 | #define swap(x,y) do \ | 17 | #define swap(x,y) do \ |
17 | { unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x) : -1]; \ | 18 | { unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x) : -1]; \ |
18 | memcpy(swap_temp,&y,sizeof(x)); \ | 19 | memcpy(swap_temp,&y,sizeof(x)); \ |
@@ -93,14 +94,14 @@ static void test_addto_lists_update(DHT *dht, | |||
93 | { | 94 | { |
94 | int used, test, test1, test2, found; | 95 | int used, test, test1, test2, found; |
95 | IP_Port test_ipp; | 96 | IP_Port test_ipp; |
96 | uint8_t test_id[crypto_box_PUBLICKEYBYTES]; | 97 | uint8_t test_id[CRYPTO_PUBLIC_KEY_SIZE]; |
97 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; | 98 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; |
98 | 99 | ||
99 | // check id update for existing ip_port | 100 | // check id update for existing ip_port |
100 | test = rand() % length; | 101 | test = rand() % length; |
101 | ipport_copy(&test_ipp, ipv6 ? &list[test].assoc6.ip_port : &list[test].assoc4.ip_port); | 102 | ipport_copy(&test_ipp, ipv6 ? &list[test].assoc6.ip_port : &list[test].assoc4.ip_port); |
102 | 103 | ||
103 | randombytes(test_id, sizeof(test_id)); | 104 | random_bytes(test_id, sizeof(test_id)); |
104 | used = addto_lists(dht, test_ipp, test_id); | 105 | used = addto_lists(dht, test_ipp, test_id); |
105 | ck_assert_msg(used >= 1, "Wrong number of added clients"); | 106 | ck_assert_msg(used >= 1, "Wrong number of added clients"); |
106 | // it is possible to have ip_port duplicates in the list, so ip_port @ found not always equal to ip_port @ test | 107 | // it is possible to have ip_port duplicates in the list, so ip_port @ found not always equal to ip_port @ test |
@@ -167,11 +168,11 @@ static void test_addto_lists_bad(DHT *dht, | |||
167 | { | 168 | { |
168 | // check "bad" clients replacement | 169 | // check "bad" clients replacement |
169 | int used, test1, test2, test3; | 170 | int used, test1, test2, test3; |
170 | uint8_t public_key[crypto_box_PUBLICKEYBYTES], test_id1[crypto_box_PUBLICKEYBYTES], test_id2[crypto_box_PUBLICKEYBYTES], | 171 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], |
171 | test_id3[crypto_box_PUBLICKEYBYTES]; | 172 | test_id3[CRYPTO_PUBLIC_KEY_SIZE]; |
172 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; | 173 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; |
173 | 174 | ||
174 | randombytes(public_key, sizeof(public_key)); | 175 | random_bytes(public_key, sizeof(public_key)); |
175 | mark_all_good(list, length, ipv6); | 176 | mark_all_good(list, length, ipv6); |
176 | 177 | ||
177 | test1 = rand() % (length / 3); | 178 | test1 = rand() % (length / 3); |
@@ -211,11 +212,11 @@ static void test_addto_lists_possible_bad(DHT *dht, | |||
211 | { | 212 | { |
212 | // check "possibly bad" clients replacement | 213 | // check "possibly bad" clients replacement |
213 | int used, test1, test2, test3; | 214 | int used, test1, test2, test3; |
214 | uint8_t public_key[crypto_box_PUBLICKEYBYTES], test_id1[crypto_box_PUBLICKEYBYTES], test_id2[crypto_box_PUBLICKEYBYTES], | 215 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], |
215 | test_id3[crypto_box_PUBLICKEYBYTES]; | 216 | test_id3[CRYPTO_PUBLIC_KEY_SIZE]; |
216 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; | 217 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; |
217 | 218 | ||
218 | randombytes(public_key, sizeof(public_key)); | 219 | random_bytes(public_key, sizeof(public_key)); |
219 | mark_all_good(list, length, ipv6); | 220 | mark_all_good(list, length, ipv6); |
220 | 221 | ||
221 | test1 = rand() % (length / 3); | 222 | test1 = rand() % (length / 3); |
@@ -274,14 +275,14 @@ static void test_addto_lists_good(DHT *dht, | |||
274 | IP_Port *ip_port, | 275 | IP_Port *ip_port, |
275 | const uint8_t *comp_client_id) | 276 | const uint8_t *comp_client_id) |
276 | { | 277 | { |
277 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | 278 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
278 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; | 279 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; |
279 | 280 | ||
280 | mark_all_good(list, length, ipv6); | 281 | mark_all_good(list, length, ipv6); |
281 | 282 | ||
282 | // check "good" client id replacement | 283 | // check "good" client id replacement |
283 | do { | 284 | do { |
284 | randombytes(public_key, sizeof(public_key)); | 285 | random_bytes(public_key, sizeof(public_key)); |
285 | } while (is_furthest(comp_client_id, list, length, public_key)); | 286 | } while (is_furthest(comp_client_id, list, length, public_key)); |
286 | 287 | ||
287 | ip_port->port += 1; | 288 | ip_port->port += 1; |
@@ -290,7 +291,7 @@ static void test_addto_lists_good(DHT *dht, | |||
290 | 291 | ||
291 | // check "good" client id skip | 292 | // check "good" client id skip |
292 | do { | 293 | do { |
293 | randombytes(public_key, sizeof(public_key)); | 294 | random_bytes(public_key, sizeof(public_key)); |
294 | } while (!is_furthest(comp_client_id, list, length, public_key)); | 295 | } while (!is_furthest(comp_client_id, list, length, public_key)); |
295 | 296 | ||
296 | ip_port->port += 1; | 297 | ip_port->port += 1; |
@@ -307,12 +308,12 @@ static void test_addto_lists(IP ip) | |||
307 | ck_assert_msg(dht != 0, "Failed to create DHT"); | 308 | ck_assert_msg(dht != 0, "Failed to create DHT"); |
308 | 309 | ||
309 | IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT }; | 310 | IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT }; |
310 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | 311 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
311 | int i, used; | 312 | int i, used; |
312 | 313 | ||
313 | // check lists filling | 314 | // check lists filling |
314 | for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) { | 315 | for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) { |
315 | randombytes(public_key, sizeof(public_key)); | 316 | random_bytes(public_key, sizeof(public_key)); |
316 | used = addto_lists(dht, ip_port, public_key); | 317 | used = addto_lists(dht, ip_port, public_key); |
317 | ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing ip_port"); | 318 | ck_assert_msg(used == dht->num_friends + 1, "Wrong number of added clients with existing ip_port"); |
318 | } | 319 | } |
@@ -325,7 +326,7 @@ static void test_addto_lists(IP ip) | |||
325 | 326 | ||
326 | for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) { | 327 | for (i = 0; i < MAX(LCLIENT_LIST, MAX_FRIEND_CLIENTS); ++i) { |
327 | ip_port.port += 1; | 328 | ip_port.port += 1; |
328 | randombytes(public_key, sizeof(public_key)); | 329 | random_bytes(public_key, sizeof(public_key)); |
329 | used = addto_lists(dht, ip_port, public_key); | 330 | used = addto_lists(dht, ip_port, public_key); |
330 | ck_assert_msg(used >= 1, "Wrong number of added clients"); | 331 | ck_assert_msg(used >= 1, "Wrong number of added clients"); |
331 | } | 332 | } |
@@ -346,13 +347,15 @@ static void test_addto_lists(IP ip) | |||
346 | } | 347 | } |
347 | 348 | ||
348 | // check "possibly bad" entries | 349 | // check "possibly bad" entries |
349 | /* | 350 | if (enable_broken_tests) { |
350 | test_addto_lists_possible_bad(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key); | 351 | test_addto_lists_possible_bad(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key); |
352 | |||
353 | for (i = 0; i < dht->num_friends; ++i) { | ||
354 | test_addto_lists_possible_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, | ||
355 | dht->friends_list[i].public_key); | ||
356 | } | ||
357 | } | ||
351 | 358 | ||
352 | for (i = 0; i < dht->num_friends; ++i) | ||
353 | test_addto_lists_possible_bad(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, | ||
354 | dht->friends_list[i].public_key); | ||
355 | */ | ||
356 | // check "good" entries | 359 | // check "good" entries |
357 | test_addto_lists_good(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key); | 360 | test_addto_lists_good(dht, dht->close_clientlist, LCLIENT_LIST, &ip_port, dht->self_public_key); |
358 | 361 | ||
@@ -379,7 +382,6 @@ START_TEST(test_addto_lists_ipv6) | |||
379 | test_addto_lists(ip); | 382 | test_addto_lists(ip); |
380 | } | 383 | } |
381 | END_TEST | 384 | END_TEST |
382 | #endif | ||
383 | 385 | ||
384 | #define DHT_DEFAULT_PORT (TOX_PORT_DEFAULT + 20) | 386 | #define DHT_DEFAULT_PORT (TOX_PORT_DEFAULT + 20) |
385 | 387 | ||
@@ -389,36 +391,36 @@ static void print_pk(uint8_t *public_key) | |||
389 | { | 391 | { |
390 | uint32_t j; | 392 | uint32_t j; |
391 | 393 | ||
392 | for (j = 0; j < crypto_box_PUBLICKEYBYTES; j++) { | 394 | for (j = 0; j < CRYPTO_PUBLIC_KEY_SIZE; j++) { |
393 | printf("%02hhX", public_key[j]); | 395 | printf("%02hhX", public_key[j]); |
394 | } | 396 | } |
395 | 397 | ||
396 | printf("\n"); | 398 | printf("\n"); |
397 | } | 399 | } |
398 | 400 | ||
399 | static void test_add_to_list(uint8_t cmp_list[][crypto_box_PUBLICKEYBYTES + 1], | 401 | static void test_add_to_list(uint8_t cmp_list[][CRYPTO_PUBLIC_KEY_SIZE + 1], |
400 | unsigned int length, const uint8_t *pk, | 402 | unsigned int length, const uint8_t *pk, |
401 | const uint8_t *cmp_pk) | 403 | const uint8_t *cmp_pk) |
402 | { | 404 | { |
403 | uint8_t p_b[crypto_box_PUBLICKEYBYTES]; | 405 | uint8_t p_b[CRYPTO_PUBLIC_KEY_SIZE]; |
404 | unsigned int i; | 406 | unsigned int i; |
405 | 407 | ||
406 | for (i = 0; i < length; ++i) { | 408 | for (i = 0; i < length; ++i) { |
407 | if (!cmp_list[i][crypto_box_PUBLICKEYBYTES]) { | 409 | if (!cmp_list[i][CRYPTO_PUBLIC_KEY_SIZE]) { |
408 | memcpy(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES); | 410 | memcpy(cmp_list[i], pk, CRYPTO_PUBLIC_KEY_SIZE); |
409 | cmp_list[i][crypto_box_PUBLICKEYBYTES] = 1; | 411 | cmp_list[i][CRYPTO_PUBLIC_KEY_SIZE] = 1; |
410 | return; | 412 | return; |
411 | } | 413 | } |
412 | 414 | ||
413 | if (memcmp(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES) == 0) { | 415 | if (memcmp(cmp_list[i], pk, CRYPTO_PUBLIC_KEY_SIZE) == 0) { |
414 | return; | 416 | return; |
415 | } | 417 | } |
416 | } | 418 | } |
417 | 419 | ||
418 | for (i = 0; i < length; ++i) { | 420 | for (i = 0; i < length; ++i) { |
419 | if (id_closest(cmp_pk, cmp_list[i], pk) == 2) { | 421 | if (id_closest(cmp_pk, cmp_list[i], pk) == 2) { |
420 | memcpy(p_b, cmp_list[i], crypto_box_PUBLICKEYBYTES); | 422 | memcpy(p_b, cmp_list[i], CRYPTO_PUBLIC_KEY_SIZE); |
421 | memcpy(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES); | 423 | memcpy(cmp_list[i], pk, CRYPTO_PUBLIC_KEY_SIZE); |
422 | test_add_to_list(cmp_list, length, p_b, cmp_pk); | 424 | test_add_to_list(cmp_list, length, p_b, cmp_pk); |
423 | break; | 425 | break; |
424 | } | 426 | } |
@@ -431,7 +433,7 @@ static void test_list_main(void) | |||
431 | { | 433 | { |
432 | DHT *dhts[NUM_DHT]; | 434 | DHT *dhts[NUM_DHT]; |
433 | 435 | ||
434 | uint8_t cmp_list1[NUM_DHT][MAX_FRIEND_CLIENTS][crypto_box_PUBLICKEYBYTES + 1]; | 436 | uint8_t cmp_list1[NUM_DHT][MAX_FRIEND_CLIENTS][CRYPTO_PUBLIC_KEY_SIZE + 1]; |
435 | memset(cmp_list1, 0, sizeof(cmp_list1)); | 437 | memset(cmp_list1, 0, sizeof(cmp_list1)); |
436 | 438 | ||
437 | unsigned int i, j, k, l; | 439 | unsigned int i, j, k, l; |
@@ -480,7 +482,7 @@ static void test_list_main(void) | |||
480 | for (l = 0; l < NUM_DHT; ++l) { | 482 | for (l = 0; l < NUM_DHT; ++l) { |
481 | for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { | 483 | for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { |
482 | for (j = 1; j < NUM_DHT; ++j) { | 484 | for (j = 1; j < NUM_DHT; ++j) { |
483 | if (memcmp(cmp_list1[l][i], dhts[(l + j) % NUM_DHT]->self_public_key, crypto_box_PUBLICKEYBYTES) != 0) { | 485 | if (memcmp(cmp_list1[l][i], dhts[(l + j) % NUM_DHT]->self_public_key, CRYPTO_PUBLIC_KEY_SIZE) != 0) { |
484 | continue; | 486 | continue; |
485 | } | 487 | } |
486 | 488 | ||
@@ -488,7 +490,7 @@ static void test_list_main(void) | |||
488 | 490 | ||
489 | for (k = 0; k < LCLIENT_LIST; ++k) { | 491 | for (k = 0; k < LCLIENT_LIST; ++k) { |
490 | if (memcmp(dhts[l]->self_public_key, dhts[(l + j) % NUM_DHT]->close_clientlist[k].public_key, | 492 | if (memcmp(dhts[l]->self_public_key, dhts[(l + j) % NUM_DHT]->close_clientlist[k].public_key, |
491 | crypto_box_PUBLICKEYBYTES) == 0) { | 493 | CRYPTO_PUBLIC_KEY_SIZE) == 0) { |
492 | ++count; | 494 | ++count; |
493 | } | 495 | } |
494 | } | 496 | } |
@@ -519,7 +521,7 @@ static void test_list_main(void) | |||
519 | count = 0; | 521 | count = 0; |
520 | 522 | ||
521 | for (k = 0; k < MAX_SENT_NODES; ++k) { | 523 | for (k = 0; k < MAX_SENT_NODES; ++k) { |
522 | if (memcmp(dhts[l]->self_public_key, ln[k].public_key, crypto_box_PUBLICKEYBYTES) == 0) { | 524 | if (memcmp(dhts[l]->self_public_key, ln[k].public_key, CRYPTO_PUBLIC_KEY_SIZE) == 0) { |
523 | ++count; | 525 | ++count; |
524 | } | 526 | } |
525 | } | 527 | } |
@@ -653,16 +655,16 @@ END_TEST | |||
653 | START_TEST(test_dht_create_packet) | 655 | START_TEST(test_dht_create_packet) |
654 | { | 656 | { |
655 | uint8_t plain[100] = {0}; | 657 | uint8_t plain[100] = {0}; |
656 | uint8_t pkt[1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + sizeof(plain) + crypto_box_MACBYTES]; | 658 | uint8_t pkt[1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + sizeof(plain) + CRYPTO_MAC_SIZE]; |
657 | 659 | ||
658 | uint8_t key[crypto_box_KEYBYTES]; | 660 | uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE]; |
659 | new_symmetric_key(key); | 661 | new_symmetric_key(key); |
660 | 662 | ||
661 | int length = DHT_create_packet(key, key, NET_PACKET_GET_NODES, plain, sizeof(plain), pkt); | 663 | int length = DHT_create_packet(key, key, NET_PACKET_GET_NODES, plain, sizeof(plain), pkt); |
662 | 664 | ||
663 | ck_assert_msg(pkt[0] == NET_PACKET_GET_NODES, "Malformed packet."); | 665 | ck_assert_msg(pkt[0] == NET_PACKET_GET_NODES, "Malformed packet."); |
664 | ck_assert_msg(memcmp(pkt + 1, key, crypto_box_KEYBYTES) == 0, "Malformed packet."); | 666 | ck_assert_msg(memcmp(pkt + 1, key, CRYPTO_SYMMETRIC_KEY_SIZE) == 0, "Malformed packet."); |
665 | ck_assert_msg(length == 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + sizeof(plain) + crypto_box_MACBYTES, | 667 | ck_assert_msg(length == 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + sizeof(plain) + CRYPTO_MAC_SIZE, |
666 | "Invalid size. Should be %d got %d", sizeof(pkt), length); | 668 | "Invalid size. Should be %d got %d", sizeof(pkt), length); |
667 | 669 | ||
668 | printf("Create Packet Successful!\n"); | 670 | printf("Create Packet Successful!\n"); |
@@ -676,10 +678,12 @@ static Suite *dht_suite(void) | |||
676 | 678 | ||
677 | DEFTESTCASE_SLOW(list, 20); | 679 | DEFTESTCASE_SLOW(list, 20); |
678 | DEFTESTCASE_SLOW(DHT_test, 50); | 680 | DEFTESTCASE_SLOW(DHT_test, 50); |
679 | #if 0 | 681 | |
680 | DEFTESTCASE(addto_lists_ipv4); | 682 | if (enable_broken_tests) { |
681 | DEFTESTCASE(addto_lists_ipv6); | 683 | DEFTESTCASE(addto_lists_ipv4); |
682 | #endif | 684 | DEFTESTCASE(addto_lists_ipv6); |
685 | } | ||
686 | |||
683 | return s; | 687 | return s; |
684 | } | 688 | } |
685 | 689 | ||
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 895d129b..ec98797c 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -17,6 +17,8 @@ | |||
17 | #include "../toxencryptsave/toxencryptsave.h" | 17 | #include "../toxencryptsave/toxencryptsave.h" |
18 | #ifdef VANILLA_NACL | 18 | #ifdef VANILLA_NACL |
19 | #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" | 19 | #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" |
20 | #else | ||
21 | #include <sodium.h> | ||
20 | #endif | 22 | #endif |
21 | 23 | ||
22 | static unsigned char test_salt[TOX_PASS_SALT_LENGTH] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F}; | 24 | static unsigned char test_salt[TOX_PASS_SALT_LENGTH] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F}; |
@@ -24,7 +26,7 @@ static unsigned char known_key[TOX_PASS_KEY_LENGTH] = {0x29, 0x36, 0x1c, 0x9e, 0 | |||
24 | static const char *pw = "hunter2"; | 26 | static const char *pw = "hunter2"; |
25 | static unsigned int pwlen = 7; | 27 | static unsigned int pwlen = 7; |
26 | 28 | ||
27 | static unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1}; | 29 | static unsigned char known_key2[CRYPTO_SHARED_KEY_SIZE] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1}; |
28 | // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat | 30 | // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat |
29 | 31 | ||
30 | /* cause I'm shameless */ | 32 | /* cause I'm shameless */ |
@@ -41,16 +43,16 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8 | |||
41 | 43 | ||
42 | START_TEST(test_known_kdf) | 44 | START_TEST(test_known_kdf) |
43 | { | 45 | { |
44 | unsigned char out[crypto_box_BEFORENMBYTES]; | 46 | unsigned char out[CRYPTO_SHARED_KEY_SIZE]; |
45 | int res = crypto_pwhash_scryptsalsa208sha256(out, | 47 | int res = crypto_pwhash_scryptsalsa208sha256(out, |
46 | crypto_box_BEFORENMBYTES, | 48 | CRYPTO_SHARED_KEY_SIZE, |
47 | pw, | 49 | pw, |
48 | pwlen, | 50 | pwlen, |
49 | test_salt, | 51 | test_salt, |
50 | crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8, | 52 | crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8, |
51 | crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE); | 53 | crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE); |
52 | ck_assert_msg(res != -1, "crypto function failed"); | 54 | ck_assert_msg(res != -1, "crypto function failed"); |
53 | ck_assert_msg(memcmp(out, known_key, crypto_box_BEFORENMBYTES) == 0, "derived key is wrong"); | 55 | ck_assert_msg(memcmp(out, known_key, CRYPTO_SHARED_KEY_SIZE) == 0, "derived key is wrong"); |
54 | } | 56 | } |
55 | END_TEST | 57 | END_TEST |
56 | 58 | ||
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 329d7371..44ea9c7d 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -75,22 +75,24 @@ void print_client_id(uint8_t *client_id, uint32_t length) | |||
75 | #endif | 75 | #endif |
76 | static uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; | 76 | static uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; |
77 | static int handled_test_3; | 77 | static int handled_test_3; |
78 | static uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES]; | 78 | static uint8_t test_3_pub_key[CRYPTO_PUBLIC_KEY_SIZE]; |
79 | static uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; | 79 | static uint8_t test_3_ping_id[CRYPTO_SHA256_SIZE]; |
80 | static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 80 | static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
81 | { | 81 | { |
82 | Onion *onion = (Onion *)object; | 82 | Onion *onion = (Onion *)object; |
83 | 83 | ||
84 | if (length != (1 + crypto_box_NONCEBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + 1 + crypto_hash_sha256_BYTES + | 84 | if (length != (1 + CRYPTO_NONCE_SIZE + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + 1 + CRYPTO_SHA256_SIZE + |
85 | crypto_box_MACBYTES)) { | 85 | CRYPTO_MAC_SIZE)) { |
86 | return 1; | 86 | return 1; |
87 | } | 87 | } |
88 | 88 | ||
89 | uint8_t plain[1 + crypto_hash_sha256_BYTES]; | 89 | uint8_t plain[1 + CRYPTO_SHA256_SIZE]; |
90 | //print_client_id(packet, length); | 90 | #if 0 |
91 | print_client_id(packet, length); | ||
92 | #endif | ||
91 | int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, | 93 | int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, |
92 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES, | 94 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE, |
93 | 1 + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain); | 95 | 1 + CRYPTO_SHA256_SIZE + CRYPTO_MAC_SIZE, plain); |
94 | 96 | ||
95 | if (len == -1) { | 97 | if (len == -1) { |
96 | return 1; | 98 | return 1; |
@@ -101,31 +103,33 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui | |||
101 | return 1; | 103 | return 1; |
102 | } | 104 | } |
103 | 105 | ||
104 | memcpy(test_3_ping_id, plain + 1, crypto_hash_sha256_BYTES); | 106 | memcpy(test_3_ping_id, plain + 1, CRYPTO_SHA256_SIZE); |
105 | //print_client_id(test_3_ping_id, sizeof(test_3_ping_id)); | 107 | #if 0 |
108 | print_client_id(test_3_ping_id, sizeof(test_3_ping_id)); | ||
109 | #endif | ||
106 | handled_test_3 = 1; | 110 | handled_test_3 = 1; |
107 | return 0; | 111 | return 0; |
108 | } | 112 | } |
109 | 113 | ||
110 | static uint8_t nonce[crypto_box_NONCEBYTES]; | 114 | static uint8_t nonce[CRYPTO_NONCE_SIZE]; |
111 | static int handled_test_4; | 115 | static int handled_test_4; |
112 | static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 116 | static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
113 | { | 117 | { |
114 | Onion *onion = (Onion *)object; | 118 | Onion *onion = (Onion *)object; |
115 | 119 | ||
116 | if (length != (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof("Install gentoo") + | 120 | if (length != (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + sizeof("Install gentoo") + |
117 | crypto_box_MACBYTES)) { | 121 | CRYPTO_MAC_SIZE)) { |
118 | return 1; | 122 | return 1; |
119 | } | 123 | } |
120 | 124 | ||
121 | uint8_t plain[sizeof("Install gentoo")] = {0}; | 125 | uint8_t plain[sizeof("Install gentoo")] = {0}; |
122 | 126 | ||
123 | if (memcmp(nonce, packet + 1, crypto_box_NONCEBYTES) != 0) { | 127 | if (memcmp(nonce, packet + 1, CRYPTO_NONCE_SIZE) != 0) { |
124 | return 1; | 128 | return 1; |
125 | } | 129 | } |
126 | 130 | ||
127 | int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion->dht->self_secret_key, packet + 1, | 131 | int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, onion->dht->self_secret_key, packet + 1, |
128 | packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, sizeof("Install gentoo") + crypto_box_MACBYTES, plain); | 132 | packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, sizeof("Install gentoo") + CRYPTO_MAC_SIZE, plain); |
129 | 133 | ||
130 | if (len == -1) { | 134 | if (len == -1) { |
131 | return 1; | 135 | return 1; |
@@ -151,12 +155,12 @@ START_TEST(test_basic) | |||
151 | 155 | ||
152 | IP_Port on1 = {ip, onion1->net->port}; | 156 | IP_Port on1 = {ip, onion1->net->port}; |
153 | Node_format n1; | 157 | Node_format n1; |
154 | memcpy(n1.public_key, onion1->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 158 | memcpy(n1.public_key, onion1->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
155 | n1.ip_port = on1; | 159 | n1.ip_port = on1; |
156 | 160 | ||
157 | IP_Port on2 = {ip, onion2->net->port}; | 161 | IP_Port on2 = {ip, onion2->net->port}; |
158 | Node_format n2; | 162 | Node_format n2; |
159 | memcpy(n2.public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 163 | memcpy(n2.public_key, onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
160 | n2.ip_port = on2; | 164 | n2.ip_port = on2; |
161 | 165 | ||
162 | Node_format nodes[4]; | 166 | Node_format nodes[4]; |
@@ -190,10 +194,10 @@ START_TEST(test_basic) | |||
190 | networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1); | 194 | networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1); |
191 | ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing."); | 195 | ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing."); |
192 | uint8_t zeroes[64] = {0}; | 196 | uint8_t zeroes[64] = {0}; |
193 | randombytes(sb_data, sizeof(sb_data)); | 197 | random_bytes(sb_data, sizeof(sb_data)); |
194 | uint64_t s; | 198 | uint64_t s; |
195 | memcpy(&s, sb_data, sizeof(uint64_t)); | 199 | memcpy(&s, sb_data, sizeof(uint64_t)); |
196 | memcpy(test_3_pub_key, nodes[3].public_key, crypto_box_PUBLICKEYBYTES); | 200 | memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
197 | ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, | 201 | ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, |
198 | onion1->dht->self_secret_key, | 202 | onion1->dht->self_secret_key, |
199 | zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, s); | 203 | zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, s); |
@@ -206,16 +210,16 @@ START_TEST(test_basic) | |||
206 | c_sleep(50); | 210 | c_sleep(50); |
207 | } | 211 | } |
208 | 212 | ||
209 | randombytes(sb_data, sizeof(sb_data)); | 213 | random_bytes(sb_data, sizeof(sb_data)); |
210 | memcpy(&s, sb_data, sizeof(uint64_t)); | 214 | memcpy(&s, sb_data, sizeof(uint64_t)); |
211 | memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 215 | memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
212 | onion2_a->entries[1].time = unix_time(); | 216 | onion2_a->entries[1].time = unix_time(); |
213 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); | 217 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); |
214 | send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key, | 218 | send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key, |
215 | test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, s); | 219 | test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, s); |
216 | 220 | ||
217 | while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->self_public_key, | 221 | while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->self_public_key, |
218 | crypto_box_PUBLICKEYBYTES) != 0) { | 222 | CRYPTO_PUBLIC_KEY_SIZE) != 0) { |
219 | do_onion(onion1); | 223 | do_onion(onion1); |
220 | do_onion(onion2); | 224 | do_onion(onion2); |
221 | c_sleep(50); | 225 | c_sleep(50); |
@@ -340,8 +344,8 @@ static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) | |||
340 | } | 344 | } |
341 | 345 | ||
342 | static bool first, last; | 346 | static bool first, last; |
343 | static uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; | 347 | static uint8_t first_dht_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
344 | static uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; | 348 | static uint8_t last_dht_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
345 | 349 | ||
346 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) | 350 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) |
347 | { | 351 | { |
@@ -355,7 +359,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub | |||
355 | if (NUM_FIRST == number && !first) { | 359 | if (NUM_FIRST == number && !first) { |
356 | first = 1; | 360 | first = 1; |
357 | 361 | ||
358 | if (memcmp(dht_public_key, last_dht_pk, crypto_box_PUBLICKEYBYTES) != 0) { | 362 | if (memcmp(dht_public_key, last_dht_pk, CRYPTO_PUBLIC_KEY_SIZE) != 0) { |
359 | ck_abort_msg("Error wrong dht key."); | 363 | ck_abort_msg("Error wrong dht key."); |
360 | } | 364 | } |
361 | 365 | ||
@@ -365,7 +369,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub | |||
365 | if (NUM_LAST == number && !last) { | 369 | if (NUM_LAST == number && !last) { |
366 | last = 1; | 370 | last = 1; |
367 | 371 | ||
368 | if (memcmp(dht_public_key, first_dht_pk, crypto_box_PUBLICKEYBYTES) != 0) { | 372 | if (memcmp(dht_public_key, first_dht_pk, CRYPTO_PUBLIC_KEY_SIZE) != 0) { |
369 | ck_abort_msg("Error wrong dht key."); | 373 | ck_abort_msg("Error wrong dht key."); |
370 | } | 374 | } |
371 | 375 | ||
@@ -422,8 +426,8 @@ START_TEST(test_announce) | |||
422 | c_sleep(50); | 426 | c_sleep(50); |
423 | } | 427 | } |
424 | 428 | ||
425 | memcpy(first_dht_pk, onions[NUM_FIRST]->onion->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 429 | memcpy(first_dht_pk, onions[NUM_FIRST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
426 | memcpy(last_dht_pk, onions[NUM_LAST]->onion->dht->self_public_key, crypto_box_PUBLICKEYBYTES); | 430 | memcpy(last_dht_pk, onions[NUM_LAST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
427 | 431 | ||
428 | printf("adding friend\n"); | 432 | printf("adding friend\n"); |
429 | int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c, onions[NUM_LAST]->onion_c->c->self_public_key); | 433 | int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c, onions[NUM_LAST]->onion_c->c->self_public_key); |