Skip to content

Commit

Permalink
Merge branch 'fix/mbedtls_test_app_perf_logs_esp32c2' into 'master'
Browse files Browse the repository at this point in the history
mbedtls/test_apps: Fix performance logs

See merge request espressif/esp-idf!22340
  • Loading branch information
mahavirj committed Feb 28, 2023
2 parents df00fd8 + 47c153a commit 4db6cae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 12 additions & 4 deletions components/mbedtls/test_apps/main/test_ecp.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
#define ACCESS_ECDH(S, var) S.MBEDTLS_PRIVATE(ctx).MBEDTLS_PRIVATE(mbed_ecdh).MBEDTLS_PRIVATE(var)
#endif

#if CONFIG_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]")
{
mbedtls_ecdh_context ctx;
Expand Down Expand Up @@ -248,9 +256,9 @@ static void test_ecp_mul(mbedtls_ecp_group_id id, const uint8_t *x_coord, const
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, "%" PRId64 " us", elapsed_time);
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, "%" PRId64 " us", elapsed_time);
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECP_P256_POINT_MULTIPLY_OP, "%" NEWLIB_NANO_COMPAT_FORMAT" us", NEWLIB_NANO_COMPAT_CAST(elapsed_time));
}

mbedtls_ecp_point_free(&R);
Expand Down Expand Up @@ -304,9 +312,9 @@ static void test_ecp_verify(mbedtls_ecp_group_id id, const uint8_t *x_coord, con
TEST_ASSERT_EQUAL(0, ret);

if (id == MBEDTLS_ECP_DP_SECP192R1) {
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECP_P192_POINT_VERIFY_OP, "%" PRId64 " us", elapsed_time);
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, "%" PRId64 " us", elapsed_time);
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECP_P256_POINT_VERIFY_OP, "%" NEWLIB_NANO_COMPAT_FORMAT" us", NEWLIB_NANO_COMPAT_CAST(elapsed_time));
}

mbedtls_ecp_point_free(&P);
Expand Down
12 changes: 10 additions & 2 deletions components/mbedtls/test_apps/main/test_mbedtls_ecdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

#define TEST_ASSERT_MBEDTLS_OK(X) TEST_ASSERT_EQUAL_HEX32(0, -(X))

#if CONFIG_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

#if CONFIG_MBEDTLS_HARDWARE_ECC

/*
Expand Down Expand Up @@ -115,9 +123,9 @@ void test_ecdsa_verify(mbedtls_ecp_group_id id, const uint8_t *hash, const uint8
elapsed_time = ccomp_timer_stop();

if (id == MBEDTLS_ECP_DP_SECP192R1) {
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECDSA_P192_VERIFY_OP, "%" PRId64 " us", elapsed_time);
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECDSA_P192_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(ECDSA_P256_VERIFY_OP, "%" PRId64 " us", elapsed_time);
TEST_PERFORMANCE_CCOMP_LESS_THAN(ECDSA_P256_VERIFY_OP, "%" NEWLIB_NANO_COMPAT_FORMAT" us", NEWLIB_NANO_COMPAT_CAST(elapsed_time));
}

mbedtls_mpi_free(&r);
Expand Down

0 comments on commit 4db6cae

Please sign in to comment.