Skip to content

Commit dfe5d9b

Browse files
committed
Fixes.
Fixed bug from merged PR. Don't build useless files when building with libsodium.
1 parent ccfa6c6 commit dfe5d9b

File tree

8 files changed

+23
-14
lines changed

8 files changed

+23
-14
lines changed

auto_tests/encryptsave_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "../toxcore/crypto_core.h"
1818
#ifdef VANILLA_NACL
1919
#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h"
20-
#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h" /* sodium_memzero */
2120
#endif
2221

2322
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};

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ AM_CONDITIONAL(BUILD_TESTS, test "x$BUILD_TESTS" = "xyes")
688688
AM_CONDITIONAL(BUILD_NTOX, test "x$BUILD_NTOX" = "xyes")
689689
AM_CONDITIONAL(BUILD_AV, test "x$BUILD_AV" = "xyes")
690690
AM_CONDITIONAL(BUILD_TESTING, test "x$BUILD_TESTING" = "xyes")
691+
AM_CONDITIONAL(WITH_NACL, test "x$WANT_NACL" = "xyes")
691692
AM_CONDITIONAL(WIN32, test "x$WIN32" = "xyes")
692693

693694
AC_CONFIG_FILES([Makefile

toxcore/crypto_core.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void increment_nonce(uint8_t *nonce)
158158
*/
159159
uint32_t i = crypto_box_NONCEBYTES;
160160
uint_fast16_t carry = 1U;
161+
161162
for (; i != 0; --i) {
162163
carry += (uint_fast16_t) nonce[i - 1];
163164
nonce[i - 1] = (uint8_t) carry;
@@ -173,7 +174,7 @@ void increment_nonce_number(uint8_t *nonce, uint32_t host_order_num)
173174
* are independent of user-controlled input (you may have heard of the Heartbleed bug).
174175
*/
175176
const uint32_t big_endian_num = htonl(host_order_num);
176-
const uint8_t* const num_vec = (const uint8_t*) &big_endian_num;
177+
const uint8_t *const num_vec = (const uint8_t *) &big_endian_num;
177178
uint8_t num_as_nonce[crypto_box_NONCEBYTES] = {0};
178179
num_as_nonce[crypto_box_NONCEBYTES - 4] = num_vec[0];
179180
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)
182183

183184
uint32_t i = crypto_box_NONCEBYTES;
184185
uint_fast16_t carry = 0U;
186+
185187
for (; i != 0; --i) {
186-
carry += (uint_fast16_t) nonce[i] + (uint_fast16_t) num_as_nonce[i];
187-
nonce[i] = (unsigned char) carry;
188+
carry += (uint_fast16_t) nonce[i - 1] + (uint_fast16_t) num_as_nonce[i - 1];
189+
nonce[i - 1] = (unsigned char) carry;
188190
carry >>= 8;
189191
}
190192
}
@@ -227,7 +229,7 @@ int create_request(const uint8_t *send_public_key, const uint8_t *send_secret_ke
227229
crypto_box_MACBYTES)
228230
return -1;
229231

230-
uint8_t* nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2;
232+
uint8_t *nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2;
231233
new_nonce(nonce);
232234
uint8_t temp[MAX_CRYPTO_REQUEST_SIZE]; // FIXME sodium_memzero before exit function
233235
memcpy(temp + 1, data, length);
@@ -265,7 +267,7 @@ int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_ke
265267
return -1;
266268

267269
memcpy(public_key, packet + 1 + crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES);
268-
const uint8_t* nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2;
270+
const uint8_t *nonce = packet + 1 + crypto_box_PUBLICKEYBYTES * 2;
269271
uint8_t temp[MAX_CRYPTO_REQUEST_SIZE]; // FIXME sodium_memzero before exit function
270272
int len1 = decrypt_data(public_key, self_secret_key, nonce,
271273
packet + 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES,

toxcore/crypto_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include <crypto_verify_32.h>
3838
#include <crypto_scalarmult_curve25519.h>
3939
#define crypto_box_MACBYTES (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES)
40+
/* I know */
41+
#define sodium_memcmp(a, b, c) memcmp(a, b, c)
42+
#define sodium_memzero(a, c) memset(a, 0, c)
4043
#endif
4144

4245
#define crypto_box_KEYBYTES (crypto_box_BEFORENMBYTES)

toxcore/net_crypto.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t
363363
if (len != sizeof(plain))
364364
return -1;
365365

366-
if (sodium_memcmp(cookie_hash, plain + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, crypto_hash_sha512_BYTES) != 0)
366+
if (sodium_memcmp(cookie_hash, plain + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES,
367+
crypto_hash_sha512_BYTES) != 0)
367368
return -1;
368369

369370
memcpy(nonce, plain, crypto_box_NONCEBYTES);

toxcore/onion_announce.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ static int handle_announce_request(void *object, IP_Port source, const uint8_t *
316316

317317
uint8_t *data_public_key = plain + ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES;
318318

319-
if (sodium_memcmp(ping_id1, plain, ONION_PING_ID_SIZE) == 0 || sodium_memcmp(ping_id2, plain, ONION_PING_ID_SIZE) == 0) {
319+
if (sodium_memcmp(ping_id1, plain, ONION_PING_ID_SIZE) == 0
320+
|| sodium_memcmp(ping_id2, plain, ONION_PING_ID_SIZE) == 0) {
320321
index = add_to_entries(onion_a, source, packet_public_key, data_public_key,
321322
packet + (ANNOUNCE_REQUEST_SIZE_RECV - ONION_RETURN_3));
322323
} else {

toxencryptsave/Makefile.inc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ libtoxencryptsave_la_include_HEADERS = \
55

66
libtoxencryptsave_la_includedir = $(includedir)/tox
77

8-
libtoxencryptsave_la_SOURCES = ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h \
8+
libtoxencryptsave_la_SOURCES = ../toxencryptsave/toxencryptsave.h \
9+
../toxencryptsave/toxencryptsave.c
10+
11+
12+
if WITH_NACL
13+
libtoxencryptsave_la_SOURCES += ../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h \
914
../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt.h \
1015
../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c \
1116
../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c \
@@ -19,10 +24,8 @@ libtoxencryptsave_la_SOURCES = ../toxencryptsave/crypto_pwhash_scryptsalsa208sha
1924
../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sysendian.h \
2025
../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h \
2126
../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c \
22-
../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c \
23-
../toxencryptsave/toxencryptsave.h \
24-
../toxencryptsave/toxencryptsave.c
25-
27+
../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c
28+
endif
2629

2730
libtoxencryptsave_la_CFLAGS = -I$(top_srcdir) \
2831
-I$(top_srcdir)/toxcore \

toxencryptsave/toxencryptsave.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
#ifdef VANILLA_NACL
3434
#include "crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h"
35-
#include "crypto_pwhash_scryptsalsa208sha256/utils.h" /* sodium_memzero */
3635
#include <crypto_hash_sha256.h>
3736
#endif
3837

0 commit comments

Comments
 (0)