Skip to content

Commit 299ca1c

Browse files
committed
fixes from peer review: added comments for clarity, and remove errant condition added in _InitRng().
1 parent d504baa commit 299ca1c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

linuxkm/lkcapi_sha_glue.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,11 +1020,20 @@ static int wc_linuxkm_drbg_init_tfm(struct crypto_tfm *tfm)
10201020
ret = wc_InitRng(&ctx->rngs[i].rng);
10211021
if (need_reenable_vec)
10221022
REENABLE_VECTOR_REGISTERS();
1023-
if (can_sleep)
1023+
if (can_sleep) {
1024+
/* if we're allowed to sleep, relax the loop between each inner
1025+
* iteration even on success, assuring relaxation of the outer
1026+
* iterations.
1027+
*/
10241028
cond_resched();
1029+
}
10251030
if (ret == 0)
10261031
break;
10271032
if (can_sleep) {
1033+
/* Allow interrupt only if we're stuck spinning retries -- i.e.,
1034+
* don't allow an untimely user signal to derail an
1035+
* initialization that is proceeding expeditiously.
1036+
*/
10281037
if (WC_CHECK_FOR_INTR_SIGNALS() == WC_NO_ERR_TRACE(INTERRUPTED_E)) {
10291038
ret = -EINTR;
10301039
break;
@@ -1036,7 +1045,7 @@ static int wc_linuxkm_drbg_init_tfm(struct crypto_tfm *tfm)
10361045
++nretries;
10371046
}
10381047
if (ret != 0) {
1039-
pr_warn("WARNING: wc_InitRng returned %d after %d retries.\n",ret,nretries);
1048+
pr_warn("WARNING: wc_InitRng returned %d after %d retries.\n", ret, nretries);
10401049
ret = -EINVAL;
10411050
break;
10421051
}

wolfcrypt/src/random.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,16 @@ static int Hash_gen(DRBG_internal* drbg, byte* out, word32 outSz, const byte* V)
537537
#endif
538538

539539
#ifdef WC_VERBOSE_RNG
540-
if ((ret != DRBG_SUCCESS) && (ret != DRBG_FAILURE))
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+
*/
541548
WOLFSSL_DEBUG_PRINTF("Hash_gen failed with err %d.", ret);
549+
}
542550
#endif
543551

544552
return (ret == 0) ? DRBG_SUCCESS : DRBG_FAILURE;
@@ -652,8 +660,10 @@ static int Hash_DRBG_Generate(DRBG_internal* drbg, byte* out, word32 outSz)
652660
}
653661

654662
#ifdef WC_VERBOSE_RNG
655-
if ((ret != DRBG_SUCCESS) && (ret != DRBG_FAILURE))
663+
if ((ret != DRBG_SUCCESS) && (ret != DRBG_FAILURE)) {
664+
/* see note above regarding log spam reduction */
656665
WOLFSSL_DEBUG_PRINTF("Hash_DRBG_Generate failed with err %d.", ret);
666+
}
657667
#endif
658668

659669
return (ret == 0) ? DRBG_SUCCESS : DRBG_FAILURE;
@@ -1033,7 +1043,6 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
10331043
ret = RNG_FAILURE_E;
10341044
}
10351045
else {
1036-
if ((ret != DRBG_SUCCESS) && (ret != DRBG_FAILURE))
10371046
rng->status = DRBG_FAILED;
10381047
}
10391048
#endif /* HAVE_HASHDRBG */

0 commit comments

Comments
 (0)