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

33c701
From b93796b1890b35a0922bfba9cd08e8a1a5f956cf Mon Sep 17 00:00:00 2001
33c701
From: Alexander Scheel <ascheel@redhat.com>
33c701
Date: Fri, 28 Sep 2018 09:54:46 -0400
33c701
Subject: [PATCH 1/2] Replace HMAC-MD5 implementation with OpenSSL's
33c701
33c701
If OpenSSL EVP is not found, fallback to internal implementation of
33c701
HMAC-MD5.
33c701
33c701
Signed-off-by: Alexander Scheel <ascheel@redhat.com>
33c701
---
33c701
 src/lib/hmacmd5.c | 34 +++++++++++++++++++++++++++++++++-
33c701
 1 file changed, 33 insertions(+), 1 deletion(-)
33c701
33c701
diff --git a/src/lib/hmacmd5.c b/src/lib/hmacmd5.c
33c701
index 2c662ff368..1cca00fa2a 100644
33c701
--- a/src/lib/hmacmd5.c
33c701
+++ b/src/lib/hmacmd5.c
33c701
@@ -27,10 +27,41 @@
33c701
33c701
 RCSID("$Id: 2c662ff368e46556edd2cfdf408bd0fca0ab5f18 $")
33c701
33c701
+#ifdef HAVE_OPENSSL_EVP_H
33c701
+#include <openssl/hmac.h>
33c701
+#include <openssl/evp.h>
33c701
+#endif
33c701
+
33c701
 #include <freeradius-devel/libradius.h>
33c701
 #include <freeradius-devel/md5.h>
33c701
33c701
-/** Calculate HMAC using MD5
33c701
+#ifdef HAVE_OPENSSL_EVP_H
33c701
+/** Calculate HMAC using OpenSSL's MD5 implementation
33c701
+ *
33c701
+ * @param digest Caller digest to be filled in.
33c701
+ * @param text Pointer to data stream.
33c701
+ * @param text_len length of data stream.
33c701
+ * @param key Pointer to authentication key.
33c701
+ * @param key_len Length of authentication key.
33c701
+ *
33c701
+ */
33c701
+void fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *text, size_t text_len,
33c701
+		 uint8_t const *key, size_t key_len)
33c701
+{
33c701
+	HMAC_CTX *ctx  = HMAC_CTX_new();
33c701
+
33c701
+#ifdef EVP_MD_CTX_FLAG_NON_FIPS_ALLOW
33c701
+	/* Since MD5 is not allowed by FIPS, explicitly allow it. */
33c701
+	HMAC_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
33c701
+#endif /* EVP_MD_CTX_FLAG_NON_FIPS_ALLOW */
33c701
+
33c701
+	HMAC_Init_ex(ctx, key, key_len, EVP_md5(), NULL);
33c701
+	HMAC_Update(ctx, text, text_len);
33c701
+	HMAC_Final(ctx, digest, NULL);
33c701
+	HMAC_CTX_free(ctx);
33c701
+}
33c701
+#else
33c701
+/** Calculate HMAC using internal MD5 implementation
33c701
  *
33c701
  * @param digest Caller digest to be filled in.
33c701
  * @param text Pointer to data stream.
33c701
@@ -101,6 +132,7 @@
33c701
 					      * hash */
33c701
 	fr_md5_final(digest, &context);	  /* finish up 2nd pass */
33c701
 }
33c701
+#endif /* HAVE_OPENSSL_EVP_H */
33c701
33c701
 /*
33c701
 Test Vectors (Trailing '\0' of a character string not included in test):