[tor-commits] [tor/master] Add whitebox test for the long-output optimization of fast_rng

dgoulet at torproject.org dgoulet at torproject.org
Thu Feb 14 16:48:45 UTC 2019


commit 6a29aa7b8c86151701df4b881aded4fc152ea116
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Feb 7 08:18:46 2019 -0500

    Add whitebox test for the long-output optimization of fast_rng
---
 src/test/test_crypto_rng.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/test/test_crypto_rng.c b/src/test/test_crypto_rng.c
index 075c876b8..23b0c6651 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[] = {





More information about the tor-commits mailing list