diff options
author | Matt Caswell <matt@openssl.org> | 2021-08-13 14:14:51 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2021-08-24 14:22:07 +0100 |
commit | 36cf45ef3ba71e44a8be06ee81cb31aa02cb0010 (patch) | |
tree | 0ee29a85738c2ad5363c826336e5543accbf41ea /include/crypto | |
parent | 4b8a8bb75229b64d1c7598d845fdc3c7e7d7eee2 (diff) |
Correctly calculate the length of SM2 plaintext given the ciphertext
Previously the length of the SM2 plaintext could be incorrectly calculated.
The plaintext length was calculated by taking the ciphertext length and
taking off an "overhead" value.
The overhead value was assumed to have a "fixed" element of 10 bytes.
This is incorrect since in some circumstances it can be more than 10 bytes.
Additionally the overhead included the length of two integers C1x and C1y,
which were assumed to be the same length as the field size (32 bytes for
the SM2 curve). However in some cases these integers can have an additional
padding byte when the msb is set, to disambiguate them from negative
integers. Additionally the integers can also be less than 32 bytes in
length in some cases.
If the calculated overhead is incorrect and larger than the actual value
this can result in the calculated plaintext length being too small.
Applications are likely to allocate buffer sizes based on this and therefore
a buffer overrun can occur.
CVE-2021-3711
Issue reported by John Ouyang.
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Diffstat (limited to 'include/crypto')
-rw-r--r-- | include/crypto/sm2.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/include/crypto/sm2.h b/include/crypto/sm2.h index 165c01810f..9ab6c0b722 100644 --- a/include/crypto/sm2.h +++ b/include/crypto/sm2.h @@ -67,8 +67,8 @@ int ossl_sm2_internal_verify(const unsigned char *dgst, int dgstlen, int ossl_sm2_ciphertext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len, size_t *ct_size); -int ossl_sm2_plaintext_size(const EC_KEY *key, const EVP_MD *digest, - size_t msg_len, size_t *pt_size); +int ossl_sm2_plaintext_size(const unsigned char *ct, size_t ct_size, + size_t *pt_size); int ossl_sm2_encrypt(const EC_KEY *key, const EVP_MD *digest, |