From 096165d1425ae299bfee8ce8b29a4738a0d5a6b8 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Sat, 27 Dec 2014 22:37:39 -0600 Subject: [PATCH] eapol: Add eapol_calculate_mic --- Makefile.am | 1 + src/eapol.c | 32 ++++++++++++++++++++++++++++++++ src/eapol.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/Makefile.am b/Makefile.am index 4e3cc51f..695b7cf9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -67,6 +67,7 @@ monitor_iwmon_SOURCES = monitor/main.c linux/nl80211.h \ src/ie.h src/ie.c \ src/util.h src/util.c \ src/sha1.h src/sha1.c \ + src/md5.h src/md5.c \ src/eapol.h src/eapol.c monitor_iwmon_LDADD = ell/libell-internal.la diff --git a/src/eapol.c b/src/eapol.c index 680a3878..52fb48cc 100644 --- a/src/eapol.c +++ b/src/eapol.c @@ -27,6 +27,8 @@ #include #include +#include "sha1.h" +#include "md5.h" #include "eapol.h" #define VERIFY_IS_ZERO(field) \ @@ -37,6 +39,36 @@ return false; \ } while (false) \ +/* + * MIC calculation depends on the selected hash function. The has function + * is given in the EAPoL Key Descriptor Version field. + * + * The MIC length is always 16 bytes for currently known Key Descriptor + * Versions. + * + * The input struct eapol_key *frame should have a zero-d MIC field + */ +bool eapol_calculate_mic(const uint8_t *kck, const struct eapol_key *frame, + uint8_t *mic) +{ + size_t frame_len = sizeof(struct eapol_key); + + frame_len += L_BE16_TO_CPU(frame->key_data_len); + + switch (frame->key_descriptor_version) { + case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4: + return hmac_md5(kck, 16, (uint8_t *) frame, frame_len, + mic, 16); + case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES: + return hmac_sha1(kck, 16, (uint8_t *) frame, frame_len, + mic, 16); + case EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES: + return false; + default: + return false; + } +} + bool eapol_verify(const uint8_t *data, size_t len) { struct eapol_key *ek; diff --git a/src/eapol.h b/src/eapol.h index 7f5a2332..27e80e71 100644 --- a/src/eapol.h +++ b/src/eapol.h @@ -93,6 +93,9 @@ struct eapol_key { uint8_t key_data[0]; } __attribute__ ((packed)); +bool eapol_calculate_mic(const uint8_t *kck, const struct eapol_key *frame, + uint8_t *mic); + bool eapol_verify(const uint8_t *data, size_t len); bool eapol_process_ptk_1_of_4(const uint8_t *data, size_t len,