From eedbb6bb8e640fe0e3d9afa91e874d544f9afa04 Mon Sep 17 00:00:00 2001 From: cuihongpeng Date: Thu, 23 Aug 2018 17:58:24 +0800 Subject: [PATCH 1/2] sm2: fix cv free error, in o2i_SM2CiphertextValue() function --- crypto/sm2/sm2_oct.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) mode change 100644 => 100755 crypto/sm2/sm2_oct.c diff --git a/crypto/sm2/sm2_oct.c b/crypto/sm2/sm2_oct.c old mode 100644 new mode 100755 index 6f951e77..f9ca4cfb --- a/crypto/sm2/sm2_oct.c +++ b/crypto/sm2/sm2_oct.c @@ -274,7 +274,9 @@ SM2CiphertextValue *o2i_SM2CiphertextValue(const EC_GROUP *group, ret = cv; end: - SM2CiphertextValue_free(cv); + if ((cv != *pout) && (!ret)) + SM2CiphertextValue_free(cv); + EC_POINT_free(point); BN_CTX_free(bn_ctx); return ret; From 41049aa0cd79dc0682bb2a852a6d54853407f837 Mon Sep 17 00:00:00 2001 From: zhaoxincheng Date: Thu, 30 Aug 2018 16:37:25 +0800 Subject: [PATCH 2/2] fix sm3 padding bug --- crypto/sm3/sm3.c | 4 ++-- include/openssl/sm3.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 crypto/sm3/sm3.c mode change 100644 => 100755 include/openssl/sm3.h diff --git a/crypto/sm3/sm3.c b/crypto/sm3/sm3.c old mode 100644 new mode 100755 index 17994f94..fdbcab1f --- a/crypto/sm3/sm3.c +++ b/crypto/sm3/sm3.c @@ -110,8 +110,8 @@ void sm3_final(sm3_ctx_t *ctx, unsigned char *digest) memset(ctx->block, 0, SM3_BLOCK_SIZE - 8); } - count[0] = cpu_to_be32((ctx->nblocks) >> 23); - count[1] = cpu_to_be32((ctx->nblocks << 9) + (ctx->num << 3)); + count[0] = cpu_to_be32((uint32_t)(ctx->nblocks >> 23)); + count[1] = cpu_to_be32((uint32_t)(ctx->nblocks << 9) + (ctx->num << 3)); sm3_compress(ctx->digest, ctx->block); for (i = 0; i < sizeof(ctx->digest)/sizeof(ctx->digest[0]); i++) { diff --git a/include/openssl/sm3.h b/include/openssl/sm3.h old mode 100644 new mode 100755 index 29ce397b..96ef60f2 --- a/include/openssl/sm3.h +++ b/include/openssl/sm3.h @@ -70,7 +70,7 @@ extern "C" { typedef struct { uint32_t digest[8]; - int nblocks; + uint64_t nblocks; unsigned char block[64]; int num; } sm3_ctx_t;