wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
eap_sim_common.h
Go to the documentation of this file.
1 
5 #ifndef EAP_SIM_COMMON_H
6 #define EAP_SIM_COMMON_H
7 
8 #define EAP_SIM_NONCE_S_LEN 16
9 #define EAP_SIM_NONCE_MT_LEN 16
10 #define EAP_SIM_MAC_LEN 16
11 #define EAP_SIM_MK_LEN 20
12 #define EAP_SIM_K_AUT_LEN 16
13 #define EAP_SIM_K_ENCR_LEN 16
14 #define EAP_SIM_KEYING_DATA_LEN 64
15 #define EAP_SIM_IV_LEN 16
16 #define EAP_SIM_KC_LEN 8
17 #define EAP_SIM_SRES_LEN 4
18 
19 #define GSM_RAND_LEN 16
20 
21 #define EAP_SIM_VERSION 1
22 
23 /* EAP-SIM Subtypes */
24 #define EAP_SIM_SUBTYPE_START 10
25 #define EAP_SIM_SUBTYPE_CHALLENGE 11
26 #define EAP_SIM_SUBTYPE_NOTIFICATION 12
27 #define EAP_SIM_SUBTYPE_REAUTHENTICATION 13
28 #define EAP_SIM_SUBTYPE_CLIENT_ERROR 14
29 
30 /* AT_CLIENT_ERROR_CODE error codes */
31 #define EAP_SIM_UNABLE_TO_PROCESS_PACKET 0
32 #define EAP_SIM_UNSUPPORTED_VERSION 1
33 #define EAP_SIM_INSUFFICIENT_NUM_OF_CHAL 2
34 #define EAP_SIM_RAND_NOT_FRESH 3
35 
36 #define EAP_SIM_MAX_FAST_REAUTHS 1000
37 
38 #define EAP_SIM_MAX_CHAL 3
39 
40 
41 /* EAP-AKA Subtypes */
42 #define EAP_AKA_SUBTYPE_CHALLENGE 1
43 #define EAP_AKA_SUBTYPE_AUTHENTICATION_REJECT 2
44 #define EAP_AKA_SUBTYPE_SYNCHRONIZATION_FAILURE 4
45 #define EAP_AKA_SUBTYPE_IDENTITY 5
46 #define EAP_AKA_SUBTYPE_NOTIFICATION 12
47 #define EAP_AKA_SUBTYPE_REAUTHENTICATION 13
48 #define EAP_AKA_SUBTYPE_CLIENT_ERROR 14
49 
50 /* AT_CLIENT_ERROR_CODE error codes */
51 #define EAP_AKA_UNABLE_TO_PROCESS_PACKET 0
52 
53 #define EAP_AKA_RAND_LEN 16
54 #define EAP_AKA_AUTN_LEN 16
55 #define EAP_AKA_AUTS_LEN 14
56 #define EAP_AKA_RES_MAX_LEN 16
57 #define EAP_AKA_IK_LEN 16
58 #define EAP_AKA_CK_LEN 16
59 #define EAP_AKA_MAX_FAST_REAUTHS 1000
60 #define EAP_AKA_MIN_RES_LEN 4
61 #define EAP_AKA_MAX_RES_LEN 16
62 #define EAP_AKA_CHECKCODE_LEN 20
63 
64 #define EAP_AKA_PRIME_K_AUT_LEN 32
65 #define EAP_AKA_PRIME_CHECKCODE_LEN 32
66 #define EAP_AKA_PRIME_K_RE_LEN 32
67 
68 struct wpabuf;
69 
70 void eap_sim_derive_mk(const u8 *identity, size_t identity_len,
71  const u8 *nonce_mt, u16 selected_version,
72  const u8 *ver_list, size_t ver_list_len,
73  int num_chal, const u8 *kc, u8 *mk);
74 void eap_aka_derive_mk(const u8 *identity, size_t identity_len,
75  const u8 *ik, const u8 *ck, u8 *mk);
76 int eap_sim_derive_keys(const u8 *mk, u8 *k_encr, u8 *k_aut, u8 *msk,
77  u8 *emsk);
78 int eap_sim_derive_keys_reauth(u16 _counter,
79  const u8 *identity, size_t identity_len,
80  const u8 *nonce_s, const u8 *mk, u8 *msk,
81  u8 *emsk);
82 int eap_sim_verify_mac(const u8 *k_aut, const struct wpabuf *req,
83  const u8 *mac, const u8 *extra, size_t extra_len);
84 void eap_sim_add_mac(const u8 *k_aut, const u8 *msg, size_t msg_len, u8 *mac,
85  const u8 *extra, size_t extra_len);
86 
87 #if defined(EAP_AKA_PRIME) || defined(EAP_SERVER_AKA_PRIME)
88 void eap_aka_prime_derive_keys(const u8 *identity, size_t identity_len,
89  const u8 *ik, const u8 *ck, u8 *k_encr,
90  u8 *k_aut, u8 *k_re, u8 *msk, u8 *emsk);
91 int eap_aka_prime_derive_keys_reauth(const u8 *k_re, u16 counter,
92  const u8 *identity, size_t identity_len,
93  const u8 *nonce_s, u8 *msk, u8 *emsk);
94 int eap_sim_verify_mac_sha256(const u8 *k_aut, const struct wpabuf *req,
95  const u8 *mac, const u8 *extra,
96  size_t extra_len);
97 void eap_sim_add_mac_sha256(const u8 *k_aut, const u8 *msg, size_t msg_len,
98  u8 *mac, const u8 *extra, size_t extra_len);
99 
100 void eap_aka_prime_derive_ck_ik_prime(u8 *ck, u8 *ik, const u8 *sqn_ak,
101  const u8 *network_name,
102  size_t network_name_len);
103 #else /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */
104 static inline void eap_aka_prime_derive_keys(const u8 *identity,
105  size_t identity_len,
106  const u8 *ik, const u8 *ck,
107  u8 *k_encr, u8 *k_aut, u8 *k_re,
108  u8 *msk, u8 *emsk)
109 {
110 }
111 
112 static inline int eap_aka_prime_derive_keys_reauth(const u8 *k_re, u16 counter,
113  const u8 *identity,
114  size_t identity_len,
115  const u8 *nonce_s, u8 *msk,
116  u8 *emsk)
117 {
118  return -1;
119 }
120 
121 static inline int eap_sim_verify_mac_sha256(const u8 *k_aut,
122  const struct wpabuf *req,
123  const u8 *mac, const u8 *extra,
124  size_t extra_len)
125 {
126  return -1;
127 }
128 #endif /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */
129 
130 
131 /* EAP-SIM/AKA Attributes (0..127 non-skippable) */
132 #define EAP_SIM_AT_RAND 1
133 #define EAP_SIM_AT_AUTN 2 /* only AKA */
134 #define EAP_SIM_AT_RES 3 /* only AKA, only peer->server */
135 #define EAP_SIM_AT_AUTS 4 /* only AKA, only peer->server */
136 #define EAP_SIM_AT_PADDING 6 /* only encrypted */
137 #define EAP_SIM_AT_NONCE_MT 7 /* only SIM, only send */
138 #define EAP_SIM_AT_PERMANENT_ID_REQ 10
139 #define EAP_SIM_AT_MAC 11
140 #define EAP_SIM_AT_NOTIFICATION 12
141 #define EAP_SIM_AT_ANY_ID_REQ 13
142 #define EAP_SIM_AT_IDENTITY 14 /* only send */
143 #define EAP_SIM_AT_VERSION_LIST 15 /* only SIM */
144 #define EAP_SIM_AT_SELECTED_VERSION 16 /* only SIM */
145 #define EAP_SIM_AT_FULLAUTH_ID_REQ 17
146 #define EAP_SIM_AT_COUNTER 19 /* only encrypted */
147 #define EAP_SIM_AT_COUNTER_TOO_SMALL 20 /* only encrypted */
148 #define EAP_SIM_AT_NONCE_S 21 /* only encrypted */
149 #define EAP_SIM_AT_CLIENT_ERROR_CODE 22 /* only send */
150 #define EAP_SIM_AT_KDF_INPUT 23 /* only AKA' */
151 #define EAP_SIM_AT_KDF 24 /* only AKA' */
152 #define EAP_SIM_AT_IV 129
153 #define EAP_SIM_AT_ENCR_DATA 130
154 #define EAP_SIM_AT_NEXT_PSEUDONYM 132 /* only encrypted */
155 #define EAP_SIM_AT_NEXT_REAUTH_ID 133 /* only encrypted */
156 #define EAP_SIM_AT_CHECKCODE 134 /* only AKA */
157 #define EAP_SIM_AT_RESULT_IND 135
158 #define EAP_SIM_AT_BIDDING 136
159 
160 /* AT_NOTIFICATION notification code values */
161 #define EAP_SIM_GENERAL_FAILURE_AFTER_AUTH 0
162 #define EAP_SIM_TEMPORARILY_DENIED 1026
163 #define EAP_SIM_NOT_SUBSCRIBED 1031
164 #define EAP_SIM_GENERAL_FAILURE_BEFORE_AUTH 16384
165 #define EAP_SIM_SUCCESS 32768
166 
167 /* EAP-AKA' AT_KDF Key Derivation Function values */
168 #define EAP_AKA_PRIME_KDF 1
169 
170 /* AT_BIDDING flags */
171 #define EAP_AKA_BIDDING_FLAG_D 0x8000
172 
173 
174 enum eap_sim_id_req {
175  NO_ID_REQ, ANY_ID, FULLAUTH_ID, PERMANENT_ID
176 };
177 
178 
180  const u8 *rand, *autn, *mac, *iv, *encr_data, *version_list, *nonce_s;
181  const u8 *next_pseudonym, *next_reauth_id;
182  const u8 *nonce_mt, *identity, *res, *auts;
183  const u8 *checkcode;
184  const u8 *kdf_input;
185  const u8 *bidding;
186  size_t num_chal, version_list_len, encr_data_len;
187  size_t next_pseudonym_len, next_reauth_id_len, identity_len, res_len;
188  size_t res_len_bits;
189  size_t checkcode_len;
190  size_t kdf_input_len;
191  enum eap_sim_id_req id_req;
192  int notification, counter, selected_version, client_error_code;
193  int counter_too_small;
194  int result_ind;
195 #define EAP_AKA_PRIME_KDF_MAX 10
196  u16 kdf[EAP_AKA_PRIME_KDF_MAX];
197  size_t kdf_count;
198 };
199 
200 int eap_sim_parse_attr(const u8 *start, const u8 *end,
201  struct eap_sim_attrs *attr, int aka, int encr);
202 u8 * eap_sim_parse_encr(const u8 *k_encr, const u8 *encr_data,
203  size_t encr_data_len, const u8 *iv,
204  struct eap_sim_attrs *attr, int aka);
205 
206 
207 struct eap_sim_msg;
208 
209 struct eap_sim_msg * eap_sim_msg_init(int code, int id, int type, int subtype);
210 struct wpabuf * eap_sim_msg_finish(struct eap_sim_msg *msg, int type,
211  const u8 *k_aut,
212  const u8 *extra, size_t extra_len);
213 void eap_sim_msg_free(struct eap_sim_msg *msg);
214 u8 * eap_sim_msg_add_full(struct eap_sim_msg *msg, u8 attr,
215  const u8 *data, size_t len);
216 u8 * eap_sim_msg_add(struct eap_sim_msg *msg, u8 attr,
217  u16 value, const u8 *data, size_t len);
218 u8 * eap_sim_msg_add_mac(struct eap_sim_msg *msg, u8 attr);
219 int eap_sim_msg_add_encr_start(struct eap_sim_msg *msg, u8 attr_iv,
220  u8 attr_encr);
221 int eap_sim_msg_add_encr_end(struct eap_sim_msg *msg, u8 *k_encr,
222  int attr_pad);
223 
224 void eap_sim_report_notification(void *msg_ctx, int notification, int aka);
225 
226 #endif /* EAP_SIM_COMMON_H */
Definition: eap_sim_common.c:968
Definition: wpabuf.h:16
Definition: eap_sim_common.h:179