Blame SOURCES/freeradius-OpenSSL-HMAC-SHA1.patch

8fa666
From 91f663ce1b46ecd99399023ad539f158419272e7 Mon Sep 17 00:00:00 2001
8fa666
From: Alexander Scheel <ascheel@redhat.com>
8fa666
Date: Fri, 28 Sep 2018 11:03:52 -0400
8fa666
Subject: [PATCH 2/2] Replace HMAC-SHA1 implementation with OpenSSL's
8fa666
8fa666
If OpenSSL EVP is not found, fallback to internal implementation of
8fa666
HMAC-SHA1.
8fa666
8fa666
Signed-off-by: Alexander Scheel <ascheel@redhat.com>
8fa666
---
8fa666
 src/lib/hmacsha1.c | 29 ++++++++++++++++++++++++++++-
8fa666
 1 file changed, 28 insertions(+), 1 deletion(-)
8fa666
8fa666
diff --git a/src/lib/hmacsha1.c b/src/lib/hmacsha1.c
8fa666
index c3cbd87a2c..211470ea35 100644
8fa666
--- a/src/lib/hmacsha1.c
8fa666
+++ b/src/lib/hmacsha1.c
8fa666
@@ -10,13 +10,19 @@
8fa666
8fa666
 RCSID("$Id: c3cbd87a2c13c47da93fdb1bdfbf6da4c22aaac5 $")
8fa666
8fa666
+#ifdef HAVE_OPENSSL_EVP_H
8fa666
+#include <openssl/hmac.h>
8fa666
+#include <openssl/evp.h>
8fa666
+#endif
8fa666
+
8fa666
 #include <freeradius-devel/libradius.h>
8fa666
8fa666
 #ifdef HMAC_SHA1_DATA_PROBLEMS
8fa666
 unsigned int sha1_data_problems = 0;
8fa666
 #endif
8fa666
8fa666
-/** Calculate HMAC using SHA1
8fa666
+#ifdef HAVE_OPENSSL_EVP_H
8fa666
+/** Calculate HMAC using OpenSSL's SHA1 implementation
8fa666
  *
8fa666
  * @param digest Caller digest to be filled in.
8fa666
  * @param text Pointer to data stream.
8fa666
@@ -28,6 +34,26 @@
8fa666
 void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_t text_len,
8fa666
 		  uint8_t const *key, size_t key_len)
8fa666
 {
8fa666
+	HMAC_CTX *ctx  = HMAC_CTX_new();
8fa666
+	HMAC_Init_ex(ctx, key, key_len, EVP_sha1(), NULL);
8fa666
+	HMAC_Update(ctx, text, text_len);
8fa666
+	HMAC_Final(ctx, digest, NULL);
8fa666
+	HMAC_CTX_free(ctx);
8fa666
+}
8fa666
+
8fa666
+#else
8fa666
+
8fa666
+/** Calculate HMAC using internal SHA1 implementation
8fa666
+ *
8fa666
+ * @param digest Caller digest to be filled in.
8fa666
+ * @param text Pointer to data stream.
8fa666
+ * @param text_len length of data stream.
8fa666
+ * @param key Pointer to authentication key.
8fa666
+ * @param key_len Length of authentication key.
8fa666
+ */
8fa666
+void fr_hmac_sha1(uint8_t digest[SHA1_DIGEST_LENGTH], uint8_t const *text, size_t text_len,
8fa666
+		  uint8_t const *key, size_t key_len)
8fa666
+{
8fa666
 	fr_sha1_ctx context;
8fa666
 	uint8_t k_ipad[65];    /* inner padding - key XORd with ipad */
8fa666
 	uint8_t k_opad[65];    /* outer padding - key XORd with opad */
8fa666
@@ -142,6 +168,7 @@
8fa666
 	}
8fa666
 #endif
8fa666
 }
8fa666
+#endif /* HAVE_OPENSSL_EVP_H */
8fa666
8fa666
 /*
8fa666
 Test Vectors (Trailing '\0' of a character string not included in test):