forked from wolfSSL/wolfssl
Merge pull request #2621 from JacobBarthelmeh/SanityChecks
sanity check on "a" input to invmod
This commit is contained in:
@ -966,8 +966,8 @@ int wolfcrypt_mp_invmod(mp_int * a, mp_int * b, mp_int * c)
|
|||||||
int mp_invmod (mp_int * a, mp_int * b, mp_int * c)
|
int mp_invmod (mp_int * a, mp_int * b, mp_int * c)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* b cannot be negative */
|
/* b cannot be negative or zero, and can not divide by 0 (1/a mod b) */
|
||||||
if (b->sign == MP_NEG || mp_iszero(b) == MP_YES) {
|
if (b->sign == MP_NEG || mp_iszero(b) == MP_YES || mp_iszero(a) == MP_YES) {
|
||||||
return MP_VAL;
|
return MP_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,6 +1023,11 @@ int fp_invmod(fp_int *a, fp_int *b, fp_int *c)
|
|||||||
#endif
|
#endif
|
||||||
int neg;
|
int neg;
|
||||||
|
|
||||||
|
/* [modified] sanity check on "a" */
|
||||||
|
if (fp_iszero(a) == FP_YES) {
|
||||||
|
return FP_VAL; /* can not divide by 0 here */
|
||||||
|
}
|
||||||
|
|
||||||
/* 2. [modified] b must be odd */
|
/* 2. [modified] b must be odd */
|
||||||
if (fp_iseven (b) == FP_YES) {
|
if (fp_iseven (b) == FP_YES) {
|
||||||
return fp_invmod_slow(a,b,c);
|
return fp_invmod_slow(a,b,c);
|
||||||
|
Reference in New Issue
Block a user