00001
00016 #include "includes.h"
00017
00018 #include "common.h"
00019 #include "sha1.h"
00020 #include "eap_pax_common.h"
00021
00022
00038 int eap_pax_kdf(u8 mac_id, const u8 *key, size_t key_len,
00039 const char *identifier,
00040 const u8 *entropy, size_t entropy_len,
00041 size_t output_len, u8 *output)
00042 {
00043 u8 mac[SHA1_MAC_LEN];
00044 u8 counter, *pos;
00045 const u8 *addr[3];
00046 size_t len[3];
00047 size_t num_blocks, left;
00048
00049 num_blocks = (output_len + EAP_PAX_MAC_LEN - 1) / EAP_PAX_MAC_LEN;
00050 if (identifier == NULL || num_blocks >= 255)
00051 return -1;
00052
00053
00054 if (mac_id != EAP_PAX_MAC_HMAC_SHA1_128)
00055 return -1;
00056
00057 addr[0] = (const u8 *) identifier;
00058 len[0] = os_strlen(identifier);
00059 addr[1] = entropy;
00060 len[1] = entropy_len;
00061 addr[2] = &counter;
00062 len[2] = 1;
00063
00064 pos = output;
00065 left = output_len;
00066 for (counter = 1; counter <= (u8) num_blocks; counter++) {
00067 size_t clen = left > EAP_PAX_MAC_LEN ? EAP_PAX_MAC_LEN : left;
00068 hmac_sha1_vector(key, key_len, 3, addr, len, mac);
00069 os_memcpy(pos, mac, clen);
00070 pos += clen;
00071 left -= clen;
00072 }
00073
00074 return 0;
00075 }
00076
00077
00095 int eap_pax_mac(u8 mac_id, const u8 *key, size_t key_len,
00096 const u8 *data1, size_t data1_len,
00097 const u8 *data2, size_t data2_len,
00098 const u8 *data3, size_t data3_len,
00099 u8 *mac)
00100 {
00101 u8 hash[SHA1_MAC_LEN];
00102 const u8 *addr[3];
00103 size_t len[3];
00104 size_t count;
00105
00106
00107 if (mac_id != EAP_PAX_MAC_HMAC_SHA1_128)
00108 return -1;
00109
00110 addr[0] = data1;
00111 len[0] = data1_len;
00112 addr[1] = data2;
00113 len[1] = data2_len;
00114 addr[2] = data3;
00115 len[2] = data3_len;
00116
00117 count = (data1 ? 1 : 0) + (data2 ? 1 : 0) + (data3 ? 1 : 0);
00118 hmac_sha1_vector(key, key_len, count, addr, len, hash);
00119 os_memcpy(mac, hash, EAP_PAX_MAC_LEN);
00120
00121 return 0;
00122 }
00123
00124
00136 int eap_pax_initial_key_derivation(u8 mac_id, const u8 *ak, const u8 *e,
00137 u8 *mk, u8 *ck, u8 *ick)
00138 {
00139 wpa_printf(MSG_DEBUG, "EAP-PAX: initial key derivation");
00140 if (eap_pax_kdf(mac_id, ak, EAP_PAX_AK_LEN, "Master Key",
00141 e, 2 * EAP_PAX_RAND_LEN, EAP_PAX_MK_LEN, mk) ||
00142 eap_pax_kdf(mac_id, mk, EAP_PAX_MK_LEN, "Confirmation Key",
00143 e, 2 * EAP_PAX_RAND_LEN, EAP_PAX_CK_LEN, ck) ||
00144 eap_pax_kdf(mac_id, mk, EAP_PAX_MK_LEN, "Integrity Check Key",
00145 e, 2 * EAP_PAX_RAND_LEN, EAP_PAX_ICK_LEN, ick))
00146 return -1;
00147
00148 wpa_hexdump_key(MSG_MSGDUMP, "EAP-PAX: AK", ak, EAP_PAX_AK_LEN);
00149 wpa_hexdump_key(MSG_MSGDUMP, "EAP-PAX: MK", mk, EAP_PAX_MK_LEN);
00150 wpa_hexdump_key(MSG_MSGDUMP, "EAP-PAX: CK", ck, EAP_PAX_CK_LEN);
00151 wpa_hexdump_key(MSG_MSGDUMP, "EAP-PAX: ICK", ick, EAP_PAX_ICK_LEN);
00152
00153 return 0;
00154 }
00155