Skip to content

Commit 6617863

Browse files
authored
Merge pull request #10145 from Frauschi/ecc_follow_up
ECC curve validation follow-up
2 parents 2a06460 + 06e63f0 commit 6617863

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10978,16 +10978,22 @@ int wc_ecc_import_x963_ex2(const byte* in, word32 inLen, ecc_key* key,
1097810978
#ifndef WOLFSSL_SP_NO_256
1097910979
if (ecc_sets[key->idx].id == ECC_SECP256R1) {
1098010980
err = sp_ecc_is_point_256(key->pubkey.x, key->pubkey.y);
10981-
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SP_SM2)
10981+
#if defined(WOLFSSL_SM2)
1098210982
if (err != MP_OKAY && curve_id < 0) {
1098310983
/* Retry with SM2 curve when P-256 returns invalid.
1098410984
* Only when no explicit curve was requested (curve_id < 0).
1098510985
* Needed because SM2 keys can be mis-identified as
1098610986
* SECP256R1 during parsing. */
10987+
#if defined(WOLFSSL_SP_SM2)
1098710988
err = sp_ecc_is_point_sm2_256(key->pubkey.x,
1098810989
key->pubkey.y);
10990+
#else
10991+
int sm2_idx = wc_ecc_get_curve_idx(ECC_SM2P256V1);
10992+
if (sm2_idx != ECC_CURVE_INVALID)
10993+
err = wc_ecc_point_is_on_curve(&key->pubkey, sm2_idx);
10994+
#endif
1098910995
if (err == MP_OKAY) {
10990-
err = wc_ecc_set_curve(key, key->dp->size,
10996+
err = wc_ecc_set_curve(key, WOLFSSL_SM2_KEY_BITS / 8,
1099110997
ECC_SM2P256V1);
1099210998
}
1099310999
}

wolfcrypt/src/evp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9542,7 +9542,8 @@ static int ECC_populate_EVP_PKEY(WOLFSSL_EVP_PKEY* pkey, WOLFSSL_EC_KEY *key)
95429542
{
95439543
if (ecc->type == ECC_PRIVATEKEY_ONLY ||
95449544
(ecc->type == ECC_PRIVATEKEY &&
9545-
mp_iszero(ecc->pubkey.x))) {
9545+
mp_iszero(ecc->pubkey.x) &&
9546+
mp_iszero(ecc->pubkey.y))) {
95469547
/* Reconstruct public key from private scalar. This covers
95479548
* both ECC_PRIVATEKEY_ONLY keys and ECC_PRIVATEKEY keys whose
95489549
* public-key point was never populated (e.g. when only

0 commit comments

Comments
 (0)