From 433b14c52fdec59672f5963249526b646d991b62 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sat, 1 Jul 2023 13:15:16 +0100 Subject: [PATCH] Simplify openssl library detection and macros --- configure.ac | 6 +----- include/aes.h | 2 +- include/cc20.h | 4 ++-- include/n2n.h | 2 +- src/aes.c | 2 +- src/cc20.c | 8 ++++---- src/edge.c | 2 +- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 95fb826..8b1bae8 100644 --- a/configure.ac +++ b/configure.ac @@ -39,11 +39,7 @@ AC_ARG_WITH([openssl], [AS_HELP_STRING([--with-openssl], [enable support for OpenSSL])], [], [with_openssl=no]) AS_IF([test "x$with_openssl" != xno], - [AC_CHECK_LIB([crypto], [EVP_CIPHER_CTX_reset], - [ - AC_DEFINE([HAVE_OPENSSL_1_1], [1], [OpenSSL 1.1 is present]) - LIBS="-lcrypto ${LIBS}" - ], + [AC_CHECK_LIB([crypto], [EVP_CIPHER_CTX_reset],, [AC_MSG_ERROR([openssl library not found])] )], ) diff --git a/include/aes.h b/include/aes.h index 4604a16..9c804ec 100644 --- a/include/aes.h +++ b/include/aes.h @@ -34,7 +34,7 @@ #define AES128_KEY_BYTES (128/8) -#if defined (HAVE_OPENSSL_1_1) // openSSL 1.1 --------------------------------------------------------------------- +#ifdef HAVE_LIBCRYPTO // openSSL 1.1 --------------------------------------------------------------------- #include #include diff --git a/include/cc20.h b/include/cc20.h index 51f4425..b59ee06 100644 --- a/include/cc20.h +++ b/include/cc20.h @@ -23,14 +23,14 @@ #include // for size_t #include // for uint32_t, uint8_t -#include "config.h" // HAVE_OPENSSL_1_1 +#include "config.h" // HAVE_LIBCRYPTO #define CC20_IV_SIZE 16 #define CC20_KEY_BYTES (256/8) -#ifdef HAVE_OPENSSL_1_1 // openSSL 1.1 ---------------------------------------------------------------------------- +#ifdef HAVE_LIBCRYPTO // openSSL 1.1 ---------------------------------------------------------------------------- #include diff --git a/include/n2n.h b/include/n2n.h index f86805f..d8b9b3a 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -85,7 +85,7 @@ #include #endif -#if defined (HAVE_OPENSSL_1_1) +#ifdef HAVE_LIBCRYPTO #include #include #endif diff --git a/src/aes.c b/src/aes.c index 8469f4f..de702c6 100644 --- a/src/aes.c +++ b/src/aes.c @@ -26,7 +26,7 @@ #include "portable_endian.h" // for be32toh, htobe32 -#if defined (HAVE_OPENSSL_1_1) // openSSL 1.1 --------------------------------------------------------------------- +#ifdef HAVE_LIBCRYPTO // openSSL 1.1 --------------------------------------------------------------------- #include // for ERR_print_errors #include // for EVP_EncryptInit_ex, EVP_CIPHER_CTX_set_p... diff --git a/src/cc20.c b/src/cc20.c index 09c4844..d0e2774 100644 --- a/src/cc20.c +++ b/src/cc20.c @@ -20,12 +20,12 @@ #include // for calloc, free, size_t #include // for memcpy #include "cc20.h" -#include "config.h" // HAVE_OPENSSL_1_1 +#include "config.h" // HAVE_LIBCRYPTO #include "n2n.h" // for TRACE_ERROR, traceEvent #include "portable_endian.h" // for htole32 -#if defined (HAVE_OPENSSL_1_1) // openSSL 1.1 --------------------------------------------------------------------- +#ifdef HAVE_LIBCRYPTO // openSSL 1.1 --------------------------------------------------------------------- // get any erorr message out of openssl @@ -406,7 +406,7 @@ int cc20_init (const unsigned char *key, cc20_context_t **ctx) { *ctx = (cc20_context_t*)calloc(1, sizeof(cc20_context_t)); if(!(*ctx)) return -1; -#if defined (HAVE_OPENSSL_1_1) +#ifdef HAVE_LIBCRYPTO if(!((*ctx)->ctx = EVP_CIPHER_CTX_new())) { traceEvent(TRACE_ERROR, "cc20_init openssl's evp_* encryption context creation failed: %s", openssl_err_as_string()); @@ -423,7 +423,7 @@ int cc20_init (const unsigned char *key, cc20_context_t **ctx) { int cc20_deinit (cc20_context_t *ctx) { -#if defined (HAVE_OPENSSL_1_1) +#ifdef HAVE_LIBCRYPTO if(ctx->ctx) EVP_CIPHER_CTX_free(ctx->ctx); #endif free(ctx); diff --git a/src/edge.c b/src/edge.c index ae9115b..3a18d5b 100644 --- a/src/edge.c +++ b/src/edge.c @@ -1109,7 +1109,7 @@ int main (int argc, char* argv[]) { traceEvent(TRACE_NORMAL, "starting n2n edge %s %s", PACKAGE_VERSION, PACKAGE_BUILDDATE); -#if defined(HAVE_OPENSSL_1_1) +#ifdef HAVE_LIBCRYPTO traceEvent(TRACE_NORMAL, "using %s", OpenSSL_version(0)); #endif