Skip to content

Commit

Permalink
Merge pull request #7532 from SparkiDev/wc_ecc_mulmod_zero
Browse files Browse the repository at this point in the history
ECC: handle zero in wc_ecc_mulmod()
  • Loading branch information
dgarske authored May 15, 2024
2 parents 92806a6 + b63f308 commit 9c4c923
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions wolfcrypt/src/ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4058,6 +4058,12 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point* G, ecc_point* R, mp_int* a,
int wc_ecc_mulmod(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
mp_int* modulus, int map)
{
if ((k != NULL) && (R != NULL) && (mp_iszero(k))) {
mp_zero(R->x);
mp_zero(R->y);
mp_zero(R->z);
return MP_OKAY;
}
return wc_ecc_mulmod_ex(k, G, R, a, modulus, map, NULL);
}

Expand Down
19 changes: 19 additions & 0 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -30563,6 +30563,9 @@ static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
ecc_key key2[1];
ecc_key key3[1];
#endif
#ifdef WOLFSSL_PUBLIC_MP
mp_int* priv;
#endif

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

#ifdef WOLFSSL_PUBLIC_MP
priv = wc_ecc_key_get_priv(key1);
mp_zero(priv);
ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
1);
if (ret != 0) {
ret = WC_TEST_RET_ENC_EC(ret);
goto done;
}
if (!wc_ecc_point_is_at_infinity(&key3->pubkey)) {
ret = WC_TEST_RET_ENC_EC(ret);
goto done;
}
#endif

done:

#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
Expand Down

0 comments on commit 9c4c923

Please sign in to comment.