From 5c4f7948d46ee34f6240e6f69e8da86cb45bba30 Mon Sep 17 00:00:00 2001 From: Sagar Bijwe Date: Wed, 26 Feb 2020 17:18:35 +0530 Subject: [PATCH] wpa_supplicant: Fix SAE test-case failure on mbedtls version udpate Problem: mbedtls_ctr_drbg_context was initialized in crypto_ec_point_mul. This was okay in releases before 2.16.4 as entropy_len used to get set to MBEDTLS_CTR_DRBG_ENTROPY_LEN in function mbedtls_ctr_drbg_seed. The function is now changed to set the length to MBEDTLS_CTR_DRBG_ENTROPY_LEN if previous length is 0 and hence the bug. Solution: Initialize mbedtls_ctr_drbg_context in crypto_ec_point_mul. --- components/wpa_supplicant/src/crypto/crypto_mbedtls.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/wpa_supplicant/src/crypto/crypto_mbedtls.c b/components/wpa_supplicant/src/crypto/crypto_mbedtls.c index b7c0870c6..0f50cd8d0 100644 --- a/components/wpa_supplicant/src/crypto/crypto_mbedtls.c +++ b/components/wpa_supplicant/src/crypto/crypto_mbedtls.c @@ -266,7 +266,7 @@ struct crypto_ec *crypto_ec_init(int group) return NULL; } - mbedtls_ecp_group_init( &e->group ); + mbedtls_ecp_group_init(&e->group); if (mbedtls_ecp_group_load(&e->group, grp_id)) { crypto_ec_deinit(e); @@ -283,7 +283,7 @@ void crypto_ec_deinit(struct crypto_ec *e) return; } - mbedtls_ecp_group_free( &e->group ); + mbedtls_ecp_group_free(&e->group); os_free(e); } @@ -417,6 +417,7 @@ int crypto_ec_point_mul(struct crypto_ec *e, const struct crypto_ec_point *p, mbedtls_ctr_drbg_context ctr_drbg; mbedtls_entropy_init(&entropy); + mbedtls_ctr_drbg_init(&ctr_drbg); MBEDTLS_MPI_CHK(mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, NULL, 0)); @@ -428,8 +429,8 @@ int crypto_ec_point_mul(struct crypto_ec *e, const struct crypto_ec_point *p, mbedtls_ctr_drbg_random, &ctr_drbg)); cleanup: - mbedtls_ctr_drbg_free( &ctr_drbg ); - mbedtls_entropy_free( &entropy ); + mbedtls_ctr_drbg_free(&ctr_drbg); + mbedtls_entropy_free(&entropy); return ret ? -1 : 0; }