mirror of https://github.com/wolfSSL/wolfssl.git
linuxkm/lkcapi_sha_glue.c: in wc_linuxkm_drbg_generate() and wc_linuxkm_drbg_seed(), check retval from wc_LockMutex().
wolfcrypt/src/random.c: in Hash_DRBG_Generate(), restore smallstack path for digest[], but use non-smallstack path for WOLFSSL_LINUXKM.pull/8840/head
parent
dbc34352c7
commit
ae15693fa8
|
@ -971,18 +971,17 @@ static int wc_linuxkm_drbg_generate(struct crypto_rng *tfm,
|
|||
{
|
||||
struct wc_linuxkm_drbg_ctx *ctx = (struct wc_linuxkm_drbg_ctx *)crypto_rng_ctx(tfm);
|
||||
int ret;
|
||||
int my_cpu =
|
||||
raw_smp_processor_id(); /* Note, core is not locked, so the actual core
|
||||
* ID may change while executing, hence the
|
||||
* mutex.
|
||||
* The mutex is also needed to coordinate with
|
||||
* wc_linuxkm_drbg_seed(), which seeds all
|
||||
* instances.
|
||||
*/
|
||||
/* Note, core is not locked, so the actual core ID may change while
|
||||
* executing, hence the mutex.
|
||||
* The mutex is also needed to coordinate with wc_linuxkm_drbg_seed(), which
|
||||
* seeds all instances.
|
||||
*/
|
||||
int my_cpu = raw_smp_processor_id();
|
||||
wolfSSL_Mutex *lock = &ctx->rngs[my_cpu].lock;
|
||||
WC_RNG *rng = &ctx->rngs[my_cpu].rng;
|
||||
|
||||
wc_LockMutex(lock);
|
||||
if (wc_LockMutex(lock) != 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (slen > 0) {
|
||||
ret = wc_RNG_DRBG_Reseed(rng, src, slen);
|
||||
|
@ -1029,7 +1028,8 @@ static int wc_linuxkm_drbg_seed(struct crypto_rng *tfm,
|
|||
seed_copy[0] = (u8)(i >> 8);
|
||||
seed_copy[1] = (u8)i;
|
||||
|
||||
wc_LockMutex(lock);
|
||||
if (wc_LockMutex(lock) != 0)
|
||||
return -EINVAL;
|
||||
|
||||
ret = wc_RNG_DRBG_Reseed(rng, seed_copy, slen + 2);
|
||||
if (ret != 0) {
|
||||
|
|
|
@ -647,7 +647,14 @@ static int Hash_DRBG_Generate(DRBG_internal* drbg, byte* out, word32 outSz)
|
|||
return DRBG_NEED_RESEED;
|
||||
}
|
||||
else {
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_LINUXKM)
|
||||
byte* digest = (byte*)XMALLOC(WC_SHA256_DIGEST_SIZE, drbg->heap,
|
||||
DYNAMIC_TYPE_DIGEST);
|
||||
if (digest == NULL)
|
||||
return DRBG_FAILURE;
|
||||
#else
|
||||
byte digest[WC_SHA256_DIGEST_SIZE];
|
||||
#endif
|
||||
|
||||
type = drbgGenerateH;
|
||||
reseedCtr = drbg->reseedCtr;
|
||||
|
@ -685,6 +692,9 @@ static int Hash_DRBG_Generate(DRBG_internal* drbg, byte* out, word32 outSz)
|
|||
drbg->reseedCtr++;
|
||||
}
|
||||
ForceZero(digest, WC_SHA256_DIGEST_SIZE);
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_LINUXKM)
|
||||
XFREE(digest, drbg->heap, DYNAMIC_TYPE_DIGEST);
|
||||
#endif
|
||||
}
|
||||
|
||||
return (ret == 0) ? DRBG_SUCCESS : DRBG_FAILURE;
|
||||
|
|
Loading…
Reference in New Issue