diff options
author | irungentoo <irungentoo@gmail.com> | 2015-06-07 21:05:30 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-06-07 21:05:30 -0400 |
commit | 3299452dd947f77f0d30842bcf1470dc760816c4 (patch) | |
tree | bd2a5208525755ff1f65d5ca2915e0bee3c1bb6f /toxcore | |
parent | 81d95809fd846ade1470ed5dee746ce98262dde9 (diff) | |
parent | ee1ab5f0c70e2d24eced938d940fe81e67f8d09b (diff) |
Merge branch 'improve-crypto' of https://github.com/codedust/toxcore
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/crypto_core.c | 42 |
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 | |||
235 | int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data, | 235 | int 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 | } |