From dfe5d9b25622b91f22b66b93bb0ab4db32195d11 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 30 Jan 2016 17:23:15 -0500 Subject: [PATCH] Fixes. Fixed bug from merged PR. Don't build useless files when building with libsodium. --- auto_tests/encryptsave_test.c | 1 - configure.ac | 1 + toxcore/crypto_core.c | 12 +++++++----- toxcore/crypto_core.h | 3 +++ toxcore/net_crypto.c | 3 ++- toxcore/onion_announce.c | 3 ++- toxencryptsave/Makefile.inc | 13 ++++++++----- toxencryptsave/toxencryptsave.c | 1 - 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index d187e352..266dfe96 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -17,7 +17,6 @@ #include "../toxcore/crypto_core.h" #ifdef VANILLA_NACL #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" -#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h" /* sodium_memzero */ #endif unsigned char salt[32] = {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}; diff --git a/configure.ac b/configure.ac index ecbb5e46..46162b44 100644 --- a/configure.ac +++ b/configure.ac @@ -688,6 +688,7 @@ AM_CONDITIONAL(BUILD_TESTS, test "x$BUILD_TESTS" = "xyes") AM_CONDITIONAL(BUILD_NTOX, test "x$BUILD_NTOX" = "xyes") AM_CONDITIONAL(BUILD_AV, test "x$BUILD_AV" = "xyes") AM_CONDITIONAL(BUILD_TESTING, test "x$BUILD_TESTING" = "xyes") +AM_CONDITIONAL(WITH_NACL, test "x$WANT_NACL" = "xyes") AM_CONDITIONAL(WIN32, test "x$WIN32" = "xyes") AC_CONFIG_FILES([Makefile diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index 679ba669..a733c38e 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c @@ -158,6 +158,7 @@ void increment_nonce(uint8_t *nonce) */ uint32_t i = crypto_box_NONCEBYTES; uint_fast16_t carry = 1U; + for (; i != 0; --i) { carry += (uint_fast16_t) nonce[i - 1]; nonce[i - 1] = (uint8_t) carry; @@ -173,7 +174,7 @@ void increment_nonce_number(uint8_t *nonce, uint32_t host_order_num) * are independent of user-controlled input (you may have heard of the Heartbleed bug). */ const uint32_t big_endian_num = htonl(host_order_num); - const uint8_t* const num_vec = (const uint8_t*) &big_endian_num; + const uint8_t *const num_vec = (const uint8_t *) &big_endian_num; uint8_t num_as_nonce[crypto_box_NONCEBYTES] = {0}; num_as_nonce[crypto_box_NONCEBYTES - 4] = num_vec[0]; num_as_nonce[crypto_box_NONCEBYTES - 3] = num_vec[1]; @@ -182,9 +183,10 @@ void increment_nonce_number(uint8_t *nonce, uint32_t host_order_num) uint32_t i = crypto_box_NONCEBYTES; uint_fast16_t carry = 0U; + for (; i != 0; --i) { - carry += (uint_fast16_t) nonce[i] + (uint_fast16_t) num_as_nonce[i]; - nonce[i] = (unsigned char) carry; + carry += (uint_fast16_t) nonce[i - 1] + (uint_fast16_t) num_as_nonce[i - 1]; + nonce[i - 1] = (unsigned char) carry; carry >>= 8; } } @@ -227,7 +229,7 @@ int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_ke crypto_box_MACBYTES) return -1; - uint8_t* nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2; + uint8_t *nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2; new_nonce(nonce); uint8_t temp[MAX_CRYPTO_REQUEST_SIZE]; // FIXME sodium_memzero before exit function memcpy(temp + 1, data, length); @@ -265,7 +267,7 @@ int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_ke return -1; memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES); - const uint8_t* nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2; + const uint8_t *nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2; uint8_t temp[MAX_CRYPTO_REQUEST_SIZE]; // FIXME sodium_memzero before exit function int len1 = decrypt_data(public_key, self_secret_key, nonce, packet + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES, diff --git a/toxcore/crypto_core.h b/toxcore/crypto_core.h index 41a5a045..ab509f09 100644 --- a/toxcore/crypto_core.h +++ b/toxcore/crypto_core.h @@ -37,6 +37,9 @@ #include #include #define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES) +/* I know */ +#define sodium_memcmp(a, b, c) memcmp(a, b, c) +#define sodium_memzero(a, c) memset(a, 0, c) #endif #define crypto_box_KEYBYTES (crypto_box_BEFORENMBYTES) diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index c6729722..f8a85adf 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -363,7 +363,8 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t if (len != sizeof(plain)) return -1; - if (sodium_memcmp(cookie_hash, plain + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, crypto_hash_sha512_BYTES) != 0) + if (sodium_memcmp(cookie_hash, plain + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, + crypto_hash_sha512_BYTES) != 0) return -1; memcpy(nonce, plain, crypto_box_NONCEBYTES); diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 82c3dc96..676b38da 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -316,7 +316,8 @@ static int handle_announce_request(void *object, IP_Port source, const uint8_t * uint8_t *data_public_key = plain + ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES; - if (sodium_memcmp(ping_id1, plain, ONION_PING_ID_SIZE) == 0 || sodium_memcmp(ping_id2, plain, ONION_PING_ID_SIZE) == 0) { + if (sodium_memcmp(ping_id1, plain, ONION_PING_ID_SIZE) == 0 + || sodium_memcmp(ping_id2, plain, ONION_PING_ID_SIZE) == 0) { index = add_to_entries(onion_a, source, packet_public_key, data_public_key, packet + (ANNOUNCE_REQUEST_SIZE_RECV - ONION_RETURN_3)); } else { diff --git a/toxencryptsave/Makefile.inc b/toxencryptsave/Makefile.inc index 1155e954..20c8b1b3 100644 --- a/toxencryptsave/Makefile.inc +++ b/toxencryptsave/Makefile.inc @@ -5,7 +5,12 @@ libtoxencryptsave_la_include_HEADERS = \ libtoxencryptsave_la_includedir = $(includedir)/tox -libtoxencryptsave_la_SOURCES = ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h \ +libtoxencryptsave_la_SOURCES = ../toxencryptsave/toxencryptsave.h \ + ../toxencryptsave/toxencryptsave.c + + +if WITH_NACL +libtoxencryptsave_la_SOURCES += ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h \ ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt.h \ ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c \ ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c \ @@ -19,10 +24,8 @@ libtoxencryptsave_la_SOURCES = ../toxencryptsave/crypto_pwhash_scryptsalsa208sha ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sysendian.h \ ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h \ ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c \ - ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c \ - ../toxencryptsave/toxencryptsave.h \ - ../toxencryptsave/toxencryptsave.c - + ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +endif libtoxencryptsave_la_CFLAGS = -I$(top_srcdir) \ -I$(top_srcdir)/toxcore \ diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index e6150ce2..5c40f639 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -32,7 +32,6 @@ #ifdef VANILLA_NACL #include "crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" -#include "crypto_pwhash_scryptsalsa208sha256/utils.h" /* sodium_memzero */ #include #endif