diff --git a/components/hal/.build-test-rules.yml b/components/hal/.build-test-rules.yml index 4e02657514..453b1e3a40 100644 --- a/components/hal/.build-test-rules.yml +++ b/components/hal/.build-test-rules.yml @@ -7,3 +7,8 @@ components/hal/test_apps/ecc: - 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 + +components/hal/test_apps/mpi: + disable: + - if: SOC_MPI_SUPPORTED != 1 + reason: Hardware MPI support not available for such targets. diff --git a/components/hal/test_apps/mpi/CMakeLists.txt b/components/hal/test_apps/mpi/CMakeLists.txt new file mode 100644 index 0000000000..b1cc26cf58 --- /dev/null +++ b/components/hal/test_apps/mpi/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.16) + +set(COMPONENTS main) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +project(mpi_test) diff --git a/components/hal/test_apps/mpi/README.md b/components/hal/test_apps/mpi/README.md new file mode 100644 index 0000000000..7bf5d8ff56 --- /dev/null +++ b/components/hal/test_apps/mpi/README.md @@ -0,0 +1,33 @@ +| Supported Targets | ESP32 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | + +## MPI peripheral test + +This application contains basic test cases for the MPI peripheral without using any OS functionality or higher abstraction layer. + +This contains tests for the following features of MPI peripheral: + +- MPI Modular Multiplication +- MPI Multiplication +- MPI Modular Exponentiation + +# Building + +```bash +idf.py set-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 +``` diff --git a/components/hal/test_apps/mpi/main/CMakeLists.txt b/components/hal/test_apps/mpi/main/CMakeLists.txt new file mode 100644 index 0000000000..c1e569ffca --- /dev/null +++ b/components/hal/test_apps/mpi/main/CMakeLists.txt @@ -0,0 +1,6 @@ +set(srcs "app_main.c" + "test_mpi.c") + +idf_component_register(SRCS ${srcs} + REQUIRES unity + WHOLE_ARCHIVE) diff --git a/components/hal/test_apps/mpi/main/app_main.c b/components/hal/test_apps/mpi/main/app_main.c new file mode 100644 index 0000000000..ecde0a6c5d --- /dev/null +++ b/components/hal/test_apps/mpi/main/app_main.c @@ -0,0 +1,13 @@ +/* + * 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(); +} diff --git a/components/hal/test_apps/mpi/main/test_mpi.c b/components/hal/test_apps/mpi/main/test_mpi.c new file mode 100644 index 0000000000..9a7d67adf2 --- /dev/null +++ b/components/hal/test_apps/mpi/main/test_mpi.c @@ -0,0 +1,145 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include +#include + +#include "esp_log.h" +#include "esp_private/periph_ctrl.h" +#include "unity.h" + +#if CONFIG_IDF_TARGET_ESP32 +#define ESP_MPI_USE_MONT_EXP +#endif + +#include "hal/mpi_hal.h" +#include "test_params.h" + +#define _DEBUG_ 0 + + +static void esp_mpi_enable_hardware_hw_op( void ) +{ + /* Enable RSA hardware */ + periph_module_enable(PERIPH_RSA_MODULE); + + mpi_hal_enable_hardware_hw_op(); +} + + +static void esp_mpi_disable_hardware_hw_op( void ) +{ + mpi_hal_disable_hardware_hw_op(); + + /* Disable RSA hardware */ + periph_module_disable(PERIPH_RSA_MODULE); +} + + +static void mpi_mul_mpi_mod_hw_op(void) +{ + esp_mpi_enable_hardware_hw_op(); + for(int i = 0; i < TEST_CASES_NUM; i++){ +#if CONFIG_IDF_TARGET_ESP32 + mpi_hal_set_mode((test_cases_num_words[i] / 16) - 1); +#else + mpi_hal_set_mode(test_cases_num_words[i] - 1); +#endif + /* Load M, X, Rinv, Mprime (Mprime is mod 2^32) */ + mpi_hal_write_to_mem_block(MPI_PARAM_M, 0, test_cases_M_p[i], test_cases_M_n[i], test_cases_num_words[i]); + mpi_hal_write_to_mem_block(MPI_PARAM_X, 0, test_cases_X_p[i], test_cases_X_n[i], test_cases_num_words[i]); + +#if !CONFIG_IDF_TARGET_ESP32 + mpi_hal_write_to_mem_block(MPI_PARAM_Y, 0, test_cases_Y_p[i], test_cases_Y_n[i], test_cases_num_words[i]); +#endif + + mpi_hal_write_to_mem_block(MPI_PARAM_Z, 0, test_cases_Rinv_p[i], test_cases_Rinv_n[i], test_cases_num_words[i]); + mpi_hal_write_m_prime(test_cases_Mprime[i]); + +#if CONFIG_IDF_TARGET_ESP32 + mpi_hal_start_op(MPI_MULT); + mpi_hal_wait_op_complete(); + /* execute second stage */ + /* Load Y to X input memory block, rerun */ + mpi_hal_write_to_mem_block(MPI_PARAM_X, 0, test_cases_Y_p[i], test_cases_Y_n[i], test_cases_num_words[i]); + mpi_hal_start_op(MPI_MULT); +#else + mpi_hal_start_op(MPI_MODMULT); +#endif + uint32_t* Z_p = (uint32_t*)calloc(test_cases_Z_words[i], sizeof(uint32_t)); + mpi_hal_read_result_hw_op(Z_p, test_cases_Z_words[i], test_cases_Z_words[i]); + + printf("Test Case %d: ", i+1); + +#if _DEBUG_ + printf("\n"); + ESP_LOG_BUFFER_HEX("Expected Z:", test_cases_Z_p[i], test_cases_Z_words[i]*4); + ESP_LOG_BUFFER_HEX("Got Z:", Z_p, test_cases_Z_words[i]*4); +#endif + + TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(test_cases_Z_p[i], Z_p, test_cases_Z_words[i], "Result"); + printf("PASS\n"); + } + esp_mpi_disable_hardware_hw_op(); +} + + +static void mpi_exp_mpi_mod_hw_op(void) +{ + + for (int i = 0; i < EXP_TEST_CASES_NUM; i++) { + if (i == 14 || i == 16 || i == 18 || i == 22) // cases when Y == 0 (in Z = X ^ Y mod M) should be handled in the software level + continue; +#ifdef ESP_MPI_USE_MONT_EXP // CONFIG_IDF_TARGET_ESP32 + printf("Support for montgomery exponentiation to be added.\n"); + break; +#else + esp_mpi_enable_hardware_hw_op(); + + mpi_hal_set_mode(exp_test_cases_num_words[i] - 1); + mpi_hal_write_to_mem_block(MPI_PARAM_X, 0, exp_test_cases_X_p[i], exp_test_cases_X_n[i], exp_test_cases_num_words[i]); + mpi_hal_write_to_mem_block(MPI_PARAM_Y, 0, exp_test_cases_Y_p[i], exp_test_cases_Y_n[i], exp_test_cases_num_words[i]); + mpi_hal_write_to_mem_block(MPI_PARAM_M, 0, exp_test_cases_M_p[i], exp_test_cases_M_n[i], exp_test_cases_num_words[i]); + mpi_hal_write_to_mem_block(MPI_PARAM_Z, 0, exp_test_cases_Rinv_p[i], exp_test_cases_Rinv_n[i], exp_test_cases_num_words[i]); + + mpi_hal_write_m_prime(exp_test_cases_Mprime[i]); + + /* Enable acceleration options */ + mpi_hal_enable_constant_time(false); + mpi_hal_enable_search(true); + mpi_hal_set_search_position(exp_test_cases_y_bits[i] - 1); + + /* Execute first stage montgomery multiplication */ + mpi_hal_start_op(MPI_MODEXP); + + mpi_hal_enable_search(false); +#endif + uint32_t* Z_p = (uint32_t*)calloc(exp_test_cases_m_words[i], sizeof(uint32_t)); + /* Read back the result */ + mpi_hal_read_result_hw_op(Z_p, exp_test_cases_m_words[i], exp_test_cases_m_words[i]); + esp_mpi_disable_hardware_hw_op(); + + printf("Test Case %d: ", i+1); + +#if _DEBUG_ + printf("\n"); + ESP_LOG_BUFFER_HEX("Expected Z:", test_cases_Z_p[i], test_cases_Z_words[i]*4); + ESP_LOG_BUFFER_HEX("Got Z:", Z_p, test_cases_Z_words[i]*4); +#endif + + TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(exp_test_cases_Z_p[i], Z_p, exp_test_cases_m_words[i], "Result"); + printf("PASS\n"); + } +} + +TEST_CASE("Test MPI multiplication", "[mpi][hal]") +{ + mpi_mul_mpi_mod_hw_op(); +} + +TEST_CASE("Test MPI exponentiation", "[mpi][hal]") +{ + mpi_exp_mpi_mod_hw_op(); +} diff --git a/components/hal/test_apps/mpi/main/test_params.h b/components/hal/test_apps/mpi/main/test_params.h new file mode 100644 index 0000000000..ed3959b62a --- /dev/null +++ b/components/hal/test_apps/mpi/main/test_params.h @@ -0,0 +1,382 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#define TEST_CASES_NUM 11 + +const uint32_t M_p_1[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_1[] = { 0x10 }; +const uint32_t Y_p_1[] = { 0x100 }; +const uint32_t Rinv_p_1[] = { 0x1 }; +const uint32_t Z_p_1[] = { 0x1000 }; + +const uint32_t M_p_2[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_2[] = { 0x10 }; +const uint32_t Y_p_2[] = { 0x100 }; +const uint32_t Rinv_p_2[] = { 0x1 }; +const uint32_t Z_p_2[] = { 0x1000 }; + +const uint32_t M_p_3[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_3[] = { 0x10 }; +const uint32_t Y_p_3[] = { 0x100 }; +const uint32_t Rinv_p_3[] = { 0x1 }; +const uint32_t Z_p_3[] = { 0x1000 }; + +const uint32_t M_p_4[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_4[] = { 0x10 }; +const uint32_t Y_p_4[] = { 0x100 }; +const uint32_t Rinv_p_4[] = { 0x1 }; +const uint32_t Z_p_4[] = { 0x1000 }; + +const uint32_t M_p_5[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_5[] = { 0x10 }; +const uint32_t Y_p_5[] = { 0x100 }; +const uint32_t Rinv_p_5[] = { 0x1 }; +const uint32_t Z_p_5[] = { 0x1000 }; + +const uint32_t M_p_6[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_6[] = { 0x10 }; +const uint32_t Y_p_6[] = { 0x100 }; +const uint32_t Rinv_p_6[] = { 0x1 }; +const uint32_t Z_p_6[] = { 0x1000 }; + +const uint32_t M_p_7[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_7[] = { 0x0, 0xd3101957, 0xecee5346, 0xb54d2f52, 0x442296ec, 0x19cd3ca8, 0x8550f006, 0x41c3f1e1, 0xa488720b, 0xcc4cb107, 0x85fb0e86, 0xcf2ed8f6, 0x4f108e15, 0x60ffaadb, 0x46be39b8, 0x8d3e3bd7, 0x60006fa }; +const uint32_t Y_p_7[] = { 0xbf474ca7 }; +const uint32_t Rinv_p_7[] = { 0x1 }; +const uint32_t Z_p_7[] = { 0x0, 0x67275bc1, 0x404ee63b, 0x2e2c03aa, 0x2e4998f4, 0x20653a31, 0x1dffabd1, 0x6aa51a39, 0xde0e2bad, 0xd7762fc2, 0x88e65fef, 0x2a4e310f, 0x2b9b939a, 0x3051d823, 0x31bc0b75, 0xd3d97e42, 0xcaf58a48, 0x47bb102 }; + +const uint32_t M_p_8[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_8[] = { 0x80000000, 0xd64787bc, 0x19d05e3d, 0xbd83a839, 0xd2f4a5db, 0x9a770400, 0xaea5e366, 0xafab037d, 0x2f72be37, 0x41e9e9f0, 0xfa4a3585, 0x148ba01f, 0x40d718ca, 0x7be1c5, 0xc033696c, 0x9fdf9e27, 0x5c9d44c0, 0xad60775d, 0xaa67e3aa, 0xe76bd66f, 0x5738985c, 0xdf079b6b, 0x99626884, 0x5361ec05, 0x756ed496, 0xf5e04245, 0xc87d1791, 0xdf9abc30, 0xc44768ea, 0xeaf3bbeb, 0xc01eeb01, 0xc229831e, 0x49493a }; +const uint32_t Y_p_8[] = { 0xb878cc29 }; +const uint32_t Rinv_p_8[] = { 0x1 }; +const uint32_t Z_p_8[] = { 0x80000000, 0x6dfaf330, 0xcc7839bf, 0x29754f1f, 0x6c9121d6, 0xc430620, 0x80e52130, 0x619ccf81, 0x39521993, 0x3f9293c8, 0x165fc8a8, 0x98d8c9d3, 0xa7b1fd46, 0x66d156e7, 0xcb373706, 0x819f0d65, 0xd52d2cbe, 0xb1e5f6e3, 0x78ae1381, 0xc5f8e002, 0x435c6bf7, 0xc912fdbc, 0x7aa2a247, 0xba1e460, 0xd28d4e10, 0x12b0ab73, 0xbff58710, 0x64b6e727, 0x55daff98, 0x66604e0d, 0xf1fe7bda, 0xbda2c86c, 0x13066d5, 0x34cf37 }; + +const uint32_t M_p_9[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_9[] = { 0xcae9a34d, 0xa031f21e, 0x1e85b5df, 0xe071513a, 0xe81a1521, 0x74ca15f3, 0xdde2beb6, 0x7af1fedf, 0xc8632240, 0x3b9f880f, 0xcf78b817, 0x4cabb724, 0x19816423, 0x7f123142, 0xe07ee72c, 0xddf79c5c, 0x634f9e8c, 0xf7ee8c0c, 0x4a8a9a45, 0x37ae1b48, 0x2d288558, 0xe33fa325, 0x77937f, 0x5091386c, 0xa9d3bfa7, 0x3102f8b4, 0x2bc44d25, 0xfc66ca47, 0x3d25e64e, 0xfdd30308, 0x85468786, 0x24bf61 }; +const uint32_t Y_p_9[] = { 0x10001 }; +const uint32_t Rinv_p_9[] = { 0x1 }; +const uint32_t Z_p_9[] = { 0x6e36a34d, 0x9250bd08, 0xd4655611, 0x31ab6fbf, 0xfd3bf593, 0x8abdfe0d, 0x9c993380, 0x79d1dcc2, 0xeaa39d32, 0xc3af5072, 0x878ff3b6, 0x3d0869d, 0x7da4b0cf, 0xb0544ac3, 0xc7ab663e, 0x7a547cdb, 0x1dc7c84, 0x83faef5c, 0xe4d09234, 0x52f665d2, 0xb280bd06, 0x8664d04d, 0x93f776bf, 0x88fd38e3, 0x697b1038, 0x29b7a288, 0x78e97e28, 0xc6adf60b, 0x2374e2b5, 0xdb402e, 0xccd855a, 0xbf8644a8, 0x24 }; + +const uint32_t M_p_10[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_10[] = { 0x35893620, 0x6f4b348d, 0x95c4fc96, 0xef12340b, 0xa7dec5d5, 0x56fe1e8e, 0x9486fc80, 0x6f8819d6, 0x467ada31, 0x856a2147, 0x780e9b54, 0xe9da7683, 0x46a906b7, 0x22137235, 0xc417edd0, 0x5d88b669 }; +const uint32_t Y_p_10[] = { 0x6f48ea08, 0xf5a8c50d, 0xc169d74b, 0xa74206ce, 0xeb9f2d2f, 0xbbccba7f, 0xd33605ae, 0xf5a3b2a5, 0xe2bf4411, 0x275aa977, 0xb2f0e2dd, 0xf38d18d2, 0x239eadae, 0xf71896fc, 0x9546432d, 0x9ae7fbc9 }; +const uint32_t Rinv_p_10[] = { 0x1 }; +const uint32_t Z_p_10[] = { 0x30c2f100, 0xadeea408, 0x678bd2f4, 0x99540c47, 0xeba56331, 0x72d75ec6, 0x8fd72c77, 0x3a8b12c3, 0x49eb461a, 0xd332b1ff, 0xcdf59485, 0x4b0a83bb, 0xe4432ee7, 0x74a9bbeb, 0xaf573efb, 0xbc97b670, 0x8c3442f3, 0x8fbf01de, 0xd646884e, 0x76095187, 0x98628219, 0x93746469, 0xf900c0c9, 0x2b2be5a7, 0xa2949bc8, 0x3d832701, 0xc4c9270a, 0xbb7cd629, 0x339aee72, 0x3b5e6aee, 0xeb21810e, 0x38990016 }; + +const uint32_t M_p_11[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; +const uint32_t X_p_11[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4 }; +const uint32_t Y_p_11[] = { 0x1234 }; +const uint32_t Rinv_p_11[] = { 0x1 }; +const uint32_t Z_p_11[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x48d0 }; + +const uint32_t* test_cases_M_p[TEST_CASES_NUM] = { + M_p_1, M_p_2, M_p_3, M_p_4, M_p_5, M_p_6, M_p_7, M_p_8, M_p_9, M_p_10, M_p_11, +}; + +const uint32_t* test_cases_X_p[TEST_CASES_NUM] = { + X_p_1, X_p_2, X_p_3, X_p_4, X_p_5, X_p_6, X_p_7, X_p_8, X_p_9, X_p_10, X_p_11, +}; + +const uint32_t* test_cases_Y_p[TEST_CASES_NUM] = { + Y_p_1, Y_p_2, Y_p_3, Y_p_4, Y_p_5, Y_p_6, Y_p_7, Y_p_8, Y_p_9, Y_p_10, Y_p_11, +}; + +const uint32_t* test_cases_Rinv_p[TEST_CASES_NUM] = { + Rinv_p_1, Rinv_p_2, Rinv_p_3, Rinv_p_4, Rinv_p_5, Rinv_p_6, Rinv_p_7, Rinv_p_8, Rinv_p_9, Rinv_p_10, Rinv_p_11, +}; + +const uint32_t* test_cases_Z_p[TEST_CASES_NUM] = { + Z_p_1, Z_p_2, Z_p_3, Z_p_4, Z_p_5, Z_p_6, Z_p_7, Z_p_8, Z_p_9, Z_p_10, Z_p_11, +}; + +const uint32_t test_cases_Mprime[TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +size_t test_cases_M_n[TEST_CASES_NUM] = { + 16, 32, 48, 64, 80, 96, 32, 96, 48, 64, 96, +}; + +size_t test_cases_X_n[TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 17, 33, 32, 16, 65, +}; + +size_t test_cases_Y_n[TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 1, +}; + +size_t test_cases_Rinv_n[TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +size_t test_cases_Z_n[TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 18, 34, 33, 32, 65, +}; + +size_t test_cases_Z_words[TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 18, 34, 33, 32, 65, +}; + +size_t test_cases_num_words[TEST_CASES_NUM] = { + 16, 32, 48, 64, 80, 96, 32, 96, 48, 64, 96, +}; + + + +#define EXP_TEST_CASES_NUM 33 + +const uint32_t exp_M_p_1[] = { 0xffffffff,}; +const uint32_t exp_X_p_1[] = { 0x1000,}; +const uint32_t exp_Y_p_1[] = { 0x2, }; +const uint32_t exp_Rinv_p_1[] = { 0x1, }; +const uint32_t exp_Z_p_1[] = { 0x1000000, }; + +const uint32_t exp_M_p_2[] = { 0xfffffff,}; +const uint32_t exp_X_p_2[] = { 0x1234,}; +const uint32_t exp_Y_p_2[] = { 0x2, }; +const uint32_t exp_Rinv_p_2[] = { 0x100, }; +const uint32_t exp_Z_p_2[] = { 0x14b5a90, }; + +const uint32_t exp_M_p_3[] = { 0xffffffff,}; +const uint32_t exp_X_p_3[] = { 0x1111,}; +const uint32_t exp_Y_p_3[] = { 0x2, }; +const uint32_t exp_Rinv_p_3[] = { 0x1, }; +const uint32_t exp_Z_p_3[] = { 0x1234321, }; + +const uint32_t exp_M_p_4[] = { 0x3,}; +const uint32_t exp_X_p_4[] = { 0x5,}; +const uint32_t exp_Y_p_4[] = { 0x1, }; +const uint32_t exp_Rinv_p_4[] = { 0x1, }; +const uint32_t exp_Z_p_4[] = { 0x2, }; + +const uint32_t exp_M_p_5[] = { 0x33,}; +const uint32_t exp_X_p_5[] = { 0x55,}; +const uint32_t exp_Y_p_5[] = { 0x1, }; +const uint32_t exp_Rinv_p_5[] = { 0x1, }; +const uint32_t exp_Z_p_5[] = { 0x22, }; + +const uint32_t exp_M_p_6[] = { 0x333,}; +const uint32_t exp_X_p_6[] = { 0x555,}; +const uint32_t exp_Y_p_6[] = { 0x1, }; +const uint32_t exp_Rinv_p_6[] = { 0x10, }; +const uint32_t exp_Z_p_6[] = { 0x222, }; + +const uint32_t exp_M_p_7[] = { 0x3333,}; +const uint32_t exp_X_p_7[] = { 0x5555,}; +const uint32_t exp_Y_p_7[] = { 0x1, }; +const uint32_t exp_Rinv_p_7[] = { 0x1, }; +const uint32_t exp_Z_p_7[] = { 0x2222, }; + +const uint32_t exp_M_p_8[] = { 0x33,}; +const uint32_t exp_X_p_8[] = { 0x5555,}; +const uint32_t exp_Y_p_8[] = { 0x1, }; +const uint32_t exp_Rinv_p_8[] = { 0x1, }; +const uint32_t exp_Z_p_8[] = { 0x11, }; + +const uint32_t exp_M_p_9[] = { 0x77,}; +const uint32_t exp_X_p_9[] = { 0x1111,}; +const uint32_t exp_Y_p_9[] = { 0x1, }; +const uint32_t exp_Rinv_p_9[] = { 0x56, }; +const uint32_t exp_Z_p_9[] = { 0x55, }; + +const uint32_t exp_M_p_10[] = { 0xbb,}; +const uint32_t exp_X_p_10[] = { 0x1111,}; +const uint32_t exp_Y_p_10[] = { 0x2, }; +const uint32_t exp_Rinv_p_10[] = { 0x89, }; +const uint32_t exp_Z_p_10[] = { 0x88, }; + +const uint32_t exp_M_p_11[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xff,}; +const uint32_t exp_X_p_11[] = { 0x2,}; +const uint32_t exp_Y_p_11[] = { 0x128, }; +const uint32_t exp_Rinv_p_11[] = { 0x0, 0x10000, }; +const uint32_t exp_Z_p_11[] = { 0x1000000, 0x0, 0x0, 0x0, 0x0, }; + +const uint32_t exp_M_p_12[] = { 0xffffffff, 0xffff,}; +const uint32_t exp_X_p_12[] = { 0xdef12345, 0xabc,}; +const uint32_t exp_Y_p_12[] = { 0x1, }; +const uint32_t exp_Rinv_p_12[] = { 0x0, 0x1, }; +const uint32_t exp_Z_p_12[] = { 0xdef12345, 0xabc, }; + +const uint32_t exp_M_p_13[] = { 0xfffff,}; +const uint32_t exp_X_p_13[] = { 0xabcde,}; +const uint32_t exp_Y_p_13[] = { 0x1, }; +const uint32_t exp_Rinv_p_13[] = { 0x10, }; +const uint32_t exp_Z_p_13[] = { 0xabcde, }; + +const uint32_t exp_M_p_14[] = { 0x9,}; +const uint32_t exp_X_p_14[] = { 0x2,}; +const uint32_t exp_Y_p_14[] = { 0x2, }; +const uint32_t exp_Rinv_p_14[] = { 0x7, }; +const uint32_t exp_Z_p_14[] = { 0x4, }; + +const uint32_t exp_M_p_15[] = { 0x9,}; +const uint32_t exp_X_p_15[] = { 0x2,}; +const uint32_t exp_Y_p_15[] = { 0x0, }; +const uint32_t exp_Rinv_p_15[] = { 0x7, }; +const uint32_t exp_Z_p_15[] = { 0x0, }; + +const uint32_t exp_M_p_16[] = { 0x9,}; +const uint32_t exp_X_p_16[] = { 0x0,}; +const uint32_t exp_Y_p_16[] = { 0x2, }; +const uint32_t exp_Rinv_p_16[] = { 0x7, }; +const uint32_t exp_Z_p_16[] = { 0x0, }; + +const uint32_t exp_M_p_17[] = { 0x9,}; +const uint32_t exp_X_p_17[] = { 0x0,}; +const uint32_t exp_Y_p_17[] = { 0x0, }; +const uint32_t exp_Rinv_p_17[] = { 0x7, }; +const uint32_t exp_Z_p_17[] = { 0x0, }; + +const uint32_t exp_M_p_18[] = { 0x9,}; +const uint32_t exp_X_p_18[] = { 0x2,}; +const uint32_t exp_Y_p_18[] = { 0x2, }; +const uint32_t exp_Rinv_p_18[] = { 0x7, }; +const uint32_t exp_Z_p_18[] = { 0x4, }; + +const uint32_t exp_M_p_19[] = { 0x9,}; +const uint32_t exp_X_p_19[] = { 0x2,}; +const uint32_t exp_Y_p_19[] = { 0x0, }; +const uint32_t exp_Rinv_p_19[] = { 0x7, }; +const uint32_t exp_Z_p_19[] = { 0x0, }; + +const uint32_t exp_M_p_20[] = { 0x9,}; +const uint32_t exp_X_p_20[] = { 0x2,}; +const uint32_t exp_Y_p_20[] = { 0x7, }; +const uint32_t exp_Rinv_p_20[] = { 0x7, }; +const uint32_t exp_Z_p_20[] = { 0x2, }; + +const uint32_t exp_M_p_21[] = { 0x9,}; +const uint32_t exp_X_p_21[] = { 0x2,}; +const uint32_t exp_Y_p_21[] = { 0x1, }; +const uint32_t exp_Rinv_p_21[] = { 0x7, }; +const uint32_t exp_Z_p_21[] = { 0x2, }; + +const uint32_t exp_M_p_22[] = { 0x9,}; +const uint32_t exp_X_p_22[] = { 0x2,}; +const uint32_t exp_Y_p_22[] = { 0x1, }; +const uint32_t exp_Rinv_p_22[] = { 0x7, }; +const uint32_t exp_Z_p_22[] = { 0x2, }; + +const uint32_t exp_M_p_23[] = { 0x9,}; +const uint32_t exp_X_p_23[] = { 0x2,}; +const uint32_t exp_Y_p_23[] = { 0x0, }; +const uint32_t exp_Rinv_p_23[] = { 0x7, }; +const uint32_t exp_Z_p_23[] = { 0x0, }; + +const uint32_t exp_M_p_24[] = { 0x7,}; +const uint32_t exp_X_p_24[] = { 0x5,}; +const uint32_t exp_Y_p_24[] = { 0x7, }; +const uint32_t exp_Rinv_p_24[] = { 0x2, }; +const uint32_t exp_Z_p_24[] = { 0x5, }; + +const uint32_t exp_M_p_25[] = { 0x7,}; +const uint32_t exp_X_p_25[] = { 0x5,}; +const uint32_t exp_Y_p_25[] = { 0x7, }; +const uint32_t exp_Rinv_p_25[] = { 0x2, }; +const uint32_t exp_Z_p_25[] = { 0x5, }; + +const uint32_t exp_M_p_26[] = { 0x3,}; +const uint32_t exp_X_p_26[] = { 0x5,}; +const uint32_t exp_Y_p_26[] = { 0x7, }; +const uint32_t exp_Rinv_p_26[] = { 0x1, }; +const uint32_t exp_Z_p_26[] = { 0x2, }; + +const uint32_t exp_M_p_27[] = { 0x23456789, 0x1,}; +const uint32_t exp_X_p_27[] = { 0x23456789, 0x1,}; +const uint32_t exp_Y_p_27[] = { 0x23456789, 0x1, }; +const uint32_t exp_Rinv_p_27[] = { 0x34890700, }; +const uint32_t exp_Z_p_27[] = { 0x0, 0x0, }; + +const uint32_t exp_M_p_28[] = { 0x23456789, 0x1,}; +const uint32_t exp_X_p_28[] = { 0x23456788, 0x1,}; +const uint32_t exp_Y_p_28[] = { 0x23456788, 0x1, }; +const uint32_t exp_Rinv_p_28[] = { 0x34890700, }; +const uint32_t exp_Z_p_28[] = { 0x1, 0x0, }; + +const uint32_t exp_M_p_29[] = { 0x23456789, 0x1,}; +const uint32_t exp_X_p_29[] = { 0x2345678a, 0x1,}; +const uint32_t exp_Y_p_29[] = { 0x2345678a, 0x1, }; +const uint32_t exp_Rinv_p_29[] = { 0x34890700, }; +const uint32_t exp_Z_p_29[] = { 0x1, 0x0, }; + +const uint32_t exp_M_p_30[] = { 0x7,}; +const uint32_t exp_X_p_30[] = { 0x32,}; +const uint32_t exp_Y_p_30[] = { 0x3e9, }; +const uint32_t exp_Rinv_p_30[] = { 0x2, }; +const uint32_t exp_Z_p_30[] = { 0x1, }; + +const uint32_t exp_M_p_31[] = { 0xd2f86373, 0x7dc0eddd, 0x1a27c06f, 0xbe6e3437, 0xa3fa8342, 0x47be20c9, 0x4532cdf5, 0x728e8766, 0x31e46aa7, 0xdc5e8c72, 0xba39c6b2, 0x29c291b4, 0xab5f5cf4, 0xa90e51bb, 0xfc1e677d, 0x5347c68a, 0xd95f7d6, 0xae98132b, 0x135c643c, 0x2e9e82e9, 0x5a540609, 0x3274e472, 0xb24222d0, 0x9153bd76, 0x1a5c9640, 0xaa94b8bb, 0xeb740f69, 0xc3cdd261, 0x323b9c45, 0x957ff5dd, 0x8419a724, 0xcf5cf5c3,}; +const uint32_t exp_X_p_31[] = { 0x2,}; +const uint32_t exp_Y_p_31[] = { 0xa9e42102, 0x5ab4a0f, 0xc529b673, 0x1684435d, 0x33f2d8fb, 0xdb42b4e7, 0x103e8eb9, 0xbf8de4ed, 0x91537869, 0x11c88a96, 0xcdff05bd, 0x157f8be2, 0xf6c63d3d, 0x36e4ee76, 0xd15c29a7, 0x3e6071e0, 0x3e2b0c1d, 0x54444d19, 0x62699c34, 0xe9ffd47a, 0x1acf4cb1, 0x3617251a, 0x29a256a, 0x884c0e32, 0xcb883a85, 0xcf364770, 0xa5f2da4, 0x32166b1f, 0xda3deaf5, 0xb4fed79a, 0xa82ccab3, 0x471cc5f6, }; +const uint32_t exp_Rinv_p_31[] = { 0x6787f727, 0xc0dc79ce, 0x22066424, 0x4c6a2bf8, 0x5b81cb65, 0x169a350a, 0x47a07b05, 0x2a086619, 0xe5143481, 0xaddd2a07, 0xf3087ad4, 0xb7e7b5cd, 0xeff1c6f6, 0xa35ab988, 0x3cb3c643, 0xd53b3480, 0xcda6a846, 0xd51c411a, 0x840fea4, 0x2b55e639, 0x680557e2, 0x46c77daf, 0x1d110ae6, 0x9cf0f62b, 0x51257507, 0x63d1c63e, 0xdaccc4cf, 0xe3af579d, 0xe58ed7b0, 0x6950d5aa, 0x21471db1, 0x4ca3e886, }; +const uint32_t exp_Z_p_31[] = { 0xe0b8c80b, 0xba541503, 0x26937a8c, 0xd0372fac, 0xc4cb31b4, 0x40d71bbc, 0xefb6ac09, 0x15ad27f9, 0xcee9542a, 0xa247a4a2, 0xf204c903, 0x18728efd, 0x28b5313f, 0x21b6d67f, 0x7efb40c2, 0xf5df3fd7, 0xa49ed483, 0x8024b012, 0xbf355f2a, 0xd19d4b1f, 0xa308f006, 0x20cd0b86, 0x5e9db2bb, 0xf0c89b5c, 0x801c9b5a, 0x277ab525, 0x90ce4180, 0x7df883ab, 0xdad05b20, 0x6cb02835, 0x76a157ec, 0x5fa6cb1f, }; + +const uint32_t exp_M_p_32[] = { 0xd2f86373, 0x7dc0eddd, 0x1a27c06f, 0xbe6e3437, 0xa3fa8342, 0x47be20c9, 0x4532cdf5, 0x728e8766, 0x31e46aa7, 0xdc5e8c72, 0xba39c6b2, 0x29c291b4, 0xab5f5cf4, 0xa90e51bb, 0xfc1e677d, 0x5347c68a, 0xd95f7d6, 0xae98132b, 0x135c643c, 0x2e9e82e9, 0x5a540609, 0x3274e472, 0xb24222d0, 0x9153bd76, 0x1a5c9640, 0xaa94b8bb, 0xeb740f69, 0xc3cdd261, 0x323b9c45, 0x957ff5dd, 0x8419a724, 0xcf5cf5c3,}; +const uint32_t exp_X_p_32[] = { 0x2,}; +const uint32_t exp_Y_p_32[] = { 0xc0ac270d, 0x6a920e46, 0x8b4cdbf7, 0x96bc5489, 0xdc34fba7, 0xc94c1e56, 0x5eb67c32, 0xa5cb5328, 0x2c08454e, 0x185d67c0, 0x3e0fc930, 0xc1d9a7ce, 0xf73a0e3d, 0x53793857, 0x321e02fe, 0xaee0f18e, 0xb90d3299, 0xc5d34dc6, 0xb22d47a0, 0x9d109034, 0x659ac869, 0xb2a2de08, 0x9f7fc81, 0x229e03b5, 0x3e84ebc3, 0x60838601, 0xc82c0d5c, 0x1d4c659a, 0x8af97f04, 0xda8a3379, 0xc81a8696, 0x31fbcfdd, }; +const uint32_t exp_Rinv_p_32[] = { 0x6787f727, 0xc0dc79ce, 0x22066424, 0x4c6a2bf8, 0x5b81cb65, 0x169a350a, 0x47a07b05, 0x2a086619, 0xe5143481, 0xaddd2a07, 0xf3087ad4, 0xb7e7b5cd, 0xeff1c6f6, 0xa35ab988, 0x3cb3c643, 0xd53b3480, 0xcda6a846, 0xd51c411a, 0x840fea4, 0x2b55e639, 0x680557e2, 0x46c77daf, 0x1d110ae6, 0x9cf0f62b, 0x51257507, 0x63d1c63e, 0xdaccc4cf, 0xe3af579d, 0xe58ed7b0, 0x6950d5aa, 0x21471db1, 0x4ca3e886, }; +const uint32_t exp_Z_p_32[] = { 0x72837fbb, 0xa05c374, 0x63313198, 0xb1279b89, 0xfa1d0aed, 0xeb85c9fe, 0x9d459304, 0x6b756906, 0x4df3a615, 0xe70a90f6, 0xf9354188, 0xf3bc207, 0xa5b817c1, 0xdd4c5b68, 0x222da242, 0x8e683e34, 0xa6674536, 0xfc607769, 0x7a6dd910, 0x36c37489, 0x2ae01e97, 0x87ed74ef, 0xb7528452, 0x242a381f, 0xf886bd3e, 0xb8240556, 0x7ae70a33, 0x9c193652, 0x636c4ab6, 0x11be9d23, 0x1ea9b22b, 0x368a3229, }; + +const uint32_t exp_M_p_33[] = { 0xd2f86373, 0x7dc0eddd, 0x1a27c06f, 0xbe6e3437, 0xa3fa8342, 0x47be20c9, 0x4532cdf5, 0x728e8766, 0x31e46aa7, 0xdc5e8c72, 0xba39c6b2, 0x29c291b4, 0xab5f5cf4, 0xa90e51bb, 0xfc1e677d, 0x5347c68a, 0xd95f7d6, 0xae98132b, 0x135c643c, 0x2e9e82e9, 0x5a540609, 0x3274e472, 0xb24222d0, 0x9153bd76, 0x1a5c9640, 0xaa94b8bb, 0xeb740f69, 0xc3cdd261, 0x323b9c45, 0x957ff5dd, 0x8419a724, 0xcf5cf5c3,}; +const uint32_t exp_X_p_33[] = { 0xf17d532d, 0x9136fa85, 0x5daf568, 0x36bed5aa, 0x4e2e5ca1, 0x90ca0228, 0x5d795c60, 0x264a452a, 0xe88187b5, 0x400f8fd8, 0x834268f1, 0x876eb7ee, 0x5165b72c, 0x162dd5ba, 0x4034c1f2, 0x6e58383, 0xb26c5b24, 0x7bbe3afb, 0x9722db6b, 0xe6624ae8, 0x1546d7dd, 0xddc0b14f, 0xf10ed6c2, 0x5dcfd1f9, 0x43658bc4, 0x18084e67, 0xf2b57c8a, 0x445d45f1, 0xc1465fff, 0xa7efdf9e, 0x632d9e50, 0xbdad66c8,}; +const uint32_t exp_Y_p_33[] = { 0xa9e42102, 0x5ab4a0f, 0xc529b673, 0x1684435d, 0x33f2d8fb, 0xdb42b4e7, 0x103e8eb9, 0xbf8de4ed, 0x91537869, 0x11c88a96, 0xcdff05bd, 0x157f8be2, 0xf6c63d3d, 0x36e4ee76, 0xd15c29a7, 0x3e6071e0, 0x3e2b0c1d, 0x54444d19, 0x62699c34, 0xe9ffd47a, 0x1acf4cb1, 0x3617251a, 0x29a256a, 0x884c0e32, 0xcb883a85, 0xcf364770, 0xa5f2da4, 0x32166b1f, 0xda3deaf5, 0xb4fed79a, 0xa82ccab3, 0x471cc5f6, }; +const uint32_t exp_Rinv_p_33[] = { 0x6787f727, 0xc0dc79ce, 0x22066424, 0x4c6a2bf8, 0x5b81cb65, 0x169a350a, 0x47a07b05, 0x2a086619, 0xe5143481, 0xaddd2a07, 0xf3087ad4, 0xb7e7b5cd, 0xeff1c6f6, 0xa35ab988, 0x3cb3c643, 0xd53b3480, 0xcda6a846, 0xd51c411a, 0x840fea4, 0x2b55e639, 0x680557e2, 0x46c77daf, 0x1d110ae6, 0x9cf0f62b, 0x51257507, 0x63d1c63e, 0xdaccc4cf, 0xe3af579d, 0xe58ed7b0, 0x6950d5aa, 0x21471db1, 0x4ca3e886, }; +const uint32_t exp_Z_p_33[] = { 0xe0fc973d, 0xf77f5348, 0x3a34dcb9, 0x7c323908, 0xd6c67c28, 0x2844e745, 0x51819313, 0x5495d3fc, 0x5a52558f, 0x7b6f5c96, 0x1d74077e, 0xb987d7b1, 0xe2b04598, 0xe81a5a33, 0xfa3ec8e3, 0x4c28e076, 0x49e971eb, 0xfc954377, 0x81edfd23, 0xf59a8dd4, 0x9186e5e4, 0xf3136a00, 0x9cdba411, 0x1ca4bb10, 0x8a32ca07, 0xf17b5b75, 0x24083905, 0xcbaefcb, 0x284ae12, 0Xc030e665, 0X24600e91, 0X631b2a91 }; + +const uint32_t* exp_test_cases_M_p[EXP_TEST_CASES_NUM] = { + exp_M_p_1, exp_M_p_2, exp_M_p_3, exp_M_p_4, exp_M_p_5, exp_M_p_6, exp_M_p_7, exp_M_p_8, exp_M_p_9, exp_M_p_10, exp_M_p_11, exp_M_p_12, exp_M_p_13, exp_M_p_14, exp_M_p_15, exp_M_p_16, exp_M_p_17, exp_M_p_18, exp_M_p_19, exp_M_p_20, exp_M_p_21, exp_M_p_22, exp_M_p_23, exp_M_p_24, exp_M_p_25, exp_M_p_26, exp_M_p_27, exp_M_p_28, exp_M_p_29, exp_M_p_30, exp_M_p_31, exp_M_p_32, exp_M_p_33, +}; + +const uint32_t* exp_test_cases_X_p[EXP_TEST_CASES_NUM] = { + exp_X_p_1, exp_X_p_2, exp_X_p_3, exp_X_p_4, exp_X_p_5, exp_X_p_6, exp_X_p_7, exp_X_p_8, exp_X_p_9, exp_X_p_10, exp_X_p_11, exp_X_p_12, exp_X_p_13, exp_X_p_14, exp_X_p_15, exp_X_p_16, exp_X_p_17, exp_X_p_18, exp_X_p_19, exp_X_p_20, exp_X_p_21, exp_X_p_22, exp_X_p_23, exp_X_p_24, exp_X_p_25, exp_X_p_26, exp_X_p_27, exp_X_p_28, exp_X_p_29, exp_X_p_30, exp_X_p_31, exp_X_p_32, exp_X_p_33, +}; + +const uint32_t* exp_test_cases_Y_p[EXP_TEST_CASES_NUM] = { + exp_Y_p_1, exp_Y_p_2, exp_Y_p_3, exp_Y_p_4, exp_Y_p_5, exp_Y_p_6, exp_Y_p_7, exp_Y_p_8, exp_Y_p_9, exp_Y_p_10, exp_Y_p_11, exp_Y_p_12, exp_Y_p_13, exp_Y_p_14, exp_Y_p_15, exp_Y_p_16, exp_Y_p_17, exp_Y_p_18, exp_Y_p_19, exp_Y_p_20, exp_Y_p_21, exp_Y_p_22, exp_Y_p_23, exp_Y_p_24, exp_Y_p_25, exp_Y_p_26, exp_Y_p_27, exp_Y_p_28, exp_Y_p_29, exp_Y_p_30, exp_Y_p_31, exp_Y_p_32, exp_Y_p_33, +}; + +const uint32_t* exp_test_cases_Rinv_p[EXP_TEST_CASES_NUM] = { + exp_Rinv_p_1, exp_Rinv_p_2, exp_Rinv_p_3, exp_Rinv_p_4, exp_Rinv_p_5, exp_Rinv_p_6, exp_Rinv_p_7, exp_Rinv_p_8, exp_Rinv_p_9, exp_Rinv_p_10, exp_Rinv_p_11, exp_Rinv_p_12, exp_Rinv_p_13, exp_Rinv_p_14, exp_Rinv_p_15, exp_Rinv_p_16, exp_Rinv_p_17, exp_Rinv_p_18, exp_Rinv_p_19, exp_Rinv_p_20, exp_Rinv_p_21, exp_Rinv_p_22, exp_Rinv_p_23, exp_Rinv_p_24, exp_Rinv_p_25, exp_Rinv_p_26, exp_Rinv_p_27, exp_Rinv_p_28, exp_Rinv_p_29, exp_Rinv_p_30, exp_Rinv_p_31, exp_Rinv_p_32, exp_Rinv_p_33, +}; + +const uint32_t* exp_test_cases_Z_p[EXP_TEST_CASES_NUM] = { + exp_Z_p_1, exp_Z_p_2, exp_Z_p_3, exp_Z_p_4, exp_Z_p_5, exp_Z_p_6, exp_Z_p_7, exp_Z_p_8, exp_Z_p_9, exp_Z_p_10, exp_Z_p_11, exp_Z_p_12, exp_Z_p_13, exp_Z_p_14, exp_Z_p_15, exp_Z_p_16, exp_Z_p_17, exp_Z_p_18, exp_Z_p_19, exp_Z_p_20, exp_Z_p_21, exp_Z_p_22, exp_Z_p_23, exp_Z_p_24, exp_Z_p_25, exp_Z_p_26, exp_Z_p_27, exp_Z_p_28, exp_Z_p_29, exp_Z_p_30, exp_Z_p_31, exp_Z_p_32, exp_Z_p_33, +}; + +const uint32_t exp_test_cases_Mprime[EXP_TEST_CASES_NUM] = { + 0x1, 0x10000001, 0x1, 0x55555555, 0x5050505, 0x5005005, 0x50005, 0x5050505, 0xb90226b9, 0x5e75bb8d, 0x1, 0x1, 0x100001, 0xc71c71c7, 0xc71c71c7, 0xc71c71c7, 0xc71c71c7, 0xc71c71c7, 0xc71c71c7, 0xc71c71c7, 0xc71c71c7, 0xc71c71c7, 0xc71c71c7, 0x49249249, 0x49249249, 0x55555555, 0x60a2c147, 0x60a2c147, 0x60a2c147, 0x49249249, 0x2b458645, 0x2b458645, 0x2b458645, +}; + +size_t exp_test_cases_M_n[EXP_TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 32, 32, 32, +}; + +size_t exp_test_cases_X_n[EXP_TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 32, +}; + +size_t exp_test_cases_Y_n[EXP_TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 32, 32, 32, +}; + +size_t exp_test_cases_Rinv_n[EXP_TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 32, 32, 32, +}; + +size_t exp_test_cases_Z_n[EXP_TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 32, 32, 32, +}; + +size_t exp_test_cases_num_words[EXP_TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 32, 32, 32, +}; + +size_t exp_test_cases_m_words[EXP_TEST_CASES_NUM] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 32, 32, 32, +}; + +size_t exp_test_cases_y_bits[EXP_TEST_CASES_NUM] = { + 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 9, 1, 1, 2, 0, 2, 0, 2, 0, 3, 1, 1, 0, 3, 3, 3, 33, 33, 33, 10, 1023, 1022, 1023, +}; diff --git a/components/hal/test_apps/mpi/pytest_mpi.py b/components/hal/test_apps/mpi/pytest_mpi.py new file mode 100644 index 0000000000..247537496a --- /dev/null +++ b/components/hal/test_apps/mpi/pytest_mpi.py @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32s3 +@pytest.mark.esp32c3 +@pytest.mark.esp32c6 +@pytest.mark.esp32h2 +@pytest.mark.generic +def test_bignum(dut: Dut) -> None: + dut.run_all_single_board_cases() diff --git a/components/hal/test_apps/mpi/sdkconfig.defaults b/components/hal/test_apps/mpi/sdkconfig.defaults new file mode 100644 index 0000000000..a4ba403514 --- /dev/null +++ b/components/hal/test_apps/mpi/sdkconfig.defaults @@ -0,0 +1,2 @@ +CONFIG_ESP_TASK_WDT_EN=y +CONFIG_ESP_TASK_WDT_INIT=n