]> git.codecow.com Git - Monocypher.git/commitdiff
Fixed various compiler warnings
authorLoup Vaillant <loup@loup-vaillant.fr>
Fri, 29 May 2020 18:09:41 +0000 (20:09 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Fri, 29 May 2020 18:10:13 +0000 (20:10 +0200)
Fixes #179

src/monocypher.c
tests/gen/vector_to_header.c
tests/speed/speed.c
tests/test.c
tests/utils.c
tests/utils.h

index c588f22e215c86c78aaa5e36c7242f36a9658692..b26883d0145111259640b9cc88ebef1e95445d9d 100644 (file)
@@ -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;
index ad601095215d8b7cad08f1851aa275b47ee2549d..20d0337a46bd09677ab1561798d9278c5d8594a8 100644 (file)
@@ -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);
     }
index 225488431209e80c72b9e0ed382e69957d4b0754..fbc2532ea6afa330bb6d7ed137203ae6d877542b 100644 (file)
@@ -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);
 
index 4beeb2f14bd547ea0325059ed44a038acb541de1..271fd9706e4fe367eb3af387a89ead1945b3194f 100644 (file)
@@ -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) {
index 48768bfd5a8a44e31c8b0e0056e8af865f6bd62a..933afca85631df3f3cf3641bb9e021cc58c6e756 100644 (file)
@@ -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;
index b0da6356bc61ffb7f647cf4a442f3664dd8b3d87..7ddfb8124285ef54ef1774bcb8df57e248a2225f 100644 (file)
@@ -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);