Merge pull request #5252 from SparkiDev/mod_zero

TFM: mp_exptmod_ex didn't handle exceptional cases
This commit is contained in:
David Garske
2022-06-16 07:42:17 -07:00
committed by GitHub

View File

@ -2895,14 +2895,21 @@ int fp_exptmod_ex(fp_int * G, fp_int * X, int digits, fp_int * P, fp_int * Y)
int x = fp_count_bits (X);
#endif
if (fp_iszero(G)) {
/* handle modulus of zero and prevent overflows */
if (fp_iszero(P) || (P->used > (FP_SIZE/2))) {
return FP_VAL;
}
if (fp_isone(P)) {
fp_set(Y, 0);
return FP_OKAY;
}
/* prevent overflows */
if (P->used > (FP_SIZE/2)) {
return FP_VAL;
if (fp_iszero(X)) {
fp_set(Y, 1);
return FP_OKAY;
}
if (fp_iszero(G)) {
fp_set(Y, 0);
return FP_OKAY;
}
#if defined(WOLFSSL_ESP32WROOM32_CRYPT_RSA_PRI) && \