From: Loup Vaillant Date: Fri, 29 May 2020 18:09:41 +0000 (+0200) Subject: Fixed various compiler warnings X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=234cd2c2c4559d13e1b05b86af57dddb234931e5;p=Monocypher.git Fixed various compiler warnings Fixes #179 --- diff --git a/src/monocypher.c b/src/monocypher.c index c588f22..b26883d 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -932,7 +932,7 @@ static u32 gidx_next(gidx_ctx *ctx) u64 y = (area_size * x) >> 32; u64 z = (area_size - 1) - y; u64 ref = start_pos + z; // ref < 2 * nb_blocks - return ref < ctx->nb_blocks ? ref : ref - ctx->nb_blocks; + return (u32)(ref < ctx->nb_blocks ? ref : ref - ctx->nb_blocks); } // Main algorithm @@ -1405,7 +1405,7 @@ static int scalar_bit(const u8 s[32], int i) /// X-25519 /// Taken from SUPERCOP's ref10 implementation. /////////////// static void scalarmult(u8 q[32], const u8 scalar[32], const u8 p[32], - size_t nb_bits) + int nb_bits) { // computes the scalar product fe x1; diff --git a/tests/gen/vector_to_header.c b/tests/gen/vector_to_header.c index ad60109..20d0337 100644 --- a/tests/gen/vector_to_header.c +++ b/tests/gen/vector_to_header.c @@ -86,7 +86,7 @@ int main(int argc, char** argv) printf("#define %s_%d 0\n", prefix, nb_vec); } else { - printf("uint8_t %s_%d[] = { ", prefix, nb_vec); + printf("static uint8_t %s_%d[] = { ", prefix, nb_vec); while (c != ':') { char msb = (char)c; c = getchar(); char lsb = (char)c; c = getchar(); @@ -105,15 +105,15 @@ int main(int argc, char** argv) nb_vec++; } - printf("size_t nb_%s_vectors = %d;\n", prefix, nb_vec); + printf("static size_t nb_%s_vectors = %d;\n", prefix, nb_vec); - printf("uint8_t *%s_vectors[] = { ", prefix); + printf("static uint8_t *%s_vectors[] = { ", prefix); for (int i = 0; i < nb_vec; i++) { printf("%s_%d, ", prefix, i); } printf("};\n"); - printf("size_t %s_sizes[] = { ", prefix); + printf("static size_t %s_sizes[] = { ", prefix); for (int i = 0; i < nb_vec; i++) { printf("%s_%d_size, ", prefix, i); } diff --git a/tests/speed/speed.c b/tests/speed/speed.c index 2254884..fbc2532 100644 --- a/tests/speed/speed.c +++ b/tests/speed/speed.c @@ -118,9 +118,9 @@ static u64 sha512(void) static u64 argon2i(void) { - u64 work_area[SIZE / 8]; - u8 hash [32]; - size_t nb_blocks = SIZE / 1024; + u64 work_area[SIZE / 8]; + u8 hash [32]; + u32 nb_blocks = (u32)(SIZE / 1024); RANDOM_INPUT(password, 16); RANDOM_INPUT(salt , 16); diff --git a/tests/test.c b/tests/test.c index 4beeb2f..271fd97 100644 --- a/tests/test.c +++ b/tests/test.c @@ -58,7 +58,6 @@ #include "vectors.h" #define CHACHA_BLOCK_SIZE 64 -#define CHACHA_NB_BLOCKS 10 #define POLY1305_BLOCK_SIZE 16 #define BLAKE2B_BLOCK_SIZE 128 #define SHA_512_BLOCK_SIZE 128 @@ -88,7 +87,7 @@ static void ietf_chacha20(const vector in[], vector *out) u32 ctr = load32_le(in[3].buf); u32 new_ctr = crypto_ietf_chacha20_ctr(out->buf, plain->buf, plain->size, key->buf, nonce->buf, ctr); - u32 nb_blocks = plain->size / 64 + (plain->size % 64 != 0); + u32 nb_blocks = (u32)(plain->size / 64 + (plain->size % 64 != 0)); if (new_ctr - ctr != nb_blocks) { printf("FAILURE: IETF Chacha20 returned counter not correct: "); } @@ -243,8 +242,8 @@ static void ed_25519_check(const vector in[], vector *out) const vector *public_k = in; const vector *msg = in + 1; const vector *sig = in + 2; - out->buf[0] = crypto_ed25519_check(sig->buf, public_k->buf, - msg->buf, msg->size); + out->buf[0] = (u8)crypto_ed25519_check(sig->buf, public_k->buf, + msg->buf, msg->size); } static void iterate_x25519(u8 k[32], u8 u[32]) @@ -331,7 +330,7 @@ static int p_verify(size_t size, int (*compare)(const u8*, const u8*)) } a[k] = (u8)i; a[k + size/2 - 1] = (u8)i; b[k] = (u8)j; b[k + size/2 - 1] = (u8)j; - int cmp = compare(a, b); + cmp = compare(a, b); status |= (i == j ? cmp : ~cmp); } } @@ -659,10 +658,10 @@ static int p_argon2i_overlap() u32 ad_offset = rand64() % 64; u8 hash1[32]; u8 hash2[32]; - u8 pass [16]; FOR (i, 0, 16) { pass[i] = work_area[i + pass_offset]; } - u8 salt [16]; FOR (i, 0, 16) { salt[i] = work_area[i + salt_offset]; } - u8 key [32]; FOR (i, 0, 32) { key [i] = work_area[i + key_offset]; } - u8 ad [32]; FOR (i, 0, 32) { ad [i] = work_area[i + ad_offset]; } + u8 pass [16]; FOR (j, 0, 16) { pass[j] = work_area[j + pass_offset]; } + u8 salt [16]; FOR (j, 0, 16) { salt[j] = work_area[j + salt_offset]; } + u8 key [32]; FOR (j, 0, 32) { key [j] = work_area[j + key_offset]; } + u8 ad [32]; FOR (j, 0, 32) { ad [j] = work_area[j + ad_offset]; } crypto_argon2i_general(hash1, 32, clean_work_area, 8, 1, pass, 16, salt, 16, key, 32, ad, 32); @@ -947,7 +946,7 @@ static int p_elligator_x25519() // Maximise tweak diversity. // We want to set the bits 1 (sign) and 6-7 (padding) - u8 tweak = (i & 1) + (i << 6); + u8 tweak = (u8)((i & 1) + (i << 6)); u8 r[32]; if (crypto_curve_to_hidden(r, pkf, tweak)) { continue; // retry untill success (doesn't increment the tweak) @@ -1063,7 +1062,7 @@ static int p_x25519_inverse_overlap() return status; } -int p_from_eddsa() +static int p_from_eddsa() { int status = 0; FOR (i, 0, 32) { @@ -1078,7 +1077,7 @@ int p_from_eddsa() return status; } -int p_from_ed25519() +static int p_from_ed25519() { int status = 0; FOR (i, 0, 32) { diff --git a/tests/utils.c b/tests/utils.c index 48768bf..933afca 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -69,10 +69,10 @@ void store64_le(u8 out[8], u64 in) u32 load32_le(const u8 s[4]) { - return (u64)s[0] - | ((u64)s[1] << 8) - | ((u64)s[2] << 16) - | ((u64)s[3] << 24); + return (u32)s[0] + | ((u32)s[1] << 8) + | ((u32)s[2] << 16) + | ((u32)s[3] << 24); } u64 load64_le(const u8 s[8]) @@ -85,7 +85,7 @@ u64 load64_le(const u8 s[8]) u64 random_state = 12345; // Pseudo-random 64 bit number, based on xorshift* -u64 rand64() +u64 rand64(void) { random_state ^= random_state >> 12; random_state ^= random_state << 25; diff --git a/tests/utils.h b/tests/utils.h index b0da635..7ddfb81 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -82,7 +82,7 @@ typedef struct { void store64_le(u8 out[8], u64 in); u64 load64_le(const u8 s[8]); u32 load32_le(const u8 s[8]); -u64 rand64(); // Pseudo-random 64 bit number, based on xorshift* +u64 rand64(void); // Pseudo-random 64 bit number, based on xorshift* void p_random(u8 *stream, size_t size); void print_vector(const u8 *buf, size_t size); void print_number(u64 n);