forked from espressif/esp-idf
hal: combine ecc hal test app into security peripherals test app
This commit is contained in:
@ -1,9 +0,0 @@
|
||||
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
|
||||
|
||||
components/hal/test_apps/ecc:
|
||||
disable:
|
||||
- if: SOC_ECC_SUPPORTED != 1
|
||||
disable_test:
|
||||
- if: IDF_TARGET == "esp32c2"
|
||||
temporary: true
|
||||
reason: C2 ECC peripheral has a bug in ECC point verification, if value of K is zero the verification fails
|
@ -1,7 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(COMPONENTS main)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(ecc_test)
|
@ -1,43 +0,0 @@
|
||||
| Supported Targets | ESP32-C2 | ESP32-C6 | ESP32-H2 |
|
||||
| ----------------- | -------- | -------- | -------- |
|
||||
|
||||
## ECC peripheral test
|
||||
|
||||
This application contains basic test cases for the ECC peripheral without using any OS functionality or higher abstraction layer.
|
||||
|
||||
This contains tests for the following features of ECC peripheral:
|
||||
|
||||
- ECC Point multiplication for P192 and P256 curve
|
||||
- ECC Point verification for P192 and P256 curve
|
||||
- ECC Point verify and multiply for P192 and P256 curve
|
||||
- ECC Inverse multiplication for P192 and P256
|
||||
|
||||
If the hardware supports extended work modes then it also tests:
|
||||
- ECC Jacobian multiplication for P192 and P256 curve
|
||||
- ECC Jacobian verification for P192 and P256 curve
|
||||
- ECC Point verification and Jacobian multiplication for P192 and P256 curve
|
||||
- ECC Point addition for P192 and P256 curve
|
||||
- Mod addition
|
||||
- Mod subtraction
|
||||
- Mod multiplication
|
||||
|
||||
# Building
|
||||
|
||||
```bash
|
||||
idf.py set-target <TARGET>
|
||||
idf.py build
|
||||
```
|
||||
|
||||
# Running the app manually
|
||||
|
||||
```bash
|
||||
idf.py flash monitor
|
||||
```
|
||||
|
||||
Enter the test that you want to run locally
|
||||
|
||||
# Running tests
|
||||
|
||||
```bash
|
||||
pytest --target <TARGET>
|
||||
```
|
@ -1,6 +0,0 @@
|
||||
set(srcs "app_main.c"
|
||||
"test_ecc.c")
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
REQUIRES unity
|
||||
WHOLE_ARCHIVE)
|
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "unity_test_runner.h"
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
unity_run_menu();
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.esp32c6
|
||||
@pytest.mark.esp32h2
|
||||
@pytest.mark.generic
|
||||
def test_ecc(dut: Dut) -> None:
|
||||
dut.run_all_single_board_cases()
|
@ -1,2 +0,0 @@
|
||||
CONFIG_ESP_TASK_WDT_EN=y
|
||||
CONFIG_ESP_TASK_WDT_INIT=n
|
@ -12,6 +12,21 @@ This contains tests for the following features of the security peripherals:
|
||||
- MPI Multiplication
|
||||
- MPI Modular Exponentiation
|
||||
|
||||
- ECC peripheral
|
||||
- ECC Point multiplication for P192 and P256 curve
|
||||
- ECC Point verification for P192 and P256 curve
|
||||
- ECC Point verify and multiply for P192 and P256 curve
|
||||
- ECC Inverse multiplication for P192 and P256
|
||||
|
||||
If the hardware supports extended work modes then it also tests:
|
||||
- ECC Jacobian multiplication for P192 and P256 curve
|
||||
- ECC Jacobian verification for P192 and P256 curve
|
||||
- ECC Point verification and Jacobian multiplication for P192 and P256 curve
|
||||
- ECC Point addition for P192 and P256 curve
|
||||
- Mod addition
|
||||
- Mod subtraction
|
||||
- Mod multiplication
|
||||
|
||||
# Building
|
||||
|
||||
```bash
|
||||
|
@ -4,6 +4,10 @@ if(CONFIG_SOC_MPI_SUPPORTED)
|
||||
list(APPEND srcs "mpi/test_mpi.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_SOC_ECC_SUPPORTED)
|
||||
list(APPEND srcs "ecc/test_ecc.c")
|
||||
endif()
|
||||
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
REQUIRES test_utils unity
|
||||
|
@ -9,7 +9,13 @@
|
||||
|
||||
static void run_all_tests(void)
|
||||
{
|
||||
#if CONFIG_SOC_MPI_SUPPORTED
|
||||
RUN_TEST_GROUP(mpi);
|
||||
#endif
|
||||
|
||||
#if CONFIG_SOC_ECC_SUPPORTED
|
||||
RUN_TEST_GROUP(ecc);
|
||||
#endif
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
|
@ -9,12 +9,13 @@
|
||||
#include <string.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_log.h"
|
||||
#include "test_params.h"
|
||||
#include "ecc_params.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/ecc_hal.h"
|
||||
#include "hal/clk_gate_ll.h"
|
||||
|
||||
#include "unity.h"
|
||||
#include "memory_checks.h"
|
||||
#include "unity_fixture.h"
|
||||
|
||||
#define _DEBUG_ 0
|
||||
#define SOC_ECC_SUPPORT_POINT_MULT 1
|
||||
@ -45,6 +46,21 @@ static void ecc_enable_and_reset(void)
|
||||
periph_ll_enable_clk_clear_rst(PERIPH_ECC_MODULE);
|
||||
}
|
||||
|
||||
|
||||
TEST_GROUP(ecc);
|
||||
|
||||
TEST_SETUP(ecc)
|
||||
{
|
||||
test_utils_record_free_mem();
|
||||
TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL));
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(ecc)
|
||||
{
|
||||
test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL),
|
||||
test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL));
|
||||
}
|
||||
|
||||
#if SOC_ECC_SUPPORT_POINT_MULT
|
||||
static void ecc_point_mul(const uint8_t *k_le, const uint8_t *x_le, const uint8_t *y_le, uint8_t len, bool verify_first,
|
||||
uint8_t *res_x_le, uint8_t *res_y_le)
|
||||
@ -126,7 +142,7 @@ static void test_ecc_point_mul_inner(bool verify_first)
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(y_mul_le, y_res_le, 24, "Y coordinate of P192 point multiplication ");
|
||||
}
|
||||
|
||||
TEST_CASE("ECC point multiplication on SECP192R1 and SECP256R1", "[ecc][hal]")
|
||||
TEST(ecc, ecc_point_multiplication_on_SECP192R1_and_SECP256R1)
|
||||
{
|
||||
test_ecc_point_mul_inner(false);
|
||||
}
|
||||
@ -148,7 +164,7 @@ static int ecc_point_verify(const uint8_t *x_le, const uint8_t *y_le, uint8_t le
|
||||
return ecc_hal_read_verify_result();
|
||||
}
|
||||
|
||||
TEST_CASE("ECC point verification on SECP192R1 and SECP256R1", "[ecc][hal]")
|
||||
TEST(ecc, ecc_point_verification_on_SECP192R1_and_SECP256R1)
|
||||
{
|
||||
int res;
|
||||
uint8_t x_le[32];
|
||||
@ -183,7 +199,7 @@ TEST_CASE("ECC point verification on SECP192R1 and SECP256R1", "[ecc][hal]")
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_POINT_MULT && SOC_ECC_SUPPORT_POINT_VERIFY && !defined(SOC_ECC_SUPPORT_POINT_VERIFY_QUIRK)
|
||||
TEST_CASE("ECC point verification and multiplication on SECP192R1 and SECP256R1", "[ecc][hal]")
|
||||
TEST(ecc, ecc_point_verification_and_multiplication_on_SECP192R1_and_SECP256R1)
|
||||
{
|
||||
test_ecc_point_mul_inner(true);
|
||||
}
|
||||
@ -208,7 +224,7 @@ static void ecc_point_inv_mul(const uint8_t *num_le, const uint8_t *deno_le, uin
|
||||
ecc_hal_read_mul_result(zero, res_le, len);
|
||||
}
|
||||
|
||||
TEST_CASE("ECC inverse multiplication (or mod division) using SECP192R1 and SECP256R1 order of curve", "[ecc][hal]")
|
||||
TEST(ecc, ecc_inverse_multiplication_or_mod_division_using_SECP192R1_and_SECP256R1_order_of_curve)
|
||||
{
|
||||
uint8_t res[32] = {0};
|
||||
ecc_point_inv_mul(ecc256_num, ecc256_den, 32, res);
|
||||
@ -277,7 +293,7 @@ static void test_ecc_jacob_mul_inner(bool verify_first)
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(ecc_p192_jacob_mul_res_z_le, z_res_le, 24, "Z coordinate of P192 point jacobian multiplication ");
|
||||
}
|
||||
|
||||
TEST_CASE("ECC jacobian point multiplication on SECP192R1 and SECP256R1", "[ecc][hal]")
|
||||
TEST(ecc, ecc_jacobian_point_multiplication_on_SECP192R1_and_SECP256R1)
|
||||
{
|
||||
test_ecc_jacob_mul_inner(false);
|
||||
}
|
||||
@ -301,7 +317,7 @@ static int ecc_jacob_verify(const uint8_t *x_le, const uint8_t *y_le, const uint
|
||||
return ecc_hal_read_verify_result();
|
||||
}
|
||||
|
||||
TEST_CASE("ECC jacobian point verification on SECP192R1 and SECP256R1", "[ecc][hal]")
|
||||
TEST(ecc, ecc_jacobian_point_verification_on_SECP192R1_and_SECP256R1)
|
||||
{
|
||||
int res;
|
||||
/* P256 */
|
||||
@ -315,7 +331,7 @@ TEST_CASE("ECC jacobian point verification on SECP192R1 and SECP256R1", "[ecc][h
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_JACOB_POINT_MULT && SOC_ECC_SUPPORT_JACOB_POINT_VERIFY
|
||||
TEST_CASE("ECC point verification and Jacobian point multiplication on SECP192R1 and SECP256R1", "[ecc][hal]")
|
||||
TEST(ecc, ecc_point_verification_and_jacobian_point_multiplication_on_SECP192R1_and_SECP256R1)
|
||||
{
|
||||
test_ecc_jacob_mul_inner(true);
|
||||
}
|
||||
@ -341,7 +357,7 @@ static void ecc_point_addition(uint8_t *px_le, uint8_t *py_le, uint8_t *qx_le, u
|
||||
ecc_hal_read_point_add_result(x_res_le, y_res_le, z_res_le, len, jacob_output);
|
||||
}
|
||||
|
||||
TEST_CASE("ECC point addition on SECP192R1 and SECP256R1", "[ecc][hal]")
|
||||
TEST(ecc, ecc_point_addition_on_SECP192R1_and_SECP256R1)
|
||||
{
|
||||
uint8_t scalar_le[32] = {0};
|
||||
uint8_t x_le[32] = {0};
|
||||
@ -414,7 +430,7 @@ static void ecc_mod_op(ecc_mode_t mode, const uint8_t *a, const uint8_t *b, uint
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_MOD_ADD
|
||||
TEST_CASE("ECC mod addition using SECP192R1 and SECP256R1 order of curve", "[ecc][hal]")
|
||||
TEST(ecc, ecc_mod_addition_using_SECP192R1_and_SECP256R1_order_of_curve)
|
||||
{
|
||||
uint8_t res[32] = {0};
|
||||
ecc_mod_op(ECC_MODE_MOD_ADD, ecc256_x, ecc256_y, 32, res);
|
||||
@ -426,7 +442,7 @@ TEST_CASE("ECC mod addition using SECP192R1 and SECP256R1 order of curve", "[ecc
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_MOD_SUB
|
||||
TEST_CASE("ECC mod subtraction using SECP192R1 and SECP256R1 order of curve", "[ecc][hal]")
|
||||
TEST(ecc, ecc_mod_subtraction_using_SECP192R1_and_SECP256R1_order_of_curve)
|
||||
{
|
||||
uint8_t res[32] = {0};
|
||||
ecc_mod_op(ECC_MODE_MOD_SUB, ecc256_x, ecc256_y, 32, res);
|
||||
@ -438,7 +454,7 @@ TEST_CASE("ECC mod subtraction using SECP192R1 and SECP256R1 order of curve", "[
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_MOD_MUL
|
||||
TEST_CASE("ECC mod multiplication using SECP192R1 and SECP256R1 order of curve", "[ecc][hal]")
|
||||
TEST(ecc, ecc_mod_multiplication_using_SECP192R1_and_SECP256R1_order_of_curve)
|
||||
{
|
||||
uint8_t res[32] = {0};
|
||||
ecc_mod_op(ECC_MODE_MOD_MUL, ecc256_x, ecc256_y, 32, res);
|
||||
@ -448,3 +464,51 @@ TEST_CASE("ECC mod multiplication using SECP192R1 and SECP256R1 order of curve",
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(ecc192_mul_res, res, 24, "P192 mod multiplication");
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_GROUP_RUNNER(ecc)
|
||||
{
|
||||
#if SOC_ECC_SUPPORT_POINT_MULT
|
||||
RUN_TEST_CASE(ecc, ecc_point_multiplication_on_SECP192R1_and_SECP256R1);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_POINT_VERIFY && !defined(SOC_ECC_SUPPORT_POINT_VERIFY_QUIRK)
|
||||
RUN_TEST_CASE(ecc, ecc_point_verification_on_SECP192R1_and_SECP256R1);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_POINT_MULT && SOC_ECC_SUPPORT_POINT_VERIFY && !defined(SOC_ECC_SUPPORT_POINT_VERIFY_QUIRK)
|
||||
RUN_TEST_CASE(ecc, ecc_point_verification_and_multiplication_on_SECP192R1_and_SECP256R1);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_POINT_DIVISION
|
||||
RUN_TEST_CASE(ecc, ecc_inverse_multiplication_or_mod_division_using_SECP192R1_and_SECP256R1_order_of_curve);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_JACOB_POINT_MULT
|
||||
RUN_TEST_CASE(ecc, ecc_jacobian_point_multiplication_on_SECP192R1_and_SECP256R1);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_JACOB_POINT_VERIFY
|
||||
RUN_TEST_CASE(ecc, ecc_jacobian_point_verification_on_SECP192R1_and_SECP256R1);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_JACOB_POINT_MULT && SOC_ECC_SUPPORT_JACOB_POINT_VERIFY
|
||||
RUN_TEST_CASE(ecc, ecc_point_verification_and_jacobian_point_multiplication_on_SECP192R1_and_SECP256R1);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_POINT_ADDITION
|
||||
RUN_TEST_CASE(ecc, ecc_point_addition_on_SECP192R1_and_SECP256R1);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_MOD_ADD
|
||||
RUN_TEST_CASE(ecc, ecc_mod_addition_using_SECP192R1_and_SECP256R1_order_of_curve);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_MOD_SUB
|
||||
RUN_TEST_CASE(ecc, ecc_mod_subtraction_using_SECP192R1_and_SECP256R1_order_of_curve);
|
||||
#endif
|
||||
|
||||
#if SOC_ECC_SUPPORT_MOD_MUL
|
||||
RUN_TEST_CASE(ecc, ecc_mod_multiplication_using_SECP192R1_and_SECP256R1_order_of_curve);
|
||||
#endif
|
||||
|
||||
}
|
Reference in New Issue
Block a user