diff --git a/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c b/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c index 6c235f3d..989c8650 100644 --- a/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +++ b/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c @@ -12,6 +12,7 @@ #include "crypto_aead_aes256gcm.h" #include "export.h" +#include "private/common.h" #include "randombytes.h" #include "runtime.h" #include "utils.h" @@ -480,7 +481,7 @@ crypto_aead_aes256gcm_beforenm(crypto_aead_aes256gcm_state *ctx_, __m128i zero = _mm_setzero_si128(); unsigned char *H = ctx->H; - (void) sizeof(int[(sizeof *ctx_) >= (sizeof *ctx) ? 1 : -1]); + COMPILER_ASSERT((sizeof *ctx_) >= (sizeof *ctx)); aesni_key256_expand(k, rkeys); aesni_encrypt1(H, zero, rkeys); diff --git a/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c b/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c index cbab7d59..406dcf25 100644 --- a/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +++ b/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c @@ -196,7 +196,7 @@ crypto_aead_chacha20poly1305_decrypt_detached(unsigned char *m, crypto_onetimeauth_poly1305_final(&state, computed_mac); sodium_memzero(&state, sizeof state); - (void) sizeof(int[sizeof computed_mac == 16U ? 1 : -1]); + COMPILER_ASSERT(sizeof computed_mac == 16U); ret = crypto_verify_16(computed_mac, mac); sodium_memzero(computed_mac, sizeof computed_mac); if (m == NULL) { @@ -280,7 +280,7 @@ crypto_aead_chacha20poly1305_ietf_decrypt_detached(unsigned char *m, crypto_onetimeauth_poly1305_final(&state, computed_mac); sodium_memzero(&state, sizeof state); - (void) sizeof(int[sizeof computed_mac == 16U ? 1 : -1]); + COMPILER_ASSERT(sizeof computed_mac == 16U); ret = crypto_verify_16(computed_mac, mac); sodium_memzero(computed_mac, sizeof computed_mac); if (m == NULL) { diff --git a/src/libsodium/crypto_box/crypto_box_easy.c b/src/libsodium/crypto_box/crypto_box_easy.c index 04e1f138..364a359c 100644 --- a/src/libsodium/crypto_box/crypto_box_easy.c +++ b/src/libsodium/crypto_box/crypto_box_easy.c @@ -5,6 +5,7 @@ #include "crypto_box.h" #include "crypto_secretbox.h" +#include "private/common.h" #include "utils.h" int @@ -24,8 +25,7 @@ crypto_box_detached(unsigned char *c, unsigned char *mac, unsigned char k[crypto_box_BEFORENMBYTES]; int ret; - (void) sizeof(int[crypto_box_BEFORENMBYTES >= - crypto_secretbox_KEYBYTES ? 1 : -1]); + COMPILER_ASSERT(crypto_box_BEFORENMBYTES >= crypto_secretbox_KEYBYTES); if (crypto_box_beforenm(k, pk, sk) != 0) { return -1; } diff --git a/src/libsodium/crypto_box/crypto_box_seal.c b/src/libsodium/crypto_box/crypto_box_seal.c index 64cc5ff6..71813345 100644 --- a/src/libsodium/crypto_box/crypto_box_seal.c +++ b/src/libsodium/crypto_box/crypto_box_seal.c @@ -3,6 +3,7 @@ #include "crypto_box.h" #include "crypto_generichash.h" +#include "private/common.h" #include "utils.h" static int @@ -54,7 +55,7 @@ crypto_box_seal_open(unsigned char *m, const unsigned char *c, } _crypto_box_seal_nonce(nonce, c, pk); - (void) sizeof(int[crypto_box_PUBLICKEYBYTES < crypto_box_SEALBYTES ? 1 : -1]); + COMPILER_ASSERT(crypto_box_PUBLICKEYBYTES < crypto_box_SEALBYTES); return crypto_box_open_easy(m, c + crypto_box_PUBLICKEYBYTES, clen - crypto_box_PUBLICKEYBYTES, nonce, c, sk); diff --git a/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c b/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c index 79583241..f71173f5 100644 --- a/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c +++ b/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c @@ -9,6 +9,7 @@ #include "crypto_hash_sha512.h" #include "crypto_secretbox_xchacha20poly1305.h" #include "crypto_scalarmult_curve25519.h" +#include "private/common.h" #include "randombytes.h" #include "utils.h" @@ -73,9 +74,8 @@ crypto_box_curve25519xchacha20poly1305_detached(unsigned char *c, unsigned char k[crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES]; int ret; - (void) sizeof(int[crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES - >= crypto_secretbox_xchacha20poly1305_KEYBYTES ? - 1 : -1]); + COMPILER_ASSERT(crypto_box_curve25519xchacha20poly1305_BEFORENMBYTES + >= crypto_secretbox_xchacha20poly1305_KEYBYTES); if (crypto_box_curve25519xchacha20poly1305_beforenm(k, pk, sk) != 0) { return -1; } diff --git a/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c b/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c index 6f26d88f..15d783a4 100644 --- a/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c +++ b/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c @@ -174,7 +174,7 @@ blake2b_init_param(blake2b_state *S, const blake2b_param *P) size_t i; const uint8_t *p; - (void) sizeof(int[sizeof *P == 64 ? 1 : -1]); + COMPILER_ASSERT(sizeof *P == 64); blake2b_init0(S); p = (const uint8_t *) (P); diff --git a/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c b/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c index aa83d974..a71e3020 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c @@ -1,6 +1,7 @@ #include "poly1305_donna.h" #include "crypto_verify_16.h" +#include "private/common.h" #include "utils.h" #ifdef HAVE_TI_MODE @@ -72,10 +73,8 @@ static int crypto_onetimeauth_poly1305_donna_init(crypto_onetimeauth_poly1305_state *state, const unsigned char * key) { - (void) sizeof(int[sizeof(crypto_onetimeauth_poly1305_state) >= - sizeof(poly1305_state_internal_t) - ? 1 - : -1]); + COMPILER_ASSERT(sizeof(crypto_onetimeauth_poly1305_state) >= + sizeof(poly1305_state_internal_t)); poly1305_init((poly1305_state_internal_t *) (void *) state, key); return 0; diff --git a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c index 008c680b..082aaec5 100644 --- a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +++ b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c @@ -9,6 +9,7 @@ #include "crypto_onetimeauth_poly1305.h" #include "crypto_secretbox.h" #include "crypto_stream_salsa20.h" +#include "private/common.h" #include "utils.h" int @@ -33,7 +34,7 @@ crypto_secretbox_detached(unsigned char *c, unsigned char *mac, m = c; } memset(block0, 0U, crypto_secretbox_ZEROBYTES); - (void) sizeof(int[64U >= crypto_secretbox_ZEROBYTES ? 1 : -1]); + COMPILER_ASSERT(64U >= crypto_secretbox_ZEROBYTES); mlen0 = mlen; if (mlen0 > 64U - crypto_secretbox_ZEROBYTES) { mlen0 = 64U - crypto_secretbox_ZEROBYTES; @@ -44,8 +45,8 @@ crypto_secretbox_detached(unsigned char *c, unsigned char *mac, crypto_stream_salsa20_xor(block0, block0, mlen0 + crypto_secretbox_ZEROBYTES, n + 16, subkey); - (void) sizeof(int[crypto_secretbox_ZEROBYTES >= - crypto_onetimeauth_poly1305_KEYBYTES ? 1 : -1]); + COMPILER_ASSERT(crypto_secretbox_ZEROBYTES >= + crypto_onetimeauth_poly1305_KEYBYTES); crypto_onetimeauth_poly1305_init(&state, block0); for (i = 0U; i < mlen0; i++) { diff --git a/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c b/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c index 445dff0d..47852457 100644 --- a/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c +++ b/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c @@ -9,6 +9,7 @@ #include "crypto_onetimeauth_poly1305.h" #include "crypto_secretbox_xchacha20poly1305.h" #include "crypto_stream_chacha20.h" +#include "private/common.h" #include "utils.h" #define crypto_secretbox_xchacha20poly1305_ZEROBYTES 32U @@ -37,8 +38,7 @@ crypto_secretbox_xchacha20poly1305_detached(unsigned char *c, m = c; } memset(block0, 0U, crypto_secretbox_xchacha20poly1305_ZEROBYTES); - (void) sizeof(int[64U >= crypto_secretbox_xchacha20poly1305_ZEROBYTES ? - 1 : -1]); + COMPILER_ASSERT(64U >= crypto_secretbox_xchacha20poly1305_ZEROBYTES); mlen0 = mlen; if (mlen0 > 64U - crypto_secretbox_xchacha20poly1305_ZEROBYTES) { mlen0 = 64U - crypto_secretbox_xchacha20poly1305_ZEROBYTES; @@ -49,8 +49,8 @@ crypto_secretbox_xchacha20poly1305_detached(unsigned char *c, crypto_stream_chacha20_xor(block0, block0, mlen0 + crypto_secretbox_xchacha20poly1305_ZEROBYTES, n + 16, subkey); - (void) sizeof(int[crypto_secretbox_xchacha20poly1305_ZEROBYTES >= - crypto_onetimeauth_poly1305_KEYBYTES ? 1 : -1]); + COMPILER_ASSERT(crypto_secretbox_xchacha20poly1305_ZEROBYTES >= + crypto_onetimeauth_poly1305_KEYBYTES); crypto_onetimeauth_poly1305_init(&state, block0); for (i = 0U; i < mlen0; i++) { diff --git a/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c b/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c index 76cfee99..52b710d1 100644 --- a/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +++ b/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c @@ -9,12 +9,13 @@ #include #include -#include "../stream_chacha20.h" #include "crypto_stream_chacha20.h" #include "private/common.h" -#include "stream_chacha20_ref.h" #include "utils.h" +#include "../stream_chacha20.h" +#include "stream_chacha20_ref.h" + struct chacha_ctx { uint32_t input[16]; }; @@ -232,7 +233,7 @@ stream_ref(unsigned char *c, unsigned long long clen, const unsigned char *n, if (!clen) { return 0; } - (void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]); + COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8); chacha_keysetup(&ctx, k); chacha_ivsetup(&ctx, n, NULL); memset(c, 0, clen); @@ -251,7 +252,7 @@ stream_ietf_ref(unsigned char *c, unsigned long long clen, if (!clen) { return 0; } - (void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]); + COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8); chacha_keysetup(&ctx, k); chacha_ietf_ivsetup(&ctx, n, NULL); memset(c, 0, clen); diff --git a/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c b/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c index c18885e7..578b6b3e 100644 --- a/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c +++ b/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c @@ -3,9 +3,11 @@ #include #include -#include "export.h" -#include "utils.h" #include "crypto_stream_chacha20.h" +#include "export.h" +#include "private/common.h" +#include "utils.h" + #include "stream_chacha20_vec.h" #include "../stream_chacha20.h" @@ -258,7 +260,7 @@ stream_vec(unsigned char *c, unsigned long long clen, if (!clen) { return 0; } - (void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]); + COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8); chacha_keysetup(&ctx, k); chacha_ivsetup(&ctx, n, 0ULL); memset(c, 0, clen); @@ -277,7 +279,7 @@ stream_ietf_vec(unsigned char *c, unsigned long long clen, if (!clen) { return 0; } - (void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]); + COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES == 256 / 8); chacha_keysetup(&ctx, k); chacha_ietf_ivsetup(&ctx, n, 0ULL); memset(c, 0, clen);