From 8f946c0cdcf6eb7ae248129d3aa9a6782905d8cf Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Thu, 22 Jan 2015 17:58:23 +0200 Subject: [PATCH] eapol: Change function signatures The frame which comes in is an EAPoL-key frame, thus changing the name accordingly (as well as the parameter names). Also, returning the cast pointer instead of a boolean is easier to use as there won't be any need to perform the cast ourselves afterward --- src/eapol.c | 38 ++++++++++++++++++-------------------- src/eapol.h | 6 +++--- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/eapol.c b/src/eapol.c index 52fb48cc..4b7b37bc 100644 --- a/src/eapol.c +++ b/src/eapol.c @@ -69,22 +69,22 @@ bool eapol_calculate_mic(const uint8_t *kck, const struct eapol_key *frame, } } -bool eapol_verify(const uint8_t *data, size_t len) +const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len) { - struct eapol_key *ek; + const struct eapol_key *ek; uint16_t key_data_len; if (len < sizeof(struct eapol_key)) - return false; + return NULL; - ek = (struct eapol_key *) data; + ek = (const struct eapol_key *) frame; if (ek->protocol_version != EAPOL_PROTOCOL_VERSION_2001 && ek->protocol_version != EAPOL_PROTOCOL_VERSION_2004) - return false; + return NULL; if (ek->packet_type != 3) - return false; + return NULL; switch (ek->descriptor_type) { case EAPOL_DESCRIPTOR_TYPE_RC4: @@ -92,7 +92,7 @@ bool eapol_verify(const uint8_t *data, size_t len) case EAPOL_DESCRIPTOR_TYPE_WPA: break; default: - return false; + return NULL; } switch (ek->key_descriptor_version) { @@ -101,26 +101,25 @@ bool eapol_verify(const uint8_t *data, size_t len) case EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES: break; default: - return false; + return NULL; } key_data_len = L_BE16_TO_CPU(ek->key_data_len); if (len < sizeof(struct eapol_key) + key_data_len) - return false; + return NULL; - return true; + return ek; } -bool eapol_process_ptk_1_of_4(const uint8_t *data, size_t len, +bool eapol_process_ptk_1_of_4(const uint8_t *frame, size_t len, uint8_t out_anonce[]) { - struct eapol_key *ek; + const struct eapol_key *ek; - if (!eapol_verify(data, len)) + ek = eapol_key_validate(frame, len); + if (!ek) return false; - ek = (struct eapol_key *) data; - /* Verify according to 802.11, Section 11.6.6.2 */ if (!ek->key_type) return false; @@ -159,17 +158,16 @@ bool eapol_process_ptk_1_of_4(const uint8_t *data, size_t len, return true; } -bool eapol_process_ptk_2_of_4(const uint8_t *data, size_t len, +bool eapol_process_ptk_2_of_4(const uint8_t *frame, size_t len, uint8_t out_snonce[]) { - struct eapol_key *ek; + const struct eapol_key *ek; uint16_t key_len; - if (!eapol_verify(data, len)) + ek = eapol_key_validate(frame, len); + if (!ek) return false; - ek = (struct eapol_key *) data; - /* Verify according to 802.11, Section 11.6.6.2 */ if (!ek->key_type) return false; diff --git a/src/eapol.h b/src/eapol.h index 27e80e71..935d6515 100644 --- a/src/eapol.h +++ b/src/eapol.h @@ -96,11 +96,11 @@ struct eapol_key { 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); +const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len); -bool eapol_process_ptk_1_of_4(const uint8_t *data, size_t len, +bool eapol_process_ptk_1_of_4(const uint8_t *frame, size_t len, uint8_t out_anonce[]); -bool eapol_process_ptk_2_of_4(const uint8_t *data, size_t len, +bool eapol_process_ptk_2_of_4(const uint8_t *frame, size_t len, uint8_t out_snonce[]); struct eapol_key *eapol_create_ptk_2_of_4( enum eapol_protocol_version protocol,