mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-28 00:21:48 +03:00
Bignum: clean up use of enums
- Made use of enums in struct and function declaration - All enums are handled by switch case now - If the switch does nothing on default, omit the default case to make compiler warnings more powerful - The two enums are now disjoint and the value 1 is skipped to make mistakes easier to detect Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
@ -26,6 +26,22 @@
|
||||
#include "mbedtls/bignum.h"
|
||||
#endif
|
||||
|
||||
/* Skip 1 as it is slightly easier to accidentally pass to functions. */
|
||||
typedef enum
|
||||
{
|
||||
MBEDTLS_MPI_MOD_REP_INVALID = 0,
|
||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY = 2,
|
||||
MBEDTLS_MPI_MOD_REP_OPT_RED
|
||||
} mbedtls_mpi_mod_rep_selector;
|
||||
|
||||
/* Make mbedtls_mpi_mod_rep_selector and mbedtls_mpi_mod_ext_rep disjoint to
|
||||
* make it easier to catch when they are accidentally swapped. */
|
||||
typedef enum
|
||||
{
|
||||
MBEDTLS_MPI_MOD_EXT_REP_INVALID = 0,
|
||||
MBEDTLS_MPI_MOD_EXT_REP_LE = 8,
|
||||
MBEDTLS_MPI_MOD_EXT_REP_BE
|
||||
} mbedtls_mpi_mod_ext_rep;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -38,10 +54,10 @@ typedef void* mbedtls_mpi_opt_red_struct;
|
||||
|
||||
typedef struct {
|
||||
mbedtls_mpi_uint *p;
|
||||
size_t n; // number of limbs
|
||||
size_t plen; // bitlen of p
|
||||
int ext_rep; // signals external representation (eg. byte order)
|
||||
int int_rep; // selector to signal the active member of the union
|
||||
size_t n; // number of limbs
|
||||
size_t plen; // bitlen of p
|
||||
mbedtls_mpi_mod_ext_rep ext_rep; // signals external representation (eg. byte order)
|
||||
mbedtls_mpi_mod_rep_selector int_rep; // selector to signal the active member of the union
|
||||
union rep
|
||||
{
|
||||
mbedtls_mpi_mont_struct mont;
|
||||
@ -49,21 +65,6 @@ typedef struct {
|
||||
} rep;
|
||||
} mbedtls_mpi_mod_modulus;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MBEDTLS_MPI_MOD_REP_INVALID = 0,
|
||||
MBEDTLS_MPI_MOD_REP_MONTGOMERY,
|
||||
MBEDTLS_MPI_MOD_REP_OPT_RED
|
||||
} mbedtls_mpi_mod_rep_selector;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MBEDTLS_MPI_MOD_EXT_REP_INVALID = 0,
|
||||
MBEDTLS_MPI_MOD_EXT_REP_LE,
|
||||
MBEDTLS_MPI_MOD_EXT_REP_BE
|
||||
} mbedtls_mpi_mod_ext_rep;
|
||||
|
||||
|
||||
/** Setup a residue structure.
|
||||
*
|
||||
* \param r The address of residue to setup. The size is determined by \p m.
|
||||
@ -124,8 +125,8 @@ void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *m );
|
||||
int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *m,
|
||||
mbedtls_mpi_uint *p,
|
||||
size_t pn,
|
||||
int ext_rep,
|
||||
int int_rep );
|
||||
mbedtls_mpi_mod_ext_rep ext_rep,
|
||||
mbedtls_mpi_mod_rep_selector int_rep );
|
||||
|
||||
/** Free elements of a modulus structure.
|
||||
*
|
||||
|
Reference in New Issue
Block a user