3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 17:59:25 +01:00

eapol: Add eapol_calculate_mic

This commit is contained in:
Denis Kenzior 2014-12-27 22:37:39 -06:00
parent 27d25efc0b
commit 096165d142
3 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -27,6 +27,8 @@
#include <string.h>
#include <ell/ell.h>
#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;

View File

@ -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,