sha1-tprf.c
Go to the documentation of this file.
00001 /*
00002  * SHA1 T-PRF for EAP-FAST
00003  * Copyright (c) 2003-2005, 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 "sha1.h"
00019 #include "crypto.h"
00020 
00035 int sha1_t_prf(const u8 *key, size_t key_len, const char *label,
00036                const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len)
00037 {
00038         unsigned char counter = 0;
00039         size_t pos, plen;
00040         u8 hash[SHA1_MAC_LEN];
00041         size_t label_len = os_strlen(label);
00042         u8 output_len[2];
00043         const unsigned char *addr[5];
00044         size_t len[5];
00045 
00046         addr[0] = hash;
00047         len[0] = 0;
00048         addr[1] = (unsigned char *) label;
00049         len[1] = label_len + 1;
00050         addr[2] = seed;
00051         len[2] = seed_len;
00052         addr[3] = output_len;
00053         len[3] = 2;
00054         addr[4] = &counter;
00055         len[4] = 1;
00056 
00057         output_len[0] = (buf_len >> 8) & 0xff;
00058         output_len[1] = buf_len & 0xff;
00059         pos = 0;
00060         while (pos < buf_len) {
00061                 counter++;
00062                 plen = buf_len - pos;
00063                 if (hmac_sha1_vector(key, key_len, 5, addr, len, hash))
00064                         return -1;
00065                 if (plen >= SHA1_MAC_LEN) {
00066                         os_memcpy(&buf[pos], hash, SHA1_MAC_LEN);
00067                         pos += SHA1_MAC_LEN;
00068                 } else {
00069                         os_memcpy(&buf[pos], hash, plen);
00070                         break;
00071                 }
00072                 len[0] = SHA1_MAC_LEN;
00073         }
00074 
00075         return 0;
00076 }


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Jan 2 2014 11:25:14