Change version number to v2.6 for the release
[mech_eap.git] / src / eap_common / eap_sim_common.h
index 7d2093c..daeb0e2 100644 (file)
@@ -2,14 +2,8 @@
  * EAP peer/server: EAP-SIM/AKA/AKA' shared routines
  * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #ifndef EAP_SIM_COMMON_H
@@ -73,6 +67,7 @@
 
 #define EAP_AKA_PRIME_K_AUT_LEN 32
 #define EAP_AKA_PRIME_CHECKCODE_LEN 32
+#define EAP_AKA_PRIME_K_RE_LEN 32
 
 struct wpabuf;
 
@@ -92,12 +87,50 @@ int eap_sim_verify_mac(const u8 *k_aut, const struct wpabuf *req,
                       const u8 *mac, const u8 *extra, size_t extra_len);
 void eap_sim_add_mac(const u8 *k_aut, const u8 *msg, size_t msg_len, u8 *mac,
                     const u8 *extra, size_t extra_len);
+
+#if defined(EAP_AKA_PRIME) || defined(EAP_SERVER_AKA_PRIME)
+void eap_aka_prime_derive_keys(const u8 *identity, size_t identity_len,
+                              const u8 *ik, const u8 *ck, u8 *k_encr,
+                              u8 *k_aut, u8 *k_re, u8 *msk, u8 *emsk);
+int eap_aka_prime_derive_keys_reauth(const u8 *k_re, u16 counter,
+                                    const u8 *identity, size_t identity_len,
+                                    const u8 *nonce_s, u8 *msk, u8 *emsk);
 int eap_sim_verify_mac_sha256(const u8 *k_aut, const struct wpabuf *req,
                              const u8 *mac, const u8 *extra,
                              size_t extra_len);
 void eap_sim_add_mac_sha256(const u8 *k_aut, const u8 *msg, size_t msg_len,
                            u8 *mac, const u8 *extra, size_t extra_len);
 
+void eap_aka_prime_derive_ck_ik_prime(u8 *ck, u8 *ik, const u8 *sqn_ak,
+                                     const u8 *network_name,
+                                     size_t network_name_len);
+#else /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */
+static inline void eap_aka_prime_derive_keys(const u8 *identity,
+                                            size_t identity_len,
+                                            const u8 *ik, const u8 *ck,
+                                            u8 *k_encr, u8 *k_aut, u8 *k_re,
+                                            u8 *msk, u8 *emsk)
+{
+}
+
+static inline int eap_aka_prime_derive_keys_reauth(const u8 *k_re, u16 counter,
+                                                  const u8 *identity,
+                                                  size_t identity_len,
+                                                  const u8 *nonce_s, u8 *msk,
+                                                  u8 *emsk)
+{
+       return -1;
+}
+
+static inline int eap_sim_verify_mac_sha256(const u8 *k_aut,
+                                           const struct wpabuf *req,
+                                           const u8 *mac, const u8 *extra,
+                                           size_t extra_len)
+{
+       return -1;
+}
+#endif /* EAP_AKA_PRIME || EAP_SERVER_AKA_PRIME */
+
 
 /* EAP-SIM/AKA Attributes (0..127 non-skippable) */
 #define EAP_SIM_AT_RAND 1
@@ -118,12 +151,15 @@ void eap_sim_add_mac_sha256(const u8 *k_aut, const u8 *msg, size_t msg_len,
 #define EAP_SIM_AT_COUNTER_TOO_SMALL 20 /* only encrypted */
 #define EAP_SIM_AT_NONCE_S 21 /* only encrypted */
 #define EAP_SIM_AT_CLIENT_ERROR_CODE 22 /* only send */
+#define EAP_SIM_AT_KDF_INPUT 23 /* only AKA' */
+#define EAP_SIM_AT_KDF 24 /* only AKA' */
 #define EAP_SIM_AT_IV 129
 #define EAP_SIM_AT_ENCR_DATA 130
 #define EAP_SIM_AT_NEXT_PSEUDONYM 132 /* only encrypted */
 #define EAP_SIM_AT_NEXT_REAUTH_ID 133 /* only encrypted */
 #define EAP_SIM_AT_CHECKCODE 134 /* only AKA */
 #define EAP_SIM_AT_RESULT_IND 135
+#define EAP_SIM_AT_BIDDING 136
 
 /* AT_NOTIFICATION notification code values */
 #define EAP_SIM_GENERAL_FAILURE_AFTER_AUTH 0
@@ -132,6 +168,12 @@ void eap_sim_add_mac_sha256(const u8 *k_aut, const u8 *msg, size_t msg_len,
 #define EAP_SIM_GENERAL_FAILURE_BEFORE_AUTH 16384
 #define EAP_SIM_SUCCESS 32768
 
+/* EAP-AKA' AT_KDF Key Derivation Function values */
+#define EAP_AKA_PRIME_KDF 1
+
+/* AT_BIDDING flags */
+#define EAP_AKA_BIDDING_FLAG_D 0x8000
+
 
 enum eap_sim_id_req {
        NO_ID_REQ, ANY_ID, FULLAUTH_ID, PERMANENT_ID
@@ -143,14 +185,20 @@ struct eap_sim_attrs {
        const u8 *next_pseudonym, *next_reauth_id;
        const u8 *nonce_mt, *identity, *res, *auts;
        const u8 *checkcode;
+       const u8 *kdf_input;
+       const u8 *bidding;
        size_t num_chal, version_list_len, encr_data_len;
        size_t next_pseudonym_len, next_reauth_id_len, identity_len, res_len;
        size_t res_len_bits;
        size_t checkcode_len;
+       size_t kdf_input_len;
        enum eap_sim_id_req id_req;
        int notification, counter, selected_version, client_error_code;
        int counter_too_small;
        int result_ind;
+#define EAP_AKA_PRIME_KDF_MAX 10
+       u16 kdf[EAP_AKA_PRIME_KDF_MAX];
+       size_t kdf_count;
 };
 
 int eap_sim_parse_attr(const u8 *start, const u8 *end,
@@ -163,7 +211,8 @@ u8 * eap_sim_parse_encr(const u8 *k_encr, const u8 *encr_data,
 struct eap_sim_msg;
 
 struct eap_sim_msg * eap_sim_msg_init(int code, int id, int type, int subtype);
-struct wpabuf * eap_sim_msg_finish(struct eap_sim_msg *msg, const u8 *k_aut,
+struct wpabuf * eap_sim_msg_finish(struct eap_sim_msg *msg, int type,
+                                  const u8 *k_aut,
                                   const u8 *extra, size_t extra_len);
 void eap_sim_msg_free(struct eap_sim_msg *msg);
 u8 * eap_sim_msg_add_full(struct eap_sim_msg *msg, u8 attr,