md5-non-fips.c

Go to the documentation of this file.
00001 
00016 #include "includes.h"
00017 
00018 #include "common.h"
00019 #include "md5.h"
00020 #include "crypto.h"
00021 
00022 
00034 int hmac_md5_vector_non_fips_allow(const u8 *key, size_t key_len,
00035                                    size_t num_elem, const u8 *addr[],
00036                                    const size_t *len, u8 *mac)
00037 {
00038         u8 k_pad[64]; /* padding - key XORd with ipad/opad */
00039         u8 tk[16];
00040         const u8 *_addr[6];
00041         size_t i, _len[6];
00042 
00043         if (num_elem > 5) {
00044                 /*
00045                  * Fixed limit on the number of fragments to avoid having to
00046                  * allocate memory (which could fail).
00047                  */
00048                 return -1;
00049         }
00050 
00051         /* if key is longer than 64 bytes reset it to key = MD5(key) */
00052         if (key_len > 64) {
00053                 if (md5_vector_non_fips_allow(1, &key, &key_len, tk))
00054                         return -1;
00055                 key = tk;
00056                 key_len = 16;
00057         }
00058 
00059         /* the HMAC_MD5 transform looks like:
00060          *
00061          * MD5(K XOR opad, MD5(K XOR ipad, text))
00062          *
00063          * where K is an n byte key
00064          * ipad is the byte 0x36 repeated 64 times
00065          * opad is the byte 0x5c repeated 64 times
00066          * and text is the data being protected */
00067 
00068         /* start out by storing key in ipad */
00069         os_memset(k_pad, 0, sizeof(k_pad));
00070         os_memcpy(k_pad, key, key_len);
00071 
00072         /* XOR key with ipad values */
00073         for (i = 0; i < 64; i++)
00074                 k_pad[i] ^= 0x36;
00075 
00076         /* perform inner MD5 */
00077         _addr[0] = k_pad;
00078         _len[0] = 64;
00079         for (i = 0; i < num_elem; i++) {
00080                 _addr[i + 1] = addr[i];
00081                 _len[i + 1] = len[i];
00082         }
00083         if (md5_vector_non_fips_allow(1 + num_elem, _addr, _len, mac))
00084                 return -1;
00085 
00086         os_memset(k_pad, 0, sizeof(k_pad));
00087         os_memcpy(k_pad, key, key_len);
00088         /* XOR key with opad values */
00089         for (i = 0; i < 64; i++)
00090                 k_pad[i] ^= 0x5c;
00091 
00092         /* perform outer MD5 */
00093         _addr[0] = k_pad;
00094         _len[0] = 64;
00095         _addr[1] = mac;
00096         _len[1] = MD5_MAC_LEN;
00097         return md5_vector_non_fips_allow(2, _addr, _len, mac);
00098 }
00099 
00100 
00111 int hmac_md5_non_fips_allow(const u8 *key, size_t key_len, const u8 *data,
00112                             size_t data_len, u8 *mac)
00113 {
00114         return hmac_md5_vector_non_fips_allow(key, key_len, 1, &data,
00115                                               &data_len, mac);
00116 }
00117 
 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