From fd78a1f65b3e698b0e99f29584b060750b89bdab Mon Sep 17 00:00:00 2001 From: Benoît Ganne Date: Tue, 29 Mar 2022 17:29:49 +0200 Subject: crypto-openssl: use getrandom to reseed openssl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Type: improvement Change-Id: I84d594d8baaf18056580455f3b2790d0f31b7b0f Signed-off-by: Benoît Ganne --- src/plugins/crypto_openssl/main.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/plugins/crypto_openssl') diff --git a/src/plugins/crypto_openssl/main.c b/src/plugins/crypto_openssl/main.c index 38da2766e13..6843880eed0 100644 --- a/src/plugins/crypto_openssl/main.c +++ b/src/plugins/crypto_openssl/main.c @@ -15,6 +15,8 @@ *------------------------------------------------------------------ */ +#include + #include #include #include @@ -474,9 +476,12 @@ crypto_openssl_init (vlib_main_t * vm) { vlib_thread_main_t *tm = vlib_get_thread_main (); openssl_per_thread_data_t *ptd; - u8 *seed_data = 0; - time_t t; - pid_t pid; + u8 seed[32]; + + if (getrandom (&seed, sizeof (seed), 0) != sizeof (seed)) + return clib_error_return_unix (0, "getrandom() failed"); + + RAND_seed (seed, sizeof (seed)); u32 eidx = vnet_crypto_register_engine (vm, "openssl", 50, "OpenSSL"); @@ -522,16 +527,6 @@ crypto_openssl_init (vlib_main_t * vm) #endif } - t = time (NULL); - pid = getpid (); - vec_add (seed_data, &t, sizeof (t)); - vec_add (seed_data, &pid, sizeof (pid)); - vec_add (seed_data, &seed_data, sizeof (seed_data)); - - RAND_seed ((const void *) seed_data, vec_len (seed_data)); - - vec_free (seed_data); - return 0; } -- cgit 1.2.3-korg