Skip to content

Commit 11c53ab

Browse files
committed
random.c: fix fips v7 define guards.
1 parent 0913436 commit 11c53ab

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

wolfcrypt/src/random.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,17 @@ static int Hash512_DRBG_Uninstantiate(DRBG_SHA512_internal* drbg);
367367
* calls cannot bypass the mutual-exclusion guard and disable both DRBG types.
368368
* _InitRng also holds the mutex while reading the flags to get a consistent
369369
* snapshot, and returns BAD_STATE_E if both are somehow disabled. */
370+
#if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
370371
#ifndef NO_SHA256
371372
#ifdef WOLFSSL_NO_SHA256_DRBG
372373
static int sha256DrbgDisabled = 1;
373374
#else
374375
static int sha256DrbgDisabled = 0;
375-
#endif
376-
#endif
376+
#endif /* WOLFSSL_NO_SHA256_DRBG */
377+
#endif /* !NO_SHA256 */
377378
#ifdef WOLFSSL_DRBG_SHA512
378379
static int sha512DrbgDisabled = 0;
379-
#endif
380+
#endif /* WOLFSSL_DRBG_SHA512 */
380381

381382
#ifndef SINGLE_THREADED
382383
static wolfSSL_Mutex drbgStateMutex
@@ -433,6 +434,8 @@ static int UnlockDrbgState(void)
433434
#endif
434435
}
435436

437+
#endif /* !HAVE_SELFTEST && (!HAVE_FIPS || FIPS v7+) */
438+
436439
static int wc_RNG_HealthTestLocal(WC_RNG* rng, int reseed, void* heap,
437440
int devId);
438441

@@ -1669,7 +1672,6 @@ int wc_Sha256Drbg_Disable(void) { return NOT_COMPILED_IN; }
16691672
int wc_Sha256Drbg_Enable(void) { return 0; }
16701673
int wc_Sha256Drbg_IsDisabled(void) { return 1; } /* always disabled */
16711674
#endif /* !NO_SHA256 */
1672-
#endif /* !HAVE_SELFTEST && (!HAVE_FIPS || FIPS v7+) */
16731675

16741676
#ifdef WOLFSSL_DRBG_SHA512
16751677
int wc_Sha512Drbg_Disable(void)
@@ -1708,7 +1710,7 @@ int wc_Sha512Drbg_IsDisabled(void)
17081710
return val;
17091711
}
17101712
#endif /* WOLFSSL_DRBG_SHA512 */
1711-
1713+
#endif /* !HAVE_SELFTEST && (!HAVE_FIPS || FIPS v7+) */
17121714
#endif /* HAVE_HASHDRBG */
17131715
/* End NIST DRBG Code */
17141716

@@ -1764,20 +1766,20 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
17641766
#ifdef WOLFSSL_SMALL_STACK_CACHE
17651767
rng->drbg_scratch = NULL;
17661768
#endif
1767-
#endif
1769+
#endif /* !NO_SHA256 */
17681770
#ifdef WOLFSSL_DRBG_SHA512
17691771
rng->drbg512 = NULL;
17701772
#ifdef WOLFSSL_SMALL_STACK_CACHE
17711773
rng->drbg512_scratch = NULL;
17721774
rng->health_check_scratch_512 = NULL;
17731775
#endif
1774-
#endif
1776+
#endif /* WOLFSSL_DRBG_SHA512 */
17751777
#ifdef WOLFSSL_SMALL_STACK_CACHE
17761778
rng->newSeed_buf = NULL;
1777-
#ifndef NO_SHA256
1779+
#ifndef NO_SHA256
17781780
rng->health_check_scratch = NULL;
1779-
#endif
1780-
#endif
1781+
#endif /* !NO_SHA256 */
1782+
#endif /* WOLFSSL_SMALL_STACK_CACHE */
17811783
rng->status = DRBG_NOT_INIT;
17821784

17831785
/* Select DRBG type: prefer SHA-512 unless disabled or not compiled.
@@ -1786,25 +1788,25 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
17861788
ret = LockDrbgState();
17871789
if (ret != 0)
17881790
return ret;
1789-
#ifdef WOLFSSL_DRBG_SHA512
1791+
#ifdef WOLFSSL_DRBG_SHA512
17901792
if (!sha512DrbgDisabled)
17911793
rng->drbgType = WC_DRBG_SHA512;
17921794
else
1793-
#endif
1794-
#ifndef NO_SHA256
1795+
#endif /* WOLFSSL_DRBG_SHA512 */
1796+
#ifndef NO_SHA256
17951797
if (!sha256DrbgDisabled)
17961798
rng->drbgType = WC_DRBG_SHA256;
17971799
else
1798-
#endif
1800+
#endif /* !NO_SHA256 */
17991801
{
18001802
UnlockDrbgState();
18011803
return BAD_STATE_E; /* no DRBG available */
18021804
}
18031805
UnlockDrbgState();
18041806
#else
18051807
rng->drbgType = WC_DRBG_SHA256;
1806-
#endif
1807-
#endif
1808+
#endif /* !HAVE_SELFTEST && (!HAVE_FIPS || FIPS v7+) */
1809+
#endif /* HAVE_HASHDRBG */
18081810

18091811
#if defined(HAVE_INTEL_RDSEED) || defined(HAVE_INTEL_RDRAND) || \
18101812
defined(HAVE_AMD_RDSEED)
@@ -3289,7 +3291,8 @@ int wc_RNG_HealthTest_SHA512(int reseed,
32893291

32903292
#endif /* WOLFSSL_DRBG_SHA512 */
32913293

3292-
#ifndef NO_SHA256
3294+
#if !defined(NO_SHA256) && !defined(HAVE_SELFTEST) && \
3295+
(!defined(HAVE_FIPS) || FIPS_VERSION3_GE(7,0,0))
32933296
/* Extended SHA-256 Hash_DRBG health test per SP 800-90A.
32943297
* Supports flexible output sizes, prediction resistance, personalization
32953298
* strings, and additional input.
@@ -3387,7 +3390,7 @@ int wc_RNG_HealthTest_SHA256_ex(
33873390

33883391
return ret;
33893392
}
3390-
#endif /* !NO_SHA256 */
3393+
#endif /* !NO_SHA256 && !HAVE_SELFTEST && FIPS v7+ */
33913394

33923395

33933396
#ifdef WOLFSSL_DRBG_SHA512

0 commit comments

Comments
 (0)