From: Loup Vaillant Date: Thu, 1 Sep 2022 16:26:27 +0000 (+0200) Subject: Fixed various compiler warnings X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=9c510680fab78aa0530b6917e4e903b182d92a24;p=Monocypher.git Fixed various compiler warnings - Global constant should have been `static` - Reserved identifier (double underscores) - Loss of precision in implicit conversions - Implicit change of sign --- diff --git a/src/monocypher.c b/src/monocypher.c index 7462903..bf66a69 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -62,8 +62,8 @@ namespace MONOCYPHER_CPP_NAMESPACE { ///////////////// #define FOR_T(type, i, start, end) for (type i = (start); i < (end); i++) #define FOR(i, start, end) FOR_T(size_t, i, start, end) -#define COPY(dst, src, size) FOR(i__, 0, size) (dst)[i__] = (src)[i__] -#define ZERO(buf, size) FOR(i__, 0, size) (buf)[i__] = 0 +#define COPY(dst, src, size) FOR(_i_, 0, size) (dst)[_i_] = (src)[_i_] +#define ZERO(buf, size) FOR(_i_, 0, size) (buf)[_i_] = 0 #define WIPE_CTX(ctx) crypto_wipe(ctx , sizeof(*(ctx))) #define WIPE_BUFFER(buffer) crypto_wipe(buffer, sizeof(buffer)) #define MIN(a, b) ((a) <= (b) ? (a) : (b)) @@ -196,7 +196,7 @@ static void chacha20_rounds(u32 out[16], const u32 in[16]) out[12] = t12; out[13] = t13; out[14] = t14; out[15] = t15; } -const u8 *chacha20_constant = (const u8*)"expand 32-byte k"; // 16 bytes +static const u8 *chacha20_constant = (const u8*)"expand 32-byte k"; // 16 bytes void crypto_hchacha20(u8 out[32], const u8 key[32], const u8 in [16]) { @@ -1162,7 +1162,7 @@ static void fe_ccopy(fe f, const fe g, int b) // which means ignoring 2 bits instead. static void fe_frombytes_mask(fe h, const u8 s[32], unsigned nb_mask) { - i32 mask = 0xffffff >> nb_mask; + u32 mask = 0xffffff >> nb_mask; i64 t0 = load32_le(s); // t0 < 2^32 i64 t1 = load24_le(s + 4) << 6; // t1 < 2^30 i64 t2 = load24_le(s + 7) << 5; // t2 < 2^29 @@ -1634,7 +1634,7 @@ static int is_above_l(const u32 x[8]) // otherwise the result will be wrong static void remove_l(u32 r[8], const u32 x[8]) { - u64 carry = is_above_l(x); + u64 carry = (u64)is_above_l(x); u32 mask = ~(u32)carry + 1; // carry == 0 or 1 FOR (i, 0, 8) { carry += (u64)x[i] + (~L[i] & mask); diff --git a/tests/test.c b/tests/test.c index 4eb1211..9a8aad5 100644 --- a/tests/test.c +++ b/tests/test.c @@ -86,11 +86,11 @@ static void ietf_chacha20(vector_reader *reader) vector key = next_input(reader); vector nonce = next_input(reader); vector plain = next_input(reader); - u64 ctr = load64_le(next_input(reader).buf); + u32 ctr = load32_le(next_input(reader).buf); vector out = next_output(reader); u32 nb_blocks = (u32)(plain.size / 64 + (plain.size % 64 != 0)); u32 new_ctr = crypto_ietf_chacha20_ctr(out.buf, plain.buf, plain.size, - key.buf, nonce.buf, ctr); + key.buf, nonce.buf, ctr); if (new_ctr - ctr != nb_blocks) { printf("FAILURE: IETF Chacha20 returned counter not correct: "); exit(1); diff --git a/tests/utils.c b/tests/utils.c index d56e3a7..427d315 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -146,7 +146,7 @@ static vector vector_of_string(const char *s) FOR (i, 0, v.size) { int msb = to_num(*s); s++; int lsb = to_num(*s); s++; - v.buf[i] = msb * 16 + lsb; + v.buf[i] = (u8)(msb * 16 + lsb); } return v; }