mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-22 16:26:28 +08:00
Bug fix
Thanks to github.com/Jkinglyf
This commit is contained in:
@@ -1422,8 +1422,10 @@ void ERR_load_EVP_strings(void);
|
||||
# define EVP_F_EVP_CIPHER_CTX_CTRL 124
|
||||
# define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122
|
||||
# define EVP_F_EVP_DECRYPTFINAL_EX 101
|
||||
# define EVP_F_EVP_DECRYPT_EX 201
|
||||
# define EVP_F_EVP_DIGESTINIT_EX 128
|
||||
# define EVP_F_EVP_ENCRYPTFINAL_EX 127
|
||||
# define EVP_F_EVP_ENCRYPT_EX 200
|
||||
# define EVP_F_EVP_MD_CTX_COPY_EX 110
|
||||
# define EVP_F_EVP_MD_SIZE 162
|
||||
# define EVP_F_EVP_OPENINIT 102
|
||||
@@ -1481,11 +1483,6 @@ void ERR_load_EVP_strings(void);
|
||||
# define EVP_F_RC2_MAGIC_TO_METH 109
|
||||
# define EVP_F_RC5_CTRL 125
|
||||
|
||||
# ifndef OPENSSL_NO_GMSSL
|
||||
# define EVP_F_EVP_ENCRYPT_EX 200
|
||||
# define EVP_F_EVP_DECRYPT_EX 201
|
||||
# endif
|
||||
|
||||
/* Reason codes. */
|
||||
# define EVP_R_AES_IV_SETUP_FAILED 162
|
||||
# define EVP_R_AES_KEY_SETUP_FAILED 143
|
||||
@@ -1541,6 +1538,7 @@ void ERR_load_EVP_strings(void);
|
||||
# define EVP_R_PRIVATE_KEY_DECODE_ERROR 145
|
||||
# define EVP_R_PRIVATE_KEY_ENCODE_ERROR 146
|
||||
# define EVP_R_PUBLIC_KEY_NOT_RSA 106
|
||||
# define EVP_R_RSA_PUBLIC_ENCRYPT_FAILED 171
|
||||
# define EVP_R_TOO_LARGE 164
|
||||
# define EVP_R_UNKNOWN_CIPHER 160
|
||||
# define EVP_R_UNKNOWN_DIGEST 161
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* crypto/evp/evp_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2013 The OpenSSL Project. All rights reserved.
|
||||
* Copyright (c) 1999-2016 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -92,8 +92,10 @@ static ERR_STRING_DATA EVP_str_functs[] = {
|
||||
{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH),
|
||||
"EVP_CIPHER_CTX_set_key_length"},
|
||||
{ERR_FUNC(EVP_F_EVP_DECRYPTFINAL_EX), "EVP_DecryptFinal_ex"},
|
||||
{ERR_FUNC(EVP_F_EVP_DECRYPT_EX), "EVP_Decrypt_ex"},
|
||||
{ERR_FUNC(EVP_F_EVP_DIGESTINIT_EX), "EVP_DigestInit_ex"},
|
||||
{ERR_FUNC(EVP_F_EVP_ENCRYPTFINAL_EX), "EVP_EncryptFinal_ex"},
|
||||
{ERR_FUNC(EVP_F_EVP_ENCRYPT_EX), "EVP_Encrypt_ex"},
|
||||
{ERR_FUNC(EVP_F_EVP_MD_CTX_COPY_EX), "EVP_MD_CTX_copy_ex"},
|
||||
{ERR_FUNC(EVP_F_EVP_MD_SIZE), "EVP_MD_size"},
|
||||
{ERR_FUNC(EVP_F_EVP_OPENINIT), "EVP_OpenInit"},
|
||||
@@ -152,10 +154,6 @@ static ERR_STRING_DATA EVP_str_functs[] = {
|
||||
{ERR_FUNC(EVP_F_PKEY_SET_TYPE), "PKEY_SET_TYPE"},
|
||||
{ERR_FUNC(EVP_F_RC2_MAGIC_TO_METH), "RC2_MAGIC_TO_METH"},
|
||||
{ERR_FUNC(EVP_F_RC5_CTRL), "RC5_CTRL"},
|
||||
#ifndef OPENSSL_NO_GMSSL
|
||||
{ERR_FUNC(EVP_F_EVP_ENCRYPT_EX), "EVP_Encrypt_ex"},
|
||||
{ERR_FUNC(EVP_F_EVP_DECRYPT_EX), "EVP_Decrypt_ex"},
|
||||
#endif
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
@@ -169,8 +167,7 @@ static ERR_STRING_DATA EVP_str_reasons[] = {
|
||||
{ERR_REASON(EVP_R_BN_DECODE_ERROR), "bn decode error"},
|
||||
{ERR_REASON(EVP_R_BN_PUBKEY_ERROR), "bn pubkey error"},
|
||||
{ERR_REASON(EVP_R_BUFFER_TOO_SMALL), "buffer too small"},
|
||||
{ERR_REASON(EVP_R_CAMELLIA_KEY_SETUP_FAILED),
|
||||
"camellia key setup failed"},
|
||||
{ERR_REASON(EVP_R_CAMELLIA_KEY_SETUP_FAILED), "camellia key setup failed"},
|
||||
{ERR_REASON(EVP_R_CIPHER_PARAMETER_ERROR), "cipher parameter error"},
|
||||
{ERR_REASON(EVP_R_COMMAND_NOT_SUPPORTED), "command not supported"},
|
||||
{ERR_REASON(EVP_R_CTRL_NOT_IMPLEMENTED), "ctrl not implemented"},
|
||||
@@ -216,11 +213,11 @@ static ERR_STRING_DATA EVP_str_reasons[] = {
|
||||
{ERR_REASON(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE),
|
||||
"operation not supported for this keytype"},
|
||||
{ERR_REASON(EVP_R_OPERATON_NOT_INITIALIZED), "operaton not initialized"},
|
||||
{ERR_REASON(EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE),
|
||||
"pkcs8 unknown broken type"},
|
||||
{ERR_REASON(EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE), "pkcs8 unknown broken type"},
|
||||
{ERR_REASON(EVP_R_PRIVATE_KEY_DECODE_ERROR), "private key decode error"},
|
||||
{ERR_REASON(EVP_R_PRIVATE_KEY_ENCODE_ERROR), "private key encode error"},
|
||||
{ERR_REASON(EVP_R_PUBLIC_KEY_NOT_RSA), "public key not rsa"},
|
||||
{ERR_REASON(EVP_R_RSA_PUBLIC_ENCRYPT_FAILED), "rsa public encrypt failed"},
|
||||
{ERR_REASON(EVP_R_TOO_LARGE), "too large"},
|
||||
{ERR_REASON(EVP_R_UNKNOWN_CIPHER), "unknown cipher"},
|
||||
{ERR_REASON(EVP_R_UNKNOWN_DIGEST), "unknown digest"},
|
||||
|
||||
@@ -75,16 +75,29 @@ int EVP_PKEY_encrypt_old(unsigned char *out, const unsigned char *in,
|
||||
size_t size;
|
||||
|
||||
if (pkey->type == EVP_PKEY_RSA) {
|
||||
ret = RSA_public_encrypt(inlen, in, out, pkey->pkey.rsa,
|
||||
RSA_PKCS1_PADDING);
|
||||
if ((ret = RSA_public_encrypt(inlen, in, out, pkey->pkey.rsa,
|
||||
RSA_PKCS1_PADDING)) < 0) {
|
||||
EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD,
|
||||
EVP_R_RSA_PUBLIC_ENCRYPT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (!(ctx = EVP_PKEY_CTX_new(pkey, NULL))) {
|
||||
EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD, ERR_R_EVP_LIB);
|
||||
return 0;
|
||||
}
|
||||
if (1 != EVP_PKEY_encrypt_init(ctx)) {
|
||||
if (!EVP_PKEY_encrypt_init(ctx)) {
|
||||
EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD, ERR_R_EVP_LIB);
|
||||
return 0;
|
||||
}
|
||||
if (1 != EVP_PKEY_encrypt(ctx, out, &size, in, inlen)) {
|
||||
if (!EVP_PKEY_CTX_set_ec_enc_type(ctx, NID_sm_scheme)) {
|
||||
EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
}
|
||||
/* FIXME: this old API lost input buffer length */
|
||||
size = inlen + 256;
|
||||
if (!EVP_PKEY_encrypt(ctx, out, &size, in, inlen)) {
|
||||
EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
}
|
||||
ret = (int)size;
|
||||
|
||||
@@ -82,12 +82,13 @@ int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
|
||||
if (!priv)
|
||||
return 1;
|
||||
|
||||
if (priv->type != EVP_PKEY_RSA) {
|
||||
if ((EVP_PKEY_base_id(priv) != EVP_PKEY_RSA) &&
|
||||
(EVP_PKEY_base_id(priv) != EVP_PKEY_EC)) {
|
||||
EVPerr(EVP_F_EVP_OPENINIT, EVP_R_PUBLIC_KEY_NOT_RSA);
|
||||
goto err;
|
||||
}
|
||||
|
||||
size = RSA_size(priv->pkey.rsa);
|
||||
size = EVP_PKEY_size(priv);
|
||||
key = (unsigned char *)OPENSSL_malloc(size + 2);
|
||||
if (key == NULL) {
|
||||
/* ERROR */
|
||||
|
||||
Reference in New Issue
Block a user