Skip to content

Commit

Permalink
Merge pull request #6622 from philljj/zd16426
Browse files Browse the repository at this point in the history
tfm fp_exptmod_nct: set result to zero when base is zero
  • Loading branch information
JacobBarthelmeh authored Jul 17, 2023
2 parents 31aac92 + df58c4d commit 67d35ea
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions wolfcrypt/src/tfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3171,14 +3171,21 @@ int fp_exptmod_nct(fp_int * G, fp_int * X, fp_int * P, fp_int * Y)
int x = fp_count_bits (X);
#endif

if (fp_iszero(G)) {
fp_set(G, 0);
/* 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_ESP32_CRYPT_RSA_PRI) && \
Expand Down

0 comments on commit 67d35ea

Please sign in to comment.