mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-22 21:23:56 +08:00
Bug fix
Thanks to github.com/Jkinglyf
This commit is contained in:
@@ -1299,6 +1299,10 @@ void ERR_load_EC_strings(void);
|
||||
# define EC_R_D2I_ECPKPARAMETERS_FAILURE 117
|
||||
# define EC_R_DECODE_ERROR 142
|
||||
# define EC_R_DISCRIMINANT_IS_ZERO 118
|
||||
# define EC_R_ECIES_DECRYPT_FAILED 152
|
||||
# define EC_R_ECIES_DECRYPT_WITH_RECOMMENDED_FAILED 153
|
||||
# define EC_R_ECIES_ENCRYPT_FAILED 154
|
||||
# define EC_R_ECIES_ENCRYPT_WITH_RECOMMENDED_FAILED 155
|
||||
# define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 119
|
||||
# define EC_R_FIELD_TOO_LARGE 143
|
||||
# define EC_R_GF2M_NOT_SUPPORTED 147
|
||||
@@ -1312,6 +1316,7 @@ void ERR_load_EC_strings(void);
|
||||
# define EC_R_INVALID_DIGEST 151
|
||||
# define EC_R_INVALID_DIGEST_TYPE 138
|
||||
# define EC_R_INVALID_ENCODING 102
|
||||
# define EC_R_INVALID_ENC_TYPE 156
|
||||
# define EC_R_INVALID_FIELD 103
|
||||
# define EC_R_INVALID_FORM 104
|
||||
# define EC_R_INVALID_GROUP_ORDER 122
|
||||
@@ -1335,6 +1340,10 @@ void ERR_load_EC_strings(void);
|
||||
# define EC_R_POINT_IS_NOT_ON_CURVE 107
|
||||
# define EC_R_SHARED_INFO_ERROR 150
|
||||
# define EC_R_SLOT_FULL 108
|
||||
# define EC_R_SM2_DECRYPT_FAILED 157
|
||||
# define EC_R_SM2_DECRYPT_WITH_RECOMMENDED_FAILED 158
|
||||
# define EC_R_SM2_ENCRYPT_FAILED 159
|
||||
# define EC_R_SM2_ENCRYPT_WITH_RECOMMENDED_FAILED 160
|
||||
# define EC_R_UNDEFINED_GENERATOR 113
|
||||
# define EC_R_UNDEFINED_ORDER 128
|
||||
# define EC_R_UNKNOWN_GROUP 129
|
||||
|
||||
@@ -288,6 +288,12 @@ static ERR_STRING_DATA EC_str_reasons[] = {
|
||||
"d2i ecpkparameters failure"},
|
||||
{ERR_REASON(EC_R_DECODE_ERROR), "decode error"},
|
||||
{ERR_REASON(EC_R_DISCRIMINANT_IS_ZERO), "discriminant is zero"},
|
||||
{ERR_REASON(EC_R_ECIES_DECRYPT_FAILED), "ecies decrypt failed"},
|
||||
{ERR_REASON(EC_R_ECIES_DECRYPT_WITH_RECOMMENDED_FAILED),
|
||||
"ecies decrypt with recommended failed"},
|
||||
{ERR_REASON(EC_R_ECIES_ENCRYPT_FAILED), "ecies encrypt failed"},
|
||||
{ERR_REASON(EC_R_ECIES_ENCRYPT_WITH_RECOMMENDED_FAILED),
|
||||
"ecies encrypt with recommended failed"},
|
||||
{ERR_REASON(EC_R_EC_GROUP_NEW_BY_NAME_FAILURE),
|
||||
"ec group new by name failure"},
|
||||
{ERR_REASON(EC_R_FIELD_TOO_LARGE), "field too large"},
|
||||
@@ -304,6 +310,7 @@ static ERR_STRING_DATA EC_str_reasons[] = {
|
||||
{ERR_REASON(EC_R_INVALID_DIGEST), "invalid digest"},
|
||||
{ERR_REASON(EC_R_INVALID_DIGEST_TYPE), "invalid digest type"},
|
||||
{ERR_REASON(EC_R_INVALID_ENCODING), "invalid encoding"},
|
||||
{ERR_REASON(EC_R_INVALID_ENC_TYPE), "invalid enc type"},
|
||||
{ERR_REASON(EC_R_INVALID_FIELD), "invalid field"},
|
||||
{ERR_REASON(EC_R_INVALID_FORM), "invalid form"},
|
||||
{ERR_REASON(EC_R_INVALID_GROUP_ORDER), "invalid group order"},
|
||||
@@ -329,6 +336,12 @@ static ERR_STRING_DATA EC_str_reasons[] = {
|
||||
{ERR_REASON(EC_R_POINT_IS_NOT_ON_CURVE), "point is not on curve"},
|
||||
{ERR_REASON(EC_R_SHARED_INFO_ERROR), "shared info error"},
|
||||
{ERR_REASON(EC_R_SLOT_FULL), "slot full"},
|
||||
{ERR_REASON(EC_R_SM2_DECRYPT_FAILED), "sm2 decrypt failed"},
|
||||
{ERR_REASON(EC_R_SM2_DECRYPT_WITH_RECOMMENDED_FAILED),
|
||||
"sm2 decrypt with recommended failed"},
|
||||
{ERR_REASON(EC_R_SM2_ENCRYPT_FAILED), "sm2 encrypt failed"},
|
||||
{ERR_REASON(EC_R_SM2_ENCRYPT_WITH_RECOMMENDED_FAILED),
|
||||
"sm2 encrypt with recommended failed"},
|
||||
{ERR_REASON(EC_R_UNDEFINED_GENERATOR), "undefined generator"},
|
||||
{ERR_REASON(EC_R_UNDEFINED_ORDER), "undefined order"},
|
||||
{ERR_REASON(EC_R_UNKNOWN_GROUP), "unknown group"},
|
||||
|
||||
@@ -195,7 +195,7 @@ static int pkey_ec_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
|
||||
dctx->sign_type != NID_sm_scheme) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (dctx->md)
|
||||
type = EVP_MD_type(dctx->md);
|
||||
else if (dctx->sign_type == NID_secg_scheme)
|
||||
@@ -324,7 +324,7 @@ static int pkey_ec_verifyctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
|
||||
|
||||
|
||||
if (dctx->sign_type == NID_sm_scheme) {
|
||||
|
||||
|
||||
zidlen = sizeof(zid);
|
||||
if (!SM2_compute_id_digest(md, zid, &zidlen, ec_key)) {
|
||||
goto end;
|
||||
@@ -369,55 +369,87 @@ static int pkey_ec_verifyctx(EVP_PKEY_CTX *ctx,
|
||||
static int pkey_ec_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen)
|
||||
{
|
||||
int ret = 0;
|
||||
EC_PKEY_CTX *dctx = ctx->data;
|
||||
EC_KEY *ec_key = ctx->pkey->pkey.ec;
|
||||
|
||||
switch (dctx->enc_type) {
|
||||
case NID_sm_scheme:
|
||||
if (dctx->enc_param.sm2) {
|
||||
ret = SM2_encrypt(dctx->enc_param.sm2, out, outlen, in, inlen, ec_key);
|
||||
if (!SM2_encrypt(dctx->enc_param.sm2, out, outlen, in, inlen, ec_key)) {
|
||||
ECerr(EC_F_PKEY_EC_ENCRYPT, EC_R_SM2_ENCRYPT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
ret = SM2_encrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
if (!SM2_encrypt_with_recommended(out, outlen, in, inlen, ec_key)) {
|
||||
ECerr(EC_F_PKEY_EC_ENCRYPT, EC_R_SM2_ENCRYPT_WITH_RECOMMENDED_FAILED);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NID_secg_scheme:
|
||||
if (dctx->enc_param.ecies) {
|
||||
ret = ECIES_encrypt(dctx->enc_param.ecies, out, outlen, in, inlen, ec_key);
|
||||
if (!ECIES_encrypt(dctx->enc_param.ecies, out, outlen, in, inlen, ec_key)) {
|
||||
ECerr(EC_F_PKEY_EC_ENCRYPT, EC_R_ECIES_ENCRYPT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
ret = ECIES_encrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
if (!ECIES_encrypt_with_recommended(out, outlen, in, inlen, ec_key)) {
|
||||
ECerr(EC_F_PKEY_EC_ENCRYPT, EC_R_ECIES_ENCRYPT_WITH_RECOMMENDED_FAILED);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ECerr(EC_F_PKEY_EC_ENCRYPT, EC_R_INVALID_ENC_TYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pkey_ec_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen)
|
||||
{
|
||||
int ret;
|
||||
EC_PKEY_CTX *dctx = ctx->data;
|
||||
EC_KEY *ec_key = ctx->pkey->pkey.ec;
|
||||
|
||||
switch (dctx->enc_type) {
|
||||
case NID_sm_scheme:
|
||||
if (dctx->enc_param.sm2) {
|
||||
ret = SM2_decrypt(dctx->enc_param.sm2, out, outlen, in, inlen, ec_key);
|
||||
if (!SM2_decrypt(dctx->enc_param.sm2, out, outlen, in, inlen, ec_key)) {
|
||||
ECerr(EC_F_PKEY_EC_DECRYPT, EC_R_SM2_DECRYPT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
ret = SM2_decrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
if (!SM2_decrypt_with_recommended(out, outlen, in, inlen, ec_key)) {
|
||||
ECerr(EC_F_PKEY_EC_DECRYPT, EC_R_SM2_DECRYPT_WITH_RECOMMENDED_FAILED);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NID_secg_scheme:
|
||||
if (dctx->enc_param.ecies) {
|
||||
ret = ECIES_decrypt(dctx->enc_param.ecies, out, outlen, in, inlen, ec_key);
|
||||
if (dctx->enc_param.ecies) {
|
||||
if (!ECIES_decrypt(dctx->enc_param.ecies, out, outlen, in, inlen, ec_key)) {
|
||||
ECerr(EC_F_PKEY_EC_DECRYPT, EC_R_ECIES_DECRYPT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
ret = ECIES_decrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
if (!ECIES_decrypt_with_recommended(out, outlen, in, inlen, ec_key)) {
|
||||
ECerr(EC_F_PKEY_EC_DECRYPT, EC_R_ECIES_DECRYPT_WITH_RECOMMENDED_FAILED);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ECerr(EC_F_PKEY_EC_DECRYPT, EC_R_INVALID_ENC_TYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_ECDH
|
||||
@@ -680,7 +712,6 @@ static int pkey_ec_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||
ECerr(EC_F_PKEY_EC_CTRL_STR, EC_R_INVALID_CURVE);
|
||||
return 0;
|
||||
}
|
||||
printf("curve = %s\n", value);
|
||||
return EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid);
|
||||
} else if (!strcmp(type, "ec_param_enc")) {
|
||||
int param_enc;
|
||||
|
||||
Reference in New Issue
Block a user