From 7d4e69d5fafcd93d9f4aecdd31618cc6f204a856 Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Fri, 26 May 2023 18:15:48 +0530 Subject: [PATCH] hal: minor fixes needed in the crypto hal test app --- components/hal/test_apps/crypto/README.md | 14 +++++++------- components/hal/test_apps/crypto/main/app_main.c | 12 +++++++++++- components/hal/test_apps/crypto/main/ds/test_ds.c | 12 ++++++------ .../hal/test_apps/crypto/main/ecdsa/test_ecdsa.c | 4 ++-- components/hal/test_apps/crypto/pytest_crypto.py | 8 +++++++- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/components/hal/test_apps/crypto/README.md b/components/hal/test_apps/crypto/README.md index e405032663..138e9e0dde 100644 --- a/components/hal/test_apps/crypto/README.md +++ b/components/hal/test_apps/crypto/README.md @@ -53,9 +53,9 @@ This contains tests for the following features of the crypto peripherals: The HMAC tests need an HMAC key to be burned in the `BLOCK_KEY3` and `BLOCK_KEY4` of the efuses. As this verification application is independent of the efuse component, the user needs to manually burn the keys and their key purposes using `espefuse.py`. ```bash -espefuse.py -p $ESPPORT burn_key BLOCK_KEY3 hmac_key.bin HMAC_DOWN_JTAG +espefuse.py -p $ESPPORT burn_key BLOCK_KEY3 main/hmac/hmac_key.bin HMAC_DOWN_JTAG -espefuse.py -p $ESPPORT burn_key BLOCK_KEY4 hmac_key.bin HMAC_UP +espefuse.py -p $ESPPORT burn_key BLOCK_KEY4 main/hmac/hmac_key.bin HMAC_UP ``` # Burning the HMAC keys for Digital Signature tests @@ -63,11 +63,11 @@ espefuse.py -p $ESPPORT burn_key BLOCK_KEY4 hmac_key.bin HMAC_UP The tests needs some HMAC keys to be burned in the `BLOCK_KEY1`, `BLOCK_KEY2` and `BLOCK_KEY3` of the efuses. As this verification application is independent of the efuse component, the user needs to manually burn the keys and their key purposes using `espefuse.py`. ```bash -espefuse.py -p $ESPPORT burn_key BLOCK_KEY1 ds_key1.bin HMAC_DOWN_DIGITAL_SIGNATURE --no-read-protect --no-write-protect --do-not-confirm +espefuse.py -p $ESPPORT burn_key BLOCK_KEY1 main/ds/ds_key1.bin HMAC_DOWN_DIGITAL_SIGNATURE --do-not-confirm -espefuse.py -p $ESPPORT burn_key BLOCK_KEY2 ds_key2.bin HMAC_DOWN_DIGITAL_SIGNATURE --no-read-protect --no-write-protect --do-not-confirm +espefuse.py -p $ESPPORT burn_key BLOCK_KEY2 main/ds/ds_key2.bin HMAC_DOWN_DIGITAL_SIGNATURE --do-not-confirm -espefuse.py -p $ESPPORT burn_key BLOCK_KEY3 ds_key3.bin HMAC_DOWN_DIGITAL_SIGNATURE --no-read-protect --no-write-protect --do-not-confirm +espefuse.py -p $ESPPORT burn_key BLOCK_KEY3 main/ds/ds_key3.bin HMAC_DOWN_DIGITAL_SIGNATURE --do-not-confirm ``` # Burning the ECDSA keys @@ -75,9 +75,9 @@ espefuse.py -p $ESPPORT burn_key BLOCK_KEY3 ds_key3.bin HMAC_DOWN_DIGITAL_SIGNAT The ECDSA tests need some ECDSA keys to be burned in the `BLOCK_KEY1` and `BLOCK_KEY2` of the efuses. As this verification application is independent of the efuse component, the user needs to manually burn the keys and their key purposes using `espefuse.py`. ```bash -espefuse.py -p $ESPPORT burn_key BLOCK_KEY1 ecdsa192_priv_key.pem ECDSA_KEY --no-read-protect --no-write-protect --do-not-confirm +espefuse.py -p $ESPPORT burn_key BLOCK_KEY1 main/ecdsa/ecdsa192_priv_key.pem ECDSA_KEY --do-not-confirm -espefuse.py -p $ESPPORT burn_key BLOCK_KEY2 ecdsa256_priv_key.pem ECDSA_KEY --no-read-protect --no-write-protect --do-not-confirm +espefuse.py -p $ESPPORT burn_key BLOCK_KEY2 main/ecdsa/ecdsa256_priv_key.pem ECDSA_KEY --do-not-confirm ``` # Building diff --git a/components/hal/test_apps/crypto/main/app_main.c b/components/hal/test_apps/crypto/main/app_main.c index 7779b0db2f..7f95e09050 100644 --- a/components/hal/test_apps/crypto/main/app_main.c +++ b/components/hal/test_apps/crypto/main/app_main.c @@ -4,6 +4,9 @@ * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "unity.h" #include "unity_fixture.h" #include "unity_fixture_extras.h" @@ -34,7 +37,14 @@ static void run_all_tests(void) #endif /* CONFIG_IDF_ENV_FPGA */ } +static void test_task(void *pvParameters) +{ + vTaskDelay(2); /* Delay a bit to let the main task be deleted */ + UNITY_MAIN_FUNC(run_all_tests); + vTaskDelete(NULL); +} + void app_main(void) { - UNITY_MAIN_FUNC(run_all_tests); + xTaskCreatePinnedToCore(test_task, "testTask", CONFIG_UNITY_FREERTOS_STACK_SIZE, NULL, CONFIG_UNITY_FREERTOS_PRIORITY, NULL, CONFIG_UNITY_FREERTOS_CPU); } diff --git a/components/hal/test_apps/crypto/main/ds/test_ds.c b/components/hal/test_apps/crypto/main/ds/test_ds.c index 79a221c7d0..98addff6dd 100644 --- a/components/hal/test_apps/crypto/main/ds/test_ds.c +++ b/components/hal/test_apps/crypto/main/ds/test_ds.c @@ -531,10 +531,10 @@ TEST(ds, digital_signature_invalid_data) TEST_GROUP_RUNNER(ds) { - RUN_TEST_CASE(ds, digital_siganture_parameter_encryption); - RUN_TEST_CASE(ds, digital_siganture_wrong_hmac_key_purpose); - RUN_TEST_CASE(ds, digital_siganture_blocking_wrong_hmac_key_purpose); - RUN_TEST_CASE(ds, digital_siganture_operation); - RUN_TEST_CASE(ds, digital_siganture_blocking_operation); - RUN_TEST_CASE(ds, digital_siganture_invalid_data); + RUN_TEST_CASE(ds, digital_signature_parameter_encryption); + RUN_TEST_CASE(ds, digital_signature_wrong_hmac_key_purpose); + RUN_TEST_CASE(ds, digital_signature_blocking_wrong_hmac_key_purpose); + RUN_TEST_CASE(ds, digital_signature_operation); + RUN_TEST_CASE(ds, digital_signature_blocking_operation); + RUN_TEST_CASE(ds, digital_signature_invalid_data); } diff --git a/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c b/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c index fef0354f66..120e96cf5d 100644 --- a/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c +++ b/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c @@ -120,11 +120,11 @@ static void test_ecdsa_sign(bool is_p256, uint8_t* sha, uint8_t* r_le, uint8_t* if (is_p256) { conf.curve = ECDSA_CURVE_SECP256R1; - conf.efuse_key_blk = 5; + conf.efuse_key_blk = 6; len = 32; } else { conf.curve = ECDSA_CURVE_SECP192R1; - conf.efuse_key_blk = 6; + conf.efuse_key_blk = 5; len = 24; } diff --git a/components/hal/test_apps/crypto/pytest_crypto.py b/components/hal/test_apps/crypto/pytest_crypto.py index 8aa5b7dde1..7887c65f2b 100644 --- a/components/hal/test_apps/crypto/pytest_crypto.py +++ b/components/hal/test_apps/crypto/pytest_crypto.py @@ -1,6 +1,8 @@ # SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 +import os + import pytest from pytest_embedded import Dut @@ -8,4 +10,8 @@ from pytest_embedded import Dut @pytest.mark.supported_targets @pytest.mark.generic def test_crypto(dut: Dut) -> None: - dut.expect('main_task: Returned from app_main()') + # if the env variable IDF_FPGA_ENV is set, we would need a longer timeout + # as tests for efuses burning security peripherals would be run + timeout = 600 if os.environ.get('IDF_ENV_FPGA') else 60 + + dut.expect('main_task: Returned from app_main()', timeout=timeout)