mirror of https://github.com/wolfSSL/wolfssl.git
Merge pull request #8044 from douzzer/20241004-wc_static_assert
20241004-wc_static_assertpull/8046/head
commit
c230e10f4a
|
@ -71,7 +71,7 @@ typedef struct Dtls13HandshakeHeader {
|
||||||
byte fragmentLength[3];
|
byte fragmentLength[3];
|
||||||
} Dtls13HandshakeHeader;
|
} Dtls13HandshakeHeader;
|
||||||
|
|
||||||
static_assert(sizeof(Dtls13HandshakeHeader) == DTLS13_HANDSHAKE_HEADER_SZ);
|
wc_static_assert(sizeof(Dtls13HandshakeHeader) == DTLS13_HANDSHAKE_HEADER_SZ);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct Dtls13Recordplaintextheader: represent header of unprotected DTLSv1.3
|
* struct Dtls13Recordplaintextheader: represent header of unprotected DTLSv1.3
|
||||||
|
|
|
@ -2923,8 +2923,7 @@ void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* in, WOLFSSL_DES_cblock* out,
|
||||||
static int wolfssl_aes_set_key(const unsigned char *key, const int bits,
|
static int wolfssl_aes_set_key(const unsigned char *key, const int bits,
|
||||||
AES_KEY *aes, int enc)
|
AES_KEY *aes, int enc)
|
||||||
{
|
{
|
||||||
typedef char aes_test[sizeof(AES_KEY) >= sizeof(Aes) ? 1 : -1];
|
wc_static_assert(sizeof(AES_KEY) >= sizeof(Aes));
|
||||||
(void)sizeof(aes_test);
|
|
||||||
|
|
||||||
/* Validate parameters. */
|
/* Validate parameters. */
|
||||||
if ((key == NULL) || (aes == NULL)) {
|
if ((key == NULL) || (aes == NULL)) {
|
||||||
|
@ -3438,8 +3437,7 @@ size_t wolfSSL_CRYPTO_cts128_decrypt(const unsigned char *in,
|
||||||
void wolfSSL_RC4_set_key(WOLFSSL_RC4_KEY* key, int len,
|
void wolfSSL_RC4_set_key(WOLFSSL_RC4_KEY* key, int len,
|
||||||
const unsigned char* data)
|
const unsigned char* data)
|
||||||
{
|
{
|
||||||
typedef char rc4_test[sizeof(WOLFSSL_RC4_KEY) >= sizeof(Arc4) ? 1 : -1];
|
wc_static_assert(sizeof(WOLFSSL_RC4_KEY) >= sizeof(Arc4));
|
||||||
(void)sizeof(rc4_test);
|
|
||||||
|
|
||||||
WOLFSSL_ENTER("wolfSSL_RC4_set_key");
|
WOLFSSL_ENTER("wolfSSL_RC4_set_key");
|
||||||
|
|
||||||
|
|
|
@ -10495,6 +10495,9 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
|
||||||
const WOLFSSL_EVP_MD* md)
|
const WOLFSSL_EVP_MD* md)
|
||||||
{
|
{
|
||||||
int ret = WOLFSSL_SUCCESS;
|
int ret = WOLFSSL_SUCCESS;
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
wc_static_assert(WC_ASYNC_DEV_SIZE >= sizeof(WC_ASYNC_DEV));
|
||||||
|
#endif
|
||||||
|
|
||||||
WOLFSSL_ENTER("EVP_DigestInit");
|
WOLFSSL_ENTER("EVP_DigestInit");
|
||||||
|
|
||||||
|
@ -10502,14 +10505,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
|
||||||
/* compile-time validation of ASYNC_CTX_SIZE */
|
|
||||||
typedef char async_test[WC_ASYNC_DEV_SIZE >= sizeof(WC_ASYNC_DEV) ?
|
|
||||||
1 : -1];
|
|
||||||
(void)sizeof(async_test);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set to 0 if no match */
|
/* Set to 0 if no match */
|
||||||
ctx->macType = EvpMd2MacType(md);
|
ctx->macType = EvpMd2MacType(md);
|
||||||
if (md == NULL) {
|
if (md == NULL) {
|
||||||
|
|
|
@ -841,11 +841,11 @@ static void render_error_message(const char* msg, wc_test_ret_t es)
|
||||||
* stores an error string in the supplied buffer. this is all most
|
* stores an error string in the supplied buffer. this is all most
|
||||||
* infelicitous...
|
* infelicitous...
|
||||||
*/
|
*/
|
||||||
#if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
|
#if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
|
||||||
(defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199901L)) && \
|
(defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199901L)) && \
|
||||||
((defined(__GLIBC__) && (__GLIBC__ >= 2)) || \
|
((defined(__GLIBC__) && (__GLIBC__ >= 2) && defined(__USE_GNU)) || \
|
||||||
(defined(__USE_XOPEN2K) && \
|
(defined(__USE_XOPEN2K) && \
|
||||||
defined(_POSIX_C_SOURCE) && \
|
defined(_POSIX_C_SOURCE) && \
|
||||||
(_POSIX_C_SOURCE >= 200112L)))
|
(_POSIX_C_SOURCE >= 200112L)))
|
||||||
|
|
||||||
char errno_buf[64], *errno_string;
|
char errno_buf[64], *errno_string;
|
||||||
|
|
|
@ -2071,18 +2071,9 @@ enum Misc {
|
||||||
|
|
||||||
#define MAX_ENCRYPT_SZ ENCRYPT_LEN
|
#define MAX_ENCRYPT_SZ ENCRYPT_LEN
|
||||||
|
|
||||||
/* A static check to assert a relation between x and y */
|
#define WOLFSSL_ASSERT_EQ(x, y) wc_static_assert((x) == (y))
|
||||||
#define WOLFSSL_ASSERT_TEST(x, y, op) do { \
|
|
||||||
typedef char _args_test_[(x) op (y) ? 1 : -1]; \
|
|
||||||
(void)sizeof(_args_test_); \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
#define WOLFSSL_ASSERT_EQ(x, y) WOLFSSL_ASSERT_TEST(x, y, ==)
|
#define WOLFSSL_ASSERT_SIZEOF_GE(x, y) wc_static_assert(sizeof(x) >= sizeof(y))
|
||||||
|
|
||||||
#define WOLFSSL_ASSERT_SIZEOF_TEST(x, y, op) \
|
|
||||||
WOLFSSL_ASSERT_TEST(sizeof(x), sizeof(y), op)
|
|
||||||
|
|
||||||
#define WOLFSSL_ASSERT_SIZEOF_GE(x, y) WOLFSSL_ASSERT_SIZEOF_TEST(x, y, >=)
|
|
||||||
|
|
||||||
/* states. Adding state before HANDSHAKE_DONE will break session importing */
|
/* states. Adding state before HANDSHAKE_DONE will break session importing */
|
||||||
enum states {
|
enum states {
|
||||||
|
|
|
@ -20,24 +20,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ************************************************************************
|
* Note, this file should not be edited to activate/deactivate features.
|
||||||
*
|
*
|
||||||
* ******************************** NOTICE ********************************
|
* Instead, add/edit user_settings.h, and compile with -DWOLFSSL_USER_SETTINGS
|
||||||
*
|
|
||||||
* ************************************************************************
|
|
||||||
*
|
|
||||||
* This method of uncommenting a line in settings.h is outdated.
|
|
||||||
*
|
|
||||||
* Please use user_settings.h / WOLFSSL_USER_SETTINGS
|
|
||||||
*
|
*
|
||||||
* or
|
* or
|
||||||
*
|
*
|
||||||
* ./configure CFLAGS="-DFLAG"
|
* ./configure CFLAGS="-DFEATURE_FLAG_TO_DEFINE -UFEATURE_FLAG_TO_CLEAR [...]"
|
||||||
*
|
*
|
||||||
* For more information see:
|
* For more information see:
|
||||||
*
|
*
|
||||||
* https://www.wolfssl.com/how-do-i-manage-the-build-configuration-of-wolfssl/
|
* https://www.wolfssl.com/how-do-i-manage-the-build-configuration-of-wolfssl/
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1695,13 +1695,25 @@ typedef struct w64wrapper {
|
||||||
|
|
||||||
#define WC_CPP_CAT_(a, b) a ## b
|
#define WC_CPP_CAT_(a, b) a ## b
|
||||||
#define WC_CPP_CAT(a, b) WC_CPP_CAT_(a, b)
|
#define WC_CPP_CAT(a, b) WC_CPP_CAT_(a, b)
|
||||||
#if (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
|
#if defined(WC_NO_STATIC_ASSERT)
|
||||||
(defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))
|
#define wc_static_assert(expr) struct wc_static_assert_dummy_struct
|
||||||
#ifndef static_assert2
|
#define wc_static_assert2(expr, msg) wc_static_assert(expr)
|
||||||
#define static_assert2 static_assert
|
#elif !defined(wc_static_assert)
|
||||||
#endif
|
#if (defined(__cplusplus) && (__cplusplus >= 201703L)) || \
|
||||||
#elif !defined(static_assert)
|
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)) || \
|
||||||
#if !defined(__cplusplus) && \
|
(defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))
|
||||||
|
/* native variadic static_assert() */
|
||||||
|
#define wc_static_assert static_assert
|
||||||
|
#ifndef wc_static_assert2
|
||||||
|
#define wc_static_assert2 static_assert
|
||||||
|
#endif
|
||||||
|
#elif defined(_MSC_VER) && (__STDC_VERSION__ >= 201112L)
|
||||||
|
/* native 2-argument static_assert() */
|
||||||
|
#define wc_static_assert(expr) static_assert(expr, #expr)
|
||||||
|
#ifndef wc_static_assert2
|
||||||
|
#define wc_static_assert2(expr, msg) static_assert(expr, msg)
|
||||||
|
#endif
|
||||||
|
#elif !defined(__cplusplus) && \
|
||||||
!defined(__STRICT_ANSI__) && \
|
!defined(__STRICT_ANSI__) && \
|
||||||
!defined(WOLF_C89) && \
|
!defined(WOLF_C89) && \
|
||||||
defined(__STDC_VERSION__) && \
|
defined(__STDC_VERSION__) && \
|
||||||
|
@ -1709,19 +1721,23 @@ typedef struct w64wrapper {
|
||||||
((defined(__GNUC__) && \
|
((defined(__GNUC__) && \
|
||||||
(__GNUC__ >= 5)) || \
|
(__GNUC__ >= 5)) || \
|
||||||
defined(__clang__))
|
defined(__clang__))
|
||||||
#define static_assert(expr) _Static_assert(expr, #expr)
|
/* native 2-argument _Static_assert() */
|
||||||
#ifndef static_assert2
|
#define wc_static_assert(expr) _Static_assert(expr, #expr)
|
||||||
#define static_assert2(expr, msg) _Static_assert(expr, msg)
|
#ifndef wc_static_assert2
|
||||||
|
#define wc_static_assert2(expr, msg) _Static_assert(expr, msg)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define static_assert(expr) \
|
/* C89-compatible fallback */
|
||||||
struct WC_CPP_CAT(wc_dummy_struct_L, __LINE__)
|
#define wc_static_assert(expr) \
|
||||||
#ifndef static_assert2
|
struct WC_CPP_CAT(wc_static_assert_dummy_struct_L, __LINE__) { \
|
||||||
#define static_assert2(expr, msg) static_assert(expr)
|
char t[(expr) ? 1 : -1]; \
|
||||||
|
}
|
||||||
|
#ifndef wc_static_assert2
|
||||||
|
#define wc_static_assert2(expr, msg) wc_static_assert(expr)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#elif !defined(static_assert2)
|
#elif !defined(wc_static_assert2)
|
||||||
#define static_assert2(expr, msg) static_assert(expr)
|
#define wc_static_assert2(expr, msg) wc_static_assert(expr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SAVE_VECTOR_REGISTERS
|
#ifndef SAVE_VECTOR_REGISTERS
|
||||||
|
|
Loading…
Reference in New Issue