diff options
author | dgp <dgp@users.sourceforge.net> | 2018-03-15 14:06:52 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2018-03-15 14:06:52 (GMT) |
commit | 47152d94c197241698dc4fd03322b6694b25d2d4 (patch) | |
tree | 2ac7affdbbf5610b73d47d78435e28789065a723 /libtommath/bn_fast_mp_invmod.c | |
parent | 1dd89810eb1cba2b78eeeb42df4c3e966a55102e (diff) | |
parent | aa199edba612a516e6309290fb6dc4442a49a5ee (diff) | |
download | tcl-47152d94c197241698dc4fd03322b6694b25d2d4.zip tcl-47152d94c197241698dc4fd03322b6694b25d2d4.tar.gz tcl-47152d94c197241698dc4fd03322b6694b25d2d4.tar.bz2 |
merge 8.7
Diffstat (limited to 'libtommath/bn_fast_mp_invmod.c')
-rw-r--r-- | libtommath/bn_fast_mp_invmod.c | 10 |
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; } |