From 3c3635e53a87b77fbb10bd826c4e47f054cf9ac4 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 1 Jun 2015 12:29:02 +0200 Subject: [PATCH] salsa20_random(): just abort(3) if the pid changes and _stir() wasn't called --- .../randombytes/salsa20/randombytes_salsa20_random.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c index 1ab34b70..0c3cd1c9 100644 --- a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +++ b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c @@ -271,6 +271,9 @@ randombytes_salsa20_random_stir(void) stream.key[i] ^= m0[i]; } sodium_memzero(m0, sizeof m0); +#ifndef _MSC_VER + stream.pid = getpid(); +#endif } static void @@ -281,11 +284,10 @@ randombytes_salsa20_random_stir_if_needed(void) randombytes_salsa20_random_stir(); } #else - const pid_t pid = getpid(); - - if (stream.initialized == 0 || stream.pid != pid) { - stream.pid = pid; + if (stream.initialized == 0) { randombytes_salsa20_random_stir(); + } else if (stream.pid != getpid()) { + abort(); } #endif } @@ -339,6 +341,7 @@ randombytes_salsa20_random_close(void) close(stream.random_data_source_fd) == 0) { stream.random_data_source_fd = -1; stream.initialized = 0; + stream.pid = (pid_t) 0; ret = 0; } # ifdef SYS_getrandom