fips_prf_openssl.c

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