Bläddra i källkod

hal: minor fixes needed in the crypto hal test app

harshal.patil 2 år sedan
förälder
incheckning
7d4e69d5fa

+ 7 - 7
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

+ 11 - 1
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 */
 }
 
-void app_main(void)
+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)
+{
+    xTaskCreatePinnedToCore(test_task, "testTask", CONFIG_UNITY_FREERTOS_STACK_SIZE, NULL, CONFIG_UNITY_FREERTOS_PRIORITY, NULL, CONFIG_UNITY_FREERTOS_CPU);
 }

+ 6 - 6
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);
 }

+ 2 - 2
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;
     }
 

+ 7 - 1
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)