2 * EAP-PEAP common routines
3 * Copyright (c) 2008, 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.
20 void peap_prfplus(int version
, const u8
*key
, size_t key_len
,
21 const char *label
, const u8
*seed
, size_t seed_len
,
22 u8
*buf
, size_t buf_len
)
24 unsigned char counter
= 0;
26 u8 hash
[SHA1_MAC_LEN
];
27 size_t label_len
= os_strlen(label
);
29 const unsigned char *addr
[5];
34 addr
[1] = (unsigned char *) label
;
41 * PRF+(K, S, LEN) = T1 | T2 | ... | Tn
42 * T1 = HMAC-SHA1(K, S | 0x01 | 0x00 | 0x00)
43 * T2 = HMAC-SHA1(K, T1 | S | 0x02 | 0x00 | 0x00)
45 * Tn = HMAC-SHA1(K, Tn-1 | S | n | 0x00 | 0x00)
57 * PRF (K,S,LEN) = T1 | T2 | T3 | T4 | ... where:
58 * T1 = HMAC-SHA1(K, S | LEN | 0x01)
59 * T2 = HMAC-SHA1 (K, T1 | S | LEN | 0x02)
60 * T3 = HMAC-SHA1 (K, T2 | S | LEN | 0x03)
61 * T4 = HMAC-SHA1 (K, T3 | S | LEN | 0x04)
65 extra
[0] = buf_len
& 0xff;
74 while (pos
< buf_len
) {
77 hmac_sha1_vector(key
, key_len
, 5, addr
, len
, hash
);
78 if (plen
>= SHA1_MAC_LEN
) {
79 os_memcpy(&buf
[pos
], hash
, SHA1_MAC_LEN
);
82 os_memcpy(&buf
[pos
], hash
, plen
);
85 len
[0] = SHA1_MAC_LEN
;