mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
ci(esp_wifi): skip timing test if hw not available
This commit is contained in:
@@ -50,7 +50,9 @@ static void dpp_test_clear_overrides(void)
|
||||
|
||||
static u32 dpp_test_prod_limit_us(void)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
|
||||
#if !defined(CONFIG_MBEDTLS_HARDWARE_ECC) && !defined(CONFIG_MBEDTLS_HARDWARE_MPI)
|
||||
return 0;
|
||||
#elif CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
|
||||
return 300000;
|
||||
#elif SOC_ECC_SUPPORTED
|
||||
return 100000;
|
||||
|
||||
@@ -7,21 +7,63 @@
|
||||
#include <inttypes.h>
|
||||
#include "unity.h"
|
||||
#include "utils/common.h"
|
||||
#include "mbedtls/private/pkcs5.h"
|
||||
#include "psa/crypto.h"
|
||||
#include "crypto/sha1.h"
|
||||
#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);
|
||||
|
||||
static int psa_pbkdf2_sha1(const unsigned char *password, size_t plen,
|
||||
const unsigned char *salt, size_t slen,
|
||||
unsigned int iterations,
|
||||
uint32_t key_length, unsigned char *output)
|
||||
{
|
||||
psa_key_derivation_operation_t op = PSA_KEY_DERIVATION_OPERATION_INIT;
|
||||
psa_status_t status;
|
||||
|
||||
status = psa_key_derivation_setup(&op, PSA_ALG_PBKDF2_HMAC(PSA_ALG_SHA_1));
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
status = psa_key_derivation_input_integer(&op, PSA_KEY_DERIVATION_INPUT_COST, iterations);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
status = psa_key_derivation_input_bytes(&op, PSA_KEY_DERIVATION_INPUT_SALT, salt, slen);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
status = psa_key_derivation_input_bytes(&op, PSA_KEY_DERIVATION_INPUT_PASSWORD, password, plen);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
status = psa_key_derivation_output_bytes(&op, output, key_length);
|
||||
|
||||
cleanup:
|
||||
psa_key_derivation_abort(&op);
|
||||
return status == PSA_SUCCESS ? 0 : -1;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_MBEDTLS_SHA1_C) || defined(CONFIG_MBEDTLS_HARDWARE_SHA)
|
||||
TEST_CASE("Test pbkdf2", "[crypto-pbkdf2]")
|
||||
{
|
||||
@@ -43,16 +85,21 @@ TEST_CASE("Test pbkdf2", "[crypto-pbkdf2]")
|
||||
pbkdf2_sha1("espressif", (uint8_t *)"espressif", strlen("espressif"), 4096, PMK, PMK_LEN);
|
||||
TEST_ASSERT(memcmp(PMK, expected_pmk1, PMK_LEN) == 0);
|
||||
|
||||
/* Compare fast PBKDF output with mbedtls pbkdf2 function's output */
|
||||
/* Compare fast PBKDF output with PSA pbkdf2 function's output */
|
||||
pbkdf2_sha1("espressif2", (uint8_t *)"espressif2", strlen("espressif2"), 4096, PMK, PMK_LEN);
|
||||
mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, (const unsigned char *) "espressif2",
|
||||
strlen("espressif2"), (const unsigned char *)"espressif2",
|
||||
strlen("espressif2"), 4096, PMK_LEN, expected_pmk);
|
||||
psa_pbkdf2_sha1((const unsigned char *) "espressif2", strlen("espressif2"),
|
||||
(const unsigned char *)"espressif2", 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 +117,21 @@ TEST_CASE("Test pbkdf2", "[crypto-pbkdf2]")
|
||||
}
|
||||
|
||||
os_get_random(passphrase, passphrase_len);
|
||||
|
||||
/* Reference: PSA PBKDF2 */
|
||||
int64_t start_time = esp_timer_get_time();
|
||||
pbkdf2_sha1((char *)passphrase, ssid, ssid_len, 4096, PMK, PMK_LEN);
|
||||
psa_pbkdf2_sha1((const unsigned char *) passphrase, strlen((char *)passphrase),
|
||||
(const unsigned char *)ssid, ssid_len,
|
||||
4096, PMK_LEN, expected_pmk);
|
||||
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();
|
||||
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 +140,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 psa_pbkdf2: %lld us", total_time_mbedtls / NUM_ITERATIONS);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -310,7 +310,9 @@ TEST_CASE("Test SAE functionality with ECC group", "[wpa3_sae]")
|
||||
(long long) total_us, limit_us);
|
||||
ESP_LOGI("SAE Test", "Task stack high watermark(bytes): %u",
|
||||
test_task_stack_high_watermark_bytes());
|
||||
#if defined(CONFIG_MBEDTLS_HARDWARE_ECC) || defined(CONFIG_MBEDTLS_HARDWARE_MPI)
|
||||
TEST_ASSERT_MESSAGE(total_us <= limit_us, "SAE commit/parse timing regression");
|
||||
#endif
|
||||
|
||||
}
|
||||
ESP_LOGI("SAE Test", "=========== Complete ============");
|
||||
|
||||
Reference in New Issue
Block a user