From 812a55177c69f61ab5f6365b681958ef36eb9afe Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Sat, 27 Dec 2014 22:53:14 -0600 Subject: [PATCH] unit: Add eapol_calculate_mic test --- unit/test-eapol.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/unit/test-eapol.c b/unit/test-eapol.c index 2cc4bccf..6b183f28 100644 --- a/unit/test-eapol.c +++ b/unit/test-eapol.c @@ -360,6 +360,35 @@ static void eapol_key_mic_test(const void *data) assert(!memcmp(test->mic, mic, sizeof(mic))); } +struct eapol_calculate_mic_test { + const uint8_t *frame; + size_t frame_len; + const uint8_t *kck; + const uint8_t *mic; +}; + +static const struct eapol_calculate_mic_test eapol_calculate_mic_test_1 = { + .frame = eapol_key_mic_data_1, + .frame_len = sizeof(eapol_key_mic_data_1), + .kck = kck_data_1, + .mic = eapol_key_mic_2, +}; + +static void eapol_calculate_mic_test(const void *data) +{ + const struct eapol_calculate_mic_test *test = data; + struct eapol_key *frame; + uint8_t mic[16]; + bool ret; + + memset(mic, 0, sizeof(mic)); + frame = (struct eapol_key *) test->frame; + + ret = eapol_calculate_mic(test->kck, frame, mic); + assert(ret); + assert(!memcmp(test->mic, mic, sizeof(mic))); +} + int main(int argc, char *argv[]) { l_test_init(&argc, &argv); @@ -378,5 +407,8 @@ int main(int argc, char *argv[]) l_test_add("/EAPoL Key/MIC Test 2", eapol_key_mic_test, &eapol_key_mic_test_2); + l_test_add("/EAPoL Key/Calculate MIC Test 1", + eapol_calculate_mic_test, &eapol_calculate_mic_test_1); + return l_test_run(); }