|
@@ -30,6 +30,7 @@
|
|
|
#include <crypto/skcipher.h>
|
|
|
|
|
|
/* Function Definitions and Documentation */
|
|
|
+#define MAX_HMAC_ELEMENT_CNT 10
|
|
|
|
|
|
/*
|
|
|
* xor: API to calculate xor
|
|
@@ -49,31 +50,8 @@ int qdf_get_hash(uint8_t *type,
|
|
|
uint8_t element_cnt, uint8_t *addr[], uint32_t *addr_len,
|
|
|
int8_t *hash)
|
|
|
{
|
|
|
- int i, ret;
|
|
|
- struct hash_desc desc;
|
|
|
- struct scatterlist sg;
|
|
|
-
|
|
|
- /* allocate crypto hash type */
|
|
|
- desc.tfm = crypto_alloc_hash(type, 0, CRYPTO_ALG_ASYNC);
|
|
|
-
|
|
|
- if (IS_ERR(desc.tfm)) {
|
|
|
- ret = PTR_ERR(desc.tfm);
|
|
|
- return -EINVAL;
|
|
|
- }
|
|
|
- desc.flags = 0;
|
|
|
- ret = crypto_hash_init(&desc);
|
|
|
-
|
|
|
- if (ret)
|
|
|
- return ret;
|
|
|
-
|
|
|
- for (i = 0; i < element_cnt ; i++) {
|
|
|
- sg_init_one(&sg, addr[i], addr_len[i]);
|
|
|
- crypto_hash_update(&desc, &sg, addr_len[i]);
|
|
|
- }
|
|
|
-
|
|
|
- crypto_hash_final(&desc, hash);
|
|
|
- crypto_free_hash(desc.tfm);
|
|
|
- return 0;
|
|
|
+ return qdf_get_hmac_hash(type, NULL, 0, element_cnt,
|
|
|
+ addr, addr_len, hash);
|
|
|
}
|
|
|
|
|
|
int qdf_get_hmac_hash(uint8_t *type, uint8_t *key,
|
|
@@ -81,33 +59,20 @@ int qdf_get_hmac_hash(uint8_t *type, uint8_t *key,
|
|
|
uint8_t element_cnt, uint8_t *addr[], uint32_t *addr_len,
|
|
|
int8_t *hash)
|
|
|
{
|
|
|
- int i, ret;
|
|
|
- struct hash_desc desc;
|
|
|
- struct scatterlist sg;
|
|
|
-
|
|
|
- /* allocate crypto hash type */
|
|
|
- desc.tfm = crypto_alloc_hash(type, 0, CRYPTO_ALG_ASYNC);
|
|
|
+ int i;
|
|
|
+ size_t src_len[MAX_HMAC_ELEMENT_CNT];
|
|
|
|
|
|
- if (IS_ERR(desc.tfm)) {
|
|
|
- ret = PTR_ERR(desc.tfm);
|
|
|
+ if (element_cnt > MAX_HMAC_ELEMENT_CNT) {
|
|
|
+ QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
|
|
|
+ FL("Invalid element count %d"), element_cnt);
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
- desc.flags = 0;
|
|
|
- ret = crypto_hash_setkey(desc.tfm, key, keylen);
|
|
|
-
|
|
|
- crypto_hash_init(&desc);
|
|
|
|
|
|
- if (ret)
|
|
|
- return ret;
|
|
|
-
|
|
|
- for (i = 0; i < element_cnt ; i++) {
|
|
|
- sg_init_one(&sg, addr[i], addr_len[i]);
|
|
|
- crypto_hash_update(&desc, &sg, addr_len[i]);
|
|
|
- }
|
|
|
+ for (i = 0; i < element_cnt; i++)
|
|
|
+ src_len[i] = addr_len[i];
|
|
|
|
|
|
- crypto_hash_final(&desc, hash);
|
|
|
- crypto_free_hash(desc.tfm);
|
|
|
- return 0;
|
|
|
+ return qdf_get_keyed_hash(type, key, keylen, (const uint8_t **)addr,
|
|
|
+ src_len, element_cnt, hash);
|
|
|
}
|
|
|
|
|
|
/* qdf_update_dbl from RFC 5297. Length of d is AES_BLOCK_SIZE (128 bits) */
|