Fix compatibility with LibreSSL and OpenSSL < 1.1.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 28 Feb 2018 20:34:48 +0000 (21:34 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 28 Feb 2018 20:48:04 +0000 (21:48 +0100)
Closes #184 on GitHub.

m4/openssl.m4
src/openssl/digest.c
src/openssl/digest.h

index ca9bbb55f67422bf77f53237f4a2fa379a4047fd..0ff939ba6513bd849b0358c62358522c7b987e26 100644 (file)
@@ -55,4 +55,5 @@ AC_DEFUN([tinc_OPENSSL],
   )
 
   AC_CHECK_FUNCS([BN_GENCB_new ERR_remove_state RSA_set0_key], , , [#include <openssl/rsa.h>])
+  AC_CHECK_FUNCS([HMAC_CTX_new], , , [#include <openssl/hmac.h>])
 ])
index d51dcaa971842e47a62defcdfc7dae31e8da91c1..9569f3cc64c40419be97a89dde6b15f547125a6f 100644 (file)
@@ -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);
 }
 
index d553977b35b22f386e05a99fa51fe382f78542ad..420b11e04ba4edb7104f35eb75978eaeed4a5c50 100644 (file)
@@ -21,6 +21,7 @@
 */
 
 #include <openssl/evp.h>
+#include <openssl/hmac.h>
 
 struct digest {
        const EVP_MD *digest;