浏览代码

Replace Montgomery reduction by regular modulo operation.

It seems like somehow the Montgomery reduction causes this to fail.

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 3 周之前
父节点
当前提交
0a0f1d13aa
共有 1 个文件被更改,包括 4 次插入6 次删除
  1. 4 6
      src/math/ltm_desc.c

+ 4 - 6
src/math/ltm_desc.c

@@ -403,10 +403,8 @@ static int montgomery_setup(const void *a, void **b)
    if (*b == NULL) {
    if (*b == NULL) {
       return CRYPT_MEM;
       return CRYPT_MEM;
    }
    }
-   if ((err = mpi_to_ltc_error(mp_montgomery_setup(a, *b))) != CRYPT_OK) {
-      XFREE(*b);
-   }
-   return err;
+   **(mp_digit**)b = 1;
+   return CRYPT_OK;
 }
 }
 
 
 /* get normalization value */
 /* get normalization value */
@@ -414,7 +412,7 @@ static int montgomery_normalization(void *a, const void *b)
 {
 {
    LTC_ARGCHK(a != NULL);
    LTC_ARGCHK(a != NULL);
    LTC_ARGCHK(b != NULL);
    LTC_ARGCHK(b != NULL);
-   return mpi_to_ltc_error(mp_montgomery_calc_normalization(a, b));
+   return set_int(a, 1);
 }
 }
 
 
 /* reduce */
 /* reduce */
@@ -423,7 +421,7 @@ static int montgomery_reduce(void *a, const void *b, void *c)
    LTC_ARGCHK(a != NULL);
    LTC_ARGCHK(a != NULL);
    LTC_ARGCHK(b != NULL);
    LTC_ARGCHK(b != NULL);
    LTC_ARGCHK(c != NULL);
    LTC_ARGCHK(c != NULL);
-   return mpi_to_ltc_error(mp_montgomery_reduce(a, b, *((mp_digit *)c)));
+   return mpi_to_ltc_error(mp_mod(a, b, a));
 }
 }
 
 
 /* clean up */
 /* clean up */