From 9a0a48e0939e39e81027d71a1d1b0f6facc62497 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 22 Nov 2019 15:47:05 -0700 Subject: [PATCH] sanity check on "a" input to invmod --- wolfcrypt/src/tfm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index a5c409f47..20f356de3 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -1023,6 +1023,11 @@ int fp_invmod(fp_int *a, fp_int *b, fp_int *c) #endif 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 */ if (fp_iseven (b) == FP_YES) { return fp_invmod_slow(a,b,c);