2 * SHA1 T-PRF for EAP-FAST
3 * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
16 * sha1_t_prf - EAP-FAST Pseudo-Random Function (T-PRF)
18 * @key_len: Length of the key in bytes
19 * @label: A unique label for each purpose of the PRF
20 * @seed: Seed value to bind into the key
21 * @seed_len: Length of the seed
22 * @buf: Buffer for the generated pseudo-random key
23 * @buf_len: Number of bytes of key to generate
24 * Returns: 0 on success, -1 of failure
26 * This function is used to derive new, cryptographically separate keys from a
27 * given key for EAP-FAST. T-PRF is defined in RFC 4851, Section 5.5.
29 int sha1_t_prf(const u8 *key, size_t key_len, const char *label,
30 const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len)
32 unsigned char counter = 0;
34 u8 hash[SHA1_MAC_LEN];
35 size_t label_len = os_strlen(label);
37 const unsigned char *addr[5];
42 addr[1] = (unsigned char *) label;
43 len[1] = label_len + 1;
51 output_len[0] = (buf_len >> 8) & 0xff;
52 output_len[1] = buf_len & 0xff;
54 while (pos < buf_len) {
57 if (hmac_sha1_vector(key, key_len, 5, addr, len, hash))
59 if (plen >= SHA1_MAC_LEN) {
60 os_memcpy(&buf[pos], hash, SHA1_MAC_LEN);
63 os_memcpy(&buf[pos], hash, plen);
66 len[0] = SHA1_MAC_LEN;
69 os_memset(hash, 0, SHA1_MAC_LEN);