diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-03-18 11:54:37 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2019-04-30 11:11:39 -0400 |
commit | e66b5153bd5feeb16bb18b735745d37310ae63fa (patch) | |
tree | 191f6fae4a311c59a56b39440ffee72abe04c697 /src/lib/crypt_ops/crypto_rand_fast.c | |
parent | c6a93beed83a6271eb029d4b045be9d92b34031d (diff) | |
download | tor-e66b5153bd5feeb16bb18b735745d37310ae63fa.tar.gz tor-e66b5153bd5feeb16bb18b735745d37310ae63fa.zip |
Extract add-entropy code from crypto_fast_rng to a new function
Diffstat (limited to 'src/lib/crypt_ops/crypto_rand_fast.c')
-rw-r--r-- | src/lib/crypt_ops/crypto_rand_fast.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/lib/crypt_ops/crypto_rand_fast.c b/src/lib/crypt_ops/crypto_rand_fast.c index 01817c618f..dd9bf051c8 100644 --- a/src/lib/crypt_ops/crypto_rand_fast.c +++ b/src/lib/crypt_ops/crypto_rand_fast.c @@ -193,6 +193,26 @@ cipher_from_seed(const uint8_t *seed) } /** + * Helper: mix additional entropy into <b>rng</b> by using our XOF to mix the + * old value for the seed with some additional bytes from + * crypto_strongest_rand(). + **/ +static void +crypto_fast_rng_add_entopy(crypto_fast_rng_t *rng) +{ + crypto_xof_t *xof = crypto_xof_new(); + crypto_xof_add_bytes(xof, rng->buf.seed, SEED_LEN); + { + uint8_t seedbuf[SEED_LEN]; + crypto_strongest_rand(seedbuf, SEED_LEN); + crypto_xof_add_bytes(xof, seedbuf, SEED_LEN); + memwipe(seedbuf, 0, SEED_LEN); + } + crypto_xof_squeeze_bytes(xof, rng->buf.seed, SEED_LEN); + crypto_xof_free(xof); +} + +/** * Helper: refill the seed bytes and output buffer of <b>rng</b>, using * the input seed bytes as input (key and IV) for the stream cipher. * @@ -203,20 +223,8 @@ static void crypto_fast_rng_refill(crypto_fast_rng_t *rng) { if (rng->n_till_reseed-- == 0) { - /* It's time to reseed the RNG. We'll do this by using our XOF to mix the - * old value for the seed with some additional bytes from - * crypto_strongest_rand(). */ - crypto_xof_t *xof = crypto_xof_new(); - crypto_xof_add_bytes(xof, rng->buf.seed, SEED_LEN); - { - uint8_t seedbuf[SEED_LEN]; - crypto_strongest_rand(seedbuf, SEED_LEN); - crypto_xof_add_bytes(xof, seedbuf, SEED_LEN); - memwipe(seedbuf, 0, SEED_LEN); - } - crypto_xof_squeeze_bytes(xof, rng->buf.seed, SEED_LEN); - crypto_xof_free(xof); - + /* It's time to reseed the RNG. */ + crypto_fast_rng_add_entopy(rng); rng->n_till_reseed = RESEED_AFTER; } /* Now fill rng->buf with output from our stream cipher, initialized from |