diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 9e1a64e605..b61082bf47 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -10883,6 +10883,13 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz, if (ret == 0) { ret = mp_read_radix(order, key->dp->order, MP_RADIX_HEX); } + #ifdef WOLFSSL_SM2 + /* SM2 curve: private key must be less than order-1. */ + if ((ret == 0) && (key->idx != ECC_CUSTOM_IDX) && + (ecc_sets[key->idx].id == ECC_SM2P256V1)) { + ret = mp_sub_d(order, 1, order); + } + #endif if ((ret == 0) && (mp_cmp(key->k, order) != MP_LT)) { ret = ECC_PRIV_KEY_E; }