Skip to content

Commit 1a5b2a2

Browse files
kapilkedawatHarshal5
authored andcommitted
fix(esp_wifi): Add alternate SHA1 APIs in WiFi
Add alternate SHA1 APIs to handle cases when `CONFIG_MBEDTLS_SHA1_C` is disabled.
1 parent e442f11 commit 1a5b2a2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

components/wpa_supplicant/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ if(CONFIG_ESP_WIFI_MBEDTLS_CRYPTO)
127127
if(NOT CONFIG_MBEDTLS_DES_C)
128128
set(crypto_src ${crypto_src} "src/crypto/des-internal.c")
129129
endif()
130+
if(NOT CONFIG_MBEDTLS_SHA1_C)
131+
set(crypto_src ${crypto_src} "src/crypto/sha1.c")
132+
endif()
130133
# Enabling this only for WiFi is probably not a good idea since MbedTLS
131134
# uses generic crypto init/update functions for this. That causes
132135
# binary size increment since all the other enabled module

components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "aes_wrap.h"
3636
#include "crypto.h"
3737
#include "mbedtls/esp_config.h"
38+
#include "mbedtls/sha1.h"
3839

3940
#ifdef CONFIG_FAST_PBKDF2
4041
#include "fastpbkdf2.h"
@@ -105,7 +106,28 @@ int sha512_vector(size_t num_elem, const u8 *addr[], const size_t *len,
105106

106107
int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
107108
{
109+
#if defined(MBEDTLS_SHA1_C)
108110
return digest_vector(MBEDTLS_MD_SHA1, num_elem, addr, len, mac);
111+
#elif defined(MBEDTLS_SHA1_ALT)
112+
mbedtls_sha1_context ctx;
113+
size_t i;
114+
int ret;
115+
116+
mbedtls_sha1_init(&ctx);
117+
for (i = 0; i < num_elem; i++) {
118+
ret = mbedtls_sha1_update(&ctx, addr[i], len[i]);
119+
if (ret != 0) {
120+
goto exit;
121+
}
122+
}
123+
ret = mbedtls_sha1_finish(&ctx, mac);
124+
125+
exit:
126+
mbedtls_sha1_free(&ctx);
127+
return ret;
128+
#else
129+
return -ENOTSUP;
130+
#endif
109131
}
110132

111133
int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
@@ -363,6 +385,7 @@ int hmac_md5(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
363385
return hmac_md5_vector(key, key_len, 1, &data, &data_len, mac);
364386
}
365387

388+
#ifdef MBEDTLS_SHA1_C
366389
int hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
367390
const u8 *addr[], const size_t *len, u8 *mac)
368391
{
@@ -375,6 +398,7 @@ int hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
375398
{
376399
return hmac_sha1_vector(key, key_len, 1, &data, &data_len, mac);
377400
}
401+
#endif
378402

379403
static void *aes_crypt_init(int mode, const u8 *key, size_t len)
380404
{

0 commit comments

Comments
 (0)