diff options
Diffstat (limited to 'protocols/Tox/libtox/src/toxencryptsave')
6 files changed, 23 insertions, 16 deletions
diff --git a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt-common.c b/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt-common.c index 5a5c5525f3..d3e420e068 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_scrypt-common.c +++ b/protocols/Tox/libtox/src/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/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c b/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c index 3dfe54db5f..c69d7c22e7 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pbkdf2-sha256.c +++ b/protocols/Tox/libtox/src/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/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c b/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c index 52c51abc3b..e2de3e5f74 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +++ b/protocols/Tox/libtox/src/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/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.c b/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.c index 9b5c513193..a813b50609 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/runtime.c +++ b/protocols/Tox/libtox/src/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/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index 856a655e3f..7f01523861 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/protocols/Tox/libtox/src/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/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.c b/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.c index b83d6f1c6c..7c81f72272 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.c +++ b/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.c @@ -29,7 +29,7 @@ #include "../toxcore/crypto_core.h" #include "defines.h" #include "toxencryptsave.h" -#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}} +#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0) #ifdef VANILLA_NACL #include <crypto_box.h> @@ -40,6 +40,7 @@ #include <sodium.h> #endif +#include <stdlib.h> #include <string.h> #if TOX_PASS_SALT_LENGTH != crypto_pwhash_scryptsalsa208sha256_SALTBYTES @@ -123,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); } @@ -156,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)); |