summaryrefslogtreecommitdiff
path: root/toxcore/crypto_core.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-04-28 20:14:07 -0400
committerirungentoo <irungentoo@gmail.com>2014-04-28 20:14:07 -0400
commitb9370d519ff87020cf32f3d04b6a2c4eebcc9563 (patch)
treee98aa27e47a6e09716681bce04e62aed5c889a21 /toxcore/crypto_core.c
parent50cea69f5705a7a01e31417bae29feb920bfdd59 (diff)
Added some functions to create/handle middle level protocol packets.
Diffstat (limited to 'toxcore/crypto_core.c')
-rw-r--r--toxcore/crypto_core.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c
index 59053bc4..6e8b747a 100644
--- a/toxcore/crypto_core.c
+++ b/toxcore/crypto_core.c
@@ -42,6 +42,19 @@ uint8_t crypto_iszero(uint8_t *mem, uint32_t length)
42 return check; // We return zero if mem is made out of zeroes. 42 return check; // We return zero if mem is made out of zeroes.
43} 43}
44 44
45/* Use this instead of memcmp; not vulnerable to timing attacks.
46 returns 0 if both mem locations of length are equal. */
47unsigned int crypto_cmp(uint8_t *mem1, uint8_t *mem2, uint32_t length)
48{
49 unsigned int i, check = 0;;
50
51 for (i = 0; i < length; ++i) {
52 check |= mem1[i] ^ mem2[i];
53 }
54
55 return check;
56}
57
45/* Precomputes the shared key from their public_key and our secret_key. 58/* Precomputes the shared key from their public_key and our secret_key.
46 * This way we can avoid an expensive elliptic curve scalar multiply for each 59 * This way we can avoid an expensive elliptic curve scalar multiply for each
47 * encrypt/decrypt operation. 60 * encrypt/decrypt operation.