summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_fast_mp_invmod.c
diff options
context:
space:
mode:
Diffstat (limited to 'libtommath/bn_fast_mp_invmod.c')
-rw-r--r--libtommath/bn_fast_mp_invmod.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/libtommath/bn_fast_mp_invmod.c b/libtommath/bn_fast_mp_invmod.c
index 08389dd..6be44f8 100644
--- a/libtommath/bn_fast_mp_invmod.c
+++ b/libtommath/bn_fast_mp_invmod.c
@@ -46,6 +46,12 @@ int fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
goto LBL_ERR;
}
+ /* if one of x,y is zero return an error! */
+ if ((mp_iszero(&x) == MP_YES) || (mp_iszero(&y) == MP_YES)) {
+ res = MP_VAL;
+ goto LBL_ERR;
+ }
+
/* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
if ((res = mp_copy(&x, &u)) != MP_OKAY) {
goto LBL_ERR;
@@ -53,7 +59,7 @@ int fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
if ((res = mp_copy(&y, &v)) != MP_OKAY) {
goto LBL_ERR;
}
- mp_set(&D, 1);
+ mp_set(&D, 1uL);
top:
/* 4. while u is even do */
@@ -122,7 +128,7 @@ top:
/* now a = C, b = D, gcd == g*v */
/* if v != 1 then there is no inverse */
- if (mp_cmp_d(&v, 1) != MP_EQ) {
+ if (mp_cmp_d(&v, 1uL) != MP_EQ) {
res = MP_VAL;
goto LBL_ERR;
}