mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
bug fix
err, cbcmac
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/cbcmac.h>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
|
||||
#ifndef NO_GMSSL
|
||||
# include <openssl/sm2.h>
|
||||
# include <openssl/skf.h>
|
||||
# include <openssl/skf_ex.h>
|
||||
# include <openssl/cpk.h>
|
||||
# include <openssl/ecies.h>
|
||||
# include <openssl/cbcmac.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
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user