2 * MD5 hash implementation and interface functions (non-FIPS allowed cases)
3 * Copyright (c) 2003-2009, 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 * hmac_md5_vector_non_fips_allow - HMAC-MD5 over data vector (RFC 2104)
24 * @key: Key for HMAC operations
25 * @key_len: Length of the key in bytes
26 * @num_elem: Number of elements in the data vector
27 * @addr: Pointers to the data areas
28 * @len: Lengths of the data blocks
29 * @mac: Buffer for the hash (16 bytes)
30 * Returns: 0 on success, -1 on failure
32 int hmac_md5_vector_non_fips_allow(const u8
*key
, size_t key_len
,
33 size_t num_elem
, const u8
*addr
[],
34 const size_t *len
, u8
*mac
)
36 u8 k_pad
[64]; /* padding - key XORd with ipad/opad */
43 * Fixed limit on the number of fragments to avoid having to
44 * allocate memory (which could fail).
49 /* if key is longer than 64 bytes reset it to key = MD5(key) */
51 if (md5_vector_non_fips_allow(1, &key
, &key_len
, tk
))
57 /* the HMAC_MD5 transform looks like:
59 * MD5(K XOR opad, MD5(K XOR ipad, text))
61 * where K is an n byte key
62 * ipad is the byte 0x36 repeated 64 times
63 * opad is the byte 0x5c repeated 64 times
64 * and text is the data being protected */
66 /* start out by storing key in ipad */
67 os_memset(k_pad
, 0, sizeof(k_pad
));
68 os_memcpy(k_pad
, key
, key_len
);
70 /* XOR key with ipad values */
71 for (i
= 0; i
< 64; i
++)
74 /* perform inner MD5 */
77 for (i
= 0; i
< num_elem
; i
++) {
78 _addr
[i
+ 1] = addr
[i
];
81 if (md5_vector_non_fips_allow(1 + num_elem
, _addr
, _len
, mac
))
84 os_memset(k_pad
, 0, sizeof(k_pad
));
85 os_memcpy(k_pad
, key
, key_len
);
86 /* XOR key with opad values */
87 for (i
= 0; i
< 64; i
++)
90 /* perform outer MD5 */
94 _len
[1] = MD5_MAC_LEN
;
95 return md5_vector_non_fips_allow(2, _addr
, _len
, mac
);
100 * hmac_md5_non_fips_allow - HMAC-MD5 over data buffer (RFC 2104)
101 * @key: Key for HMAC operations
102 * @key_len: Length of the key in bytes
103 * @data: Pointers to the data area
104 * @data_len: Length of the data area
105 * @mac: Buffer for the hash (16 bytes)
106 * Returns: 0 on success, -1 on failure
108 int hmac_md5_non_fips_allow(const u8
*key
, size_t key_len
, const u8
*data
,
109 size_t data_len
, u8
*mac
)
111 return hmac_md5_vector_non_fips_allow(key
, key_len
, 1, &data
,