2
* SHA1 T-PRF for EAP-FAST
3
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation.
9
* Alternatively, this software may be distributed under the terms of BSD
12
* See README and COPYING for more details.
22
* sha1_t_prf - EAP-FAST Pseudo-Random Function (T-PRF)
24
* @key_len: Length of the key in bytes
25
* @label: A unique label for each purpose of the PRF
26
* @seed: Seed value to bind into the key
27
* @seed_len: Length of the seed
28
* @buf: Buffer for the generated pseudo-random key
29
* @buf_len: Number of bytes of key to generate
30
* Returns: 0 on success, -1 of failure
32
* This function is used to derive new, cryptographically separate keys from a
33
* given key for EAP-FAST. T-PRF is defined in RFC 4851, Section 5.5.
35
int sha1_t_prf(const u8 *key, size_t key_len, const char *label,
36
const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len)
38
unsigned char counter = 0;
40
u8 hash[SHA1_MAC_LEN];
41
size_t label_len = os_strlen(label);
43
const unsigned char *addr[5];
48
addr[1] = (unsigned char *) label;
49
len[1] = label_len + 1;
57
output_len[0] = (buf_len >> 8) & 0xff;
58
output_len[1] = buf_len & 0xff;
60
while (pos < buf_len) {
63
if (hmac_sha1_vector(key, key_len, 5, addr, len, hash))
65
if (plen >= SHA1_MAC_LEN) {
66
os_memcpy(&buf[pos], hash, SHA1_MAC_LEN);
69
os_memcpy(&buf[pos], hash, plen);
72
len[0] = SHA1_MAC_LEN;