$search
00001 /* 00002 * EAP-PEAP common routines 00003 * Copyright (c) 2008, Jouni Malinen <j@w1.fi> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation. 00008 * 00009 * Alternatively, this software may be distributed under the terms of BSD 00010 * license. 00011 * 00012 * See README and COPYING for more details. 00013 */ 00014 00015 #include "includes.h" 00016 00017 #include "common.h" 00018 #include "crypto/sha1.h" 00019 #include "eap_peap_common.h" 00020 00021 void peap_prfplus(int version, const u8 *key, size_t key_len, 00022 const char *label, const u8 *seed, size_t seed_len, 00023 u8 *buf, size_t buf_len) 00024 { 00025 unsigned char counter = 0; 00026 size_t pos, plen; 00027 u8 hash[SHA1_MAC_LEN]; 00028 size_t label_len = os_strlen(label); 00029 u8 extra[2]; 00030 const unsigned char *addr[5]; 00031 size_t len[5]; 00032 00033 addr[0] = hash; 00034 len[0] = 0; 00035 addr[1] = (unsigned char *) label; 00036 len[1] = label_len; 00037 addr[2] = seed; 00038 len[2] = seed_len; 00039 00040 if (version == 0) { 00041 /* 00042 * PRF+(K, S, LEN) = T1 | T2 | ... | Tn 00043 * T1 = HMAC-SHA1(K, S | 0x01 | 0x00 | 0x00) 00044 * T2 = HMAC-SHA1(K, T1 | S | 0x02 | 0x00 | 0x00) 00045 * ... 00046 * Tn = HMAC-SHA1(K, Tn-1 | S | n | 0x00 | 0x00) 00047 */ 00048 00049 extra[0] = 0; 00050 extra[1] = 0; 00051 00052 addr[3] = &counter; 00053 len[3] = 1; 00054 addr[4] = extra; 00055 len[4] = 2; 00056 } else { 00057 /* 00058 * PRF (K,S,LEN) = T1 | T2 | T3 | T4 | ... where: 00059 * T1 = HMAC-SHA1(K, S | LEN | 0x01) 00060 * T2 = HMAC-SHA1 (K, T1 | S | LEN | 0x02) 00061 * T3 = HMAC-SHA1 (K, T2 | S | LEN | 0x03) 00062 * T4 = HMAC-SHA1 (K, T3 | S | LEN | 0x04) 00063 * ... 00064 */ 00065 00066 extra[0] = buf_len & 0xff; 00067 00068 addr[3] = extra; 00069 len[3] = 1; 00070 addr[4] = &counter; 00071 len[4] = 1; 00072 } 00073 00074 pos = 0; 00075 while (pos < buf_len) { 00076 counter++; 00077 plen = buf_len - pos; 00078 hmac_sha1_vector(key, key_len, 5, addr, len, hash); 00079 if (plen >= SHA1_MAC_LEN) { 00080 os_memcpy(&buf[pos], hash, SHA1_MAC_LEN); 00081 pos += SHA1_MAC_LEN; 00082 } else { 00083 os_memcpy(&buf[pos], hash, plen); 00084 break; 00085 } 00086 len[0] = SHA1_MAC_LEN; 00087 } 00088 }