@@ -369,6 +369,11 @@ static int Hash_df(DRBG_internal* drbg, byte* out, word32 outSz, byte type,
369369 XFREE (digest , drbg -> heap , DYNAMIC_TYPE_DIGEST );
370370#endif
371371
372+ #ifdef WC_VERBOSE_RNG
373+ if (ret != 0 )
374+ WOLFSSL_DEBUG_PRINTF ("%s failed with err = %d" , __FUNCTION__ , ret );
375+ #endif
376+
372377 return (ret == 0 ) ? DRBG_SUCCESS : DRBG_FAILURE ;
373378}
374379
@@ -406,6 +411,12 @@ static int Hash_DRBG_Reseed(DRBG_internal* drbg, const byte* seed, word32 seedSz
406411#ifndef WOLFSSL_SMALL_STACK_CACHE
407412 WC_FREE_VAR_EX (newV , drbg -> heap , DYNAMIC_TYPE_TMP_BUFFER );
408413#endif
414+
415+ #ifdef WC_VERBOSE_RNG
416+ if (ret != 0 )
417+ WOLFSSL_DEBUG_PRINTF ("Hash_DRBG_Reseed failed with err %d." , ret );
418+ #endif
419+
409420 return ret ;
410421}
411422
@@ -525,6 +536,19 @@ static int Hash_gen(DRBG_internal* drbg, byte* out, word32 outSz, const byte* V)
525536 WC_FREE_VAR_EX (data , drbg -> heap , DYNAMIC_TYPE_TMP_BUFFER );
526537#endif
527538
539+ #ifdef WC_VERBOSE_RNG
540+ if ((ret != DRBG_SUCCESS ) && (ret != DRBG_FAILURE )) {
541+ /* Note, if we're just going to return DRBG_FAILURE to the caller, then
542+ * there's no point printing it out here because (1) the lower-level
543+ * code that was remapped to DRBG_FAILURE already got printed before the
544+ * remapping, so a DRBG_FAILURE message would just be spamming the log,
545+ * and (2) the caller will actually see the DRBG_FAILURE code, and is
546+ * free to (and probably will) log it itself.
547+ */
548+ WOLFSSL_DEBUG_PRINTF ("Hash_gen failed with err %d." , ret );
549+ }
550+ #endif
551+
528552 return (ret == 0 ) ? DRBG_SUCCESS : DRBG_FAILURE ;
529553}
530554
@@ -635,6 +659,13 @@ static int Hash_DRBG_Generate(DRBG_internal* drbg, byte* out, word32 outSz)
635659 #endif
636660 }
637661
662+ #ifdef WC_VERBOSE_RNG
663+ if ((ret != DRBG_SUCCESS ) && (ret != DRBG_FAILURE )) {
664+ /* see note above regarding log spam reduction */
665+ WOLFSSL_DEBUG_PRINTF ("Hash_DRBG_Generate failed with err %d." , ret );
666+ }
667+ #endif
668+
638669 return (ret == 0 ) ? DRBG_SUCCESS : DRBG_FAILURE ;
639670}
640671
@@ -721,7 +752,6 @@ int wc_RNG_TestSeed(const byte* seed, word32 seedSz)
721752 if (ConstantCompare (seed + seedIdx ,
722753 seed + seedIdx + scratchSz ,
723754 (int )scratchSz ) == 0 ) {
724-
725755 ret = DRBG_CONT_FAILURE ;
726756 }
727757 seedIdx += SEED_BLOCK_SZ ;
@@ -926,6 +956,9 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
926956 else {
927957 ret = seedCb (& rng -> seed , seed , seedSz );
928958 if (ret != 0 ) {
959+ #ifdef WC_VERBOSE_RNG
960+ WOLFSSL_DEBUG_PRINTF ("seedCb in _InitRng() failed with err = %d" , ret );
961+ #endif
929962 ret = DRBG_FAILURE ;
930963 }
931964 }
@@ -935,6 +968,8 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
935968 if (ret != 0 ) {
936969 #if defined(DEBUG_WOLFSSL )
937970 WOLFSSL_MSG_EX ("Seed generation failed... %d" , ret );
971+ #elif defined(WC_VERBOSE_RNG )
972+ WOLFSSL_DEBUG_PRINTF ("wc_GenerateSeed() in _InitRng() failed with err %d" , ret );
938973 #endif
939974 ret = DRBG_FAILURE ;
940975 rng -> status = DRBG_FAILED ;
@@ -946,7 +981,12 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
946981 if (ret != 0 ) {
947982 WOLFSSL_MSG_EX ("wc_RNG_TestSeed failed... %d" , ret );
948983 }
984+ #elif defined(WC_VERBOSE_RNG )
985+ if (ret != DRBG_SUCCESS ) {
986+ WOLFSSL_DEBUG_PRINTF ("wc_RNG_TestSeed() in _InitRng() returned err %d." , ret );
987+ }
949988 #endif
989+
950990 if (ret == DRBG_SUCCESS )
951991 ret = Hash_DRBG_Instantiate ((DRBG_internal * )rng -> drbg ,
952992 #if defined(HAVE_FIPS ) || !defined (WOLFSSL_RNG_USE_FULL_SEED )
@@ -1120,19 +1160,30 @@ static int PollAndReSeed(WC_RNG* rng)
11201160 else {
11211161 ret = seedCb (& rng -> seed , newSeed , SEED_SZ + SEED_BLOCK_SZ );
11221162 if (ret != 0 ) {
1163+ #ifdef WC_VERBOSE_RNG
1164+ WOLFSSL_DEBUG_PRINTF ("seedCb() in PollAndReSeed() failed with err %d" , ret );
1165+ #endif
11231166 ret = DRBG_FAILURE ;
11241167 }
11251168 }
11261169 #else
11271170 ret = wc_GenerateSeed (& rng -> seed , newSeed ,
11281171 SEED_SZ + SEED_BLOCK_SZ );
1129- #endif
1130- if (ret != 0 )
1172+ if (ret != 0 ) {
1173+ #ifdef WC_VERBOSE_RNG
1174+ WOLFSSL_DEBUG_PRINTF ("wc_GenerateSeed() in PollAndReSeed() failed with err %d" , ret );
1175+ #endif
11311176 ret = DRBG_FAILURE ;
1177+ }
1178+ #endif
11321179 }
1133- if (ret == DRBG_SUCCESS )
1180+ if (ret == DRBG_SUCCESS ) {
11341181 ret = wc_RNG_TestSeed (newSeed , SEED_SZ + SEED_BLOCK_SZ );
1135-
1182+ #ifdef WC_VERBOSE_RNG
1183+ if (ret != DRBG_SUCCESS )
1184+ WOLFSSL_DEBUG_PRINTF ("wc_RNG_TestSeed() in PollAndReSeed() returned err %d." , ret );
1185+ #endif
1186+ }
11361187 if (ret == DRBG_SUCCESS )
11371188 ret = Hash_DRBG_Reseed ((DRBG_internal * )rng -> drbg ,
11381189 newSeed + SEED_BLOCK_SZ , SEED_SZ );
@@ -1202,6 +1253,10 @@ int wc_RNG_GenerateBlock(WC_RNG* rng, byte* output, word32 sz)
12021253#ifdef CUSTOM_RAND_GENERATE_BLOCK
12031254 XMEMSET (output , 0 , sz );
12041255 ret = (int )CUSTOM_RAND_GENERATE_BLOCK (output , sz );
1256+ #ifdef WC_VERBOSE_RNG
1257+ if (ret != 0 )
1258+ WOLFSSL_DEBUG_PRINTF ("CUSTOM_RAND_GENERATE_BLOCK failed with err %d." , ret );
1259+ #endif
12051260#else
12061261
12071262#ifdef HAVE_HASHDRBG
0 commit comments