mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Move the quasi reduction fixing function to bignum_mod_raw
Rename the function to 'fix_quasi_reduction' to better suite its functionality. Also changed the name prefix to suite for the new module. Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include "constant_time_internal.h"
|
||||
#include "test/constant_flow.h"
|
||||
|
||||
#include "bignum_mod_raw_invasive.h"
|
||||
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_DEPENDENCIES
|
||||
@@ -338,6 +340,96 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_mod_raw_fix_quasi_reduction(char *input_N,
|
||||
char *input_A,
|
||||
char *result)
|
||||
{
|
||||
mbedtls_mpi_uint *A = NULL;
|
||||
mbedtls_mpi_uint *N = NULL;
|
||||
mbedtls_mpi_uint *res = NULL;
|
||||
size_t limbs_A;
|
||||
size_t limbs_N;
|
||||
size_t limbs_res;
|
||||
|
||||
mbedtls_mpi_mod_modulus m;
|
||||
mbedtls_mpi_mod_modulus_init(&m);
|
||||
|
||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&A, &limbs_A, input_A), 0);
|
||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&N, &limbs_N, input_N), 0);
|
||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&res, &limbs_res, result), 0);
|
||||
|
||||
size_t limbs = limbs_N;
|
||||
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
|
||||
|
||||
TEST_EQUAL(limbs_A, limbs);
|
||||
TEST_EQUAL(limbs_res, limbs);
|
||||
|
||||
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
|
||||
&m, N, limbs,
|
||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
|
||||
|
||||
TEST_EQUAL(mbedtls_mpi_mod_raw_fix_quasi_reduction(A, &m), 0);
|
||||
ASSERT_COMPARE(A, bytes, res, bytes);
|
||||
|
||||
exit:
|
||||
mbedtls_free(A);
|
||||
mbedtls_free(res);
|
||||
|
||||
mbedtls_mpi_mod_modulus_free(&m);
|
||||
mbedtls_free(N);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_mod_raw_fix_quasi_reduction_neg(char *input_N,
|
||||
char *input_A,
|
||||
char *result)
|
||||
{
|
||||
mbedtls_mpi_uint *A = NULL;
|
||||
mbedtls_mpi_uint *N = NULL;
|
||||
mbedtls_mpi_uint *res = NULL;
|
||||
size_t limbs_A;
|
||||
size_t limbs_N;
|
||||
size_t limbs_res;
|
||||
|
||||
mbedtls_mpi_mod_modulus m;
|
||||
mbedtls_mpi_mod_modulus_init(&m);
|
||||
|
||||
mbedtls_mpi_mod_modulus fake_m;
|
||||
mbedtls_mpi_mod_modulus_init(&fake_m);
|
||||
|
||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&A, &limbs_A, input_A), 0);
|
||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&N, &limbs_N, input_N), 0);
|
||||
TEST_EQUAL(mbedtls_test_read_mpi_core(&res, &limbs_res, result), 0);
|
||||
|
||||
size_t limbs = limbs_N;
|
||||
size_t bytes = limbs * sizeof(mbedtls_mpi_uint);
|
||||
|
||||
TEST_EQUAL(limbs_A, limbs);
|
||||
TEST_EQUAL(limbs_res, limbs);
|
||||
|
||||
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
|
||||
&m, N, limbs,
|
||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY), 0);
|
||||
|
||||
TEST_EQUAL(mbedtls_mpi_mod_raw_fix_quasi_reduction(A, &m), 0);
|
||||
ASSERT_COMPARE(A, bytes, res, bytes);
|
||||
|
||||
/* Check when m is not initialized */
|
||||
TEST_EQUAL(mbedtls_mpi_mod_raw_fix_quasi_reduction(A, &fake_m),
|
||||
MBEDTLS_ERR_MPI_BAD_INPUT_DATA);
|
||||
|
||||
exit:
|
||||
mbedtls_free(A);
|
||||
mbedtls_free(res);
|
||||
|
||||
mbedtls_mpi_mod_modulus_free(&fake_m);
|
||||
mbedtls_mpi_mod_modulus_free(&m);
|
||||
mbedtls_free(N);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_mod_raw_mul(char *input_A,
|
||||
char *input_B,
|
||||
|
Reference in New Issue
Block a user