commit c80b239b93bdb23129bfd41b52f280adf5b76e22
parent aa7abb44c552063ee7934f858e7c5abe3d1ccb22
Author: Andrew Zaborowski <andrew.zaborowski@intel.com>
Date: Tue, 19 Mar 2019 01:25:25 +0100
simutil: Optimize l_checksum usage
The checksum object was created / destroyed repeatedly. It was
sufficient to simply call checksum_reset since the key was never
changed.
Diffstat:
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/simutil.c b/src/simutil.c
@@ -203,6 +203,10 @@ bool eap_aka_prf_prime(const uint8_t *ik_p, const uint8_t *ck_p,
memcpy(key, ik_p, EAP_AKA_IK_LEN);
memcpy(key + EAP_AKA_IK_LEN, ck_p, EAP_AKA_CK_LEN);
+ hmac = l_checksum_new_hmac(L_CHECKSUM_SHA256, key, 32);
+ if (!hmac)
+ return false;
+
iov[0].iov_base = digest;
/* initial iteration digest is not used */
iov[0].iov_len = 0;
@@ -215,13 +219,9 @@ bool eap_aka_prf_prime(const uint8_t *ik_p, const uint8_t *ck_p,
/* need 208 bytes for all keys */
while (pos < out + 224) {
- hmac = l_checksum_new_hmac(L_CHECKSUM_SHA256, key, 32);
- if (!hmac)
- return false;
-
+ l_checksum_reset(hmac);
l_checksum_updatev(hmac, iov, 4);
l_checksum_get_digest(hmac, digest, 32);
- l_checksum_free(hmac);
memcpy(pos, digest, 32);
pos += 32;
i++;
@@ -229,6 +229,8 @@ bool eap_aka_prf_prime(const uint8_t *ik_p, const uint8_t *ck_p,
iov[0].iov_len = 32;
}
+ l_checksum_free(hmac);
+
pos = out;
memcpy(k_encr, pos, EAP_SIM_K_ENCR_LEN);
pos += EAP_SIM_K_ENCR_LEN;