Skip to content

Commit 7048fa8

Browse files
committed
wolfcrypt/src/random.c and wolfssl/wolfcrypt/settings.h: fixes from CI and peer review:
* in wc_GenerateSeed_IntelRD(), use stack/register allocation for sanity_word{1,2}, and * don't set WC_VERBOSE_RNG if WOLFSSL_DEBUG_PRINTF is missing.
1 parent b91272c commit 7048fa8

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

wolfcrypt/src/random.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,29 +1942,32 @@ static int wc_GenerateSeed_IntelRD(OS_Seed* os, byte* output, word32 sz)
19421942
if (!IS_INTEL_RDSEED(intel_flags))
19431943
return -1;
19441944

1945+
/* Note, access to rdseed_sanity_status is benignly racey on multithreaded
1946+
* targets.
1947+
*/
19451948
if (rdseed_sanity_status == 0) {
1946-
static word64 sanity_words[2] = {0, 0};
1949+
word64 sanity_word1 = 0, sanity_word2 = 0;
19471950

1948-
ret = IntelRDseed64_r(&sanity_words[0]);
1951+
ret = IntelRDseed64_r(&sanity_word1);
19491952
if (ret != 0)
19501953
return ret;
19511954

1952-
ret = IntelRDseed64_r(&sanity_words[1]);
1955+
ret = IntelRDseed64_r(&sanity_word2);
19531956
if (ret != 0)
19541957
return ret;
19551958

1956-
if (sanity_words[0] == sanity_words[1]) {
1957-
ret = IntelRDseed64_r(&sanity_words[0]);
1959+
if (sanity_word1 == sanity_word2) {
1960+
ret = IntelRDseed64_r(&sanity_word1);
19581961
if (ret != 0)
19591962
return ret;
19601963

1961-
if (sanity_words[0] == sanity_words[1]) {
1962-
rdseed_sanity_status = -1;
1964+
if (sanity_word1 == sanity_word2) {
19631965
#ifdef WC_VERBOSE_RNG
19641966
WOLFSSL_DEBUG_PRINTF(
1965-
"WARNING: RDSEED disabled due to repeating word 0x%lx -- "
1966-
"check CPU microcode version.", sanity_words[1]);
1967+
"WARNING: disabling RDSEED due to repeating word 0x%lx -- "
1968+
"check CPU microcode version.", sanity_word2);
19671969
#endif
1970+
rdseed_sanity_status = -1;
19681971
return -1;
19691972
}
19701973
}

wolfssl/wolfcrypt/settings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@
378378
#endif
379379

380380
/* Ensure WC_VERBOSE_RNG is set when DEBUG_WOLFSSL is enabled, unless expressly
381-
* requested otherwise.
381+
* requested otherwise. Relies on a working WOLFSSL_DEBUG_PRINTF.
382382
*/
383-
#if defined(DEBUG_WOLFSSL) && !defined(WC_NO_VERBOSE_RNG) && \
384-
!defined(WC_VERBOSE_RNG)
383+
#if defined(DEBUG_WOLFSSL) && defined(WOLFSSL_DEBUG_PRINTF) && \
384+
!defined(WC_NO_VERBOSE_RNG) && !defined(WC_VERBOSE_RNG)
385385
#define WC_VERBOSE_RNG
386386
#endif
387387

0 commit comments

Comments
 (0)