sha1-tprf.c

Go to the documentation of this file.
00001 
00016 #include "includes.h"
00017 
00018 #include "common.h"
00019 #include "sha1.h"
00020 #include "crypto.h"
00021 
00037 int sha1_t_prf(const u8 *key, size_t key_len, const char *label,
00038                const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len)
00039 {
00040         unsigned char counter = 0;
00041         size_t pos, plen;
00042         u8 hash[SHA1_MAC_LEN];
00043         size_t label_len = os_strlen(label);
00044         u8 output_len[2];
00045         const unsigned char *addr[5];
00046         size_t len[5];
00047 
00048         addr[0] = hash;
00049         len[0] = 0;
00050         addr[1] = (unsigned char *) label;
00051         len[1] = label_len + 1;
00052         addr[2] = seed;
00053         len[2] = seed_len;
00054         addr[3] = output_len;
00055         len[3] = 2;
00056         addr[4] = &counter;
00057         len[4] = 1;
00058 
00059         output_len[0] = (buf_len >> 8) & 0xff;
00060         output_len[1] = buf_len & 0xff;
00061         pos = 0;
00062         while (pos < buf_len) {
00063                 counter++;
00064                 plen = buf_len - pos;
00065                 if (hmac_sha1_vector(key, key_len, 5, addr, len, hash))
00066                         return -1;
00067                 if (plen >= SHA1_MAC_LEN) {
00068                         os_memcpy(&buf[pos], hash, SHA1_MAC_LEN);
00069                         pos += SHA1_MAC_LEN;
00070                 } else {
00071                         os_memcpy(&buf[pos], hash, plen);
00072                         break;
00073                 }
00074                 len[0] = SHA1_MAC_LEN;
00075         }
00076 
00077         return 0;
00078 }
00079 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

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