Blame SOURCES/0001-Add-compatibility-with-OpenSSL-1.1.0.patch

b3b4f8
From e498737a96e8832a2cb9141ab1fe51e129185a48 Mon Sep 17 00:00:00 2001
b3b4f8
From: Simo Sorce <simo@redhat.com>
b3b4f8
Date: Wed, 29 Jun 2016 11:15:11 -0400
b3b4f8
Subject: [PATCH] Add compatibility with OpenSSL 1.1.0
b3b4f8
b3b4f8
In their continued wisdom OpenSSL developers keep breaking APIs left and right
b3b4f8
with very poor documentation and forward/backward source compatibility.
b3b4f8
b3b4f8
Signed-off-by: Simo Sorce <simo@redhat.com>
b3b4f8
---
b3b4f8
 src/crypto.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++------------
b3b4f8
 1 file changed, 48 insertions(+), 12 deletions(-)
b3b4f8
b3b4f8
diff --git a/src/crypto.c b/src/crypto.c
b3b4f8
index 9fe69f97cfe9a4c1c9a5fb1861fef3fdfb8ae596..33a0c3e9060df0fa14784e869b5edce2f462b238 100644
b3b4f8
--- a/src/crypto.c
b3b4f8
+++ b/src/crypto.c
b3b4f8
@@ -27,6 +27,32 @@
b3b4f8
 
b3b4f8
 #include "crypto.h"
b3b4f8
 
b3b4f8
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
b3b4f8
+HMAC_CTX *HMAC_CTX_new(void)
b3b4f8
+{
b3b4f8
+    HMAC_CTX *ctx;
b3b4f8
+
b3b4f8
+    ctx = OPENSSL_malloc(sizeof(HMAC_CTX));
b3b4f8
+    if (!ctx) return NULL;
b3b4f8
+
b3b4f8
+    HMAC_CTX_init(ctx);
b3b4f8
+
b3b4f8
+    return ctx;
b3b4f8
+}
b3b4f8
+
b3b4f8
+void HMAC_CTX_free(HMAC_CTX *ctx)
b3b4f8
+{
b3b4f8
+    if (ctx == NULL) return;
b3b4f8
+
b3b4f8
+    HMAC_CTX_cleanup(ctx);
b3b4f8
+    OPENSSL_free(ctx);
b3b4f8
+}
b3b4f8
+
b3b4f8
+#define EVP_MD_CTX_new EVP_MD_CTX_create
b3b4f8
+#define EVP_MD_CTX_free EVP_MD_CTX_destroy
b3b4f8
+
b3b4f8
+#endif
b3b4f8
+
b3b4f8
 int RAND_BUFFER(struct ntlm_buffer *random)
b3b4f8
 {
b3b4f8
     int ret;
b3b4f8
@@ -42,30 +68,34 @@ int HMAC_MD5_IOV(struct ntlm_buffer *key,
b3b4f8
                  struct ntlm_iov *iov,
b3b4f8
                  struct ntlm_buffer *result)
b3b4f8
 {
b3b4f8
-    HMAC_CTX hmac_ctx;
b3b4f8
+    HMAC_CTX *hmac_ctx;
b3b4f8
     unsigned int len;
b3b4f8
     size_t i;
b3b4f8
     int ret = 0;
b3b4f8
 
b3b4f8
     if (result->length != 16) return EINVAL;
b3b4f8
 
b3b4f8
-    HMAC_CTX_init(&hmac_ctx);
b3b4f8
+    hmac_ctx = HMAC_CTX_new();
b3b4f8
+    if (!hmac_ctx) {
b3b4f8
+        ret = ERR_CRYPTO;
b3b4f8
+        goto done;
b3b4f8
+    }
b3b4f8
 
b3b4f8
-    ret = HMAC_Init_ex(&hmac_ctx, key->data, key->length, EVP_md5(), NULL);
b3b4f8
+    ret = HMAC_Init_ex(hmac_ctx, key->data, key->length, EVP_md5(), NULL);
b3b4f8
     if (ret == 0) {
b3b4f8
         ret = ERR_CRYPTO;
b3b4f8
         goto done;
b3b4f8
     }
b3b4f8
 
b3b4f8
     for (i = 0; i < iov->num; i++) {
b3b4f8
-        ret = HMAC_Update(&hmac_ctx, iov->data[i]->data, iov->data[i]->length);
b3b4f8
+        ret = HMAC_Update(hmac_ctx, iov->data[i]->data, iov->data[i]->length);
b3b4f8
         if (ret == 0) {
b3b4f8
             ret = ERR_CRYPTO;
b3b4f8
             goto done;
b3b4f8
         }
b3b4f8
     }
b3b4f8
 
b3b4f8
-    ret = HMAC_Final(&hmac_ctx, result->data, &len;;
b3b4f8
+    ret = HMAC_Final(hmac_ctx, result->data, &len;;
b3b4f8
     if (ret == 0) {
b3b4f8
         ret = ERR_CRYPTO;
b3b4f8
         goto done;
b3b4f8
@@ -74,7 +104,7 @@ int HMAC_MD5_IOV(struct ntlm_buffer *key,
b3b4f8
     ret = 0;
b3b4f8
 
b3b4f8
 done:
b3b4f8
-    HMAC_CTX_cleanup(&hmac_ctx);
b3b4f8
+    HMAC_CTX_free(hmac_ctx);
b3b4f8
     return ret;
b3b4f8
 }
b3b4f8
 
b3b4f8
@@ -93,26 +123,32 @@ static int mdx_hash(const EVP_MD *type,
b3b4f8
                     struct ntlm_buffer *payload,
b3b4f8
                     struct ntlm_buffer *result)
b3b4f8
 {
b3b4f8
-    EVP_MD_CTX ctx;
b3b4f8
+    EVP_MD_CTX *ctx;
b3b4f8
     unsigned int len;
b3b4f8
     int ret;
b3b4f8
 
b3b4f8
     if (result->length != 16) return EINVAL;
b3b4f8
 
b3b4f8
-    EVP_MD_CTX_init(&ctx;;
b3b4f8
-    ret = EVP_DigestInit_ex(&ctx, type, NULL);
b3b4f8
+    ctx = EVP_MD_CTX_new();
b3b4f8
+    if (!ctx) {
b3b4f8
+        ret = ERR_CRYPTO;
b3b4f8
+        goto done;
b3b4f8
+    }
b3b4f8
+
b3b4f8
+    EVP_MD_CTX_init(ctx);
b3b4f8
+    ret = EVP_DigestInit_ex(ctx, type, NULL);
b3b4f8
     if (ret == 0) {
b3b4f8
         ret = ERR_CRYPTO;
b3b4f8
         goto done;
b3b4f8
     }
b3b4f8
 
b3b4f8
-    ret = EVP_DigestUpdate(&ctx, payload->data, payload->length);
b3b4f8
+    ret = EVP_DigestUpdate(ctx, payload->data, payload->length);
b3b4f8
     if (ret == 0) {
b3b4f8
         ret = ERR_CRYPTO;
b3b4f8
         goto done;
b3b4f8
     }
b3b4f8
 
b3b4f8
-    ret = EVP_DigestFinal_ex(&ctx, result->data, &len;;
b3b4f8
+    ret = EVP_DigestFinal_ex(ctx, result->data, &len;;
b3b4f8
     if (ret == 0) {
b3b4f8
         ret = ERR_CRYPTO;
b3b4f8
         goto done;
b3b4f8
@@ -121,7 +157,7 @@ static int mdx_hash(const EVP_MD *type,
b3b4f8
     ret = 0;
b3b4f8
 
b3b4f8
 done:
b3b4f8
-    EVP_MD_CTX_cleanup(&ctx;;
b3b4f8
+    if (ctx) EVP_MD_CTX_free(ctx);
b3b4f8
     return ret;
b3b4f8
 }
b3b4f8
 
b3b4f8
-- 
b3b4f8
2.9.3
b3b4f8