LIST_HEAD(seedlist);
struct drbg_state *drbg = container_of(work, struct drbg_state,
seed_work);
+ int ret;
get_blocking_random_bytes(drbg->seed_buf, drbg->seed_buf_len);
drbg_string_fill(&data, drbg->seed_buf, drbg->seed_buf_len);
list_add_tail(&data.list, &seedlist);
mutex_lock(&drbg->drbg_mutex);
- __drbg_seed(drbg, &seedlist, true);
+ ret = __drbg_seed(drbg, &seedlist, true);
+ if (!ret && drbg->jent) {
+ crypto_free_rng(drbg->jent);
+ drbg->jent = NULL;
+ }
memzero_explicit(drbg->seed_buf, drbg->seed_buf_len);
mutex_unlock(&drbg->drbg_mutex);
}
drbg->test_data.len);
pr_devel("DRBG: using test entropy\n");
} else {
- pr_devel("DRBG: (re)seeding with %zu bytes of entropy\n",
- drbg->seed_buf_len);
+ /* Get seed from in-kernel /dev/urandom */
get_random_bytes(drbg->seed_buf, drbg->seed_buf_len);
- drbg_string_fill(&data1, drbg->seed_buf, drbg->seed_buf_len);
+
+ /* Get seed from Jitter RNG */
+ if (!drbg->jent ||
+ crypto_rng_get_bytes(drbg->jent,
+ drbg->seed_buf + drbg->seed_buf_len,
+ drbg->seed_buf_len)) {
+ drbg_string_fill(&data1, drbg->seed_buf,
+ drbg->seed_buf_len);
+ pr_devel("DRBG: (re)seeding with %zu bytes of entropy\n",
+ drbg->seed_buf_len);
+ } else {
+ drbg_string_fill(&data1, drbg->seed_buf,
+ drbg->seed_buf_len * 2);
+ pr_devel("DRBG: (re)seeding with %zu bytes of entropy\n",
+ drbg->seed_buf_len * 2);
+ }
}
list_add_tail(&data1.list, &seedlist);
* Clear the initial entropy buffer as the async call may not overwrite
* that buffer for quite some time.
*/
- memzero_explicit(drbg->seed_buf, drbg->seed_buf_len);
+ memzero_explicit(drbg->seed_buf, drbg->seed_buf_len * 2);
if (ret)
goto out;
/*
#endif
kzfree(drbg->seed_buf);
drbg->seed_buf = NULL;
+ if (drbg->jent) {
+ crypto_free_rng(drbg->jent);
+ drbg->jent = NULL;
+ }
}
/*
ret = -EFAULT;
goto err;
}
- /* ensure we have sufficient buffer space for initial seed */
+ /*
+ * Ensure we have sufficient buffer space for initial seed which
+ * consists of the seed from get_random_bytes and the Jitter RNG.
+ */
drbg->seed_buf_len = ((drbg->seed_buf_len + 1) / 2) * 3;
- drbg->seed_buf = kzalloc(drbg->seed_buf_len, GFP_KERNEL);
+ drbg->seed_buf = kzalloc(drbg->seed_buf_len * 2, GFP_KERNEL);
if (!drbg->seed_buf)
goto err;
INIT_WORK(&drbg->seed_work, drbg_async_seed);
+ drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0);
+ if(IS_ERR(drbg->jent))
+ {
+ pr_info("DRBG: could not allocate Jitter RNG handle for seeding\n");
+ /*
+ * As the Jitter RNG is a module that may not be present, we
+ * continue with the operation and do not fully tie the DRBG
+ * to the Jitter RNG.
+ */
+ drbg->jent = NULL;
+ }
+
return 0;
err: