From e68b08a4ff4c5f54518443c92b1288cedf3989c7 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 22 May 2013 11:16:28 -0700 Subject: [PATCH] Call randombytes_salsa20_random_stir_if_needed() only when we don't have anything in stock, and reduce the number of required getpid() calls. --- src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c index 99af6dc7..b5c8e889 100644 --- a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +++ b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c @@ -205,6 +205,7 @@ randombytes_salsa20_random_getword(void) COMPILER_ASSERT(sizeof stream.rnd32 >= sizeof val); COMPILER_ASSERT(sizeof stream.rnd32 % sizeof val == (size_t) 0U); if (stream.rnd32_outleft <= (size_t) 0U) { + randombytes_salsa20_random_stir_if_needed(); COMPILER_ASSERT(sizeof stream.nonce == crypto_stream_salsa20_NONCEBYTES); ret = crypto_stream_salsa20((unsigned char *) stream.rnd32, (unsigned long long) sizeof stream.rnd32, @@ -245,8 +246,6 @@ randombytes_salsa20_random_close(void) uint32_t randombytes_salsa20_random(void) { - randombytes_salsa20_random_stir_if_needed(); - return randombytes_salsa20_random_getword(); }