summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/crypto_core.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c
index 418edcad..d1549b2a 100644
--- a/toxcore/crypto_core.c
+++ b/toxcore/crypto_core.c
@@ -235,26 +235,26 @@ int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_ke
235int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data, 235int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data,
236 uint8_t *request_id, const uint8_t *packet, uint16_t length) 236 uint8_t *request_id, const uint8_t *packet, uint16_t length)
237{ 237{
238 if (length > crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES && 238 if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES ||
239 length <= MAX_CRYPTO_REQUEST_SIZE) { 239 length > MAX_CRYPTO_REQUEST_SIZE)
240 if (memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) { 240 return -1;
241 memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES); 241
242 uint8_t nonce[crypto_box_NONCEBYTES]; 242 if (memcmp(packet + 1, self_public_key, crypto_box_PUBLICKEYBYTES) != 0)
243 uint8_t temp[MAX_CRYPTO_REQUEST_SIZE]; 243 return -1;
244 memcpy(nonce, packet + 1 + crypto_box_PUBLICKEYBYTES * 2, crypto_box_NONCEBYTES); 244
245 int len1 = decrypt_data(public_key, self_secret_key, nonce, 245 memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES);
246 packet + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES, 246 uint8_t nonce[crypto_box_NONCEBYTES];
247 length - (crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1), temp); 247 uint8_t temp[MAX_CRYPTO_REQUEST_SIZE];
248 248 memcpy(nonce, packet + 1 + crypto_box_PUBLICKEYBYTES * 2, crypto_box_NONCEBYTES);
249 if (len1 == -1 || len1 == 0) 249 int len1 = decrypt_data(public_key, self_secret_key, nonce,
250 return -1; 250 packet + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES,
251 251 length - (crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1), temp);
252 request_id[0] = temp[0]; 252
253 --len1; 253 if (len1 == -1 || len1 == 0)
254 memcpy(data, temp + 1, len1); 254 return -1;
255 return len1;
256 }
257 }
258 255
259 return -1; 256 request_id[0] = temp[0];
257 --len1;
258 memcpy(data, temp + 1, len1);
259 return len1;
260} 260}