eapol.h (5207B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2013-2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #include <stdint.h> 24 #include <stdbool.h> 25 #include <asm/byteorder.h> 26 #include <linux/types.h> 27 #include "src/eapolutil.h" 28 29 struct eapol_sm; 30 struct handshake_state; 31 struct preauth_sm; 32 enum handshake_kde; 33 enum ie_rsn_akm_suite; 34 35 typedef int (*eapol_tx_packet_func_t)(uint32_t ifindex, 36 const uint8_t *dest, uint16_t proto, 37 const struct eapol_frame *ef, 38 bool noencrypt, 39 void *user_data); 40 typedef void (*eapol_rekey_offload_func_t)(uint32_t ifindex, 41 const uint8_t *kek, 42 const uint8_t *kck, 43 uint64_t replay_counter, 44 void *user_data); 45 typedef void (*eapol_sm_event_func_t)(unsigned int event, 46 const void *event_data, 47 void *user_data); 48 typedef void (*eapol_preauth_cb_t)(const uint8_t *pmk, void *user_data); 49 typedef void (*eapol_preauth_destroy_func_t)(void *user_data); 50 typedef void (*eapol_frame_watch_func_t)(uint16_t proto, const uint8_t *from, 51 const struct eapol_frame *frame, 52 bool noencrypt, 53 void *user_data); 54 typedef void (*eapol_install_pmk_func_t)(struct handshake_state *hs, 55 const uint8_t *pmk, 56 size_t pmk_len); 57 58 bool eapol_calculate_mic(enum ie_rsn_akm_suite akm, const uint8_t *kck, 59 const struct eapol_key *frame, uint8_t *mic, 60 size_t mic_len); 61 bool eapol_verify_mic(enum ie_rsn_akm_suite akm, const uint8_t *kck, 62 const struct eapol_key *frame, size_t mic_len); 63 64 uint8_t *eapol_decrypt_key_data(enum ie_rsn_akm_suite akm, const uint8_t *kek, 65 const struct eapol_key *frame, 66 size_t *decrypted_size, size_t mic_len); 67 68 bool eapol_verify_ptk_1_of_4(const struct eapol_key *ek, size_t mic_len, 69 bool ptk_complete); 70 bool eapol_verify_ptk_2_of_4(const struct eapol_key *ek, bool ptk_complete); 71 bool eapol_verify_ptk_3_of_4(const struct eapol_key *ek, bool is_wpa, 72 size_t mic_len); 73 bool eapol_verify_ptk_4_of_4(const struct eapol_key *ek, bool is_wpa); 74 bool eapol_verify_gtk_1_of_2(const struct eapol_key *ek, bool is_wpa, 75 size_t mic_len); 76 bool eapol_verify_gtk_2_of_2(const struct eapol_key *ek, bool is_wpa); 77 78 struct eapol_key *eapol_create_ptk_2_of_4( 79 enum eapol_protocol_version protocol, 80 enum eapol_key_descriptor_version version, 81 uint64_t key_replay_counter, 82 const uint8_t snonce[], 83 size_t extra_len, 84 const uint8_t *extra_data, 85 bool is_wpa, 86 size_t mic_len, 87 bool secure); 88 89 struct eapol_key *eapol_create_ptk_4_of_4( 90 enum eapol_protocol_version protocol, 91 enum eapol_key_descriptor_version version, 92 uint64_t key_replay_counter, 93 bool is_wpa, 94 size_t mic_len); 95 96 struct eapol_key *eapol_create_gtk_2_of_2( 97 enum eapol_protocol_version protocol, 98 enum eapol_key_descriptor_version version, 99 uint64_t key_replay_counter, 100 size_t extra_len, 101 const uint8_t *extra_data, 102 bool is_wpa, uint8_t wpa_key_id, 103 size_t mic_len); 104 105 void __eapol_rx_packet(uint32_t ifindex, const uint8_t *src, uint16_t proto, 106 const uint8_t *frame, size_t len, bool noencrypt); 107 void __eapol_tx_packet(uint32_t ifindex, const uint8_t *dst, uint16_t proto, 108 const struct eapol_frame *frame, bool noencrypt); 109 void __eapol_set_tx_packet_func(eapol_tx_packet_func_t func); 110 void __eapol_set_tx_user_data(void *user_data); 111 112 void __eapol_set_install_pmk_func(eapol_install_pmk_func_t func); 113 114 void __eapol_set_rekey_offload_func(eapol_rekey_offload_func_t func); 115 void __eapol_update_replay_counter(uint32_t ifindex, const uint8_t *spa, 116 const uint8_t *aa, uint64_t replay_counter); 117 void __eapol_set_config(struct l_settings *config); 118 119 struct eapol_sm *eapol_sm_new(struct handshake_state *hs); 120 void eapol_sm_free(struct eapol_sm *sm); 121 122 void eapol_sm_set_protocol_version(struct eapol_sm *sm, 123 enum eapol_protocol_version protocol_version); 124 125 void eapol_sm_set_use_eapol_start(struct eapol_sm *sm, bool enabled); 126 void eapol_sm_set_require_handshake(struct eapol_sm *sm, bool enabled); 127 void eapol_sm_set_listen_interval(struct eapol_sm *sm, uint16_t interval); 128 void eapol_sm_set_user_data(struct eapol_sm *sm, void *user_data); 129 130 void eapol_register(struct eapol_sm *sm); 131 bool eapol_start(struct eapol_sm *sm); 132 133 struct preauth_sm *eapol_preauth_start(const uint8_t *aa, 134 const struct handshake_state *hs, 135 eapol_preauth_cb_t cb, void *user_data, 136 eapol_preauth_destroy_func_t destroy); 137 void eapol_preauth_cancel(uint32_t ifindex); 138 139 int eapol_init(void); 140 void eapol_exit(void);