From 4d4504ac205b452cb17a0565e231e03ce6e68a89 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Wed, 27 Feb 2019 16:00:06 +0100 Subject: [PATCH 1/5] Set windows warnings to W4 --- test/Makefile.Microsoft_nmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Makefile.Microsoft_nmake b/test/Makefile.Microsoft_nmake index 2237af4a..60e0682f 100644 --- a/test/Makefile.Microsoft_nmake +++ b/test/Makefile.Microsoft_nmake @@ -16,7 +16,7 @@ COMMON_OBJECTS_NOPATH=fips202.obj sha2.obj DEST_DIR=..\bin -CFLAGS=/I $(COMMON_DIR) /W1 /WX # FIXME: Should be /W4 but many compiler warnings in common files +CFLAGS=/I $(COMMON_DIR) /W4 /WX all: $(DEST_DIR)\functest_$(SCHEME)_$(IMPLEMENTATION).EXE $(DEST_DIR)\testvectors_$(SCHEME)_$(IMPLEMENTATION).EXE From 06955dfc211e2e1bb661d9d41f6a5f445799c1cc Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Wed, 27 Feb 2019 16:19:00 +0100 Subject: [PATCH 2/5] Explicit casts in conversions --- common/fips202.c | 2 +- common/randombytes.c | 8 ++-- common/sha2.c | 94 ++++++++++++++++++++++---------------------- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/common/fips202.c b/common/fips202.c index 2afe5b54..66e97ae2 100644 --- a/common/fips202.c +++ b/common/fips202.c @@ -41,7 +41,7 @@ static uint64_t load64(const uint8_t *x) { **************************************************/ static void store64(uint8_t *x, uint64_t u) { for (size_t i = 0; i < 8; ++i) { - x[i] = u >> 8 * i; + x[i] = (uint8_t) (u >> 8 * i); } } diff --git a/common/randombytes.c b/common/randombytes.c index fcb44922..0ffd74ee 100644 --- a/common/randombytes.c +++ b/common/randombytes.c @@ -111,7 +111,7 @@ static int randombytes_linux_randombytes_getrandom(void *buf, size_t n) { * (250 MB/s on my laptop). */ size_t offset = 0, chunk; - int ret; + long int ret; while (n > 0) { /* getrandom does not allow chunks larger than 33554431 */ chunk = n <= 33554431 ? n : 33554431; @@ -119,10 +119,10 @@ static int randombytes_linux_randombytes_getrandom(void *buf, size_t n) { ret = syscall(SYS_getrandom, (char *)buf + offset, chunk, 0); } while (ret == -1 && errno == EINTR); if (ret < 0) { - return ret; + return (int) ret; } - offset += ret; - n -= ret; + offset += (size_t) ret; + n -= (size_t) ret; } assert(n == 0); return 0; diff --git a/common/sha2.c b/common/sha2.c index d8c72fb9..13582c1d 100644 --- a/common/sha2.c +++ b/common/sha2.c @@ -15,21 +15,21 @@ static uint64_t load_bigendian(const unsigned char *x) { } static void store_bigendian(uint8_t *x, uint64_t u) { - x[7] = u; + x[7] = (uint8_t) u; u >>= 8; - x[6] = u; + x[6] = (uint8_t) u; u >>= 8; - x[5] = u; + x[5] = (uint8_t) u; u >>= 8; - x[4] = u; + x[4] = (uint8_t) u; u >>= 8; - x[3] = u; + x[3] = (uint8_t) u; u >>= 8; - x[2] = u; + x[2] = (uint8_t) u; u >>= 8; - x[1] = u; + x[1] = (uint8_t) u; u >>= 8; - x[0] = u; + x[0] = (uint8_t) u; } #define SHR(x, c) ((x) >> (c)) @@ -74,9 +74,9 @@ static void store_bigendian(uint8_t *x, uint64_t u) { b = a; \ a = T1 + T2; -static int crypto_hashblocks_sha512(uint8_t *statebytes, - const uint8_t *in, - size_t inlen) { +static size_t crypto_hashblocks_sha512(uint8_t *statebytes, + const uint8_t *in, + size_t inlen) { uint64_t state[8]; uint64_t a; uint64_t b; @@ -294,29 +294,29 @@ int sha384(uint8_t *out, const uint8_t *in, size_t inlen) { for (size_t i = inlen + 1; i < 119; ++i) { padded[i] = 0; } - padded[119] = bytes >> 61; - padded[120] = bytes >> 53; - padded[121] = bytes >> 45; - padded[122] = bytes >> 37; - padded[123] = bytes >> 29; - padded[124] = bytes >> 21; - padded[125] = bytes >> 13; - padded[126] = bytes >> 5; - padded[127] = bytes << 3; + padded[119] = (uint8_t) (bytes >> 61); + padded[120] = (uint8_t) (bytes >> 53); + padded[121] = (uint8_t) (bytes >> 45); + padded[122] = (uint8_t) (bytes >> 37); + padded[123] = (uint8_t) (bytes >> 29); + padded[124] = (uint8_t) (bytes >> 21); + padded[125] = (uint8_t) (bytes >> 13); + padded[126] = (uint8_t) (bytes >> 5); + padded[127] = (uint8_t) (bytes << 3); blocks(h, padded, 128); } else { for (size_t i = inlen + 1; i < 247; ++i) { padded[i] = 0; } - padded[247] = bytes >> 61; - padded[248] = bytes >> 53; - padded[249] = bytes >> 45; - padded[250] = bytes >> 37; - padded[251] = bytes >> 29; - padded[252] = bytes >> 21; - padded[253] = bytes >> 13; - padded[254] = bytes >> 5; - padded[255] = bytes << 3; + padded[247] = (uint8_t) (bytes >> 61); + padded[248] = (uint8_t) (bytes >> 53); + padded[249] = (uint8_t) (bytes >> 45); + padded[250] = (uint8_t) (bytes >> 37); + padded[251] = (uint8_t) (bytes >> 29); + padded[252] = (uint8_t) (bytes >> 21); + padded[253] = (uint8_t) (bytes >> 13); + padded[254] = (uint8_t) (bytes >> 5); + padded[255] = (uint8_t) (bytes << 3); blocks(h, padded, 256); } @@ -350,29 +350,29 @@ int sha512(uint8_t *out, const uint8_t *in, size_t inlen) { for (size_t i = inlen + 1; i < 119; ++i) { padded[i] = 0; } - padded[119] = bytes >> 61; - padded[120] = bytes >> 53; - padded[121] = bytes >> 45; - padded[122] = bytes >> 37; - padded[123] = bytes >> 29; - padded[124] = bytes >> 21; - padded[125] = bytes >> 13; - padded[126] = bytes >> 5; - padded[127] = bytes << 3; + padded[119] = (uint8_t) (bytes >> 61); + padded[120] = (uint8_t) (bytes >> 53); + padded[121] = (uint8_t) (bytes >> 45); + padded[122] = (uint8_t) (bytes >> 37); + padded[123] = (uint8_t) (bytes >> 29); + padded[124] = (uint8_t) (bytes >> 21); + padded[125] = (uint8_t) (bytes >> 13); + padded[126] = (uint8_t) (bytes >> 5); + padded[127] = (uint8_t) (bytes << 3); blocks(h, padded, 128); } else { for (size_t i = inlen + 1; i < 247; ++i) { padded[i] = 0; } - padded[247] = bytes >> 61; - padded[248] = bytes >> 53; - padded[249] = bytes >> 45; - padded[250] = bytes >> 37; - padded[251] = bytes >> 29; - padded[252] = bytes >> 21; - padded[253] = bytes >> 13; - padded[254] = bytes >> 5; - padded[255] = bytes << 3; + padded[247] = (uint8_t) (bytes >> 61); + padded[248] = (uint8_t) (bytes >> 53); + padded[249] = (uint8_t) (bytes >> 45); + padded[250] = (uint8_t) (bytes >> 37); + padded[251] = (uint8_t) (bytes >> 29); + padded[252] = (uint8_t) (bytes >> 21); + padded[253] = (uint8_t) (bytes >> 13); + padded[254] = (uint8_t) (bytes >> 5); + padded[255] = (uint8_t) (bytes << 3); blocks(h, padded, 256); } From ea19211d2148ef9ef790b9892d831479056f919d Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Wed, 27 Feb 2019 17:06:27 +0100 Subject: [PATCH 3/5] Cast size_t to DWORD on Windows --- common/randombytes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/randombytes.c b/common/randombytes.c index 0ffd74ee..82f2107c 100644 --- a/common/randombytes.c +++ b/common/randombytes.c @@ -90,7 +90,7 @@ static int randombytes_win32_randombytes(void *buf, const size_t n) { return -1; } - tmp = CryptGenRandom(ctx, n, (BYTE *)buf); + tmp = CryptGenRandom(ctx, (DWORD)n, (BYTE *)buf); if (tmp == FALSE) { return -1; } From 58aba49ca2e8a6067e9bbed2c84dbef52d525575 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Wed, 27 Feb 2019 17:08:59 +0100 Subject: [PATCH 4/5] take out assignment in conditional because windows is not happy about it --- test/crypto_sign/functest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/crypto_sign/functest.c b/test/crypto_sign/functest.c index 014b0542..41ab091a 100644 --- a/test/crypto_sign/functest.c +++ b/test/crypto_sign/functest.c @@ -114,9 +114,9 @@ static int test_wrong_pk(void) { // By relying on m == sm we prevent having to allocate CRYPTO_BYTES // twice - if (!(returncode = crypto_sign_open(sm, &mlen, sm, smlen, pk2))) { - printf("ERROR Signature did verify correctly under wrong public " - "key!\n"); + returncode = crypto_sign_open(sm, &mlen, sm, smlen, pk2); + if (!returncode) { + printf("ERROR Signature did verify correctly under wrong public key!\n"); if (returncode > 0) { puts("ERROR return code should be < 0"); } From b7bc9b6cb028d8bb7dfdfe90939e3e6d90682486 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Wed, 27 Feb 2019 17:18:07 +0100 Subject: [PATCH 5/5] Cast a value in notrandombytes.c --- common/notrandombytes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/notrandombytes.c b/common/notrandombytes.c index f8145026..6b2b8529 100644 --- a/common/notrandombytes.c +++ b/common/notrandombytes.c @@ -70,7 +70,7 @@ int randombytes(uint8_t *buf, size_t xlen) { surf(); outleft = 8; } - *buf = out[--outleft]; + *buf = (uint8_t) out[--outleft]; ++buf; --xlen; }