From 12365a7cc97de1d169530678a1a99fee7256c74e Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 25 Jun 2018 17:26:05 +0000 Subject: Fixes to the imported sodium sources to compile without warnings. --- .../crypto_scrypt-common.c | 8 +-- .../pbkdf2-sha256.c | 8 +-- .../pwhash_scryptsalsa208sha256.c | 9 ++- .../crypto_pwhash_scryptsalsa208sha256/runtime.c | 4 ++ .../sse/pwhash_scryptsalsa208sha256_sse.c | 3 + .../crypto_pwhash_scryptsalsa208sha256/utils.c | 78 ---------------------- .../crypto_pwhash_scryptsalsa208sha256/utils.h | 40 ----------- toxencryptsave/toxencryptsave.c | 4 +- 8 files changed, 21 insertions(+), 133 deletions(-) delete mode 100644 toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.c delete mode 100644 toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h (limited to 'toxencryptsave') diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt-common.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt-common.c index 5a5c5525..d3e420e0 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt-common.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt-common.c @@ -29,7 +29,7 @@ #include "crypto_pwhash_scryptsalsa208sha256.h" #include "crypto_scrypt.h" #include "runtime.h" -#include "utils.h" +#include "../../toxcore/crypto_core.h" static const char * const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -147,11 +147,11 @@ escrypt_r(escrypt_local_t * local, const uint8_t * passwd, size_t passwdlen, prefixlen = src - setting; salt = src; - src = (uint8_t *) strrchr((char *)salt, '$'); + src = (uint8_t *) strrchr((const char *)salt, '$'); if (src) { saltlen = src - salt; } else { - saltlen = strlen((char *)salt); + saltlen = strlen((const char *)salt); } need = prefixlen + saltlen + 1 + crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES_ENCODED + 1; @@ -175,7 +175,7 @@ escrypt_r(escrypt_local_t * local, const uint8_t * passwd, size_t passwdlen, *dst++ = '$'; dst = encode64(dst, buflen - (dst - buf), hash, sizeof(hash)); - sodium_memzero(hash, sizeof hash); + crypto_memzero(hash, sizeof hash); if (!dst || dst >= buf + buflen) { /* Can't happen */ return NULL; } diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c index 3dfe54db..c69d7c22 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c @@ -40,7 +40,7 @@ #include "pbkdf2-sha256.h" #include "sysendian.h" -#include "utils.h" +#include "../../toxcore/crypto_core.h" /** * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): @@ -61,8 +61,8 @@ PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, size_t clen; if (passwdlen > 32) { - /* For some reason libsodium allows 64byte keys meaning keys - * between 32byte and 64bytes are not compatible with libsodium. + /* For some reason libsodium allows 64byte keys meaning keys + * between 32byte and 64bytes are not compatible with libsodium. toxencryptsave should only give 32byte passwds so this isn't an issue here.*/ crypto_hash_sha256(key, passwd, passwdlen); } else { @@ -91,7 +91,7 @@ PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, } memcpy(&buf[i * 32], T, clen); } - sodium_memzero((void *) key, sizeof(key)); + crypto_memzero((void *) key, sizeof(key)); } #endif diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c index 52c51abc..e2de3e5f 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c @@ -12,8 +12,7 @@ #include "crypto_pwhash_scryptsalsa208sha256.h" #include "crypto_scrypt.h" -#include "randombytes.h" -#include "utils.h" +#include "../../toxcore/crypto_core.h" #define SETTING_SIZE(saltbytes) \ (sizeof "$7$" - 1U) + \ @@ -150,7 +149,7 @@ crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha2 errno = EINVAL; return -1; } - randombytes(salt, sizeof salt); + random_bytes(salt, sizeof salt); if (escrypt_gensalt_r(N_log2, r, p, salt, sizeof salt, (uint8_t *) setting, sizeof setting) == NULL) { errno = EINVAL; @@ -202,8 +201,8 @@ crypto_pwhash_scryptsalsa208sha256_str_verify(const char str[crypto_pwhash_scryp return -1; } escrypt_free_local(&escrypt_local); - ret = sodium_memcmp(wanted, str, sizeof wanted); - sodium_memzero(wanted, sizeof wanted); + ret = crypto_memcmp(wanted, str, sizeof wanted); + crypto_memzero(wanted, sizeof wanted); return ret; } diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.c index 9b5c5131..a813b506 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.c @@ -18,8 +18,12 @@ typedef struct CPUFeatures_ { static CPUFeatures _cpu_features; +#ifdef HAVE_EMMINTRIN_H #define CPUID_SSE2 0x04000000 +#endif +#ifdef HAVE_PMMINTRIN_H #define CPUIDECX_SSE3 0x00000001 +#endif static int _sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index 856a655e..7f015238 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c @@ -396,3 +396,6 @@ escrypt_kdf_sse(escrypt_local_t * local, #endif #endif + +/* ISO C requires a translation unit to contain at least one declaration */ +extern int non_empty_tu_decl; diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.c deleted file mode 100644 index e61ccf3e..00000000 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.c +++ /dev/null @@ -1,78 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ - -#ifndef __STDC_WANT_LIB_EXT1__ -# define __STDC_WANT_LIB_EXT1__ 1 -#endif -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_SYS_MMAN_H -# include -#endif - -#include "utils.h" - -#ifdef _WIN32 -# include -# include -#else -# include -#endif - -#ifdef HAVE_WEAK_SYMBOLS -__attribute__((weak)) void -__sodium_dummy_symbol_to_prevent_lto(void * const pnt, const size_t len) -{ - (void) pnt; - (void) len; -} -#endif - -void -sodium_memzero(void * const pnt, const size_t len) -{ -#ifdef _WIN32 - SecureZeroMemory(pnt, len); -#elif defined(HAVE_MEMSET_S) - if (memset_s(pnt, (rsize_t) len, 0, (rsize_t) len) != 0) { - abort(); - } -#elif defined(HAVE_EXPLICIT_BZERO) - explicit_bzero(pnt, len); -#elif HAVE_WEAK_SYMBOLS - memset(pnt, 0, len); - __sodium_dummy_symbol_to_prevent_lto(pnt, len); -#else - volatile unsigned char *pnt_ = (volatile unsigned char *) pnt; - size_t i = (size_t) 0U; - - while (i < len) { - pnt_[i++] = 0U; - } -#endif -} - -int -sodium_memcmp(const void * const b1_, const void * const b2_, size_t len) -{ - const unsigned char *b1 = (const unsigned char *) b1_; - const unsigned char *b2 = (const unsigned char *) b2_; - size_t i; - unsigned char d = (unsigned char) 0U; - - for (i = 0U; i < len; i++) { - d |= b1[i] ^ b2[i]; - } - return (int) ((1 & ((d - 1) >> 8)) - 1); -} - -#endif diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h deleted file mode 100644 index fb2020c3..00000000 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/utils.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ - -#ifndef __SODIUM_UTILS_H__ -#define __SODIUM_UTILS_H__ - -#include - -#include "export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(__cplusplus) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L -# define _SODIUM_C99(X) -#else -# define _SODIUM_C99(X) X -#endif - -SODIUM_EXPORT -void sodium_memzero(void * const pnt, const size_t len); - -/* WARNING: sodium_memcmp() must be used to verify if two secret keys - * are equal, in constant time. - * It returns 0 if the keys are equal, and -1 if they differ. - * This function is not designed for lexicographical comparisons. - */ -SODIUM_EXPORT -int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len); - -#ifdef __cplusplus -} -#endif - -#endif - -#endif diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index c1300348..4f827c9e 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -124,7 +124,7 @@ Tox_Pass_Key *tox_pass_key_derive(const uint8_t *passphrase, size_t pplength, TOX_ERR_KEY_DERIVATION *error) { uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES]; - randombytes(salt, sizeof salt); + random_bytes(salt, sizeof salt); return tox_pass_key_derive_with_salt(passphrase, pplength, salt, error); } @@ -157,7 +157,7 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt(const uint8_t *passphrase, size_t pp return nullptr; } - sodium_memzero(passkey, crypto_hash_sha256_BYTES); /* wipe plaintext pw */ + crypto_memzero(passkey, crypto_hash_sha256_BYTES); /* wipe plaintext pw */ Tox_Pass_Key *out_key = (Tox_Pass_Key *)malloc(sizeof(Tox_Pass_Key)); -- cgit v1.2.3