From 68a140d0c59b4f0a858217e4a0d527c07f486e8b Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 5 Jan 2017 09:06:31 +0100 Subject: [PATCH] Fix OpenSSL 1.1.0 compatibility If backward-compatible API is not defined (-DOPENSSL_API_COMPAT=0x10100000L) deprecated symbols cannot be used. Also see https://bugs.gentoo.org/show_bug.cgi?id=604698 Thanks eroen for reporting this. --- lib/crypto_backend/crypto_openssl.c | 61 +++++++++++++++++++---------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/lib/crypto_backend/crypto_openssl.c b/lib/crypto_backend/crypto_openssl.c index b1e14b6f..61ddb817 100644 --- a/lib/crypto_backend/crypto_openssl.c +++ b/lib/crypto_backend/crypto_openssl.c @@ -49,31 +49,20 @@ struct crypt_hmac { int hash_len; }; -int crypt_backend_init(struct crypt_device *ctx) -{ - if (crypto_backend_initialised) - return 0; - - OpenSSL_add_all_algorithms(); - - crypto_backend_initialised = 1; - return 0; -} - -uint32_t crypt_backend_flags(void) -{ - return 0; -} - -const char *crypt_backend_version(void) -{ - return SSLeay_version(SSLEAY_VERSION); -} - /* * Compatible wrappers for OpenSSL < 1.1.0 */ #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) +static void openssl_backend_init(void) +{ + OpenSSL_add_all_algorithms(); +} + +static const char *openssl_backend_version(void) +{ + return SSLeay_version(SSLEAY_VERSION); +} + static EVP_MD_CTX *EVP_MD_CTX_new(void) { EVP_MD_CTX *md = malloc(sizeof(*md)); @@ -105,8 +94,38 @@ static void HMAC_CTX_free(HMAC_CTX *md) HMAC_CTX_cleanup(md); free(md); } +#else +static void openssl_backend_init(void) +{ +} + +static const char *openssl_backend_version(void) +{ + return OpenSSL_version(OPENSSL_VERSION); +} #endif +int crypt_backend_init(struct crypt_device *ctx) +{ + if (crypto_backend_initialised) + return 0; + + openssl_backend_init(); + + crypto_backend_initialised = 1; + return 0; +} + +uint32_t crypt_backend_flags(void) +{ + return 0; +} + +const char *crypt_backend_version(void) +{ + return openssl_backend_version(); +} + /* HASH */ int crypt_hash_size(const char *name) {