add overrideable HAVE_ANONYMOUS_INLINE_AGGREGATES macro, set to 0 or 1 in wolfcrypt/types.h, and use it to conditionalize feature usage in wolfcrypt/cryptocb.h.

This commit is contained in:
Daniel Pouzzner
2021-08-05 15:30:16 -05:00
parent 3e894a9804
commit 6a92db7722
3 changed files with 34 additions and 0 deletions

View File

@ -75,10 +75,15 @@
/* Crypto Information Structure for callbacks */ /* Crypto Information Structure for callbacks */
typedef struct wc_CryptoInfo { typedef struct wc_CryptoInfo {
int algo_type; /* enum wc_AlgoType */ int algo_type; /* enum wc_AlgoType */
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
union {
#endif
#if !defined(NO_RSA) || defined(HAVE_ECC) #if !defined(NO_RSA) || defined(HAVE_ECC)
struct { struct {
int type; /* enum wc_PkType */ int type; /* enum wc_PkType */
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
union { union {
#endif
#ifndef NO_RSA #ifndef NO_RSA
struct { struct {
const byte* in; const byte* in;
@ -182,14 +187,18 @@ typedef struct wc_CryptoInfo {
byte contextLen; byte contextLen;
} ed25519verify; } ed25519verify;
#endif #endif
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
}; };
#endif
} pk; } pk;
#endif /* !NO_RSA || HAVE_ECC */ #endif /* !NO_RSA || HAVE_ECC */
#if !defined(NO_AES) || !defined(NO_DES3) #if !defined(NO_AES) || !defined(NO_DES3)
struct { struct {
int type; /* enum wc_CipherType */ int type; /* enum wc_CipherType */
int enc; int enc;
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
union { union {
#endif
#ifdef HAVE_AESGCM #ifdef HAVE_AESGCM
struct { struct {
Aes* aes; Aes* aes;
@ -232,7 +241,9 @@ typedef struct wc_CryptoInfo {
word32 sz; word32 sz;
} des3; } des3;
#endif #endif
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
}; };
#endif
} cipher; } cipher;
#endif /* !NO_AES || !NO_DES3 */ #endif /* !NO_AES || !NO_DES3 */
#if !defined(NO_SHA) || !defined(NO_SHA256) || \ #if !defined(NO_SHA) || !defined(NO_SHA256) || \
@ -242,7 +253,9 @@ typedef struct wc_CryptoInfo {
const byte* in; const byte* in;
word32 inSz; word32 inSz;
byte* digest; byte* digest;
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
union { union {
#endif
#ifndef NO_SHA #ifndef NO_SHA
wc_Sha* sha1; wc_Sha* sha1;
#endif #endif
@ -255,7 +268,9 @@ typedef struct wc_CryptoInfo {
#ifdef WOLFSSL_SHA512 #ifdef WOLFSSL_SHA512
wc_Sha512* sha512; wc_Sha512* sha512;
#endif #endif
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
}; };
#endif
} hash; } hash;
#endif /* !NO_SHA || !NO_SHA256 */ #endif /* !NO_SHA || !NO_SHA256 */
#ifndef NO_HMAC #ifndef NO_HMAC
@ -292,6 +307,9 @@ typedef struct wc_CryptoInfo {
int type; int type;
} cmac; } cmac;
#endif #endif
#if HAVE_ANONYMOUS_INLINE_AGGREGATES
};
#endif
} wc_CryptoInfo; } wc_CryptoInfo;

View File

@ -95,6 +95,17 @@ decouple library dependencies with standard string, memory and so on.
typedef const char* const wcchar; typedef const char* const wcchar;
#endif #endif
#ifndef HAVE_ANONYMOUS_INLINE_AGGREGATES
/* if __STDC__, pivot on the version, otherwise guess it's allowed,
* subject to override.
*/
#if !defined(__STDC__) \
|| (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201101L))
#define HAVE_ANONYMOUS_INLINE_AGGREGATES 1
#else
#define HAVE_ANONYMOUS_INLINE_AGGREGATES 0
#endif
#endif
/* try to set SIZEOF_LONG or SIZEOF_LONG_LONG if user didn't */ /* try to set SIZEOF_LONG or SIZEOF_LONG_LONG if user didn't */
#if defined(_MSC_VER) || defined(HAVE_LIMITS_H) #if defined(_MSC_VER) || defined(HAVE_LIMITS_H)

View File

@ -130,6 +130,11 @@
_Pragma("GCC diagnostic pop"); _Pragma("GCC diagnostic pop");
/* the kernel uses -std=c89, but not -pedantic, and makes full use of anon
* structs/unions, so we should too.
*/
#define HAVE_ANONYMOUS_INLINE_AGGREGATES 1
/* Linux headers define these using C expressions, but we need /* Linux headers define these using C expressions, but we need
* them to be evaluable by the preprocessor, for use in sp_int.h. * them to be evaluable by the preprocessor, for use in sp_int.h.
*/ */