eap_peap_common.c

Go to the documentation of this file.
00001 
00016 #include "includes.h"
00017 
00018 #include "common.h"
00019 #include "sha1.h"
00020 #include "eap_peap_common.h"
00021 
00022 void peap_prfplus(int version, const u8 *key, size_t key_len,
00023                   const char *label, const u8 *seed, size_t seed_len,
00024                   u8 *buf, size_t buf_len)
00025 {
00026         unsigned char counter = 0;
00027         size_t pos, plen;
00028         u8 hash[SHA1_MAC_LEN];
00029         size_t label_len = os_strlen(label);
00030         u8 extra[2];
00031         const unsigned char *addr[5];
00032         size_t len[5];
00033 
00034         addr[0] = hash;
00035         len[0] = 0;
00036         addr[1] = (unsigned char *) label;
00037         len[1] = label_len;
00038         addr[2] = seed;
00039         len[2] = seed_len;
00040 
00041         if (version == 0) {
00042                 /*
00043                  * PRF+(K, S, LEN) = T1 | T2 | ... | Tn
00044                  * T1 = HMAC-SHA1(K, S | 0x01 | 0x00 | 0x00)
00045                  * T2 = HMAC-SHA1(K, T1 | S | 0x02 | 0x00 | 0x00)
00046                  * ...
00047                  * Tn = HMAC-SHA1(K, Tn-1 | S | n | 0x00 | 0x00)
00048                  */
00049 
00050                 extra[0] = 0;
00051                 extra[1] = 0;
00052 
00053                 addr[3] = &counter;
00054                 len[3] = 1;
00055                 addr[4] = extra;
00056                 len[4] = 2;
00057         } else {
00058                 /*
00059                  * PRF (K,S,LEN) = T1 | T2 | T3 | T4 | ... where:
00060                  * T1 = HMAC-SHA1(K, S | LEN | 0x01)
00061                  * T2 = HMAC-SHA1 (K, T1 | S | LEN | 0x02)
00062                  * T3 = HMAC-SHA1 (K, T2 | S | LEN | 0x03)
00063                  * T4 = HMAC-SHA1 (K, T3 | S | LEN | 0x04)
00064                  *   ...
00065                  */
00066 
00067                 extra[0] = buf_len & 0xff;
00068 
00069                 addr[3] = extra;
00070                 len[3] = 1;
00071                 addr[4] = &counter;
00072                 len[4] = 1;
00073         }
00074 
00075         pos = 0;
00076         while (pos < buf_len) {
00077                 counter++;
00078                 plen = buf_len - pos;
00079                 hmac_sha1_vector(key, key_len, 5, addr, len, hash);
00080                 if (plen >= SHA1_MAC_LEN) {
00081                         os_memcpy(&buf[pos], hash, SHA1_MAC_LEN);
00082                         pos += SHA1_MAC_LEN;
00083                 } else {
00084                         os_memcpy(&buf[pos], hash, plen);
00085                         break;
00086                 }
00087                 len[0] = SHA1_MAC_LEN;
00088         }
00089 }
00090 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:51 2009 for hostapd by  doxygen 1.6.1