Simplify openssl library detection and macros

This commit is contained in:
Hamish Coleman
2023-07-02 22:18:09 +08:00
parent f05c24b259
commit 433b14c52f
7 changed files with 11 additions and 15 deletions
+1 -5
View File
@@ -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])]
)],
)
+1 -1
View File
@@ -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 <openssl/aes.h>
#include <openssl/evp.h>
+2 -2
View File
@@ -23,14 +23,14 @@
#include <stddef.h> // for size_t
#include <stdint.h> // 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 <openssl/evp.h>
+1 -1
View File
@@ -85,7 +85,7 @@
#include <zstd.h>
#endif
#if defined (HAVE_OPENSSL_1_1)
#ifdef HAVE_LIBCRYPTO
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#endif
+1 -1
View File
@@ -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 <openssl/err.h> // for ERR_print_errors
#include <openssl/evp.h> // for EVP_EncryptInit_ex, EVP_CIPHER_CTX_set_p...
+4 -4
View File
@@ -20,12 +20,12 @@
#include <stdlib.h> // for calloc, free, size_t
#include <string.h> // 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);
+1 -1
View File
@@ -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