summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2021-08-13 14:14:51 +0100
committerMatt Caswell <matt@openssl.org>2021-08-24 13:24:26 +0100
commit59f5e75f3bced8fc0e130d72a3f582cf7b480b46 (patch)
tree8b5f2360afb6cd85868dad064b333a81c85a3858 /test
parent8c74c9d1ade0fbdab5b815ddb747351b8b839641 (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 'test')
-rw-r--r--test/sm2_internal_test.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/test/sm2_internal_test.c b/test/sm2_internal_test.c
index 2bb73947ff..41827bb82f 100644
--- a/test/sm2_internal_test.c
+++ b/test/sm2_internal_test.c
@@ -185,7 +185,7 @@ static int test_sm2_crypt(const EC_GROUP *group,
if (!TEST_mem_eq(ctext, ctext_len, expected, ctext_len))
goto done;
- if (!TEST_true(sm2_plaintext_size(key, digest, ctext_len, &ptext_len))
+ if (!TEST_true(sm2_plaintext_size(ctext, ctext_len, &ptext_len))
|| !TEST_int_eq(ptext_len, msg_len))
goto done;