crypto: make init more readable

cute-signatures
Aydin Mercan 2022-08-26 12:39:52 +03:00
parent 962eed50db
commit 4436222e90
Signed by: jaiden
SSH Key Fingerprint: SHA256:vy6hjzotbn/MWZAbjzURNk3NL62EPkjoHsJ5xr/s7nk
1 changed files with 9 additions and 4 deletions

View File

@ -1,18 +1,22 @@
#include <sodium.h>
#include <openssl/evp.h>
#include <sodium.h>
#include "apk_crypto.h"
#include "apk_defines.h"
#if OPENSSL_VERSION_NUMBER < 0x1010000fL || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL)
#define APK_NEED_LIBCRYPTO_CLEANUP 1
#endif
#ifdef APK_NEED_LIBCRYPTO_CLEANUP
static void apk_crypto_cleanup(void)
{
EVP_cleanup();
#ifndef OPENSSL_NO_ENGINE
ENGINE_cleanup();
#endif
CRYPTO_cleanup_all_ex_data();
}
#endif
@ -22,7 +26,7 @@ int apk_crypto_init(void)
return -APKE_CRYPTO_ERROR;
}
#if OPENSSL_VERSION_NUMBER < 0x1010000fL || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL)
#ifdef APK_NEED_LIBCRYPTO_CLEANUP
atexit(apk_crypto_cleanup);
OpenSSL_add_all_algorithms();
@ -31,8 +35,9 @@ int apk_crypto_init(void)
ENGINE_register_all_complete();
#endif
#endif
return 0;
}
#undef APK_NEED_LIBCRYPTO_CLEANUP