diff options
author | Billy Brumley <bbrumley@gmail.com> | 2020-03-29 09:38:37 +0200 |
---|---|---|
committer | Nicola Tuveri <nic.tuv@gmail.com> | 2020-04-01 17:50:20 +0200 |
commit | 09736245b174a37abb87fb7ceb55462d940ff2bb (patch) | |
tree | d349d305fd51f190350633ab78096b5adb480966 /test/sm2_internal_test.c | |
parent | apps: support sendfile in s_server when ktls enabled (diff) | |
download | openssl-09736245b174a37abb87fb7ceb55462d940ff2bb.tar.xz openssl-09736245b174a37abb87fb7ceb55462d940ff2bb.zip |
[test] Make sm2_internal_test less fragile to changes in the ec module
Since these are KATs, the trailing randomness consumed by the ec module
does not really matter. So make the fake random buffer circular.
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/11435)
Diffstat (limited to 'test/sm2_internal_test.c')
-rw-r--r-- | test/sm2_internal_test.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/test/sm2_internal_test.c b/test/sm2_internal_test.c index 9188ef7011..216333cf09 100644 --- a/test/sm2_internal_test.c +++ b/test/sm2_internal_test.c @@ -37,17 +37,18 @@ static size_t fake_rand_size = 0; static int get_faked_bytes(unsigned char *buf, int num) { - int i; - if (fake_rand_bytes == NULL) return saved_rand->bytes(buf, num); - if (!TEST_size_t_le(fake_rand_bytes_offset + num, fake_rand_size)) + if (!TEST_size_t_gt(fake_rand_size, 0)) return 0; - for (i = 0; i != num; ++i) - buf[i] = fake_rand_bytes[fake_rand_bytes_offset + i]; - fake_rand_bytes_offset += num; + while (num-- > 0) { + if (fake_rand_bytes_offset >= fake_rand_size) + fake_rand_bytes_offset = 0; + *buf++ = fake_rand_bytes[fake_rand_bytes_offset++]; + } + return 1; } @@ -180,8 +181,7 @@ static int test_sm2_crypt(const EC_GROUP *group, start_fake_rand(k_hex); if (!TEST_true(sm2_encrypt(key, digest, (const uint8_t *)message, msg_len, - ctext, &ctext_len)) - || !TEST_size_t_eq(fake_rand_bytes_offset, fake_rand_size)) { + ctext, &ctext_len))) { restore_rand(); goto done; } @@ -301,8 +301,7 @@ static int test_sm2_sign(const EC_GROUP *group, start_fake_rand(k_hex); sig = sm2_do_sign(key, EVP_sm3(), (const uint8_t *)userid, strlen(userid), (const uint8_t *)message, msg_len); - if (!TEST_ptr(sig) - || !TEST_size_t_eq(fake_rand_bytes_offset, fake_rand_size)) { + if (!TEST_ptr(sig)) { restore_rand(); goto done; } |