Skip to content

Commit

Permalink
Merge pull request #6889 from SparkiDev/sm2_priv_import_range
Browse files Browse the repository at this point in the history
ECC SM2 import private key: check less than order-1
  • Loading branch information
JacobBarthelmeh authored Oct 19, 2023
2 parents 22be42a + abd7bb3 commit 1abaa94
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions wolfcrypt/src/ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1abaa94

Please sign in to comment.