diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-06-25 17:26:05 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-06-25 20:09:53 +0000 |
commit | 12365a7cc97de1d169530678a1a99fee7256c74e (patch) | |
tree | 92ff79fb38349e04a70b4bb9bbe6d252cb94b782 /toxencryptsave | |
parent | 56d249e5ad798f65a6cf97ecc9ae22b4c86ddf5b (diff) |
Fixes to the imported sodium sources to compile without warnings.
Diffstat (limited to 'toxencryptsave')
8 files changed, 21 insertions, 133 deletions
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 @@ | |||
29 | #include "crypto_pwhash_scryptsalsa208sha256.h" | 29 | #include "crypto_pwhash_scryptsalsa208sha256.h" |
30 | #include "crypto_scrypt.h" | 30 | #include "crypto_scrypt.h" |
31 | #include "runtime.h" | 31 | #include "runtime.h" |
32 | #include "utils.h" | 32 | #include "../../toxcore/crypto_core.h" |
33 | 33 | ||
34 | static const char * const itoa64 = | 34 | static const char * const itoa64 = |
35 | "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | 35 | "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
@@ -147,11 +147,11 @@ escrypt_r(escrypt_local_t * local, const uint8_t * passwd, size_t passwdlen, | |||
147 | prefixlen = src - setting; | 147 | prefixlen = src - setting; |
148 | 148 | ||
149 | salt = src; | 149 | salt = src; |
150 | src = (uint8_t *) strrchr((char *)salt, '$'); | 150 | src = (uint8_t *) strrchr((const char *)salt, '$'); |
151 | if (src) { | 151 | if (src) { |
152 | saltlen = src - salt; | 152 | saltlen = src - salt; |
153 | } else { | 153 | } else { |
154 | saltlen = strlen((char *)salt); | 154 | saltlen = strlen((const char *)salt); |
155 | } | 155 | } |
156 | need = prefixlen + saltlen + 1 + | 156 | need = prefixlen + saltlen + 1 + |
157 | crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES_ENCODED + 1; | 157 | crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES_ENCODED + 1; |
@@ -175,7 +175,7 @@ escrypt_r(escrypt_local_t * local, const uint8_t * passwd, size_t passwdlen, | |||
175 | *dst++ = '$'; | 175 | *dst++ = '$'; |
176 | 176 | ||
177 | dst = encode64(dst, buflen - (dst - buf), hash, sizeof(hash)); | 177 | dst = encode64(dst, buflen - (dst - buf), hash, sizeof(hash)); |
178 | sodium_memzero(hash, sizeof hash); | 178 | crypto_memzero(hash, sizeof hash); |
179 | if (!dst || dst >= buf + buflen) { /* Can't happen */ | 179 | if (!dst || dst >= buf + buflen) { /* Can't happen */ |
180 | return NULL; | 180 | return NULL; |
181 | } | 181 | } |
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 @@ | |||
40 | 40 | ||
41 | #include "pbkdf2-sha256.h" | 41 | #include "pbkdf2-sha256.h" |
42 | #include "sysendian.h" | 42 | #include "sysendian.h" |
43 | #include "utils.h" | 43 | #include "../../toxcore/crypto_core.h" |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): | 46 | * 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, | |||
61 | size_t clen; | 61 | size_t clen; |
62 | 62 | ||
63 | if (passwdlen > 32) { | 63 | if (passwdlen > 32) { |
64 | /* For some reason libsodium allows 64byte keys meaning keys | 64 | /* For some reason libsodium allows 64byte keys meaning keys |
65 | * between 32byte and 64bytes are not compatible with libsodium. | 65 | * between 32byte and 64bytes are not compatible with libsodium. |
66 | toxencryptsave should only give 32byte passwds so this isn't an issue here.*/ | 66 | toxencryptsave should only give 32byte passwds so this isn't an issue here.*/ |
67 | crypto_hash_sha256(key, passwd, passwdlen); | 67 | crypto_hash_sha256(key, passwd, passwdlen); |
68 | } else { | 68 | } else { |
@@ -91,7 +91,7 @@ PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, | |||
91 | } | 91 | } |
92 | memcpy(&buf[i * 32], T, clen); | 92 | memcpy(&buf[i * 32], T, clen); |
93 | } | 93 | } |
94 | sodium_memzero((void *) key, sizeof(key)); | 94 | crypto_memzero((void *) key, sizeof(key)); |
95 | } | 95 | } |
96 | 96 | ||
97 | #endif | 97 | #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 @@ | |||
12 | 12 | ||
13 | #include "crypto_pwhash_scryptsalsa208sha256.h" | 13 | #include "crypto_pwhash_scryptsalsa208sha256.h" |
14 | #include "crypto_scrypt.h" | 14 | #include "crypto_scrypt.h" |
15 | #include "randombytes.h" | 15 | #include "../../toxcore/crypto_core.h" |
16 | #include "utils.h" | ||
17 | 16 | ||
18 | #define SETTING_SIZE(saltbytes) \ | 17 | #define SETTING_SIZE(saltbytes) \ |
19 | (sizeof "$7$" - 1U) + \ | 18 | (sizeof "$7$" - 1U) + \ |
@@ -150,7 +149,7 @@ crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha2 | |||
150 | errno = EINVAL; | 149 | errno = EINVAL; |
151 | return -1; | 150 | return -1; |
152 | } | 151 | } |
153 | randombytes(salt, sizeof salt); | 152 | random_bytes(salt, sizeof salt); |
154 | if (escrypt_gensalt_r(N_log2, r, p, salt, sizeof salt, | 153 | if (escrypt_gensalt_r(N_log2, r, p, salt, sizeof salt, |
155 | (uint8_t *) setting, sizeof setting) == NULL) { | 154 | (uint8_t *) setting, sizeof setting) == NULL) { |
156 | errno = EINVAL; | 155 | errno = EINVAL; |
@@ -202,8 +201,8 @@ crypto_pwhash_scryptsalsa208sha256_str_verify(const char str[crypto_pwhash_scryp | |||
202 | return -1; | 201 | return -1; |
203 | } | 202 | } |
204 | escrypt_free_local(&escrypt_local); | 203 | escrypt_free_local(&escrypt_local); |
205 | ret = sodium_memcmp(wanted, str, sizeof wanted); | 204 | ret = crypto_memcmp(wanted, str, sizeof wanted); |
206 | sodium_memzero(wanted, sizeof wanted); | 205 | crypto_memzero(wanted, sizeof wanted); |
207 | 206 | ||
208 | return ret; | 207 | return ret; |
209 | } | 208 | } |
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_ { | |||
18 | 18 | ||
19 | static CPUFeatures _cpu_features; | 19 | static CPUFeatures _cpu_features; |
20 | 20 | ||
21 | #ifdef HAVE_EMMINTRIN_H | ||
21 | #define CPUID_SSE2 0x04000000 | 22 | #define CPUID_SSE2 0x04000000 |
23 | #endif | ||
24 | #ifdef HAVE_PMMINTRIN_H | ||
22 | #define CPUIDECX_SSE3 0x00000001 | 25 | #define CPUIDECX_SSE3 0x00000001 |
26 | #endif | ||
23 | 27 | ||
24 | static int | 28 | static int |
25 | _sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features) | 29 | _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, | |||
396 | #endif | 396 | #endif |
397 | 397 | ||
398 | #endif | 398 | #endif |
399 | |||
400 | /* ISO C requires a translation unit to contain at least one declaration */ | ||
401 | 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 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | #include "config.h" | ||
3 | #endif | ||
4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ | ||
5 | |||
6 | #ifndef __STDC_WANT_LIB_EXT1__ | ||
7 | # define __STDC_WANT_LIB_EXT1__ 1 | ||
8 | #endif | ||
9 | #include <assert.h> | ||
10 | #include <errno.h> | ||
11 | #include <limits.h> | ||
12 | #include <signal.h> | ||
13 | #include <stddef.h> | ||
14 | #include <stdint.h> | ||
15 | #include <stdlib.h> | ||
16 | #include <string.h> | ||
17 | |||
18 | #ifdef HAVE_SYS_MMAN_H | ||
19 | # include <sys/mman.h> | ||
20 | #endif | ||
21 | |||
22 | #include "utils.h" | ||
23 | |||
24 | #ifdef _WIN32 | ||
25 | # include <windows.h> | ||
26 | # include <wincrypt.h> | ||
27 | #else | ||
28 | # include <unistd.h> | ||
29 | #endif | ||
30 | |||
31 | #ifdef HAVE_WEAK_SYMBOLS | ||
32 | __attribute__((weak)) void | ||
33 | __sodium_dummy_symbol_to_prevent_lto(void * const pnt, const size_t len) | ||
34 | { | ||
35 | (void) pnt; | ||
36 | (void) len; | ||
37 | } | ||
38 | #endif | ||
39 | |||
40 | void | ||
41 | sodium_memzero(void * const pnt, const size_t len) | ||
42 | { | ||
43 | #ifdef _WIN32 | ||
44 | SecureZeroMemory(pnt, len); | ||
45 | #elif defined(HAVE_MEMSET_S) | ||
46 | if (memset_s(pnt, (rsize_t) len, 0, (rsize_t) len) != 0) { | ||
47 | abort(); | ||
48 | } | ||
49 | #elif defined(HAVE_EXPLICIT_BZERO) | ||
50 | explicit_bzero(pnt, len); | ||
51 | #elif HAVE_WEAK_SYMBOLS | ||
52 | memset(pnt, 0, len); | ||
53 | __sodium_dummy_symbol_to_prevent_lto(pnt, len); | ||
54 | #else | ||
55 | volatile unsigned char *pnt_ = (volatile unsigned char *) pnt; | ||
56 | size_t i = (size_t) 0U; | ||
57 | |||
58 | while (i < len) { | ||
59 | pnt_[i++] = 0U; | ||
60 | } | ||
61 | #endif | ||
62 | } | ||
63 | |||
64 | int | ||
65 | sodium_memcmp(const void * const b1_, const void * const b2_, size_t len) | ||
66 | { | ||
67 | const unsigned char *b1 = (const unsigned char *) b1_; | ||
68 | const unsigned char *b2 = (const unsigned char *) b2_; | ||
69 | size_t i; | ||
70 | unsigned char d = (unsigned char) 0U; | ||
71 | |||
72 | for (i = 0U; i < len; i++) { | ||
73 | d |= b1[i] ^ b2[i]; | ||
74 | } | ||
75 | return (int) ((1 & ((d - 1) >> 8)) - 1); | ||
76 | } | ||
77 | |||
78 | #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 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | #include "config.h" | ||
3 | #endif | ||
4 | #ifdef VANILLA_NACL /* toxcore only uses this when libsodium is unavailable */ | ||
5 | |||
6 | #ifndef __SODIUM_UTILS_H__ | ||
7 | #define __SODIUM_UTILS_H__ | ||
8 | |||
9 | #include <stddef.h> | ||
10 | |||
11 | #include "export.h" | ||
12 | |||
13 | #ifdef __cplusplus | ||
14 | extern "C" { | ||
15 | #endif | ||
16 | |||
17 | #if defined(__cplusplus) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L | ||
18 | # define _SODIUM_C99(X) | ||
19 | #else | ||
20 | # define _SODIUM_C99(X) X | ||
21 | #endif | ||
22 | |||
23 | SODIUM_EXPORT | ||
24 | void sodium_memzero(void * const pnt, const size_t len); | ||
25 | |||
26 | /* WARNING: sodium_memcmp() must be used to verify if two secret keys | ||
27 | * are equal, in constant time. | ||
28 | * It returns 0 if the keys are equal, and -1 if they differ. | ||
29 | * This function is not designed for lexicographical comparisons. | ||
30 | */ | ||
31 | SODIUM_EXPORT | ||
32 | int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len); | ||
33 | |||
34 | #ifdef __cplusplus | ||
35 | } | ||
36 | #endif | ||
37 | |||
38 | #endif | ||
39 | |||
40 | #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, | |||
124 | TOX_ERR_KEY_DERIVATION *error) | 124 | TOX_ERR_KEY_DERIVATION *error) |
125 | { | 125 | { |
126 | uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES]; | 126 | uint8_t salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES]; |
127 | randombytes(salt, sizeof salt); | 127 | random_bytes(salt, sizeof salt); |
128 | return tox_pass_key_derive_with_salt(passphrase, pplength, salt, error); | 128 | return tox_pass_key_derive_with_salt(passphrase, pplength, salt, error); |
129 | } | 129 | } |
130 | 130 | ||
@@ -157,7 +157,7 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt(const uint8_t *passphrase, size_t pp | |||
157 | return nullptr; | 157 | return nullptr; |
158 | } | 158 | } |
159 | 159 | ||
160 | sodium_memzero(passkey, crypto_hash_sha256_BYTES); /* wipe plaintext pw */ | 160 | crypto_memzero(passkey, crypto_hash_sha256_BYTES); /* wipe plaintext pw */ |
161 | 161 | ||
162 | Tox_Pass_Key *out_key = (Tox_Pass_Key *)malloc(sizeof(Tox_Pass_Key)); | 162 | Tox_Pass_Key *out_key = (Tox_Pass_Key *)malloc(sizeof(Tox_Pass_Key)); |
163 | 163 | ||