From 1afc0df83d0aa2e52656d94c20c772a86a233d50 Mon Sep 17 00:00:00 2001 From: jordan Date: Fri, 14 Jul 2023 13:57:29 -0500 Subject: [PATCH] tfm fp_exptmod_nct: set result to zero when base is zero --- wolfcrypt/src/tfm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index 4a4c148c7..618d532e1 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -3171,8 +3171,10 @@ int fp_exptmod_nct(fp_int * G, fp_int * X, fp_int * P, fp_int * Y) int x = fp_count_bits (X); #endif + /* 0^X mod P = 0 mod P = 0. + * Set result to 0 and return early. */ if (fp_iszero(G)) { - fp_set(G, 0); + fp_set(Y, 0); return FP_OKAY; }