mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-29 18:27:29 +02:00
Added compile-time check for DRBG size. Added support for all build variations DRBG size.
This commit is contained in:
@ -274,7 +274,7 @@ enum {
|
||||
drbgInitV
|
||||
};
|
||||
|
||||
|
||||
/* NOTE: if DRBG struct is changed please update random.h drbg_data size */
|
||||
typedef struct DRBG {
|
||||
word32 reseedCtr;
|
||||
word32 lastBlock;
|
||||
@ -758,6 +758,10 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
|
||||
(struct DRBG*)XMALLOC(sizeof(DRBG), rng->heap,
|
||||
DYNAMIC_TYPE_RNG);
|
||||
#else
|
||||
/* compile-time validation of drbg_data size */
|
||||
typedef char drbg_data_test[sizeof(rng->drbg_data) >=
|
||||
sizeof(struct DRBG) ? 1 : -1];
|
||||
(void)sizeof(drbg_data_test);
|
||||
rng->drbg = (struct DRBG*)rng->drbg_data;
|
||||
#endif
|
||||
|
||||
|
@ -157,8 +157,18 @@ struct WC_RNG {
|
||||
/* Hash-based Deterministic Random Bit Generator */
|
||||
struct DRBG* drbg;
|
||||
#if defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_STATIC_MEMORY)
|
||||
#define DRBG_STRUCT_SZ ((sizeof(word32)*2) + (DRBG_SEED_LEN*2) + sizeof(byte))
|
||||
byte drbg_data[DRBG_STRUCT_SZ];
|
||||
#define DRBG_STRUCT_SZ ((sizeof(word32)*3) + (DRBG_SEED_LEN*2))
|
||||
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||
#define DRBG_STRUCT_SZ_SHA256 (sizeof(wc_Sha256))
|
||||
#else
|
||||
#define DRBG_STRUCT_SZ_SHA256 0
|
||||
#endif
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
|
||||
#define DRBG_STRUCT_SZ_ASYNC (sizeof(void*) + sizeof(int))
|
||||
#else
|
||||
#define DRBG_STRUCT_SZ_ASYNC 0
|
||||
#endif
|
||||
byte drbg_data[DRBG_STRUCT_SZ + DRBG_STRUCT_SZ_SHA256 + DRBG_STRUCT_SZ_ASYNC];
|
||||
#endif
|
||||
byte status;
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user