]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
OpenSSL: Implement SHA1 HMAC functions using HMAC API
authorJouni Malinen <j@w1.fi>
Thu, 16 Aug 2012 17:38:25 +0000 (20:38 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 16 Aug 2012 17:38:25 +0000 (20:38 +0300)
Use the OpenSSL HMAC implementation instead of the internal sha1.c
implementation of HMAC with SHA1.

Signed-hostap: Jouni Malinen <j@w1.fi>

hostapd/Android.mk
hostapd/Makefile
src/crypto/crypto_openssl.c
wpa_supplicant/Android.mk
wpa_supplicant/Makefile

index bc6d689b6369ede40ec6134b76f63a1870d21c78..5a0136b17ff5079b53c75ece675d6052371fd279 100644 (file)
@@ -669,7 +669,9 @@ endif
 
 SHA1OBJS =
 ifdef NEED_SHA1
+ifneq ($(CONFIG_TLS), openssl)
 SHA1OBJS += src/crypto/sha1.c
+endif
 SHA1OBJS += src/crypto/sha1-prf.c
 ifdef CONFIG_INTERNAL_SHA1
 SHA1OBJS += src/crypto/sha1-internal.c
index da1517de496319c080be5ebc8c3cffe18355f7bc..120eca638f7857c836cd303a27492c0eb5e4bbb9 100644 (file)
@@ -660,7 +660,9 @@ OBJS += $(AESOBJS)
 endif
 
 ifdef NEED_SHA1
+ifneq ($(CONFIG_TLS), openssl)
 SHA1OBJS += ../src/crypto/sha1.o
+endif
 SHA1OBJS += ../src/crypto/sha1-prf.o
 ifdef CONFIG_INTERNAL_SHA1
 SHA1OBJS += ../src/crypto/sha1-internal.o
index 66cf840840941045f5186e3d13c0cbc961b15224..791f588f729c827da53718c3d32473cd15b3416c 100644 (file)
@@ -698,3 +698,42 @@ int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len,
                return -1;
        return 0;
 }
+
+
+int hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
+                    const u8 *addr[], const size_t *len, u8 *mac)
+{
+       HMAC_CTX ctx;
+       size_t i;
+       unsigned int mdlen;
+       int res;
+
+       HMAC_CTX_init(&ctx);
+#if OPENSSL_VERSION_NUMBER < 0x00909000
+       HMAC_Init_ex(&ctx, key, key_len, EVP_sha1(), NULL);
+#else /* openssl < 0.9.9 */
+       if (HMAC_Init_ex(&ctx, key, key_len, EVP_sha1(), NULL) != 1)
+               return -1;
+#endif /* openssl < 0.9.9 */
+
+       for (i = 0; i < num_elem; i++)
+               HMAC_Update(&ctx, addr[i], len[i]);
+
+       mdlen = 20;
+#if OPENSSL_VERSION_NUMBER < 0x00909000
+       HMAC_Final(&ctx, mac, &mdlen);
+       res = 1;
+#else /* openssl < 0.9.9 */
+       res = HMAC_Final(&ctx, mac, &mdlen);
+#endif /* openssl < 0.9.9 */
+       HMAC_CTX_cleanup(&ctx);
+
+       return res == 1 ? 0 : -1;
+}
+
+
+int hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
+              u8 *mac)
+{
+       return hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac);
+}
index 5ad2d678eeec5d682ffcd9fdc63ce0d53c94b0af..7ed7fc0a3ea4429e29ecbddc203b6b3318d02af2 100644 (file)
@@ -1054,7 +1054,9 @@ endif
 
 SHA1OBJS =
 ifdef NEED_SHA1
+ifneq ($(CONFIG_TLS), openssl)
 SHA1OBJS += src/crypto/sha1.c
+endif
 SHA1OBJS += src/crypto/sha1-prf.c
 ifdef CONFIG_INTERNAL_SHA1
 SHA1OBJS += src/crypto/sha1-internal.c
index 63cff71b656bc0c7c67c0803280a0c7495006b8b..8ea615016e71444a23bafa1f4c0aa21c6d68fa88 100644 (file)
@@ -1081,7 +1081,9 @@ OBJS += $(AESOBJS)
 endif
 
 ifdef NEED_SHA1
+ifneq ($(CONFIG_TLS), openssl)
 SHA1OBJS += ../src/crypto/sha1.o
+endif
 SHA1OBJS += ../src/crypto/sha1-prf.o
 ifdef CONFIG_INTERNAL_SHA1
 SHA1OBJS += ../src/crypto/sha1-internal.o