"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/sm2_internal_test.c" between
openssl-1.1.1f.tar.gz and openssl-1.1.1g.tar.gz

About: OpenSSL is a toolkit implementing the Transport Layer Security (TLS) protocols (including SSLv3) as well as a full-strength general purpose cryptographic library. Long Term Support (LTS) version (includes support for TLSv1.3).

sm2_internal_test.c  (openssl-1.1.1f):sm2_internal_test.c  (openssl-1.1.1g)
/* /*
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at * in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html * https://www.openssl.org/source/license.html
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
skipping to change at line 35 skipping to change at line 35
static RAND_METHOD fake_rand; static RAND_METHOD fake_rand;
static const RAND_METHOD *saved_rand; static const RAND_METHOD *saved_rand;
static uint8_t *fake_rand_bytes = NULL; static uint8_t *fake_rand_bytes = NULL;
static size_t fake_rand_bytes_offset = 0; static size_t fake_rand_bytes_offset = 0;
static size_t fake_rand_size = 0; static size_t fake_rand_size = 0;
static int get_faked_bytes(unsigned char *buf, int num) static int get_faked_bytes(unsigned char *buf, int num)
{ {
int i;
if (fake_rand_bytes == NULL) if (fake_rand_bytes == NULL)
return saved_rand->bytes(buf, num); 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; return 0;
for (i = 0; i != num; ++i) while (num-- > 0) {
buf[i] = fake_rand_bytes[fake_rand_bytes_offset + i]; if (fake_rand_bytes_offset >= fake_rand_size)
fake_rand_bytes_offset += num; fake_rand_bytes_offset = 0;
*buf++ = fake_rand_bytes[fake_rand_bytes_offset++];
}
return 1; return 1;
} }
static int start_fake_rand(const char *hex_bytes) static int start_fake_rand(const char *hex_bytes)
{ {
/* save old rand method */ /* save old rand method */
if (!TEST_ptr(saved_rand = RAND_get_rand_method())) if (!TEST_ptr(saved_rand = RAND_get_rand_method()))
return 0; return 0;
fake_rand = *saved_rand; fake_rand = *saved_rand;
skipping to change at line 178 skipping to change at line 179
|| !TEST_true(EC_KEY_set_public_key(key, pt)) || !TEST_true(EC_KEY_set_public_key(key, pt))
|| !TEST_true(sm2_ciphertext_size(key, digest, msg_len, &ctext_len)) ) || !TEST_true(sm2_ciphertext_size(key, digest, msg_len, &ctext_len)) )
goto done; goto done;
ctext = OPENSSL_zalloc(ctext_len); ctext = OPENSSL_zalloc(ctext_len);
if (!TEST_ptr(ctext)) if (!TEST_ptr(ctext))
goto done; goto done;
start_fake_rand(k_hex); start_fake_rand(k_hex);
if (!TEST_true(sm2_encrypt(key, digest, (const uint8_t *)message, msg_len, if (!TEST_true(sm2_encrypt(key, digest, (const uint8_t *)message, msg_len,
ctext, &ctext_len)) ctext, &ctext_len))) {
|| !TEST_size_t_eq(fake_rand_bytes_offset, fake_rand_size)) {
restore_rand(); restore_rand();
goto done; goto done;
} }
restore_rand(); restore_rand();
if (!TEST_mem_eq(ctext, ctext_len, expected, ctext_len)) if (!TEST_mem_eq(ctext, ctext_len, expected, ctext_len))
goto done; goto done;
if (!TEST_true(sm2_plaintext_size(key, digest, ctext_len, &ptext_len)) if (!TEST_true(sm2_plaintext_size(key, digest, ctext_len, &ptext_len))
|| !TEST_int_eq(ptext_len, msg_len)) || !TEST_int_eq(ptext_len, msg_len))
skipping to change at line 299 skipping to change at line 299
pt = EC_POINT_new(group); pt = EC_POINT_new(group);
if (!TEST_ptr(pt) if (!TEST_ptr(pt)
|| !TEST_true(EC_POINT_mul(group, pt, priv, NULL, NULL, NULL)) || !TEST_true(EC_POINT_mul(group, pt, priv, NULL, NULL, NULL))
|| !TEST_true(EC_KEY_set_public_key(key, pt))) || !TEST_true(EC_KEY_set_public_key(key, pt)))
goto done; goto done;
start_fake_rand(k_hex); start_fake_rand(k_hex);
sig = sm2_do_sign(key, EVP_sm3(), (const uint8_t *)userid, strlen(userid), sig = sm2_do_sign(key, EVP_sm3(), (const uint8_t *)userid, strlen(userid),
(const uint8_t *)message, msg_len); (const uint8_t *)message, msg_len);
if (!TEST_ptr(sig) if (!TEST_ptr(sig)) {
|| !TEST_size_t_eq(fake_rand_bytes_offset, fake_rand_size)) {
restore_rand(); restore_rand();
goto done; goto done;
} }
restore_rand(); restore_rand();
ECDSA_SIG_get0(sig, &sig_r, &sig_s); ECDSA_SIG_get0(sig, &sig_r, &sig_s);
if (!TEST_true(BN_hex2bn(&r, r_hex)) if (!TEST_true(BN_hex2bn(&r, r_hex))
|| !TEST_true(BN_hex2bn(&s, s_hex)) || !TEST_true(BN_hex2bn(&s, s_hex))
|| !TEST_BN_eq(r, sig_r) || !TEST_BN_eq(r, sig_r)
 End of changes. 6 change blocks. 
11 lines changed or deleted 10 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)