mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-03 23:43:40 +00:00
Add tests for optionally unsafe code paths
Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
df5e55bcb7
commit
1fa5f3a929
@ -1246,6 +1246,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;
|
||||
@ -1297,10 +1298,10 @@ void mpi_core_exp_mod(char *input_N, char *input_A,
|
||||
|
||||
TEST_CALLOC(T, working_limbs);
|
||||
|
||||
/* Test the safe variant */
|
||||
TEST_CF_SECRET(A, A_limbs * sizeof(mbedtls_mpi_uint));
|
||||
TEST_CF_SECRET(N, N_limbs * sizeof(mbedtls_mpi_uint));
|
||||
TEST_CF_SECRET(E, E_limbs * sizeof(mbedtls_mpi_uint));
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
mbedtls_mpi_optionally_safe_codepath_reset();
|
||||
#endif
|
||||
@ -1308,16 +1309,31 @@ 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)));
|
||||
|
||||
TEST_CF_PUBLIC(Y, N_limbs * sizeof(mbedtls_mpi_uint));
|
||||
|
||||
TEST_EQUAL(0, memcmp(X, Y, N_limbs * sizeof(mbedtls_mpi_uint)));
|
||||
|
||||
/* 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);
|
||||
|
||||
TEST_CF_SECRET(A, A_limbs * sizeof(mbedtls_mpi_uint));
|
||||
TEST_CF_SECRET(N, N_limbs * sizeof(mbedtls_mpi_uint));
|
||||
TEST_CF_SECRET(E, E_limbs * sizeof(mbedtls_mpi_uint));
|
||||
|
||||
/* Check when output aliased to input */
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
mbedtls_mpi_optionally_safe_codepath_reset();
|
||||
#endif
|
||||
@ -1325,13 +1341,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, A, N_limbs * sizeof(mbedtls_mpi_uint)));
|
||||
|
||||
TEST_CF_PUBLIC(A, A_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…
Reference in New Issue
Block a user