From 281ccda8a549bb75c2786f9d872427a5e466fc21 Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Tue, 19 Jul 2022 13:14:36 +0100 Subject: [PATCH] Clean up mpi_mod_init/free Signed-off-by: Janos Follath --- library/bignum_mod.h | 8 ++++++-- library/bignum_new.c | 12 +++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/library/bignum_mod.h b/library/bignum_mod.h index 7eac1df1cc..432cd00708 100644 --- a/library/bignum_mod.h +++ b/library/bignum_mod.h @@ -56,8 +56,12 @@ typedef enum MBEDTLS_MPI_MOD_REP_OPT_RED } mbedtls_mpi_mod_rep_selector; -#define MBEDTLS_MPI_MOD_EXT_REP_LE 0x1 -#define MBEDTLS_MPI_MOD_EXT_REP_BE 0x2 +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; void mbedtls_mpi_mod_residue_release( mbedtls_mpi_mod_residue *r ); diff --git a/library/bignum_new.c b/library/bignum_new.c index b6a806ecbc..5f10eadcd1 100644 --- a/library/bignum_new.c +++ b/library/bignum_new.c @@ -114,7 +114,11 @@ void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *m ) if ( m == NULL ) return; - m->rep.mont = 0; + m->p = NULL; + m->n = 0; + m->plen = 0; + m->ext_rep = MBEDTLS_MPI_MOD_EXT_REP_INVALID; + m->int_rep = MBEDTLS_MPI_MOD_REP_INVALID; } void mbedtls_mpi_mod_modulus_free( mbedtls_mpi_mod_modulus *m ) @@ -125,10 +129,8 @@ void mbedtls_mpi_mod_modulus_free( mbedtls_mpi_mod_modulus *m ) m->p = NULL; m->n = 0; m->plen = 0; - m->ext_rep = 0; - m->int_rep = 0; - m->rep.mont = NULL; - m->rep.ored = NULL; + m->ext_rep = MBEDTLS_MPI_MOD_EXT_REP_INVALID; + m->int_rep = MBEDTLS_MPI_MOD_REP_INVALID; } int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *m,