3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-26 02:19:26 +01:00

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
This commit is contained in:
Tomasz Bursztyka 2015-01-22 17:58:23 +02:00 committed by Denis Kenzior
parent 8fba847b9d
commit 8f946c0cdc
2 changed files with 21 additions and 23 deletions

View File

@ -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; uint16_t key_data_len;
if (len < sizeof(struct eapol_key)) 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 && if (ek->protocol_version != EAPOL_PROTOCOL_VERSION_2001 &&
ek->protocol_version != EAPOL_PROTOCOL_VERSION_2004) ek->protocol_version != EAPOL_PROTOCOL_VERSION_2004)
return false; return NULL;
if (ek->packet_type != 3) if (ek->packet_type != 3)
return false; return NULL;
switch (ek->descriptor_type) { switch (ek->descriptor_type) {
case EAPOL_DESCRIPTOR_TYPE_RC4: case EAPOL_DESCRIPTOR_TYPE_RC4:
@ -92,7 +92,7 @@ bool eapol_verify(const uint8_t *data, size_t len)
case EAPOL_DESCRIPTOR_TYPE_WPA: case EAPOL_DESCRIPTOR_TYPE_WPA:
break; break;
default: default:
return false; return NULL;
} }
switch (ek->key_descriptor_version) { 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: case EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES:
break; break;
default: default:
return false; return NULL;
} }
key_data_len = L_BE16_TO_CPU(ek->key_data_len); key_data_len = L_BE16_TO_CPU(ek->key_data_len);
if (len < sizeof(struct eapol_key) + 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[]) 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; return false;
ek = (struct eapol_key *) data;
/* Verify according to 802.11, Section 11.6.6.2 */ /* Verify according to 802.11, Section 11.6.6.2 */
if (!ek->key_type) if (!ek->key_type)
return false; return false;
@ -159,17 +158,16 @@ bool eapol_process_ptk_1_of_4(const uint8_t *data, size_t len,
return true; 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[]) uint8_t out_snonce[])
{ {
struct eapol_key *ek; const struct eapol_key *ek;
uint16_t key_len; uint16_t key_len;
if (!eapol_verify(data, len)) ek = eapol_key_validate(frame, len);
if (!ek)
return false; return false;
ek = (struct eapol_key *) data;
/* Verify according to 802.11, Section 11.6.6.2 */ /* Verify according to 802.11, Section 11.6.6.2 */
if (!ek->key_type) if (!ek->key_type)
return false; return false;

View File

@ -96,11 +96,11 @@ struct eapol_key {
bool eapol_calculate_mic(const uint8_t *kck, const struct eapol_key *frame, bool eapol_calculate_mic(const uint8_t *kck, const struct eapol_key *frame,
uint8_t *mic); 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[]); 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[]); uint8_t out_snonce[]);
struct eapol_key *eapol_create_ptk_2_of_4( struct eapol_key *eapol_create_ptk_2_of_4(
enum eapol_protocol_version protocol, enum eapol_protocol_version protocol,