From 7761a6992025ef06bf8dbf88d39a3bf9e459346a Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 28 Feb 2018 21:34:48 +0100 Subject: [PATCH] Fix compatibility with LibreSSL and OpenSSL < 1.1. Closes #184 on GitHub. --- m4/openssl.m4 | 1 + src/openssl/digest.c | 11 +++++++++++ src/openssl/digest.h | 1 + 3 files changed, 13 insertions(+) diff --git a/m4/openssl.m4 b/m4/openssl.m4 index ca9bbb5..0ff939b 100644 --- a/m4/openssl.m4 +++ b/m4/openssl.m4 @@ -55,4 +55,5 @@ AC_DEFUN([tinc_OPENSSL], ) AC_CHECK_FUNCS([BN_GENCB_new ERR_remove_state RSA_set0_key], , , [#include ]) + AC_CHECK_FUNCS([HMAC_CTX_new], , , [#include ]) ]) diff --git a/src/openssl/digest.c b/src/openssl/digest.c index d51dcaa..9569f3c 100644 --- a/src/openssl/digest.c +++ b/src/openssl/digest.c @@ -66,8 +66,13 @@ digest_t *digest_open_by_nid(int nid, int maclength) { } bool digest_set_key(digest_t *digest, const void *key, size_t len) { +#ifdef HAVE_HMAC_CTX_NEW digest->hmac_ctx = HMAC_CTX_new(); HMAC_Init_ex(digest->hmac_ctx, key, len, digest->digest, NULL); +#else + digest->hmac_ctx = xzalloc(sizeof(*digest->hmac_ctx)); + HMAC_Init(digest->hmac_ctx, key, len, digest->digest); +#endif if(!digest->hmac_ctx) { abort(); @@ -85,10 +90,16 @@ void digest_close(digest_t *digest) { EVP_MD_CTX_destroy(digest->md_ctx); } +#ifdef HAVE_HMAC_CTX_NEW + if(digest->hmac_ctx) { HMAC_CTX_free(digest->hmac_ctx); } +#else + free(digest->hmac_ctx); +#endif + free(digest); } diff --git a/src/openssl/digest.h b/src/openssl/digest.h index d553977..420b11e 100644 --- a/src/openssl/digest.h +++ b/src/openssl/digest.h @@ -21,6 +21,7 @@ */ #include +#include struct digest { const EVP_MD *digest; -- 2.25.1