fips_prf_internal.c

Go to the documentation of this file.
00001 
00016 #include "includes.h"
00017 
00018 #include "common.h"
00019 #include "sha1.h"
00020 #include "sha1_i.h"
00021 #include "crypto.h"
00022 
00023 
00024 int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
00025 {
00026         u8 xkey[64];
00027         u32 t[5], _t[5];
00028         int i, j, m, k;
00029         u8 *xpos = x;
00030         u32 carry;
00031 
00032         if (seed_len > sizeof(xkey))
00033                 seed_len = sizeof(xkey);
00034 
00035         /* FIPS 186-2 + change notice 1 */
00036 
00037         os_memcpy(xkey, seed, seed_len);
00038         os_memset(xkey + seed_len, 0, 64 - seed_len);
00039         t[0] = 0x67452301;
00040         t[1] = 0xEFCDAB89;
00041         t[2] = 0x98BADCFE;
00042         t[3] = 0x10325476;
00043         t[4] = 0xC3D2E1F0;
00044 
00045         m = xlen / 40;
00046         for (j = 0; j < m; j++) {
00047                 /* XSEED_j = 0 */
00048                 for (i = 0; i < 2; i++) {
00049                         /* XVAL = (XKEY + XSEED_j) mod 2^b */
00050 
00051                         /* w_i = G(t, XVAL) */
00052                         os_memcpy(_t, t, 20);
00053                         SHA1Transform(_t, xkey);
00054                         _t[0] = host_to_be32(_t[0]);
00055                         _t[1] = host_to_be32(_t[1]);
00056                         _t[2] = host_to_be32(_t[2]);
00057                         _t[3] = host_to_be32(_t[3]);
00058                         _t[4] = host_to_be32(_t[4]);
00059                         os_memcpy(xpos, _t, 20);
00060 
00061                         /* XKEY = (1 + XKEY + w_i) mod 2^b */
00062                         carry = 1;
00063                         for (k = 19; k >= 0; k--) {
00064                                 carry += xkey[k] + xpos[k];
00065                                 xkey[k] = carry & 0xff;
00066                                 carry >>= 8;
00067                         }
00068 
00069                         xpos += SHA1_MAC_LEN;
00070                 }
00071                 /* x_j = w_0|w_1 */
00072         }
00073 
00074         return 0;
00075 }
00076 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:50 2009 for hostapd by  doxygen 1.6.1