Skip to content

Commit 9c4c923

Browse files
authored
Merge pull request #7532 from SparkiDev/wc_ecc_mulmod_zero
ECC: handle zero in wc_ecc_mulmod()
2 parents 92806a6 + b63f308 commit 9c4c923

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4058,6 +4058,12 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point* G, ecc_point* R, mp_int* a,
40584058
int wc_ecc_mulmod(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
40594059
mp_int* modulus, int map)
40604060
{
4061+
if ((k != NULL) && (R != NULL) && (mp_iszero(k))) {
4062+
mp_zero(R->x);
4063+
mp_zero(R->y);
4064+
mp_zero(R->z);
4065+
return MP_OKAY;
4066+
}
40614067
return wc_ecc_mulmod_ex(k, G, R, a, modulus, map, NULL);
40624068
}
40634069

wolfcrypt/test/test.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30563,6 +30563,9 @@ static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
3056330563
ecc_key key2[1];
3056430564
ecc_key key3[1];
3056530565
#endif
30566+
#ifdef WOLFSSL_PUBLIC_MP
30567+
mp_int* priv;
30568+
#endif
3056630569

3056730570
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
3056830571
if ((key2 == NULL) || (key3 == NULL))
@@ -30597,6 +30600,22 @@ static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
3059730600
goto done;
3059830601
}
3059930602

30603+
#ifdef WOLFSSL_PUBLIC_MP
30604+
priv = wc_ecc_key_get_priv(key1);
30605+
mp_zero(priv);
30606+
ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
30607+
wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
30608+
1);
30609+
if (ret != 0) {
30610+
ret = WC_TEST_RET_ENC_EC(ret);
30611+
goto done;
30612+
}
30613+
if (!wc_ecc_point_is_at_infinity(&key3->pubkey)) {
30614+
ret = WC_TEST_RET_ENC_EC(ret);
30615+
goto done;
30616+
}
30617+
#endif
30618+
3060030619
done:
3060130620

3060230621
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)

0 commit comments

Comments
 (0)