diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-02-07 08:18:46 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-02-14 09:26:40 -0500 |
commit | 6a29aa7b8c86151701df4b881aded4fc152ea116 (patch) | |
tree | bfca3ab6687b1974fccd602fc4182cca13e28232 /src/test/test_crypto_rng.c | |
parent | 3f28b98220a49730b8c58c45e42598ad2bada47b (diff) | |
download | tor-6a29aa7b8c86151701df4b881aded4fc152ea116.tar.gz tor-6a29aa7b8c86151701df4b881aded4fc152ea116.zip |
Add whitebox test for the long-output optimization of fast_rng
Diffstat (limited to 'src/test/test_crypto_rng.c')
-rw-r--r-- | src/test/test_crypto_rng.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/test/test_crypto_rng.c b/src/test/test_crypto_rng.c index 075c876b8a..23b0c66514 100644 --- a/src/test/test_crypto_rng.c +++ b/src/test/test_crypto_rng.c @@ -229,8 +229,9 @@ test_crypto_rng_fast_whitebox(void *arg) const size_t buflen = crypto_fast_rng_get_bytes_used_per_stream(); char *buf = tor_malloc_zero(buflen); char *buf2 = tor_malloc_zero(buflen); + char *buf3 = NULL, *buf4 = NULL; - crypto_cipher_t *cipher = NULL; + crypto_cipher_t *cipher = NULL, *cipher2 = NULL; uint8_t seed[CRYPTO_FAST_RNG_SEED_LEN]; memset(seed, 0, sizeof(seed)); @@ -285,11 +286,26 @@ test_crypto_rng_fast_whitebox(void *arg) crypto_cipher_crypt_inplace(cipher, buf2, 7); tt_mem_op(buf, OP_EQ, buf2, 7); + /* Now try the optimization for long outputs. */ + buf3 = tor_malloc(65536); + crypto_fast_rng_getbytes(rng, (uint8_t*)buf3, 65536); + + buf4 = tor_malloc_zero(65536); + uint8_t seed2[CRYPTO_FAST_RNG_SEED_LEN]; + memset(seed2, 0, sizeof(seed2)); + crypto_cipher_crypt_inplace(cipher, (char*)seed2, sizeof(seed2)); + cipher2 = crypto_cipher_new_with_iv_and_bits(seed2, seed2+32, 256); + crypto_cipher_crypt_inplace(cipher2, buf4, 65536); + tt_mem_op(buf3, OP_EQ, buf4, 65536); + done: crypto_fast_rng_free(rng); crypto_cipher_free(cipher); + crypto_cipher_free(cipher2); tor_free(buf); tor_free(buf2); + tor_free(buf3); + tor_free(buf4); } struct testcase_t crypto_rng_tests[] = { |