|
@@ -27,9 +27,10 @@
|
|
|
* @addr: Pointers to the data areas
|
|
|
* @len: Lengths of the data blocks
|
|
|
* @mac: Buffer for the hash (20 bytes)
|
|
|
+ * Returns: 0 on success, -1 on failure
|
|
|
*/
|
|
|
-void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
|
|
|
- const u8 *addr[], const size_t *len, u8 *mac)
|
|
|
+int hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
|
|
|
+ const u8 *addr[], const size_t *len, u8 *mac)
|
|
|
{
|
|
|
unsigned char k_pad[64]; /* padding - key XORd with ipad/opad */
|
|
|
unsigned char tk[20];
|
|
@@ -41,12 +42,13 @@ void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
|
|
|
* Fixed limit on the number of fragments to avoid having to
|
|
|
* allocate memory (which could fail).
|
|
|
*/
|
|
|
- return;
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
/* if key is longer than 64 bytes reset it to key = SHA1(key) */
|
|
|
if (key_len > 64) {
|
|
|
- sha1_vector(1, &key, &key_len, tk);
|
|
|
+ if (sha1_vector(1, &key, &key_len, tk))
|
|
|
+ return -1;
|
|
|
key = tk;
|
|
|
key_len = 20;
|
|
|
}
|
|
@@ -74,7 +76,8 @@ void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
|
|
|
_addr[i + 1] = addr[i];
|
|
|
_len[i + 1] = len[i];
|
|
|
}
|
|
|
- sha1_vector(1 + num_elem, _addr, _len, mac);
|
|
|
+ if (sha1_vector(1 + num_elem, _addr, _len, mac))
|
|
|
+ return -1;
|
|
|
|
|
|
os_memset(k_pad, 0, sizeof(k_pad));
|
|
|
os_memcpy(k_pad, key, key_len);
|
|
@@ -87,7 +90,7 @@ void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
|
|
|
_len[0] = 64;
|
|
|
_addr[1] = mac;
|
|
|
_len[1] = SHA1_MAC_LEN;
|
|
|
- sha1_vector(2, _addr, _len, mac);
|
|
|
+ return sha1_vector(2, _addr, _len, mac);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -98,11 +101,12 @@ void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
|
|
|
* @data: Pointers to the data area
|
|
|
* @data_len: Length of the data area
|
|
|
* @mac: Buffer for the hash (20 bytes)
|
|
|
+ * Returns: 0 on success, -1 of failure
|
|
|
*/
|
|
|
-void hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
|
|
|
+int hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
|
|
|
u8 *mac)
|
|
|
{
|
|
|
- hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac);
|
|
|
+ return hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -115,12 +119,13 @@ void hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
|
|
|
* @data_len: Length of the data
|
|
|
* @buf: Buffer for the generated pseudo-random key
|
|
|
* @buf_len: Number of bytes of key to generate
|
|
|
+ * Returns: 0 on success, -1 of failure
|
|
|
*
|
|
|
* This function is used to derive new, cryptographically separate keys from a
|
|
|
* given key (e.g., PMK in IEEE 802.11i).
|
|
|
*/
|
|
|
-void sha1_prf(const u8 *key, size_t key_len, const char *label,
|
|
|
- const u8 *data, size_t data_len, u8 *buf, size_t buf_len)
|
|
|
+int sha1_prf(const u8 *key, size_t key_len, const char *label,
|
|
|
+ const u8 *data, size_t data_len, u8 *buf, size_t buf_len)
|
|
|
{
|
|
|
u8 counter = 0;
|
|
|
size_t pos, plen;
|
|
@@ -140,15 +145,19 @@ void sha1_prf(const u8 *key, size_t key_len, const char *label,
|
|
|
while (pos < buf_len) {
|
|
|
plen = buf_len - pos;
|
|
|
if (plen >= SHA1_MAC_LEN) {
|
|
|
- hmac_sha1_vector(key, key_len, 3, addr, len,
|
|
|
- &buf[pos]);
|
|
|
+ if (hmac_sha1_vector(key, key_len, 3, addr, len,
|
|
|
+ &buf[pos]))
|
|
|
+ return -1;
|
|
|
pos += SHA1_MAC_LEN;
|
|
|
} else {
|
|
|
- hmac_sha1_vector(key, key_len, 3, addr, len,
|
|
|
- hash);
|
|
|
+ if (hmac_sha1_vector(key, key_len, 3, addr, len,
|
|
|
+ hash))
|
|
|
+ return -1;
|
|
|
os_memcpy(&buf[pos], hash, plen);
|
|
|
break;
|
|
|
}
|
|
|
counter++;
|
|
|
}
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|