@@ -225,79 +225,6 @@ This library contains implementation for the random number generator.
225225#define OUTPUT_BLOCK_LEN (WC_SHA256_DIGEST_SIZE)
226226#define MAX_REQUEST_LEN (0x10000)
227227
228-
229- /* The security strength for the RNG is the target number of bits of
230- * entropy you are looking for in a seed. */
231- #ifndef RNG_SECURITY_STRENGTH
232- /* SHA-256 requires a minimum of 256-bits of entropy. */
233- #define RNG_SECURITY_STRENGTH (256)
234- #endif
235-
236- /* wolfentropy.h will define for HAVE_ENTROPY_MEMUSE */
237- #ifdef HAVE_ENTROPY_MEMUSE
238- #include <wolfssl/wolfcrypt/wolfentropy.h>
239- #endif
240-
241- #ifndef ENTROPY_SCALE_FACTOR
242- /* The entropy scale factor should be the whole number inverse of the
243- * minimum bits of entropy per bit of NDRNG output. */
244- #if defined(HAVE_AMD_RDSEED )
245- /* This will yield a SEED_SZ of 16kb. Since nonceSz will be 0,
246- * we'll add an additional 8kb on top.
247- *
248- * See "AMD RNG ESV Public Use Document". Version 0.7 of October 24,
249- * 2024 specifies 0.656 to 1.312 bits of entropy per 128 bit block of
250- * RDSEED output, depending on CPU family.
251- */
252- #define ENTROPY_SCALE_FACTOR (512)
253- #elif defined(HAVE_INTEL_RDSEED ) || defined(HAVE_INTEL_RDRAND )
254- /* The value of 2 applies to Intel's RDSEED which provides about
255- * 0.5 bits minimum of entropy per bit. The value of 4 gives a
256- * conservative margin for FIPS. */
257- #if defined(HAVE_FIPS ) && defined(HAVE_FIPS_VERSION ) && \
258- (HAVE_FIPS_VERSION >= 2 )
259- #define ENTROPY_SCALE_FACTOR (2*4)
260- #else
261- /* Not FIPS, but Intel RDSEED, only double. */
262- #define ENTROPY_SCALE_FACTOR (2)
263- #endif
264- #elif defined(HAVE_FIPS ) && defined(HAVE_FIPS_VERSION ) && \
265- (HAVE_FIPS_VERSION >= 2 )
266- /* If doing a FIPS build without a specific scale factor, default
267- * to 4. This will give 1024 bits of entropy. More is better, but
268- * more is also slower. */
269- #define ENTROPY_SCALE_FACTOR (4)
270- #else
271- /* Setting the default to 1. */
272- #define ENTROPY_SCALE_FACTOR (1)
273- #endif
274- #endif /* !ENTROPY_SCALE_FACTOR */
275-
276- #ifndef SEED_BLOCK_SZ
277- /* The seed block size, is the size of the output of the underlying NDRNG.
278- * This value is used for testing the output of the NDRNG. */
279- #if defined(HAVE_AMD_RDSEED )
280- /* AMD's RDSEED instruction works in 128-bit blocks read 64-bits
281- * at a time. */
282- #define SEED_BLOCK_SZ (sizeof(word64)*2)
283- #elif defined(HAVE_INTEL_RDSEED ) || defined(HAVE_INTEL_RDRAND )
284- /* RDSEED outputs in blocks of 64-bits. */
285- #define SEED_BLOCK_SZ sizeof(word64)
286- #else
287- /* Setting the default to 4. */
288- #define SEED_BLOCK_SZ 4
289- #endif
290- #endif
291-
292- #define SEED_SZ (RNG_SECURITY_STRENGTH*ENTROPY_SCALE_FACTOR/8)
293-
294- /* The maximum seed size will be the seed size plus a seed block for the
295- * test, and an additional half of the seed size. This additional half
296- * is in case the user does not supply a nonce. A nonce will be obtained
297- * from the NDRNG. */
298- #define MAX_SEED_SZ (SEED_SZ + SEED_SZ/2 + SEED_BLOCK_SZ)
299-
300-
301228#ifdef WC_RNG_SEED_CB
302229
303230#ifndef HAVE_FIPS
@@ -323,12 +250,13 @@ int wc_SetSeed_Cb(wc_RngSeed_Cb cb)
323250#define DRBG_NO_SEED_CB 4
324251
325252/* RNG health states */
326- #define DRBG_NOT_INIT 0
327- #define DRBG_OK 1
328- #define DRBG_FAILED 2
329- #define DRBG_CONT_FAILED 3
253+ #define DRBG_NOT_INIT WC_DRBG_NOT_INIT
254+ #define DRBG_OK WC_DRBG_OK
255+ #define DRBG_FAILED WC_DRBG_FAILED
256+ #define DRBG_CONT_FAILED WC_DRBG_CONT_FAILED
330257
331- #define RNG_HEALTH_TEST_CHECK_SIZE (WC_SHA256_DIGEST_SIZE * 4)
258+ #define SEED_SZ WC_DRBG_SEED_SZ
259+ #define MAX_SEED_SZ WC_DRBG_MAX_SEED_SZ
332260
333261/* Verify max gen block len */
334262#if RNG_MAX_BLOCK_LEN > MAX_REQUEST_LEN
0 commit comments