Skip to content

Commit

Permalink
Simplify openssl library detection and macros
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishcoleman committed Jul 1, 2023
1 parent f05c24b commit b2d32d0
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 15 deletions.
6 changes: 1 addition & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
)],
)
Expand Down
2 changes: 1 addition & 1 deletion include/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions include/cc20.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion include/n2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
8 changes: 4 additions & 4 deletions src/cc20.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b2d32d0

Please sign in to comment.