mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-31 10:06:32 +03:00
Split the idf_performance.h and target ver, which hold the performance thresholds, into the headers of each testing. In the past pytest also parse the common header to get the thresholds. Now the logic is also removed. Performance thresholds are supposed to be in the pytest scripts.
423 lines
14 KiB
C
423 lines
14 KiB
C
/* mbedTLS Elliptic Curve functionality tests
|
|
*
|
|
* Focus on testing functionality where we use ESP32 hardware
|
|
* accelerated crypto features.
|
|
*
|
|
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include <inttypes.h>
|
|
#include <esp_random.h>
|
|
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
|
#include <mbedtls/private/ecdh.h>
|
|
#include <mbedtls/private/ecdsa.h>
|
|
#include <mbedtls/error.h>
|
|
#include "psa/crypto.h"
|
|
#include "mbedtls/psa_util.h"
|
|
|
|
#include "test_utils.h"
|
|
#include "ccomp_timer.h"
|
|
#include "unity.h"
|
|
#include "crypto_performance.h"
|
|
|
|
#if CONFIG_MBEDTLS_HARDWARE_ECC
|
|
#include "hal/ecc_ll.h"
|
|
#endif
|
|
|
|
/* Note: negative value here so that assert message prints a grep-able
|
|
error hex value (mbedTLS uses -N for error codes) */
|
|
#define TEST_ASSERT_MBEDTLS_OK(X) TEST_ASSERT_EQUAL_HEX32(0, -(X))
|
|
|
|
/* TODO: Currently MBEDTLS_ECDH_LEGACY_CONTEXT is enabled by default
|
|
* when MBEDTLS_ECP_RESTARTABLE is enabled.
|
|
* This is a temporary workaround to allow that.
|
|
*
|
|
* The legacy option is soon going to be removed in future mbedtls
|
|
* versions and this workaround will be removed once the appropriate
|
|
* solution is available.
|
|
*/
|
|
#ifdef CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT
|
|
#define ACCESS_ECDH(S, var) S.MBEDTLS_PRIVATE(var)
|
|
#else
|
|
#define ACCESS_ECDH(S, var) S.MBEDTLS_PRIVATE(ctx).MBEDTLS_PRIVATE(mbed_ecdh).MBEDTLS_PRIVATE(var)
|
|
#endif
|
|
|
|
#if CONFIG_LIBC_NEWLIB_NANO_FORMAT
|
|
#define NEWLIB_NANO_COMPAT_FORMAT PRIu32
|
|
#define NEWLIB_NANO_COMPAT_CAST(int64_t_var) (uint32_t)int64_t_var
|
|
#else
|
|
#define NEWLIB_NANO_COMPAT_FORMAT PRId64
|
|
#define NEWLIB_NANO_COMPAT_CAST(int64_t_var) int64_t_var
|
|
#endif
|
|
|
|
TEST_CASE("mbedtls ECDH Generate Key", "[mbedtls]")
|
|
{
|
|
psa_key_attributes_t key_attributes;
|
|
psa_key_id_t key_id;
|
|
|
|
psa_set_key_type(&key_attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_MONTGOMERY));
|
|
psa_set_key_usage_flags(&key_attributes, PSA_KEY_USAGE_DERIVE);
|
|
psa_set_key_bits(&key_attributes, 255);
|
|
psa_set_key_lifetime(&key_attributes, PSA_KEY_LIFETIME_VOLATILE);
|
|
psa_set_key_algorithm(&key_attributes, PSA_ALG_ECDH);
|
|
|
|
psa_status_t status = psa_generate_key(&key_attributes, &key_id);
|
|
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
|
|
|
|
psa_reset_key_attributes(&key_attributes);
|
|
psa_destroy_key(key_id);
|
|
}
|
|
|
|
TEST_CASE("mbedtls ECP self-tests", "[mbedtls]")
|
|
{
|
|
TEST_ASSERT_EQUAL(0, mbedtls_ecp_self_test(1));
|
|
}
|
|
|
|
TEST_CASE("mbedtls ECP mul w/ koblitz", "[mbedtls]")
|
|
{
|
|
/* Test case code via https://github.com/espressif/esp-idf/issues/1556 */
|
|
mbedtls_ecdsa_context ctxECDSA;
|
|
|
|
mbedtls_ecdsa_init(&ctxECDSA);
|
|
|
|
TEST_ASSERT_MBEDTLS_OK( mbedtls_ecdsa_genkey(&ctxECDSA, MBEDTLS_ECP_DP_SECP256K1,
|
|
mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE) );
|
|
|
|
|
|
TEST_ASSERT_MBEDTLS_OK(mbedtls_ecp_mul(&ctxECDSA.MBEDTLS_PRIVATE(grp), &ctxECDSA.MBEDTLS_PRIVATE(Q),
|
|
&ctxECDSA.MBEDTLS_PRIVATE(d), &ctxECDSA.MBEDTLS_PRIVATE(grp).G,
|
|
mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE) );
|
|
|
|
mbedtls_ecdsa_free(&ctxECDSA);
|
|
}
|
|
|
|
#if CONFIG_MBEDTLS_HARDWARE_ECC
|
|
|
|
#define SMALL_SCALAR 127
|
|
|
|
/*
|
|
* Coordinates and integers stored in big endian format
|
|
*/
|
|
const uint8_t ecc_p192_point_x[] = {
|
|
0x18, 0x8D, 0xA8, 0x0E, 0xB0, 0x30, 0x90, 0xF6,
|
|
0x7C, 0xBF, 0x20, 0xEB, 0x43, 0xA1, 0x88, 0x00,
|
|
0xF4, 0xFF, 0x0A, 0xFD, 0x82, 0xFF, 0x10, 0x12
|
|
};
|
|
|
|
const uint8_t ecc_p192_point_y[] = {
|
|
0x07, 0x19, 0x2B, 0x95, 0xFF, 0xC8, 0xDA, 0x78,
|
|
0x63, 0x10, 0x11, 0xED, 0x6B, 0x24, 0xCD, 0xD5,
|
|
0x73, 0xF9, 0x77, 0xA1, 0x1E, 0x79, 0x48, 0x11
|
|
};
|
|
|
|
const uint8_t ecc_p192_scalar[] = {
|
|
0x6f, 0x18, 0x34, 0xeb, 0x16, 0xb7, 0xac, 0x9f,
|
|
0x3c, 0x77, 0x71, 0xb3, 0x02, 0x30, 0x70, 0x48,
|
|
0x75, 0x87, 0xbb, 0x6f, 0x80, 0x34, 0x8d, 0x5e
|
|
};
|
|
|
|
const uint8_t ecc_p192_mul_res_x[] = {
|
|
0x3F, 0xEE, 0x6F, 0x1F, 0x99, 0xDC, 0xCB, 0x78,
|
|
0xB7, 0x47, 0x1C, 0x2A, 0xF5, 0xA0, 0xAC, 0xE6,
|
|
0xEC, 0x24, 0x82, 0x37, 0x6C, 0xC0, 0x27, 0xC5,
|
|
};
|
|
|
|
const uint8_t ecc_p192_mul_res_y[] = {
|
|
0xDF, 0xF3, 0x9E, 0x76, 0x24, 0xF4, 0xF6, 0xB4,
|
|
0xF0, 0x0A, 0x18, 0xE1, 0x0B, 0xD2, 0xD9, 0x83,
|
|
0xE8, 0x29, 0x5E, 0xD9, 0x46, 0x54, 0xC3, 0xE1
|
|
};
|
|
|
|
const uint8_t ecc_p192_small_mul_res_x[] = {
|
|
0x62, 0xBF, 0x33, 0xC1, 0x75, 0xB5, 0xEB, 0x1D,
|
|
0xBE, 0xC7, 0x15, 0x04, 0x03, 0xA7, 0xDD, 0x9D,
|
|
0x0B, 0x17, 0x9D, 0x3B, 0x06, 0x63, 0xFE, 0xD3
|
|
};
|
|
|
|
const uint8_t ecc_p192_small_mul_res_y[] = {
|
|
0xD4, 0xE9, 0x4E, 0x4D, 0x89, 0x4D, 0xB5, 0x99,
|
|
0x8A, 0xE1, 0x85, 0x81, 0x27, 0x38, 0x23, 0x32,
|
|
0x92, 0xCF, 0xE8, 0x38, 0xCA, 0x39, 0xF2, 0xE1
|
|
};
|
|
|
|
const uint8_t ecc_p256_point_x[] = {
|
|
0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47,
|
|
0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2,
|
|
0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0,
|
|
0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96
|
|
};
|
|
|
|
const uint8_t ecc_p256_point_y[] = {
|
|
0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B,
|
|
0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16,
|
|
0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE,
|
|
0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5
|
|
};
|
|
|
|
const uint8_t ecc_p256_scalar[] = {
|
|
0xB2, 0xC5, 0x9E, 0x92, 0x64, 0xCD, 0x5F, 0x66,
|
|
0x9E, 0xC8, 0x83, 0x6D, 0x99, 0x61, 0x18, 0x72,
|
|
0xC8, 0x60, 0x83, 0x1E, 0xE5, 0x79, 0xCC, 0x73,
|
|
0xA9, 0xB4, 0x74, 0x85, 0x70, 0x11, 0x2D, 0xA2,
|
|
};
|
|
|
|
const uint8_t ecc_p256_mul_res_x[] = {
|
|
0x26, 0x1A, 0x0F, 0xBD, 0xA5, 0xE5, 0x1E, 0xE7,
|
|
0xB3, 0xC3, 0xB7, 0x09, 0xD1, 0x4A, 0x7A, 0x2A,
|
|
0x16, 0x69, 0x4B, 0xAF, 0x76, 0x5C, 0xD4, 0x0E,
|
|
0x93, 0x57, 0xB8, 0x67, 0xF9, 0xA1, 0xE5, 0xE8
|
|
};
|
|
|
|
const uint8_t ecc_p256_mul_res_y[] = {
|
|
0xA0, 0xF4, 0x2E, 0x62, 0x36, 0x25, 0x9F, 0xE0,
|
|
0xF2, 0xA0, 0x41, 0x42, 0xD2, 0x95, 0x89, 0x41,
|
|
0x38, 0xF0, 0xEB, 0x6E, 0xA7, 0x96, 0x29, 0x24,
|
|
0xC7, 0xD4, 0x0C, 0x90, 0xA1, 0xC9, 0xD3, 0x3A
|
|
};
|
|
|
|
const uint8_t ecc_p256_small_mul_res_x[] = {
|
|
0x53, 0x4D, 0x45, 0xDB, 0x6B, 0xAC, 0xA8, 0xE2,
|
|
0xD2, 0xA5, 0xD0, 0xA7, 0x65, 0xF1, 0x60, 0x13,
|
|
0xA8, 0xD4, 0xEB, 0x58, 0xC6, 0xAA, 0xAD, 0x35,
|
|
0x67, 0xCE, 0xBD, 0xFA, 0xC4, 0x2D, 0x62, 0x3C
|
|
};
|
|
|
|
const uint8_t ecc_p256_small_mul_res_y[] = {
|
|
0xFA, 0xD6, 0x69, 0xC8, 0x9A, 0x2A, 0x54, 0xE4,
|
|
0x41, 0x54, 0x35, 0x7F, 0x99, 0x2C, 0xCE, 0xC8,
|
|
0xEE, 0xF0, 0x93, 0xE0, 0xF2, 0x3A, 0x63, 0x1D,
|
|
0x17, 0xFD, 0xF6, 0x64, 0x41, 0x9E, 0x50, 0x0C
|
|
};
|
|
|
|
#if SOC_ECC_SUPPORT_CURVE_P384
|
|
const uint8_t ecc_p384_point_x[] = {
|
|
0xaa, 0x87, 0xca, 0x22, 0xbe, 0x8b, 0x05, 0x37,
|
|
0x8e, 0xb1, 0xc7, 0x1e, 0xf3, 0x20, 0xad, 0x74,
|
|
0x6e, 0x1d, 0x3b, 0x62, 0x8b, 0xa7, 0x9b, 0x98,
|
|
0x59, 0xf7, 0x41, 0xe0, 0x82, 0x54, 0x2a, 0x38,
|
|
0x55, 0x02, 0xf2, 0x5d, 0xbf, 0x55, 0x29, 0x6c,
|
|
0x3a, 0x54, 0x5e, 0x38, 0x72, 0x76, 0x0a, 0xb7
|
|
};
|
|
|
|
const uint8_t ecc_p384_point_y[] = {
|
|
0x36, 0x17, 0xde, 0x4a, 0x96, 0x26, 0x2c, 0x6f,
|
|
0x5d, 0x9e, 0x98, 0xbf, 0x92, 0x92, 0xdc, 0x29,
|
|
0xf8, 0xf4, 0x1d, 0xbd, 0x28, 0x9a, 0x14, 0x7c,
|
|
0xe9, 0xda, 0x31, 0x13, 0xb5, 0xf0, 0xb8, 0xc0,
|
|
0x0a, 0x60, 0xb1, 0xce, 0x1d, 0x7e, 0x81, 0x9d,
|
|
0x7a, 0x43, 0x1d, 0x7c, 0x90, 0xea, 0x0e, 0x5f
|
|
};
|
|
|
|
const uint8_t ecc_p384_scalar[] = {
|
|
0x68, 0xd1, 0x09, 0xa7, 0xc7, 0x7e, 0xeb, 0xbd,
|
|
0x43, 0x18, 0x7e, 0xdd, 0x69, 0x23, 0x7e, 0x0a,
|
|
0xef, 0x07, 0xc2, 0x0e, 0xc5, 0x3d, 0xe7, 0xcb,
|
|
0xd4, 0x36, 0xad, 0x9b, 0xdc, 0xf8, 0x6c, 0x5c,
|
|
0x0c, 0x3d, 0xce, 0x45, 0xcd, 0x6f, 0x7f, 0x18,
|
|
0x40, 0xc5, 0x29, 0xf3, 0xcd, 0x12, 0x1d, 0xc2
|
|
};
|
|
|
|
const uint8_t ecc_p384_mul_res_x[] = {
|
|
0x74, 0x1d, 0xc3, 0xba, 0xac, 0x60, 0x37, 0xfc,
|
|
0x57, 0x85, 0x90, 0x95, 0x64, 0xe6, 0xd1, 0xef,
|
|
0x86, 0xdf, 0x42, 0xe0, 0xaf, 0x11, 0x24, 0x1f,
|
|
0xe9, 0x97, 0x6e, 0x0c, 0xd9, 0xe5, 0xa0, 0x5d,
|
|
0xd9, 0x91, 0x96, 0x71, 0xef, 0x96, 0xe9, 0x7e,
|
|
0x90, 0xba, 0xa8, 0x33, 0xe2, 0x2e, 0xf0, 0x7b
|
|
};
|
|
|
|
const uint8_t ecc_p384_mul_res_y[] = {
|
|
0xc3, 0xe0, 0x66, 0x50, 0xd9, 0x1e, 0xa9, 0x42,
|
|
0xcb, 0x0d, 0xec, 0xb6, 0x29, 0xe2, 0xae, 0x75,
|
|
0xc6, 0xa2, 0xb9, 0xa6, 0xcf, 0x2c, 0x97, 0x01,
|
|
0xcc, 0xff, 0x7c, 0x1c, 0xd1, 0x01, 0xde, 0xbc,
|
|
0x40, 0x56, 0x8c, 0x18, 0x21, 0x9d, 0xbd, 0xc0,
|
|
0x2d, 0x41, 0x5b, 0x92, 0x52, 0x5a, 0x40, 0x57
|
|
};
|
|
|
|
const uint8_t ecc_p384_small_mul_res_x[] = {
|
|
0x35, 0x49, 0x60, 0x41, 0xea, 0x25, 0x3b, 0x0d,
|
|
0x15, 0x3c, 0x9b, 0xfb, 0xc1, 0x8a, 0x9e, 0x41,
|
|
0xaf, 0x34, 0x8a, 0xfd, 0x8b, 0x1c, 0x33, 0xa5,
|
|
0xca, 0x5d, 0x7f, 0xbb, 0xfa, 0x2d, 0x5d, 0x9d,
|
|
0x43, 0x6e, 0xd1, 0x01, 0x1b, 0x3d, 0x9d, 0x93,
|
|
0xe4, 0xb4, 0x5d, 0x2a, 0x4b, 0x23, 0x27, 0xf1
|
|
};
|
|
|
|
const uint8_t ecc_p384_small_mul_res_y[] = {
|
|
0x73, 0xce, 0x1e, 0xaa, 0x4f, 0xfd, 0xdc, 0x1d,
|
|
0x69, 0xd9, 0xe0, 0x9d, 0x16, 0x46, 0x19, 0xae,
|
|
0x8d, 0xd2, 0xce, 0x26, 0x6f, 0x9d, 0xb6, 0xc3,
|
|
0x30, 0xa5, 0x05, 0x7c, 0x7d, 0x62, 0xde, 0x8f,
|
|
0x8e, 0xc3, 0xce, 0x9b, 0xa7, 0xc1, 0x71, 0xb9,
|
|
0xb0, 0x2a, 0xda, 0x1c, 0xb3, 0x42, 0x61, 0x58
|
|
};
|
|
#endif /* SOC_ECC_SUPPORT_CURVE_P384 */
|
|
|
|
static int rng_wrapper(void *ctx, unsigned char *buf, size_t len)
|
|
{
|
|
esp_fill_random(buf, len);
|
|
return 0;
|
|
}
|
|
|
|
static void test_ecp_mul(mbedtls_ecp_group_id id, const uint8_t *x_coord, const uint8_t *y_coord, const uint8_t *scalar,
|
|
const uint8_t *result_x_coord, const uint8_t *result_y_coord)
|
|
{
|
|
int64_t elapsed_time;
|
|
uint8_t x[48];
|
|
uint8_t y[48];
|
|
int size;
|
|
int ret;
|
|
|
|
mbedtls_ecp_group grp;
|
|
mbedtls_ecp_point R;
|
|
mbedtls_ecp_point P;
|
|
mbedtls_mpi m;
|
|
|
|
mbedtls_ecp_group_init(&grp);
|
|
mbedtls_ecp_point_init(&R);
|
|
mbedtls_ecp_point_init(&P);
|
|
mbedtls_mpi_init(&m);
|
|
|
|
mbedtls_ecp_group_load(&grp, id);
|
|
|
|
size = grp.pbits / 8;
|
|
|
|
if (!scalar) {
|
|
mbedtls_mpi_lset(&m, SMALL_SCALAR);
|
|
} else {
|
|
mbedtls_mpi_read_binary(&m, scalar, size);
|
|
}
|
|
|
|
mbedtls_mpi_read_binary(&P.MBEDTLS_PRIVATE(X), x_coord, size);
|
|
mbedtls_mpi_read_binary(&P.MBEDTLS_PRIVATE(Y), y_coord, size);
|
|
|
|
mbedtls_mpi_lset(&P.MBEDTLS_PRIVATE(Z), 1);
|
|
|
|
ccomp_timer_start();
|
|
ret = mbedtls_ecp_mul(&grp, &R, &m, &P, rng_wrapper, NULL);
|
|
elapsed_time = ccomp_timer_stop();
|
|
|
|
TEST_ASSERT_EQUAL(0, ret);
|
|
|
|
mbedtls_mpi_write_binary(&R.MBEDTLS_PRIVATE(X), x, mbedtls_mpi_size(&R.MBEDTLS_PRIVATE(X)));
|
|
mbedtls_mpi_write_binary(&R.MBEDTLS_PRIVATE(Y), y, mbedtls_mpi_size(&R.MBEDTLS_PRIVATE(Y)));
|
|
|
|
TEST_ASSERT_EQUAL(0, memcmp(x, result_x_coord, mbedtls_mpi_size(&R.MBEDTLS_PRIVATE(X))));
|
|
TEST_ASSERT_EQUAL(0, memcmp(y, result_y_coord, mbedtls_mpi_size(&R.MBEDTLS_PRIVATE(Y))));
|
|
|
|
if (id == MBEDTLS_ECP_DP_SECP192R1) {
|
|
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECP_P192_POINT_MULTIPLY_OP, "%" NEWLIB_NANO_COMPAT_FORMAT" us", NEWLIB_NANO_COMPAT_CAST(elapsed_time));
|
|
} else if (id == MBEDTLS_ECP_DP_SECP256R1) {
|
|
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECP_P256_POINT_MULTIPLY_OP, "%" NEWLIB_NANO_COMPAT_FORMAT" us", NEWLIB_NANO_COMPAT_CAST(elapsed_time));
|
|
#if SOC_ECC_SUPPORT_CURVE_P384
|
|
} else if (id == MBEDTLS_ECP_DP_SECP384R1) {
|
|
if (ecc_ll_is_p384_curve_operations_supported()) {
|
|
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECP_P384_POINT_MULTIPLY_OP, "%" NEWLIB_NANO_COMPAT_FORMAT" us", NEWLIB_NANO_COMPAT_CAST(elapsed_time));
|
|
}
|
|
#endif
|
|
}
|
|
|
|
mbedtls_ecp_point_free(&R);
|
|
mbedtls_ecp_point_free(&P);
|
|
mbedtls_mpi_free(&m);
|
|
mbedtls_ecp_group_free(&grp);
|
|
}
|
|
|
|
TEST_CASE("mbedtls ECP point multiply with SECP192R1", "[mbedtls]")
|
|
{
|
|
test_ecp_mul(MBEDTLS_ECP_DP_SECP192R1, ecc_p192_point_x, ecc_p192_point_y, ecc_p192_scalar,
|
|
ecc_p192_mul_res_x, ecc_p192_mul_res_y);
|
|
|
|
test_ecp_mul(MBEDTLS_ECP_DP_SECP192R1, ecc_p192_point_x, ecc_p192_point_y, NULL,
|
|
ecc_p192_small_mul_res_x, ecc_p192_small_mul_res_y);
|
|
}
|
|
|
|
TEST_CASE("mbedtls ECP point multiply with SECP256R1", "[mbedtls]")
|
|
{
|
|
test_ecp_mul(MBEDTLS_ECP_DP_SECP256R1, ecc_p256_point_x, ecc_p256_point_y, ecc_p256_scalar,
|
|
ecc_p256_mul_res_x, ecc_p256_mul_res_y);
|
|
|
|
test_ecp_mul(MBEDTLS_ECP_DP_SECP256R1, ecc_p256_point_x, ecc_p256_point_y, NULL,
|
|
ecc_p256_small_mul_res_x, ecc_p256_small_mul_res_y);
|
|
}
|
|
|
|
#if SOC_ECC_SUPPORT_CURVE_P384
|
|
TEST_CASE("mbedtls ECP point multiply with SECP384R1", "[mbedtls]")
|
|
{
|
|
if (ecc_ll_is_p384_curve_operations_supported()) {
|
|
test_ecp_mul(MBEDTLS_ECP_DP_SECP384R1, ecc_p384_point_x, ecc_p384_point_y, ecc_p384_scalar,
|
|
ecc_p384_mul_res_x, ecc_p384_mul_res_y);
|
|
|
|
test_ecp_mul(MBEDTLS_ECP_DP_SECP384R1, ecc_p384_point_x, ecc_p384_point_y, NULL,
|
|
ecc_p384_small_mul_res_x, ecc_p384_small_mul_res_y);
|
|
}
|
|
}
|
|
#endif /* SOC_ECC_SUPPORT_CURVE_P384 */
|
|
|
|
static void test_ecp_verify(mbedtls_ecp_group_id id, const uint8_t *x_coord, const uint8_t *y_coord)
|
|
{
|
|
int64_t elapsed_time;
|
|
int size;
|
|
int ret;
|
|
|
|
mbedtls_ecp_group grp;
|
|
mbedtls_ecp_point P;
|
|
|
|
mbedtls_ecp_group_init(&grp);
|
|
mbedtls_ecp_point_init(&P);
|
|
|
|
mbedtls_ecp_group_load(&grp, id);
|
|
|
|
size = grp.pbits / 8;
|
|
|
|
mbedtls_mpi_read_binary(&P.MBEDTLS_PRIVATE(X), x_coord, size);
|
|
mbedtls_mpi_read_binary(&P.MBEDTLS_PRIVATE(Y), y_coord, size);
|
|
mbedtls_mpi_lset(&P.MBEDTLS_PRIVATE(Z), 1);
|
|
|
|
ccomp_timer_start();
|
|
ret = mbedtls_ecp_check_pubkey(&grp, &P);
|
|
elapsed_time = ccomp_timer_stop();
|
|
|
|
TEST_ASSERT_EQUAL(0, ret);
|
|
|
|
if (id == MBEDTLS_ECP_DP_SECP192R1) {
|
|
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECP_P192_POINT_VERIFY_OP, "%" NEWLIB_NANO_COMPAT_FORMAT" us", NEWLIB_NANO_COMPAT_CAST(elapsed_time));
|
|
} else if (id == MBEDTLS_ECP_DP_SECP256R1) {
|
|
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECP_P256_POINT_VERIFY_OP, "%" NEWLIB_NANO_COMPAT_FORMAT" us", NEWLIB_NANO_COMPAT_CAST(elapsed_time));
|
|
#if SOC_ECC_SUPPORT_CURVE_P384
|
|
} else if (id == MBEDTLS_ECP_DP_SECP384R1) {
|
|
if (ecc_ll_is_p384_curve_operations_supported()) {
|
|
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECP_P384_POINT_VERIFY_OP, "%" NEWLIB_NANO_COMPAT_FORMAT" us", NEWLIB_NANO_COMPAT_CAST(elapsed_time));
|
|
}
|
|
#endif
|
|
}
|
|
|
|
mbedtls_ecp_point_free(&P);
|
|
mbedtls_ecp_group_free(&grp);
|
|
}
|
|
|
|
TEST_CASE("mbedtls ECP point verify with SECP192R1", "[mbedtls]")
|
|
{
|
|
test_ecp_verify(MBEDTLS_ECP_DP_SECP192R1, ecc_p192_mul_res_x, ecc_p192_mul_res_y);
|
|
}
|
|
|
|
TEST_CASE("mbedtls ECP point verify with SECP256R1", "[mbedtls]")
|
|
{
|
|
test_ecp_verify(MBEDTLS_ECP_DP_SECP256R1, ecc_p256_mul_res_x, ecc_p256_mul_res_y);
|
|
}
|
|
|
|
#if SOC_ECC_SUPPORT_CURVE_P384
|
|
TEST_CASE("mbedtls ECP point verify with SECP384R1", "[mbedtls]")
|
|
{
|
|
if (ecc_ll_is_p384_curve_operations_supported()) {
|
|
test_ecp_verify(MBEDTLS_ECP_DP_SECP384R1, ecc_p384_mul_res_x, ecc_p384_mul_res_y);
|
|
}
|
|
}
|
|
#endif /* SOC_ECC_SUPPORT_CURVE_P384 */
|
|
#endif /* CONFIG_MBEDTLS_HARDWARE_ECC */
|