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