Update pre9

This commit is contained in:
2018-07-08 16:02:48 +09:00
parent 89af373a04
commit 1914ae9055
15 changed files with 416 additions and 49 deletions
+12 -10
View File
@@ -48,7 +48,8 @@ static size_t ec_field_size(const EC_GROUP *group)
if (p == NULL || a == NULL || b == NULL)
goto done;
EC_GROUP_get_curve_GFp(group, p, a, b, NULL);
if (!EC_GROUP_get_curve_GFp(group, p, a, b, NULL))
goto done;
field_size = (BN_num_bits(p) + 7) / 8;
done:
@@ -121,19 +122,20 @@ int sm2_encrypt(const EC_KEY *key,
uint8_t *msg_mask = NULL;
uint8_t *x2y2 = NULL;
uint8_t *C3 = NULL;
const size_t field_size = ec_field_size(group);
const size_t C3_size = EVP_MD_size(digest);
size_t field_size;
const int C3_size = EVP_MD_size(digest);
/* NULL these before any "goto done" */
ctext_struct.C2 = NULL;
ctext_struct.C3 = NULL;
if (hash == NULL
|| group == NULL
|| order == NULL
|| P == NULL
|| field_size == 0
|| C3_size == 0) {
if (hash == NULL || C3_size <= 0) {
SM2err(SM2_F_SM2_ENCRYPT, ERR_R_INTERNAL_ERROR);
goto done;
}
field_size = ec_field_size(group);
if (field_size == 0) {
SM2err(SM2_F_SM2_ENCRYPT, ERR_R_INTERNAL_ERROR);
goto done;
}
@@ -273,7 +275,7 @@ int sm2_decrypt(const EC_KEY *key,
int msg_len = 0;
EVP_MD_CTX *hash = NULL;
if (field_size == 0 || hash_size == 0)
if (field_size == 0 || hash_size <= 0)
goto done;
memset(ptext_buf, 0xFF, *ptext_len);
+7 -6
View File
@@ -25,19 +25,20 @@ static BIGNUM *sm2_compute_msg_hash(const EVP_MD *digest,
{
EVP_MD_CTX *hash = EVP_MD_CTX_new();
const int md_size = EVP_MD_size(digest);
uint8_t *za = OPENSSL_zalloc(md_size);
uint8_t *za = NULL;
BIGNUM *e = NULL;
if (hash == NULL || za == NULL) {
SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, ERR_R_MALLOC_FAILURE);
goto done;
}
if (md_size < 0) {
SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, SM2_R_INVALID_DIGEST);
goto done;
}
za = OPENSSL_zalloc(md_size);
if (hash == NULL || za == NULL) {
SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, ERR_R_MALLOC_FAILURE);
goto done;
}
if (!sm2_compute_userid_digest(za, digest, user_id, key)) {
/* SM2err already called */
goto done;
-2
View File
@@ -59,8 +59,6 @@ int sm2_compute_userid_digest(uint8_t *out,
goto done;
}
memset(out, 0, EVP_MD_size(digest));
if (!EVP_DigestInit(hash, digest)) {
SM2err(SM2_F_SM2_COMPUTE_USERID_DIGEST, ERR_R_EVP_LIB);
goto done;