]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Replace HMAC-MD5 implementation with OpenSSL's
authorAlexander Scheel <ascheel@redhat.com>
Fri, 28 Sep 2018 13:54:46 +0000 (09:54 -0400)
committerAlexander Scheel <ascheel@redhat.com>
Tue, 2 Oct 2018 14:19:34 +0000 (10:19 -0400)
If OpenSSL EVP is not found, fallback to internal implementation of
HMAC-MD5.

Signed-off-by: Alexander Scheel <ascheel@redhat.com>
src/lib/util/hmacmd5.c

index d5847ec6edb7763922d0b1acd8285b195bfeccfa..383fdd37bd17a0c18a069fb16518c9f9467155d7 100644 (file)
  */
 RCSID("$Id$")
 
+#ifdef HAVE_OPENSSL_EVP_H
+#include <freeradius-devel/tls/base.h>
+#endif
+
 #include <freeradius-devel/util/md5.h>
 
-/** Calculate HMAC using MD5
+#ifdef HAVE_OPENSSL_EVP_H
+/** Calculate HMAC using OpenSSL's MD5 implementation
+ *
+ * @param digest Caller digest to be filled in.
+ * @param text Pointer to data stream.
+ * @param text_len length of data stream.
+ * @param key Pointer to authentication key.
+ * @param key_len Length of authentication key.
+ *
+ */
+void fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *text, size_t text_len,
+                uint8_t const *key, size_t key_len)
+{
+       HMAC_CTX *ctx  = HMAC_CTX_new();
+
+#ifdef EVP_MD_CTX_FLAG_NON_FIPS_ALLOW
+       /* Since MD5 is not allowed by FIPS, explicitly allow it. */
+       HMAC_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
+#endif /* EVP_MD_CTX_FLAG_NON_FIPS_ALLOW */
+
+       HMAC_Init_ex(ctx, key, key_len, EVP_md5(), NULL);
+       HMAC_Update(ctx, text, text_len);
+       HMAC_Final(ctx, digest, NULL);
+}
+
+#else
+
+/** Calculate HMAC using internal MD5 implementation
  *
  * @param digest Caller digest to be filled in.
  * @param text Pointer to data stream.
@@ -103,6 +134,7 @@ void fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *text, size_t
                                              * hash */
        fr_md5_final(digest, &context);   /* finish up 2nd pass */
 }
+#endif /* HAVE_OPENSSL_EVP_H */
 
 /*
 Test Vectors (Trailing '\0' of a character string not included in test):