Merged the hostap_2.6 updates, and the Leap of Faith work, from the hostap_update...
[mech_eap.git] / libeap / src / eap_common / eap_fast_common.c
index 4de34a8..9ef671c 100644 (file)
@@ -2,14 +2,8 @@
  * EAP-FAST common helper functions (RFC 4851)
  * Copyright (c) 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"
@@ -99,71 +93,41 @@ void eap_fast_derive_master_secret(const u8 *pac_key, const u8 *server_random,
 }
 
 
-u8 * eap_fast_derive_key(void *ssl_ctx, struct tls_connection *conn,
-                        const char *label, size_t len)
+u8 * eap_fast_derive_key(void *ssl_ctx, struct tls_connection *conn, size_t len)
 {
-       struct tls_keys keys;
-       u8 *rnd = NULL, *out;
-       int block_size;
-
-       block_size = tls_connection_get_keyblock_size(ssl_ctx, conn);
-       if (block_size < 0)
-               return NULL;
+       u8 *out;
 
-       out = os_malloc(block_size + len);
+       out = os_malloc(len);
        if (out == NULL)
                return NULL;
 
-       if (tls_connection_prf(ssl_ctx, conn, label, 1, out, block_size + len)
-           == 0) {
-               os_memmove(out, out + block_size, len);
-               return out;
+       if (tls_connection_get_eap_fast_key(ssl_ctx, conn, out, len)) {
+               os_free(out);
+               return NULL;
        }
 
-       if (tls_connection_get_keys(ssl_ctx, conn, &keys))
-               goto fail;
-
-       rnd = os_malloc(keys.client_random_len + keys.server_random_len);
-       if (rnd == NULL)
-               goto fail;
-
-       os_memcpy(rnd, keys.server_random, keys.server_random_len);
-       os_memcpy(rnd + keys.server_random_len, keys.client_random,
-                 keys.client_random_len);
-
-       wpa_hexdump_key(MSG_MSGDUMP, "EAP-FAST: master_secret for key "
-                       "expansion", keys.master_key, keys.master_key_len);
-       if (tls_prf(keys.master_key, keys.master_key_len,
-                   label, rnd, keys.client_random_len +
-                   keys.server_random_len, out, block_size + len))
-               goto fail;
-       os_free(rnd);
-       os_memmove(out, out + block_size, len);
        return out;
-
-fail:
-       os_free(rnd);
-       os_free(out);
-       return NULL;
 }
 
 
-void eap_fast_derive_eap_msk(const u8 *simck, u8 *msk)
+int eap_fast_derive_eap_msk(const u8 *simck, u8 *msk)
 {
        /*
         * RFC 4851, Section 5.4: EAP Master Session Key Generation
         * MSK = T-PRF(S-IMCK[j], "Session Key Generating Function", 64)
         */
 
-       sha1_t_prf(simck, EAP_FAST_SIMCK_LEN,
-                  "Session Key Generating Function", (u8 *) "", 0,
-                  msk, EAP_FAST_KEY_LEN);
+       if (sha1_t_prf(simck, EAP_FAST_SIMCK_LEN,
+                      "Session Key Generating Function", (u8 *) "", 0,
+                      msk, EAP_FAST_KEY_LEN) < 0)
+               return -1;
        wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Derived key (MSK)",
                        msk, EAP_FAST_KEY_LEN);
+       return 0;
 }
 
 
-void eap_fast_derive_eap_emsk(const u8 *simck, u8 *emsk)
+int eap_fast_derive_eap_emsk(const u8 *simck, u8 *emsk)
 {
        /*
         * RFC 4851, Section 5.4: EAP Master Session Key Genreration
@@ -171,16 +135,18 @@ void eap_fast_derive_eap_emsk(const u8 *simck, u8 *emsk)
         *        "Extended Session Key Generating Function", 64)
         */
 
-       sha1_t_prf(simck, EAP_FAST_SIMCK_LEN,
-                  "Extended Session Key Generating Function", (u8 *) "", 0,
-                  emsk, EAP_EMSK_LEN);
+       if (sha1_t_prf(simck, EAP_FAST_SIMCK_LEN,
+                      "Extended Session Key Generating Function", (u8 *) "", 0,
+                      emsk, EAP_EMSK_LEN) < 0)
+               return -1;
        wpa_hexdump_key(MSG_DEBUG, "EAP-FAST: Derived key (EMSK)",
                        emsk, EAP_EMSK_LEN);
+       return 0;
 }
 
 
 int eap_fast_parse_tlv(struct eap_fast_tlv_parse *tlv,
-                      int tlv_type, u8 *pos, int len)
+                      int tlv_type, u8 *pos, size_t len)
 {
        switch (tlv_type) {
        case EAP_TLV_EAP_PAYLOAD_TLV: