From a5b727c47bcbb5b0e5be6325b6a350e469fdf127 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Mon, 16 Jan 2017 08:40:11 +0800 Subject: [PATCH] bug fix err, cbcmac --- crypto/cbcmac/cbcmac.c | 8 ++++--- crypto/ec/ec_pmeth.c | 54 +----------------------------------------- crypto/err/err_all.c | 2 +- crypto/opensslv.h | 4 ++-- crypto/sms4/sms4_enc.c | 2 +- 5 files changed, 10 insertions(+), 60 deletions(-) diff --git a/crypto/cbcmac/cbcmac.c b/crypto/cbcmac/cbcmac.c index 87983bb3..b22ede58 100644 --- a/crypto/cbcmac/cbcmac.c +++ b/crypto/cbcmac/cbcmac.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -53,7 +54,7 @@ int CBCMAC_CTX_copy(CBCMAC_CTX *to, const CBCMAC_CTX *from) int CBCMAC_Init(CBCMAC_CTX *ctx, const void *key, size_t keylen, const EVP_CIPHER *cipher, ENGINE *eng) { - int i, block_size; + int block_size; if (!EVP_EncryptInit_ex(&ctx->cipher_ctx, cipher, eng, key, NULL)) { CBCMACerr(CBCMAC_F_CBCMAC_INIT, CBCMAC_R_CIPHER_CTX_INIT_FAILED); @@ -123,14 +124,14 @@ int CBCMAC_Update(CBCMAC_CTX *ctx, const void *data, size_t datalen) int CBCMAC_Final(CBCMAC_CTX *ctx, unsigned char *out, size_t *outlen) { - int i; + int i, len; int block_size = EVP_CIPHER_CTX_block_size(&(ctx->cipher_ctx)); if (ctx->worklen) { for (i = ctx->worklen; i < block_size; i++) { ctx->workspace[i] = ctx->cbcstate[i]; } - if (!EVP_EncryptUpdate(&(ctx->cipher_ctx), out, outlen, ctx->workspace, block_size)) { + if (!EVP_EncryptUpdate(&(ctx->cipher_ctx), out, &len, ctx->workspace, block_size)) { CBCMACerr(CBCMAC_F_CBCMAC_FINAL, ERR_R_EVP_LIB); return 0; } @@ -141,6 +142,7 @@ int CBCMAC_Final(CBCMAC_CTX *ctx, unsigned char *out, size_t *outlen) } } + *outlen = block_size; return 1; } diff --git a/crypto/ec/ec_pmeth.c b/crypto/ec/ec_pmeth.c index b4aa4083..fc802cc2 100644 --- a/crypto/ec/ec_pmeth.c +++ b/crypto/ec/ec_pmeth.c @@ -250,38 +250,8 @@ static int pkey_ec_verify(EVP_PKEY_CTX *ctx, return ret; } -static int int_update(EVP_MD_CTX *ctx, const void *data, size_t count) -{ - if (!EVP_DigestUpdate(ctx, data, count)) - return 0; - return 1; -} - static int pkey_ec_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx) { - EC_PKEY_CTX *dctx = ctx->data; - EC_KEY *ec_key = ctx->pkey->pkey.ec; - const EVP_MD *md = EVP_sm3(); - unsigned char zid[EVP_MAX_MD_SIZE]; - unsigned int zidlen = sizeof(zid); - - //FIXME: it is wrong to do it here! -#if 0 - if (dctx->sign_type == NID_sm_scheme) { - if (!SM2_compute_id_digest(md, zid, &zidlen, ec_key)) { - ECerr(EC_F_PKEY_EC_SIGNCTX_INIT, ERR_R_SM2_LIB); - return 0; - } - - mctx->update = int_update; - - if (!mctx->update(mctx, zid, zidlen)) { - ECerr(EC_F_PKEY_EC_SIGNCTX_INIT, ERR_R_EVP_LIB); - return 0; - } - } -#endif - return 1; } @@ -324,29 +294,7 @@ static int pkey_ec_signctx(EVP_PKEY_CTX *ctx, static int pkey_ec_verifyctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx) { - int ret = 0; - EC_PKEY_CTX *dctx = ctx->data; - EC_KEY *ec_key = ctx->pkey->pkey.ec; - const EVP_MD *md = EVP_sm3(); // FIXME: we need to get md from somewhere - unsigned char zid[EVP_MAX_MD_SIZE]; - unsigned int zidlen; - -#if 0 - if (dctx->sign_type == NID_sm_scheme) { - - zidlen = sizeof(zid); - if (!SM2_compute_id_digest(md, zid, &zidlen, ec_key)) { - goto end; - } - if (!mctx->update(mctx, zid, zidlen)) { - goto end; - } - } -#endif - - ret = 1; -end: - return ret; + return 1; } static int pkey_ec_verifyctx(EVP_PKEY_CTX *ctx, diff --git a/crypto/err/err_all.c b/crypto/err/err_all.c index c72f18a2..9a59440f 100644 --- a/crypto/err/err_all.c +++ b/crypto/err/err_all.c @@ -110,7 +110,7 @@ #ifndef NO_GMSSL # include -# include +# include # include # include # include diff --git a/crypto/opensslv.h b/crypto/opensslv.h index 792b5409..dce92aa9 100644 --- a/crypto/opensslv.h +++ b/crypto/opensslv.h @@ -32,9 +32,9 @@ extern "C" { */ # define OPENSSL_VERSION_NUMBER 0x10201000L # ifdef OPENSSL_FIPS -# define OPENSSL_VERSION_TEXT "OpenSSL 1.0.2d-fips 9 Jul 2015" +# define OPENSSL_VERSION_TEXT "GmSSL 1.3.0 - OpenSSL 1.0.2d-fips 9 Jul 2015" # else -# define OPENSSL_VERSION_TEXT "GmSSL 1.2.2 (OpenSSL 1.0.2d)" +# define OPENSSL_VERSION_TEXT "GmSSL 1.3.0 - OpenSSL 1.0.2d" # endif # define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT diff --git a/crypto/sms4/sms4_enc.c b/crypto/sms4/sms4_enc.c index 12796440..b422c8c5 100644 --- a/crypto/sms4/sms4_enc.c +++ b/crypto/sms4/sms4_enc.c @@ -66,7 +66,7 @@ void sms4_encrypt(const unsigned char *in, unsigned char *out, const sms4_key_t *key) { - uint32_t *rk = key->rk; + const uint32_t *rk = key->rk; uint32_t x0, x1, x2, x3, x4; x0 = GET32(in );