It would be useful to have analogs of the nn_get_random
functions which initialize a random number from a buffer of entropy, instead of using get_random
. Specifically, a function int nn_init_from_entropy_mod(nn_t out, nn_src_t q, unsigned char *entropy, u16 *entropy_len)
which would operate roughly the same as nn_get_random_mod
, but instead of calling get_random
, it would ensure that *entropy_len
is at least 2 * q_len
, use the first 2 * q_len
bytes of entropy
to initialize tmp_rand
, subtract 2 * q_len
from *entropy_len
and advance entropy
by 2 * q_len
bytes.
My specific use case is WebAssembly, which depends on Javascript (or whatever host is running it) to provide entropy. It would be simpler and easier to provide entropy as an argument (in my use case, I know the amount of entropy I need ahead of time) rather than calling back out to the host from within the get_random
function.
An added benefit of this approach is that it would be possible to use libecc
without implementing get_random
at all.
One alternative to this approach is to pass the get_random
function as an argument to nn_get_random
, along with a context pointer. For instance, nn_get_random_ctx(nn_t out, nn_src_t q, int (*get_random_ctx)(unsigned char *buf, u16 len, void *ctx), void *random_ctx)
.
I'm happy to put a Pull Request together if one of these approaches is acceptable.