Require OpenSSL 1.1.0 or later.
[tinc] / src / openssl / crypto.c
index e594e73..8fc7e77 100644 (file)
@@ -1,6 +1,6 @@
 /*
     crypto.c -- Cryptographic miscellaneous functions and initialisation
-    Copyright (C) 2007-2014 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2007-2021 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -50,10 +50,10 @@ void randomize(void *vout, size_t outlen) {
        char *out = vout;
 
        while(outlen) {
-               size_t len = read(random_fd, out, outlen);
+               ssize_t len = read(random_fd, out, outlen);
 
                if(len <= 0) {
-                       if(errno == EAGAIN || errno == EINTR) {
+                       if(len == -1 && (errno == EAGAIN || errno == EINTR)) {
                                continue;
                        }
 
@@ -94,11 +94,8 @@ void randomize(void *out, size_t outlen) {
 void crypto_init(void) {
        random_init();
 
-       ENGINE_load_builtin_engines();
-       ENGINE_register_all_complete();
-
-       ERR_load_crypto_strings();
-       OpenSSL_add_all_algorithms();
+       uint64_t opts = OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ADD_ALL_CIPHERS | OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_ENGINE_ALL_BUILTIN;
+       OPENSSL_init_crypto(opts, NULL);
 
        if(!RAND_status()) {
                fprintf(stderr, "Not enough entropy for the PRNG!\n");
@@ -107,8 +104,6 @@ void crypto_init(void) {
 }
 
 void crypto_exit(void) {
-       EVP_cleanup();
-       ERR_free_strings();
-       ENGINE_cleanup();
+       OPENSSL_cleanup();
        random_exit();
 }