Commit f1b9bbf593051c6b1d7220758d9f1953f1ce9600

Karel Miko 2018-06-30T15:48:40

bn_fast_mp_invmod fix related to #118

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/bn_fast_mp_invmod.c b/bn_fast_mp_invmod.c
index 91b5bf6..be1a810 100644
--- a/bn_fast_mp_invmod.c
+++ b/bn_fast_mp_invmod.c
@@ -138,6 +138,14 @@ top:
          goto LBL_ERR;
       }
    }
+
+   /* too big */
+   while (mp_cmp_mag(&D, b) != MP_LT) {
+      if ((res = mp_sub(&D, b, &D)) != MP_OKAY) {
+         goto LBL_ERR;
+      }
+   }
+
    mp_exch(&D, c);
    c->sign = neg;
    res = MP_OKAY;