diff options
author | K1 <dongbeiouba@gmail.com> | 2024-01-16 21:07:38 +0800 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2024-01-31 10:27:51 +0000 |
commit | 9170cc0398222778065e098e396b8eb8cd0de1d3 (patch) | |
tree | 8318d142ec762ebc50d9898ebe810ad0adf056f9 /crypto/sm2 | |
parent | 20ddfe78e9ddc0aba8208616e1b0b33cb12f77f5 (diff) | |
download | openssl-9170cc0398222778065e098e396b8eb8cd0de1d3.tar.gz |
Optimize the implementation of ec_field_size()
No need to create and copy BIGNUM p, a and b, just call
EC_GROUP_get0_field() instead.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
(Merged from https://github.com/openssl/openssl/pull/23313)
Diffstat (limited to 'crypto/sm2')
-rw-r--r-- | crypto/sm2/sm2_crypt.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/crypto/sm2/sm2_crypt.c b/crypto/sm2/sm2_crypt.c index 971d348cce..b2d048cb59 100644 --- a/crypto/sm2/sm2_crypt.c +++ b/crypto/sm2/sm2_crypt.c @@ -46,25 +46,12 @@ IMPLEMENT_ASN1_FUNCTIONS(SM2_Ciphertext) static size_t ec_field_size(const EC_GROUP *group) { - /* Is there some simpler way to do this? */ - BIGNUM *p = BN_new(); - BIGNUM *a = BN_new(); - BIGNUM *b = BN_new(); - size_t field_size = 0; + const BIGNUM *p = EC_GROUP_get0_field(group); - if (p == NULL || a == NULL || b == NULL) - goto done; - - if (!EC_GROUP_get_curve(group, p, a, b, NULL)) - goto done; - field_size = (BN_num_bits(p) + 7) / 8; - - done: - BN_free(p); - BN_free(a); - BN_free(b); + if (p == NULL) + return 0; - return field_size; + return BN_num_bytes(p); } int ossl_sm2_plaintext_size(const unsigned char *ct, size_t ct_size, |