From 5d469203822578c88e3469285ab419d51070fc32 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Sat, 25 Apr 2026 12:46:01 +0530 Subject: [PATCH] ci(esp_wifi): skip timing test if hw not available --- .../test_apps/main/test_fast_pbkdf2.c | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/components/wpa_supplicant/test_apps/main/test_fast_pbkdf2.c b/components/wpa_supplicant/test_apps/main/test_fast_pbkdf2.c index 0b6674cf69e..abdede5b746 100644 --- a/components/wpa_supplicant/test_apps/main/test_fast_pbkdf2.c +++ b/components/wpa_supplicant/test_apps/main/test_fast_pbkdf2.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -12,13 +12,20 @@ #include "test_wpa_supplicant_common.h" #define PMK_LEN 32 -#define NUM_ITERATIONS 5 +#define NUM_ITERATIONS 2 #define MIN_PASSPHARSE_LEN 8 +#ifdef CONFIG_FAST_PBKDF2 void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw, const uint8_t *salt, size_t nsalt, uint32_t iterations, uint8_t *out, size_t nout); +#endif + +#ifdef CONFIG_FAST_PSK +int esp_fast_psk(const char *password, size_t password_len, const uint8_t *ssid, + size_t ssid_len, size_t iterations, uint8_t *output, size_t output_len); +#endif int64_t esp_timer_get_time(void); @@ -50,9 +57,14 @@ TEST_CASE("Test pbkdf2", "[crypto-pbkdf2]") strlen("espressif2"), 4096, PMK_LEN, expected_pmk); TEST_ASSERT(memcmp(PMK, expected_pmk, PMK_LEN) == 0); - int64_t total_time_pbkdf2 = 0; // Variable to store total time for pbkdf2_sha1 + int64_t total_time_pbkdf2 = 0; int64_t total_time_mbedtls = 0; +#ifdef CONFIG_FAST_PBKDF2 int64_t total_time_fast_pbkdf2 = 0; +#endif +#ifdef CONFIG_FAST_PSK + int64_t total_time_fast_psk = 0; +#endif int i; for (i = 0; i < NUM_ITERATIONS; i++) { /* Calculate PMK using random ssid and passphrase and compare */ @@ -70,17 +82,21 @@ TEST_CASE("Test pbkdf2", "[crypto-pbkdf2]") } os_get_random(passphrase, passphrase_len); + + /* Reference: mbedtls PBKDF2 */ int64_t start_time = esp_timer_get_time(); - pbkdf2_sha1((char *)passphrase, ssid, ssid_len, 4096, PMK, PMK_LEN); - int64_t end_time = esp_timer_get_time(); - total_time_pbkdf2 += (end_time - start_time); - start_time = esp_timer_get_time(); mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, (const unsigned char *) passphrase, strlen((char *)passphrase), (const unsigned char *)ssid, ssid_len, 4096, PMK_LEN, expected_pmk); - end_time = esp_timer_get_time(); + int64_t end_time = esp_timer_get_time(); total_time_mbedtls += (end_time - start_time); - /* Dump values if fails */ + + /* pbkdf2_sha1 (dispatches to fastpsk or fastpbkdf2 per chip) */ + start_time = esp_timer_get_time(); + pbkdf2_sha1((char *)passphrase, ssid, ssid_len, 4096, PMK, PMK_LEN); + end_time = esp_timer_get_time(); + total_time_pbkdf2 += (end_time - start_time); + if (memcmp(PMK, expected_pmk, PMK_LEN) != 0) { ESP_LOG_BUFFER_HEXDUMP("passphrase", passphrase, passphrase_len, ESP_LOG_INFO); ESP_LOG_BUFFER_HEXDUMP("ssid", ssid, ssid_len, ESP_LOG_INFO); @@ -89,23 +105,34 @@ TEST_CASE("Test pbkdf2", "[crypto-pbkdf2]") } TEST_ASSERT(memcmp(PMK, expected_pmk, PMK_LEN) == 0); -#if 0 +#ifdef CONFIG_FAST_PSK + /* esp_fast_psk: HW SHA accelerated (fastpsk.c) */ start_time = esp_timer_get_time(); - fastpbkdf2_hmac_sha1((const u8 *)passphrase, os_strlen((char *)passphrase), ssid, ssid_len, 4096, PMK, PMK_LEN); + esp_fast_psk((char *)passphrase, os_strlen((char *)passphrase), + ssid, ssid_len, 4096, PMK, PMK_LEN); + end_time = esp_timer_get_time(); + total_time_fast_psk += (end_time - start_time); + TEST_ASSERT(memcmp(PMK, expected_pmk, PMK_LEN) == 0); +#endif + +#ifdef CONFIG_FAST_PBKDF2 + /* fastpbkdf2: SW SHA optimized (fastpbkdf2.c) */ + start_time = esp_timer_get_time(); + fastpbkdf2_hmac_sha1((const u8 *)passphrase, os_strlen((char *)passphrase), + ssid, ssid_len, 4096, PMK, PMK_LEN); end_time = esp_timer_get_time(); total_time_fast_pbkdf2 += (end_time - start_time); + TEST_ASSERT(memcmp(PMK, expected_pmk, PMK_LEN) == 0); #endif } - // Calculate average time for pbkdf2_sha1 - int64_t avg_time_pbkdf2 = total_time_pbkdf2 / NUM_ITERATIONS; - // Calculate average time for mbedtls_pkcs5_pbkdf2_hmac_ext - int64_t avg_time_mbedtls = total_time_mbedtls / NUM_ITERATIONS; - int64_t avg_time_fast = total_time_fast_pbkdf2 / NUM_ITERATIONS; - - // Log average times - ESP_LOGI("Timing", "Average time for pbkdf2_sha1: %lld microseconds", avg_time_pbkdf2); - ESP_LOGI("Timing", "Average time for fast_pbkdf2_sha1: %lld microseconds", avg_time_fast); - ESP_LOGI("Timing", "Average time for mbedtls_pkcs5_pbkdf2_hmac_ext: %lld microseconds", avg_time_mbedtls); + ESP_LOGI("Timing", "Average time for pbkdf2_sha1: %lld us", total_time_pbkdf2 / NUM_ITERATIONS); +#ifdef CONFIG_FAST_PSK + ESP_LOGI("Timing", "Average time for esp_fast_psk (HW): %lld us", total_time_fast_psk / NUM_ITERATIONS); +#endif +#ifdef CONFIG_FAST_PBKDF2 + ESP_LOGI("Timing", "Average time for fastpbkdf2 (SW): %lld us", total_time_fast_pbkdf2 / NUM_ITERATIONS); +#endif + ESP_LOGI("Timing", "Average time for mbedtls_pbkdf2: %lld us", total_time_mbedtls / NUM_ITERATIONS); } #endif