Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / src / eap_common / eap_sim_common.c
index 56b4ded..2adc3b3 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.
  */
 
 #include "includes.h"
@@ -20,6 +14,7 @@
 #include "crypto/crypto.h"
 #include "crypto/sha1.h"
 #include "crypto/sha256.h"
+#include "crypto/random.h"
 #include "eap_common/eap_defs.h"
 #include "eap_common/eap_sim_common.h"
 
@@ -203,7 +198,7 @@ int eap_sim_verify_mac(const u8 *k_aut, const struct wpabuf *req,
                    hmac, EAP_SIM_MAC_LEN);
        os_free(tmp);
 
-       return (os_memcmp(hmac, mac, EAP_SIM_MAC_LEN) == 0) ? 0 : 1;
+       return (os_memcmp_const(hmac, mac, EAP_SIM_MAC_LEN) == 0) ? 0 : 1;
 }
 
 
@@ -398,7 +393,7 @@ int eap_sim_verify_mac_sha256(const u8 *k_aut, const struct wpabuf *req,
                    hmac, EAP_SIM_MAC_LEN);
        os_free(tmp);
 
-       return (os_memcmp(hmac, mac, EAP_SIM_MAC_LEN) == 0) ? 0 : 1;
+       return (os_memcmp_const(hmac, mac, EAP_SIM_MAC_LEN) == 0) ? 0 : 1;
 }
 
 
@@ -898,7 +893,7 @@ int eap_sim_parse_attr(const u8 *start, const u8 *end,
                        if (attr->kdf_count == EAP_AKA_PRIME_KDF_MAX) {
                                wpa_printf(MSG_DEBUG, "EAP-AKA': Too many "
                                           "AT_KDF attributes - ignore this");
-                               continue;
+                               break;
                        }
                        attr->kdf[attr->kdf_count] = WPA_GET_BE16(apos);
                        attr->kdf_count++;
@@ -977,7 +972,6 @@ u8 * eap_sim_parse_encr(const u8 *k_encr, const u8 *encr_data,
 struct eap_sim_msg {
        struct wpabuf *buf;
        size_t mac, iv, encr; /* index from buf */
-       int type;
 };
 
 
@@ -991,7 +985,6 @@ struct eap_sim_msg * eap_sim_msg_init(int code, int id, int type, int subtype)
        if (msg == NULL)
                return NULL;
 
-       msg->type = type;
        msg->buf = wpabuf_alloc(EAP_SIM_INIT_LEN);
        if (msg->buf == NULL) {
                os_free(msg);
@@ -1011,7 +1004,8 @@ 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)
 {
        struct eap_hdr *eap;
@@ -1024,7 +1018,7 @@ struct wpabuf * eap_sim_msg_finish(struct eap_sim_msg *msg, const u8 *k_aut,
        eap->length = host_to_be16(wpabuf_len(msg->buf));
 
 #if defined(EAP_AKA_PRIME) || defined(EAP_SERVER_AKA_PRIME)
-       if (k_aut && msg->mac && msg->type == EAP_TYPE_AKA_PRIME) {
+       if (k_aut && msg->mac && type == EAP_TYPE_AKA_PRIME) {
                eap_sim_add_mac_sha256(k_aut, (u8 *) wpabuf_head(msg->buf),
                                       wpabuf_len(msg->buf),
                                       (u8 *) wpabuf_mhead(msg->buf) +
@@ -1121,8 +1115,8 @@ int eap_sim_msg_add_encr_start(struct eap_sim_msg *msg, u8 attr_iv,
        if (pos == NULL)
                return -1;
        msg->iv = (pos - wpabuf_head_u8(msg->buf)) + 4;
-       if (os_get_random(wpabuf_mhead_u8(msg->buf) + msg->iv,
-                         EAP_SIM_IV_LEN)) {
+       if (random_get_bytes(wpabuf_mhead_u8(msg->buf) + msg->iv,
+                            EAP_SIM_IV_LEN)) {
                msg->iv = 0;
                return -1;
        }