mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Leverage COMPILER_ASSERT
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
+3
-3
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user