Commit 49abba0937b36e90f73cb1ab028942e57769b467

Francois Perrad 2019-09-02T18:32:33

refactor with mp_init_multi

diff --git a/bn_mp_exptmod.c b/bn_mp_exptmod.c
index f6846cc..ceb8e86 100644
--- a/bn_mp_exptmod.c
+++ b/bn_mp_exptmod.c
@@ -26,20 +26,17 @@ mp_err mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
          return MP_VAL;
       }
 
-      /* first compute 1/G mod P */
-      if ((err = mp_init(&tmpG)) != MP_OKAY) {
+      if ((err = mp_init_multi(&tmpG, &tmpX, NULL)) != MP_OKAY) {
          return err;
       }
+
+      /* first compute 1/G mod P */
       if ((err = mp_invmod(G, P, &tmpG)) != MP_OKAY) {
-         mp_clear(&tmpG);
+         mp_clear_multi(&tmpG, &tmpX, NULL);
          return err;
       }
 
       /* now get |X| */
-      if ((err = mp_init(&tmpX)) != MP_OKAY) {
-         mp_clear(&tmpG);
-         return err;
-      }
       if ((err = mp_abs(X, &tmpX)) != MP_OKAY) {
          mp_clear_multi(&tmpG, &tmpX, NULL);
          return err;
diff --git a/tommath_class.h b/tommath_class.h
index 1bd0c0b..24122d1 100644
--- a/tommath_class.h
+++ b/tommath_class.h
@@ -405,10 +405,9 @@
 
 #if defined(BN_MP_EXPTMOD_C)
 #   define BN_MP_ABS_C
-#   define BN_MP_CLEAR_C
 #   define BN_MP_CLEAR_MULTI_C
 #   define BN_MP_DR_IS_MODULUS_C
-#   define BN_MP_INIT_C
+#   define BN_MP_INIT_MULTI_C
 #   define BN_MP_INVMOD_C
 #   define BN_MP_REDUCE_IS_2K_C
 #   define BN_MP_REDUCE_IS_2K_L_C