Fixes to the imported sodium sources to compile without warnings.

This commit is contained in:
iphydf 2018-06-25 17:26:05 +00:00
parent 56d249e5ad
commit 12365a7cc9
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
8 changed files with 21 additions and 133 deletions

View File

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

View File

@ -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):
@ -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

View File

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

View File

@ -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)

View File

@ -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;

View File

@ -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 <assert.h>
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
#include "utils.h"
#ifdef _WIN32
# include <windows.h>
# include <wincrypt.h>
#else
# include <unistd.h>
#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

View File

@ -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 <stddef.h>
#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

View File

@ -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));