mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixes to the imported sodium sources to compile without warnings.
This commit is contained in:
parent
56d249e5ad
commit
12365a7cc9
|
@ -29,7 +29,7 @@
|
||||||
#include "crypto_pwhash_scryptsalsa208sha256.h"
|
#include "crypto_pwhash_scryptsalsa208sha256.h"
|
||||||
#include "crypto_scrypt.h"
|
#include "crypto_scrypt.h"
|
||||||
#include "runtime.h"
|
#include "runtime.h"
|
||||||
#include "utils.h"
|
#include "../../toxcore/crypto_core.h"
|
||||||
|
|
||||||
static const char * const itoa64 =
|
static const char * const itoa64 =
|
||||||
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
|
@ -147,11 +147,11 @@ escrypt_r(escrypt_local_t * local, const uint8_t * passwd, size_t passwdlen,
|
||||||
prefixlen = src - setting;
|
prefixlen = src - setting;
|
||||||
|
|
||||||
salt = src;
|
salt = src;
|
||||||
src = (uint8_t *) strrchr((char *)salt, '$');
|
src = (uint8_t *) strrchr((const char *)salt, '$');
|
||||||
if (src) {
|
if (src) {
|
||||||
saltlen = src - salt;
|
saltlen = src - salt;
|
||||||
} else {
|
} else {
|
||||||
saltlen = strlen((char *)salt);
|
saltlen = strlen((const char *)salt);
|
||||||
}
|
}
|
||||||
need = prefixlen + saltlen + 1 +
|
need = prefixlen + saltlen + 1 +
|
||||||
crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES_ENCODED + 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++ = '$';
|
||||||
|
|
||||||
dst = encode64(dst, buflen - (dst - buf), hash, sizeof(hash));
|
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 */
|
if (!dst || dst >= buf + buflen) { /* Can't happen */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
#include "pbkdf2-sha256.h"
|
#include "pbkdf2-sha256.h"
|
||||||
#include "sysendian.h"
|
#include "sysendian.h"
|
||||||
#include "utils.h"
|
#include "../../toxcore/crypto_core.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen):
|
* 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;
|
size_t clen;
|
||||||
|
|
||||||
if (passwdlen > 32) {
|
if (passwdlen > 32) {
|
||||||
/* For some reason libsodium allows 64byte keys meaning keys
|
/* For some reason libsodium allows 64byte keys meaning keys
|
||||||
* between 32byte and 64bytes are not compatible with libsodium.
|
* between 32byte and 64bytes are not compatible with libsodium.
|
||||||
toxencryptsave should only give 32byte passwds so this isn't an issue here.*/
|
toxencryptsave should only give 32byte passwds so this isn't an issue here.*/
|
||||||
crypto_hash_sha256(key, passwd, passwdlen);
|
crypto_hash_sha256(key, passwd, passwdlen);
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,7 +91,7 @@ PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt,
|
||||||
}
|
}
|
||||||
memcpy(&buf[i * 32], T, clen);
|
memcpy(&buf[i * 32], T, clen);
|
||||||
}
|
}
|
||||||
sodium_memzero((void *) key, sizeof(key));
|
crypto_memzero((void *) key, sizeof(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
|
|
||||||
#include "crypto_pwhash_scryptsalsa208sha256.h"
|
#include "crypto_pwhash_scryptsalsa208sha256.h"
|
||||||
#include "crypto_scrypt.h"
|
#include "crypto_scrypt.h"
|
||||||
#include "randombytes.h"
|
#include "../../toxcore/crypto_core.h"
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#define SETTING_SIZE(saltbytes) \
|
#define SETTING_SIZE(saltbytes) \
|
||||||
(sizeof "$7$" - 1U) + \
|
(sizeof "$7$" - 1U) + \
|
||||||
|
@ -150,7 +149,7 @@ crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha2
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
randombytes(salt, sizeof salt);
|
random_bytes(salt, sizeof salt);
|
||||||
if (escrypt_gensalt_r(N_log2, r, p, salt, sizeof salt,
|
if (escrypt_gensalt_r(N_log2, r, p, salt, sizeof salt,
|
||||||
(uint8_t *) setting, sizeof setting) == NULL) {
|
(uint8_t *) setting, sizeof setting) == NULL) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
|
@ -202,8 +201,8 @@ crypto_pwhash_scryptsalsa208sha256_str_verify(const char str[crypto_pwhash_scryp
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
escrypt_free_local(&escrypt_local);
|
escrypt_free_local(&escrypt_local);
|
||||||
ret = sodium_memcmp(wanted, str, sizeof wanted);
|
ret = crypto_memcmp(wanted, str, sizeof wanted);
|
||||||
sodium_memzero(wanted, sizeof wanted);
|
crypto_memzero(wanted, sizeof wanted);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,12 @@ typedef struct CPUFeatures_ {
|
||||||
|
|
||||||
static CPUFeatures _cpu_features;
|
static CPUFeatures _cpu_features;
|
||||||
|
|
||||||
|
#ifdef HAVE_EMMINTRIN_H
|
||||||
#define CPUID_SSE2 0x04000000
|
#define CPUID_SSE2 0x04000000
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_PMMINTRIN_H
|
||||||
#define CPUIDECX_SSE3 0x00000001
|
#define CPUIDECX_SSE3 0x00000001
|
||||||
|
#endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features)
|
_sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features)
|
||||||
|
|
|
@ -396,3 +396,6 @@ escrypt_kdf_sse(escrypt_local_t * local,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* ISO C requires a translation unit to contain at least one declaration */
|
||||||
|
extern int non_empty_tu_decl;
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -124,7 +124,7 @@ Tox_Pass_Key *tox_pass_key_derive(const uint8_t *passphrase, size_t pplength,
|
||||||
TOX_ERR_KEY_DERIVATION *error)
|
TOX_ERR_KEY_DERIVATION *error)
|
||||||
{
|
{
|
||||||
uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES];
|
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);
|
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;
|
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));
|
Tox_Pass_Key *out_key = (Tox_Pass_Key *)malloc(sizeof(Tox_Pass_Key));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user