2
* FIPS 186-2 PRF for internal crypto implementation
3
* Copyright (c) 2006-2007, 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.
23
int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
31
if (seed_len > sizeof(xkey))
32
seed_len = sizeof(xkey);
34
/* FIPS 186-2 + change notice 1 */
36
os_memcpy(xkey, seed, seed_len);
37
os_memset(xkey + seed_len, 0, 64 - seed_len);
45
for (j = 0; j < m; j++) {
47
for (i = 0; i < 2; i++) {
48
/* XVAL = (XKEY + XSEED_j) mod 2^b */
50
/* w_i = G(t, XVAL) */
52
SHA1Transform(_t, xkey);
53
_t[0] = host_to_be32(_t[0]);
54
_t[1] = host_to_be32(_t[1]);
55
_t[2] = host_to_be32(_t[2]);
56
_t[3] = host_to_be32(_t[3]);
57
_t[4] = host_to_be32(_t[4]);
58
os_memcpy(xpos, _t, 20);
60
/* XKEY = (1 + XKEY + w_i) mod 2^b */
62
for (k = 19; k >= 0; k--) {
63
carry += xkey[k] + xpos[k];
64
xkey[k] = carry & 0xff;