bignum_mod: Added a typedef for OPT_RED function pointer.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
This commit is contained in:
Minos Galanakis 2023-06-21 15:23:29 +01:00
parent de87461c23
commit 2a03fd3b7b
3 changed files with 10 additions and 11 deletions

View file

@ -166,8 +166,7 @@ int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *N,
int mbedtls_mpi_mod_optred_modulus_setup(mbedtls_mpi_mod_modulus *N, int mbedtls_mpi_mod_optred_modulus_setup(mbedtls_mpi_mod_modulus *N,
const mbedtls_mpi_uint *p, const mbedtls_mpi_uint *p,
size_t p_limbs, size_t p_limbs,
int (*modp)(mbedtls_mpi_uint *X, mbedtls_mpi_modp_fn modp)
size_t X_limbs))
{ {
standard_modulus_setup(N, p, p_limbs, MBEDTLS_MPI_MOD_REP_OPT_RED); standard_modulus_setup(N, p, p_limbs, MBEDTLS_MPI_MOD_REP_OPT_RED);
N->rep.ored.modp = modp; N->rep.ored.modp = modp;

View file

@ -99,10 +99,10 @@ typedef enum {
/** Montgomery representation. */ /** Montgomery representation. */
MBEDTLS_MPI_MOD_REP_MONTGOMERY = 2, MBEDTLS_MPI_MOD_REP_MONTGOMERY = 2,
/* Optimised reduction available. This indicates a coordinate modulus (P) /* Optimised reduction available. This indicates a coordinate modulus (P)
* and one of the following available: * and one or more of the following have been configured:
* - MBEDTLS_ECP_NIST_OPTIM * - A nist curve (MBEDTLS_ECP_DP_SECPXXXR1_ENABLED) & MBEDTLS_ECP_NIST_OPTIM.
* - Kobliz Curve. * - A Kobliz Curve.
* - Fast Reduction Curve CURVE25519 or CURVE448. */ * - A Fast Reduction Curve CURVE25519 or CURVE448. */
MBEDTLS_MPI_MOD_REP_OPT_RED, MBEDTLS_MPI_MOD_REP_OPT_RED,
} mbedtls_mpi_mod_rep_selector; } mbedtls_mpi_mod_rep_selector;
@ -124,9 +124,10 @@ typedef struct {
mbedtls_mpi_uint mm; /* Montgomery const for -N^{-1} mod 2^{ciL} */ mbedtls_mpi_uint mm; /* Montgomery const for -N^{-1} mod 2^{ciL} */
} mbedtls_mpi_mont_struct; } mbedtls_mpi_mont_struct;
typedef int (*mbedtls_mpi_modp_fn)(mbedtls_mpi_uint *X, size_t X_limbs);
typedef struct { typedef struct {
int (*modp)(mbedtls_mpi_uint *X, mbedtls_mpi_modp_fn modp; /* The optimised reduction function pointer */
size_t X_limbs); /* The optimised reduction function pointer */
} mbedtls_mpi_opt_red_struct; } mbedtls_mpi_opt_red_struct;
typedef struct { typedef struct {
@ -223,8 +224,7 @@ int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *N,
int mbedtls_mpi_mod_optred_modulus_setup(mbedtls_mpi_mod_modulus *N, int mbedtls_mpi_mod_optred_modulus_setup(mbedtls_mpi_mod_modulus *N,
const mbedtls_mpi_uint *p, const mbedtls_mpi_uint *p,
size_t p_limbs, size_t p_limbs,
int (*modp)(mbedtls_mpi_uint *X, mbedtls_mpi_modp_fn modp);
size_t X_limbs));
/** Free elements of a modulus structure. /** Free elements of a modulus structure.
* *

View file

@ -5833,7 +5833,7 @@ int mbedtls_ecp_modulus_setup(mbedtls_mpi_mod_modulus *N,
const mbedtls_ecp_group_id id, const mbedtls_ecp_group_id id,
const mbedtls_ecp_modulus_type ctype) const mbedtls_ecp_modulus_type ctype)
{ {
int (*modp)(mbedtls_mpi_uint *X, size_t X_limbs) = NULL; mbedtls_mpi_modp_fn modp = NULL;
mbedtls_mpi_uint *p = NULL; mbedtls_mpi_uint *p = NULL;
size_t p_limbs; size_t p_limbs;