diff options
Diffstat (limited to 'toxcore/onion.c')
-rw-r--r-- | toxcore/onion.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/toxcore/onion.c b/toxcore/onion.c index 1d5cc71f..60fdcce0 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c | |||
@@ -185,7 +185,7 @@ int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion | |||
185 | return -1; | 185 | return -1; |
186 | } | 186 | } |
187 | 187 | ||
188 | uint8_t step1[SIZE_IPPORT + length]; | 188 | VLA(uint8_t, step1, SIZE_IPPORT + length); |
189 | 189 | ||
190 | ipport_pack(step1, &dest); | 190 | ipport_pack(step1, &dest); |
191 | memcpy(step1 + SIZE_IPPORT, data, length); | 191 | memcpy(step1 + SIZE_IPPORT, data, length); |
@@ -193,21 +193,21 @@ int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion | |||
193 | uint8_t nonce[CRYPTO_NONCE_SIZE]; | 193 | uint8_t nonce[CRYPTO_NONCE_SIZE]; |
194 | random_nonce(nonce); | 194 | random_nonce(nonce); |
195 | 195 | ||
196 | uint8_t step2[SIZE_IPPORT + SEND_BASE + length]; | 196 | VLA(uint8_t, step2, SIZE_IPPORT + SEND_BASE + length); |
197 | ipport_pack(step2, &path->ip_port3); | 197 | ipport_pack(step2, &path->ip_port3); |
198 | memcpy(step2 + SIZE_IPPORT, path->public_key3, CRYPTO_PUBLIC_KEY_SIZE); | 198 | memcpy(step2 + SIZE_IPPORT, path->public_key3, CRYPTO_PUBLIC_KEY_SIZE); |
199 | 199 | ||
200 | int len = encrypt_data_symmetric(path->shared_key3, nonce, step1, sizeof(step1), | 200 | int len = encrypt_data_symmetric(path->shared_key3, nonce, step1, SIZEOF_VLA(step1), |
201 | step2 + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE); | 201 | step2 + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE); |
202 | 202 | ||
203 | if (len != SIZE_IPPORT + length + CRYPTO_MAC_SIZE) { | 203 | if (len != SIZE_IPPORT + length + CRYPTO_MAC_SIZE) { |
204 | return -1; | 204 | return -1; |
205 | } | 205 | } |
206 | 206 | ||
207 | uint8_t step3[SIZE_IPPORT + SEND_BASE * 2 + length]; | 207 | VLA(uint8_t, step3, SIZE_IPPORT + SEND_BASE * 2 + length); |
208 | ipport_pack(step3, &path->ip_port2); | 208 | ipport_pack(step3, &path->ip_port2); |
209 | memcpy(step3 + SIZE_IPPORT, path->public_key2, CRYPTO_PUBLIC_KEY_SIZE); | 209 | memcpy(step3 + SIZE_IPPORT, path->public_key2, CRYPTO_PUBLIC_KEY_SIZE); |
210 | len = encrypt_data_symmetric(path->shared_key2, nonce, step2, sizeof(step2), | 210 | len = encrypt_data_symmetric(path->shared_key2, nonce, step2, SIZEOF_VLA(step2), |
211 | step3 + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE); | 211 | step3 + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE); |
212 | 212 | ||
213 | if (len != SIZE_IPPORT + SEND_BASE + length + CRYPTO_MAC_SIZE) { | 213 | if (len != SIZE_IPPORT + SEND_BASE + length + CRYPTO_MAC_SIZE) { |
@@ -218,7 +218,7 @@ int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion | |||
218 | memcpy(packet + 1, nonce, CRYPTO_NONCE_SIZE); | 218 | memcpy(packet + 1, nonce, CRYPTO_NONCE_SIZE); |
219 | memcpy(packet + 1 + CRYPTO_NONCE_SIZE, path->public_key1, CRYPTO_PUBLIC_KEY_SIZE); | 219 | memcpy(packet + 1 + CRYPTO_NONCE_SIZE, path->public_key1, CRYPTO_PUBLIC_KEY_SIZE); |
220 | 220 | ||
221 | len = encrypt_data_symmetric(path->shared_key1, nonce, step3, sizeof(step3), | 221 | len = encrypt_data_symmetric(path->shared_key1, nonce, step3, SIZEOF_VLA(step3), |
222 | packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE); | 222 | packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE); |
223 | 223 | ||
224 | if (len != SIZE_IPPORT + SEND_BASE * 2 + length + CRYPTO_MAC_SIZE) { | 224 | if (len != SIZE_IPPORT + SEND_BASE * 2 + length + CRYPTO_MAC_SIZE) { |
@@ -244,7 +244,7 @@ int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const O | |||
244 | return -1; | 244 | return -1; |
245 | } | 245 | } |
246 | 246 | ||
247 | uint8_t step1[SIZE_IPPORT + length]; | 247 | VLA(uint8_t, step1, SIZE_IPPORT + length); |
248 | 248 | ||
249 | ipport_pack(step1, &dest); | 249 | ipport_pack(step1, &dest); |
250 | memcpy(step1 + SIZE_IPPORT, data, length); | 250 | memcpy(step1 + SIZE_IPPORT, data, length); |
@@ -252,11 +252,11 @@ int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const O | |||
252 | uint8_t nonce[CRYPTO_NONCE_SIZE]; | 252 | uint8_t nonce[CRYPTO_NONCE_SIZE]; |
253 | random_nonce(nonce); | 253 | random_nonce(nonce); |
254 | 254 | ||
255 | uint8_t step2[SIZE_IPPORT + SEND_BASE + length]; | 255 | VLA(uint8_t, step2, SIZE_IPPORT + SEND_BASE + length); |
256 | ipport_pack(step2, &path->ip_port3); | 256 | ipport_pack(step2, &path->ip_port3); |
257 | memcpy(step2 + SIZE_IPPORT, path->public_key3, CRYPTO_PUBLIC_KEY_SIZE); | 257 | memcpy(step2 + SIZE_IPPORT, path->public_key3, CRYPTO_PUBLIC_KEY_SIZE); |
258 | 258 | ||
259 | int len = encrypt_data_symmetric(path->shared_key3, nonce, step1, sizeof(step1), | 259 | int len = encrypt_data_symmetric(path->shared_key3, nonce, step1, SIZEOF_VLA(step1), |
260 | step2 + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE); | 260 | step2 + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE); |
261 | 261 | ||
262 | if (len != SIZE_IPPORT + length + CRYPTO_MAC_SIZE) { | 262 | if (len != SIZE_IPPORT + length + CRYPTO_MAC_SIZE) { |
@@ -265,7 +265,7 @@ int create_onion_packet_tcp(uint8_t *packet, uint16_t max_packet_length, const O | |||
265 | 265 | ||
266 | ipport_pack(packet + CRYPTO_NONCE_SIZE, &path->ip_port2); | 266 | ipport_pack(packet + CRYPTO_NONCE_SIZE, &path->ip_port2); |
267 | memcpy(packet + CRYPTO_NONCE_SIZE + SIZE_IPPORT, path->public_key2, CRYPTO_PUBLIC_KEY_SIZE); | 267 | memcpy(packet + CRYPTO_NONCE_SIZE + SIZE_IPPORT, path->public_key2, CRYPTO_PUBLIC_KEY_SIZE); |
268 | len = encrypt_data_symmetric(path->shared_key2, nonce, step2, sizeof(step2), | 268 | len = encrypt_data_symmetric(path->shared_key2, nonce, step2, SIZEOF_VLA(step2), |
269 | packet + CRYPTO_NONCE_SIZE + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE); | 269 | packet + CRYPTO_NONCE_SIZE + SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE); |
270 | 270 | ||
271 | if (len != SIZE_IPPORT + SEND_BASE + length + CRYPTO_MAC_SIZE) { | 271 | if (len != SIZE_IPPORT + SEND_BASE + length + CRYPTO_MAC_SIZE) { |
@@ -313,12 +313,12 @@ int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, | |||
313 | return -1; | 313 | return -1; |
314 | } | 314 | } |
315 | 315 | ||
316 | uint8_t packet[1 + RETURN_3 + length]; | 316 | VLA(uint8_t, packet, 1 + RETURN_3 + length); |
317 | packet[0] = NET_PACKET_ONION_RECV_3; | 317 | packet[0] = NET_PACKET_ONION_RECV_3; |
318 | memcpy(packet + 1, ret, RETURN_3); | 318 | memcpy(packet + 1, ret, RETURN_3); |
319 | memcpy(packet + 1 + RETURN_3, data, length); | 319 | memcpy(packet + 1 + RETURN_3, data, length); |
320 | 320 | ||
321 | if ((uint32_t)sendpacket(net, dest, packet, sizeof(packet)) != sizeof(packet)) { | 321 | if ((uint32_t)sendpacket(net, dest, packet, SIZEOF_VLA(packet)) != SIZEOF_VLA(packet)) { |
322 | return -1; | 322 | return -1; |
323 | } | 323 | } |
324 | 324 | ||