tfm fp_exptmod_nct: handle special cases better

This commit is contained in:
jordan
2023-07-15 10:00:50 -05:00
parent 1afc0df83d
commit df58c4dea7

View File

@@ -3171,16 +3171,21 @@ int fp_exptmod_nct(fp_int * G, fp_int * X, fp_int * P, fp_int * Y)
int x = fp_count_bits (X); int x = fp_count_bits (X);
#endif #endif
/* 0^X mod P = 0 mod P = 0. /* handle modulus of zero and prevent overflows */
* Set result to 0 and return early. */ if (fp_iszero(P) || (P->used > (FP_SIZE/2))) {
if (fp_iszero(G)) { return FP_VAL;
}
if (fp_isone(P)) {
fp_set(Y, 0); fp_set(Y, 0);
return FP_OKAY; return FP_OKAY;
} }
if (fp_iszero(X)) {
/* prevent overflows */ fp_set(Y, 1);
if (P->used > (FP_SIZE/2)) { return FP_OKAY;
return FP_VAL; }
if (fp_iszero(G)) {
fp_set(Y, 0);
return FP_OKAY;
} }
#if defined(WOLFSSL_ESP32_CRYPT_RSA_PRI) && \ #if defined(WOLFSSL_ESP32_CRYPT_RSA_PRI) && \