mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-16 08:42:50 +00:00
Add tests for optionally unsafe code paths
Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
e0842aa751
commit
7342656098
@ -1178,6 +1178,7 @@ void mpi_core_exp_mod(char *input_N, char *input_A,
|
||||
char *input_E, char *input_X)
|
||||
{
|
||||
mbedtls_mpi_uint *A = NULL;
|
||||
mbedtls_mpi_uint *A_copy = NULL;
|
||||
mbedtls_mpi_uint *E = NULL;
|
||||
mbedtls_mpi_uint *N = NULL;
|
||||
mbedtls_mpi_uint *X = NULL;
|
||||
@ -1229,6 +1230,8 @@ void mpi_core_exp_mod(char *input_N, char *input_A,
|
||||
|
||||
TEST_CALLOC(T, working_limbs);
|
||||
|
||||
/* Test the safe variant */
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
mbedtls_mpi_optionally_safe_codepath_reset();
|
||||
#endif
|
||||
@ -1236,10 +1239,23 @@ void mpi_core_exp_mod(char *input_N, char *input_A,
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
TEST_EQUAL(mbedtls_mpi_optionally_safe_codepath, MBEDTLS_MPI_IS_SECRET);
|
||||
#endif
|
||||
|
||||
TEST_EQUAL(0, memcmp(X, Y, N_limbs * sizeof(mbedtls_mpi_uint)));
|
||||
|
||||
/* Check when output aliased to input */
|
||||
/* Test the unsafe variant */
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
mbedtls_mpi_optionally_safe_codepath_reset();
|
||||
#endif
|
||||
mbedtls_mpi_core_exp_mod_unsafe(Y, A, N, N_limbs, E, E_limbs, R2, T);
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
TEST_EQUAL(mbedtls_mpi_optionally_safe_codepath, MBEDTLS_MPI_IS_PUBLIC);
|
||||
#endif
|
||||
TEST_EQUAL(0, memcmp(X, Y, N_limbs * sizeof(mbedtls_mpi_uint)));
|
||||
|
||||
/* Check both with output aliased to input */
|
||||
|
||||
TEST_CALLOC(A_copy, A_limbs);
|
||||
memcpy(A_copy, A, sizeof(A_copy) * A_limbs);
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
mbedtls_mpi_optionally_safe_codepath_reset();
|
||||
@ -1248,12 +1264,22 @@ void mpi_core_exp_mod(char *input_N, char *input_A,
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
TEST_EQUAL(mbedtls_mpi_optionally_safe_codepath, MBEDTLS_MPI_IS_SECRET);
|
||||
#endif
|
||||
TEST_EQUAL(0, memcmp(X, A, N_limbs * sizeof(mbedtls_mpi_uint)));
|
||||
|
||||
memcpy(A, A_copy, sizeof(A) * A_limbs);
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
mbedtls_mpi_optionally_safe_codepath_reset();
|
||||
#endif
|
||||
mbedtls_mpi_core_exp_mod_unsafe(A, A, N, N_limbs, E, E_limbs, R2, T);
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
TEST_EQUAL(mbedtls_mpi_optionally_safe_codepath, MBEDTLS_MPI_IS_PUBLIC);
|
||||
#endif
|
||||
TEST_EQUAL(0, memcmp(X, A, N_limbs * sizeof(mbedtls_mpi_uint)));
|
||||
|
||||
exit:
|
||||
mbedtls_free(T);
|
||||
mbedtls_free(A);
|
||||
mbedtls_free(A_copy);
|
||||
mbedtls_free(E);
|
||||
mbedtls_free(N);
|
||||
mbedtls_free(X);
|
||||
|
Loading…
x
Reference in New Issue
Block a user