$search
00001 /* 00002 * EAP peer/server: EAP-SIM/AKA/AKA' shared routines 00003 * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation. 00008 * 00009 * Alternatively, this software may be distributed under the terms of BSD 00010 * license. 00011 * 00012 * See README and COPYING for more details. 00013 */ 00014 00015 #ifndef EAP_SIM_COMMON_H 00016 #define EAP_SIM_COMMON_H 00017 00018 #define EAP_SIM_NONCE_S_LEN 16 00019 #define EAP_SIM_NONCE_MT_LEN 16 00020 #define EAP_SIM_MAC_LEN 16 00021 #define EAP_SIM_MK_LEN 20 00022 #define EAP_SIM_K_AUT_LEN 16 00023 #define EAP_SIM_K_ENCR_LEN 16 00024 #define EAP_SIM_KEYING_DATA_LEN 64 00025 #define EAP_SIM_IV_LEN 16 00026 #define EAP_SIM_KC_LEN 8 00027 #define EAP_SIM_SRES_LEN 4 00028 00029 #define GSM_RAND_LEN 16 00030 00031 #define EAP_SIM_VERSION 1 00032 00033 /* EAP-SIM Subtypes */ 00034 #define EAP_SIM_SUBTYPE_START 10 00035 #define EAP_SIM_SUBTYPE_CHALLENGE 11 00036 #define EAP_SIM_SUBTYPE_NOTIFICATION 12 00037 #define EAP_SIM_SUBTYPE_REAUTHENTICATION 13 00038 #define EAP_SIM_SUBTYPE_CLIENT_ERROR 14 00039 00040 /* AT_CLIENT_ERROR_CODE error codes */ 00041 #define EAP_SIM_UNABLE_TO_PROCESS_PACKET 0 00042 #define EAP_SIM_UNSUPPORTED_VERSION 1 00043 #define EAP_SIM_INSUFFICIENT_NUM_OF_CHAL 2 00044 #define EAP_SIM_RAND_NOT_FRESH 3 00045 00046 #define EAP_SIM_MAX_FAST_REAUTHS 1000 00047 00048 #define EAP_SIM_MAX_CHAL 3 00049 00050 00051 /* EAP-AKA Subtypes */ 00052 #define EAP_AKA_SUBTYPE_CHALLENGE 1 00053 #define EAP_AKA_SUBTYPE_AUTHENTICATION_REJECT 2 00054 #define EAP_AKA_SUBTYPE_SYNCHRONIZATION_FAILURE 4 00055 #define EAP_AKA_SUBTYPE_IDENTITY 5 00056 #define EAP_AKA_SUBTYPE_NOTIFICATION 12 00057 #define EAP_AKA_SUBTYPE_REAUTHENTICATION 13 00058 #define EAP_AKA_SUBTYPE_CLIENT_ERROR 14 00059 00060 /* AT_CLIENT_ERROR_CODE error codes */ 00061 #define EAP_AKA_UNABLE_TO_PROCESS_PACKET 0 00062 00063 #define EAP_AKA_RAND_LEN 16 00064 #define EAP_AKA_AUTN_LEN 16 00065 #define EAP_AKA_AUTS_LEN 14 00066 #define EAP_AKA_RES_MAX_LEN 16 00067 #define EAP_AKA_IK_LEN 16 00068 #define EAP_AKA_CK_LEN 16 00069 #define EAP_AKA_MAX_FAST_REAUTHS 1000 00070 #define EAP_AKA_MIN_RES_LEN 4 00071 #define EAP_AKA_MAX_RES_LEN 16 00072 #define EAP_AKA_CHECKCODE_LEN 20 00073 00074 #define EAP_AKA_PRIME_K_AUT_LEN 32 00075 #define EAP_AKA_PRIME_CHECKCODE_LEN 32 00076 #define EAP_AKA_PRIME_K_RE_LEN 32 00077 00078 struct wpabuf; 00079 00080 void eap_sim_derive_mk(const u8 *identity, size_t identity_len, 00081 const u8 *nonce_mt, u16 selected_version, 00082 const u8 *ver_list, size_t ver_list_len, 00083 int num_chal, const u8 *kc, u8 *mk); 00084 void eap_aka_derive_mk(const u8 *identity, size_t identity_len, 00085 const u8 *ik, const u8 *ck, u8 *mk); 00086 int eap_sim_derive_keys(const u8 *mk, u8 *k_encr, u8 *k_aut, u8 *msk, 00087 u8 *emsk); 00088 int eap_sim_derive_keys_reauth(u16 _counter, 00089 const u8 *identity, size_t identity_len, 00090 const u8 *nonce_s, const u8 *mk, u8 *msk, 00091 u8 *emsk); 00092 int eap_sim_verify_mac(const u8 *k_aut, const struct wpabuf *req, 00093 const u8 *mac, const u8 *extra, size_t extra_len); 00094 void eap_sim_add_mac(const u8 *k_aut, const u8 *msg, size_t msg_len, u8 *mac, 00095 const u8 *extra, size_t extra_len); 00096 00097 #if defined(EAP_AKA_PRIME) || defined(EAP_SERVER_AKA_PRIME) 00098 void eap_aka_prime_derive_keys(const u8 *identity, size_t identity_len, 00099 const u8 *ik, const u8 *ck, u8 *k_encr, 00100 u8 *k_aut, u8 *k_re, u8 *msk, u8 *emsk); 00101 int eap_aka_prime_derive_keys_reauth(const u8 *k_re, u16 counter, 00102 const u8 *identity, size_t identity_len, 00103 const u8 *nonce_s, u8 *msk, u8 *emsk); 00104 int eap_sim_verify_mac_sha256(const u8 *k_aut, const struct wpabuf *req, 00105 const u8 *mac, const u8 *extra, 00106 size_t extra_len); 00107 void eap_sim_add_mac_sha256(const u8 *k_aut, const u8 *msg, size_t msg_len, 00108 u8 *mac, const u8 *extra, size_t extra_len); 00109 00110 void eap_aka_prime_derive_ck_ik_prime(u8 *ck, u8 *ik, const u8 *sqn_ak, 00111 const u8 *network_name, 00112 size_t network_name_len); 00113 #else /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */ 00114 static inline void eap_aka_prime_derive_keys(const u8 *identity, 00115 size_t identity_len, 00116 const u8 *ik, const u8 *ck, 00117 u8 *k_encr, u8 *k_aut, u8 *k_re, 00118 u8 *msk, u8 *emsk) 00119 { 00120 } 00121 00122 static inline int eap_aka_prime_derive_keys_reauth(const u8 *k_re, u16 counter, 00123 const u8 *identity, 00124 size_t identity_len, 00125 const u8 *nonce_s, u8 *msk, 00126 u8 *emsk) 00127 { 00128 return -1; 00129 } 00130 00131 static inline int eap_sim_verify_mac_sha256(const u8 *k_aut, 00132 const struct wpabuf *req, 00133 const u8 *mac, const u8 *extra, 00134 size_t extra_len) 00135 { 00136 return -1; 00137 } 00138 #endif /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */ 00139 00140 00141 /* EAP-SIM/AKA Attributes (0..127 non-skippable) */ 00142 #define EAP_SIM_AT_RAND 1 00143 #define EAP_SIM_AT_AUTN 2 /* only AKA */ 00144 #define EAP_SIM_AT_RES 3 /* only AKA, only peer->server */ 00145 #define EAP_SIM_AT_AUTS 4 /* only AKA, only peer->server */ 00146 #define EAP_SIM_AT_PADDING 6 /* only encrypted */ 00147 #define EAP_SIM_AT_NONCE_MT 7 /* only SIM, only send */ 00148 #define EAP_SIM_AT_PERMANENT_ID_REQ 10 00149 #define EAP_SIM_AT_MAC 11 00150 #define EAP_SIM_AT_NOTIFICATION 12 00151 #define EAP_SIM_AT_ANY_ID_REQ 13 00152 #define EAP_SIM_AT_IDENTITY 14 /* only send */ 00153 #define EAP_SIM_AT_VERSION_LIST 15 /* only SIM */ 00154 #define EAP_SIM_AT_SELECTED_VERSION 16 /* only SIM */ 00155 #define EAP_SIM_AT_FULLAUTH_ID_REQ 17 00156 #define EAP_SIM_AT_COUNTER 19 /* only encrypted */ 00157 #define EAP_SIM_AT_COUNTER_TOO_SMALL 20 /* only encrypted */ 00158 #define EAP_SIM_AT_NONCE_S 21 /* only encrypted */ 00159 #define EAP_SIM_AT_CLIENT_ERROR_CODE 22 /* only send */ 00160 #define EAP_SIM_AT_KDF_INPUT 23 /* only AKA' */ 00161 #define EAP_SIM_AT_KDF 24 /* only AKA' */ 00162 #define EAP_SIM_AT_IV 129 00163 #define EAP_SIM_AT_ENCR_DATA 130 00164 #define EAP_SIM_AT_NEXT_PSEUDONYM 132 /* only encrypted */ 00165 #define EAP_SIM_AT_NEXT_REAUTH_ID 133 /* only encrypted */ 00166 #define EAP_SIM_AT_CHECKCODE 134 /* only AKA */ 00167 #define EAP_SIM_AT_RESULT_IND 135 00168 #define EAP_SIM_AT_BIDDING 136 00169 00170 /* AT_NOTIFICATION notification code values */ 00171 #define EAP_SIM_GENERAL_FAILURE_AFTER_AUTH 0 00172 #define EAP_SIM_TEMPORARILY_DENIED 1026 00173 #define EAP_SIM_NOT_SUBSCRIBED 1031 00174 #define EAP_SIM_GENERAL_FAILURE_BEFORE_AUTH 16384 00175 #define EAP_SIM_SUCCESS 32768 00176 00177 /* EAP-AKA' AT_KDF Key Derivation Function values */ 00178 #define EAP_AKA_PRIME_KDF 1 00179 00180 /* AT_BIDDING flags */ 00181 #define EAP_AKA_BIDDING_FLAG_D 0x8000 00182 00183 00184 enum eap_sim_id_req { 00185 NO_ID_REQ, ANY_ID, FULLAUTH_ID, PERMANENT_ID 00186 }; 00187 00188 00189 struct eap_sim_attrs { 00190 const u8 *rand, *autn, *mac, *iv, *encr_data, *version_list, *nonce_s; 00191 const u8 *next_pseudonym, *next_reauth_id; 00192 const u8 *nonce_mt, *identity, *res, *auts; 00193 const u8 *checkcode; 00194 const u8 *kdf_input; 00195 const u8 *bidding; 00196 size_t num_chal, version_list_len, encr_data_len; 00197 size_t next_pseudonym_len, next_reauth_id_len, identity_len, res_len; 00198 size_t res_len_bits; 00199 size_t checkcode_len; 00200 size_t kdf_input_len; 00201 enum eap_sim_id_req id_req; 00202 int notification, counter, selected_version, client_error_code; 00203 int counter_too_small; 00204 int result_ind; 00205 #define EAP_AKA_PRIME_KDF_MAX 10 00206 u16 kdf[EAP_AKA_PRIME_KDF_MAX]; 00207 size_t kdf_count; 00208 }; 00209 00210 int eap_sim_parse_attr(const u8 *start, const u8 *end, 00211 struct eap_sim_attrs *attr, int aka, int encr); 00212 u8 * eap_sim_parse_encr(const u8 *k_encr, const u8 *encr_data, 00213 size_t encr_data_len, const u8 *iv, 00214 struct eap_sim_attrs *attr, int aka); 00215 00216 00217 struct eap_sim_msg; 00218 00219 struct eap_sim_msg * eap_sim_msg_init(int code, int id, int type, int subtype); 00220 struct wpabuf * eap_sim_msg_finish(struct eap_sim_msg *msg, const u8 *k_aut, 00221 const u8 *extra, size_t extra_len); 00222 void eap_sim_msg_free(struct eap_sim_msg *msg); 00223 u8 * eap_sim_msg_add_full(struct eap_sim_msg *msg, u8 attr, 00224 const u8 *data, size_t len); 00225 u8 * eap_sim_msg_add(struct eap_sim_msg *msg, u8 attr, 00226 u16 value, const u8 *data, size_t len); 00227 u8 * eap_sim_msg_add_mac(struct eap_sim_msg *msg, u8 attr); 00228 int eap_sim_msg_add_encr_start(struct eap_sim_msg *msg, u8 attr_iv, 00229 u8 attr_encr); 00230 int eap_sim_msg_add_encr_end(struct eap_sim_msg *msg, u8 *k_encr, 00231 int attr_pad); 00232 00233 void eap_sim_report_notification(void *msg_ctx, int notification, int aka); 00234 00235 #endif /* EAP_SIM_COMMON_H */