X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fopenssl%2Fcrypto.c;h=6894d876d97c9c88ae7a34ebbcd6f225b642e6dd;hb=f6e87ab476a0faf8b124ecaaa27f967d825e6457;hp=ed8c8e296c6d37998505eafb906773cacc87564a;hpb=a99ded7d987c3242f972162e02767c498257f2b8;p=tinc diff --git a/src/openssl/crypto.c b/src/openssl/crypto.c index ed8c8e29..6894d876 100644 --- a/src/openssl/crypto.c +++ b/src/openssl/crypto.c @@ -31,8 +31,11 @@ static int random_fd = -1; static void random_init(void) { random_fd = open("/dev/urandom", O_RDONLY); - if(random_fd < 0) + + if(random_fd < 0) { random_fd = open("/dev/random", O_RDONLY); + } + if(random_fd < 0) { fprintf(stderr, "Could not open source of random numbers: %s\n", strerror(errno)); abort(); @@ -46,12 +49,16 @@ static void random_exit(void) { void randomize(void *out, size_t outlen) { while(outlen) { size_t len = read(random_fd, out, outlen); + if(len <= 0) { - if(errno == EAGAIN || errno == EINTR) + if(errno == EAGAIN || errno == EINTR) { continue; + } + fprintf(stderr, "Could not read random numbers: %s\n", strerror(errno)); abort(); } + out += len; outlen -= len; } @@ -99,5 +106,7 @@ void crypto_init(void) { void crypto_exit(void) { EVP_cleanup(); + ERR_free_strings(); + ENGINE_cleanup(); random_exit(); }