summaryrefslogtreecommitdiff
path: root/src/apk_openssl.h
diff options
context:
space:
mode:
authorRosen Penev <rosenp@gmail.com>2021-01-11 01:51:58 -0800
committerTimo Teräs <timo.teras@iki.fi>2021-01-27 09:13:07 +0200
commitc4c8aa5ba0ec6bf4c6d74c4807b66edfbd91be7c (patch)
treeb41da7bce64475790173cfd80366bb272a2f30ec /src/apk_openssl.h
parentbcbcbfc1fc9514db7a9ecddec5029b8d89fde5ed (diff)
downloadapk-tools-c4c8aa5ba0ec6bf4c6d74c4807b66edfbd91be7c.tar.gz
apk-tools-c4c8aa5ba0ec6bf4c6d74c4807b66edfbd91be7c.tar.bz2
apk-tools-c4c8aa5ba0ec6bf4c6d74c4807b66edfbd91be7c.tar.xz
apk-tools-c4c8aa5ba0ec6bf4c6d74c4807b66edfbd91be7c.zip
fix compilation without deprecated OpenSSL APIs
(De)initialization is deprecated under OpenSSL 1.0 and above. [TT: Some simplifications, and additional edits.] Signed-off-by: Rosen Penev <rosenp@gmail.com>
Diffstat (limited to 'src/apk_openssl.h')
-rw-r--r--src/apk_openssl.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/apk_openssl.h b/src/apk_openssl.h
index 4ee6da2..c0abdf2 100644
--- a/src/apk_openssl.h
+++ b/src/apk_openssl.h
@@ -11,7 +11,11 @@
#define APK_SSL_COMPAT_H
#include <openssl/opensslv.h>
+#include <openssl/crypto.h>
#include <openssl/evp.h>
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
#if OPENSSL_VERSION_NUMBER < 0x1010000fL || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL)
@@ -25,6 +29,29 @@ static inline void EVP_MD_CTX_free(EVP_MD_CTX *mdctx)
return EVP_MD_CTX_destroy(mdctx);
}
+static inline void apk_openssl_cleanup(void)
+{
+ EVP_cleanup();
+#ifndef OPENSSL_NO_ENGINE
+ ENGINE_cleanup();
+#endif
+ CRYPTO_cleanup_all_ex_data();
+}
+
+static inline void apk_openssl_init(void)
+{
+ atexit(apk_openssl_cleanup);
+ OpenSSL_add_all_algorithms();
+#ifndef OPENSSL_NO_ENGINE
+ ENGINE_load_builtin_engines();
+ ENGINE_register_all_complete();
+#endif
+}
+
+#else
+
+static inline void apk_openssl_init(void) {}
+
#endif
#endif