mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-08 06:03:47 +08:00
first step of v2 final release
This commit is contained in:
@@ -15,7 +15,7 @@ SOURCE[../../libcrypto]=\
|
||||
e_chacha20_poly1305.c cmeth_lib.c \
|
||||
m_sm3.c \
|
||||
e_sms4.c e_sms4_ccm.c e_sms4_gcm.c e_sms4_ocb.c e_sms4_wrap.c e_sms4_xts.c \
|
||||
evp_ctxt.c
|
||||
evp_ctxt.c names2.c evp_nomacro.c
|
||||
|
||||
INCLUDE[e_aes.o]=.. ../modes
|
||||
INCLUDE[e_aes_cbc_hmac_sha1.o]=../modes
|
||||
|
||||
@@ -49,8 +49,10 @@ void openssl_add_all_ciphers_int(void)
|
||||
EVP_add_cipher(EVP_des_ede3());
|
||||
EVP_add_cipher_alias(SN_des_ede3_ecb, "DES-EDE3-ECB");
|
||||
EVP_add_cipher_alias(SN_des_ede3_ecb, "des-ede3-ecb");
|
||||
# ifndef OPENSSL_NO_SHA
|
||||
EVP_add_cipher(EVP_des_ede3_wrap());
|
||||
EVP_add_cipher_alias(SN_id_smime_alg_CMS3DESwrap, "des3-wrap");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_RC4
|
||||
@@ -177,6 +179,8 @@ void openssl_add_all_ciphers_int(void)
|
||||
EVP_add_cipher(EVP_aes_256_wrap_pad());
|
||||
EVP_add_cipher_alias(SN_aes_256_cbc, "AES256");
|
||||
EVP_add_cipher_alias(SN_aes_256_cbc, "aes256");
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_AES) && !defined(OPENSSL_NO_SHA)
|
||||
EVP_add_cipher(EVP_aes_128_cbc_hmac_sha1());
|
||||
EVP_add_cipher(EVP_aes_256_cbc_hmac_sha1());
|
||||
EVP_add_cipher(EVP_aes_128_cbc_hmac_sha256());
|
||||
|
||||
@@ -22,9 +22,11 @@ void openssl_add_all_digests_int(void)
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
EVP_add_digest(EVP_md5());
|
||||
EVP_add_digest_alias(SN_md5, "ssl3-md5");
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_SHA)
|
||||
EVP_add_digest(EVP_md5_sha1());
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SHA1
|
||||
#ifndef OPENSSL_NO_SHA
|
||||
EVP_add_digest(EVP_sha1());
|
||||
EVP_add_digest_alias(SN_sha1, "ssl3-sha1");
|
||||
EVP_add_digest_alias(SN_sha1WithRSAEncryption, SN_sha1WithRSA);
|
||||
@@ -37,11 +39,15 @@ void openssl_add_all_digests_int(void)
|
||||
EVP_add_digest_alias(SN_ripemd160, "ripemd");
|
||||
EVP_add_digest_alias(SN_ripemd160, "rmd160");
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SHA1
|
||||
#ifndef OPENSSL_NO_SHA
|
||||
# ifndef OPENSSL_NO_SHA256
|
||||
EVP_add_digest(EVP_sha224());
|
||||
EVP_add_digest(EVP_sha256());
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_SHA512
|
||||
EVP_add_digest(EVP_sha384());
|
||||
EVP_add_digest(EVP_sha512());
|
||||
# endif
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_WHIRLPOOL
|
||||
EVP_add_digest(EVP_whirlpool());
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
#include <openssl/engine.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
# include <openssl/sm2.h>
|
||||
#endif
|
||||
|
||||
/* This call frees resources associated with the context */
|
||||
int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
|
||||
@@ -146,13 +149,13 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
if (!ctx->is_updated && ctx->pctx && ctx->pctx->pre_update) {
|
||||
if (!ctx->update(ctx, ctx->pctx->pre_update,
|
||||
ctx->pctx->pre_update_len)) {
|
||||
return 0;
|
||||
if (ctx->pctx && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_UPDATED)) {
|
||||
const unsigned char *zid;
|
||||
if (1 == EVP_PKEY_CTX_get_signer_zid(ctx->pctx, &zid)) {
|
||||
ctx->update(ctx, zid, 32);
|
||||
}
|
||||
EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_UPDATED);
|
||||
}
|
||||
ctx->is_updated = 1;
|
||||
#endif
|
||||
return ctx->update(ctx, data, count);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#ifdef OPENSSL_NO_AES
|
||||
#if defined(OPENSSL_NO_AES) || defined(OPENSSL_NO_SHA)
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#ifdef OPENSSL_NO_AES
|
||||
#if defined(OPENSSL_NO_AES) || defined(OPENSSL_NO_SHA)
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
|
||||
@@ -307,8 +307,8 @@ const EVP_CIPHER *EVP_des_ede3(void)
|
||||
return &des_ede3_ecb;
|
||||
}
|
||||
|
||||
|
||||
# include <openssl/sha.h>
|
||||
# ifndef OPENSSL_NO_SHA
|
||||
# include <openssl/sha.h>
|
||||
|
||||
static const unsigned char wrap_iv[8] =
|
||||
{ 0x4a, 0xdd, 0xa2, 0x2c, 0x79, 0xe8, 0x21, 0x05 };
|
||||
@@ -420,5 +420,5 @@ const EVP_CIPHER *EVP_des_ede3_wrap(void)
|
||||
{
|
||||
return &des3_wrap;
|
||||
}
|
||||
|
||||
# endif /* OPENSSL_NO_SHA */
|
||||
#endif
|
||||
|
||||
@@ -89,25 +89,27 @@ const EVP_CIPHER *EVP_rc5_32_12_16_cfb(void)
|
||||
}
|
||||
# endif
|
||||
|
||||
# undef EVP_aes_128_cfb
|
||||
# ifndef OPENSSL_NO_AES
|
||||
# undef EVP_aes_128_cfb
|
||||
const EVP_CIPHER *EVP_aes_128_cfb(void);
|
||||
const EVP_CIPHER *EVP_aes_128_cfb(void)
|
||||
{
|
||||
return EVP_aes_128_cfb128();
|
||||
}
|
||||
|
||||
# undef EVP_aes_192_cfb
|
||||
# undef EVP_aes_192_cfb
|
||||
const EVP_CIPHER *EVP_aes_192_cfb(void);
|
||||
const EVP_CIPHER *EVP_aes_192_cfb(void)
|
||||
{
|
||||
return EVP_aes_192_cfb128();
|
||||
}
|
||||
|
||||
# undef EVP_aes_256_cfb
|
||||
# undef EVP_aes_256_cfb
|
||||
const EVP_CIPHER *EVP_aes_256_cfb(void);
|
||||
const EVP_CIPHER *EVP_aes_256_cfb(void)
|
||||
{
|
||||
return EVP_aes_256_cfb128();
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -122,7 +122,7 @@ static int sms4_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
|
||||
const EVP_CIPHER sms4_cfb1 = {
|
||||
NID_sms4_cfb1,
|
||||
SMS4_BLOCK_SIZE,
|
||||
1,
|
||||
SMS4_KEY_LENGTH,
|
||||
SMS4_IV_LENGTH,
|
||||
EVP_CIPH_CTR_MODE,
|
||||
@@ -151,7 +151,7 @@ static int sms4_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
|
||||
const EVP_CIPHER sms4_cfb8 = {
|
||||
NID_sms4_cfb8,
|
||||
SMS4_BLOCK_SIZE,
|
||||
1,
|
||||
SMS4_KEY_LENGTH,
|
||||
SMS4_IV_LENGTH,
|
||||
EVP_CIPH_CTR_MODE,
|
||||
@@ -182,7 +182,7 @@ static int sms4_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
|
||||
const EVP_CIPHER sms4_ctr = {
|
||||
NID_sms4_ctr,
|
||||
SMS4_BLOCK_SIZE,
|
||||
1,
|
||||
SMS4_KEY_LENGTH,
|
||||
SMS4_IV_LENGTH,
|
||||
EVP_CIPH_CTR_MODE,
|
||||
|
||||
@@ -136,6 +136,7 @@ static ERR_STRING_DATA EVP_str_reasons[] = {
|
||||
{ERR_REASON(EVP_R_MESSAGE_DIGEST_IS_NULL), "message digest is null"},
|
||||
{ERR_REASON(EVP_R_METHOD_NOT_SUPPORTED), "method not supported"},
|
||||
{ERR_REASON(EVP_R_MISSING_PARAMETERS), "missing parameters"},
|
||||
{ERR_REASON(EVP_R_NO_AVAIABLE_DIGEST), "no avaiable digest"},
|
||||
{ERR_REASON(EVP_R_NO_CIPHER_SET), "no cipher set"},
|
||||
{ERR_REASON(EVP_R_NO_DEFAULT_DIGEST), "no default digest"},
|
||||
{ERR_REASON(EVP_R_NO_DIGEST_SET), "no digest set"},
|
||||
@@ -149,6 +150,7 @@ static ERR_STRING_DATA EVP_str_reasons[] = {
|
||||
{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_PUBLIC_KEY_NOT_RSA_OR_EC), "public key not rsa or ec"},
|
||||
{ERR_REASON(EVP_R_RSA_PUBLIC_ENCRYPT_FAILED),
|
||||
"rsa public encrypt failed"},
|
||||
{ERR_REASON(EVP_R_UNKNOWN_CIPHER), "unknown cipher"},
|
||||
|
||||
@@ -525,6 +525,16 @@ void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx)
|
||||
return ctx->md_data;
|
||||
}
|
||||
|
||||
void *EVP_MD_CTX_set_md_data(EVP_MD_CTX *ctx, void *md_data)
|
||||
{
|
||||
void *old_md_data;
|
||||
|
||||
old_md_data = ctx->md_data;
|
||||
ctx->md_data = md_data;
|
||||
|
||||
return old_md_data;
|
||||
}
|
||||
|
||||
int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx,
|
||||
const void *data, size_t count)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
/* EVP_MD_CTX related stuff */
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
# define EVP_MD_CTX_FLAG_UPDATED 0x0400
|
||||
#endif
|
||||
|
||||
struct evp_md_ctx_st {
|
||||
const EVP_MD *digest;
|
||||
ENGINE *engine; /* functional reference if 'digest' is
|
||||
@@ -19,7 +23,6 @@ struct evp_md_ctx_st {
|
||||
EVP_PKEY_CTX *pctx;
|
||||
/* Update function: usually copied from EVP_MD */
|
||||
int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count);
|
||||
int is_updated;
|
||||
} /* EVP_MD_CTX */ ;
|
||||
|
||||
struct evp_cipher_ctx_st {
|
||||
|
||||
306
crypto/evp/evp_nomacro.c
Normal file
306
crypto/evp/evp_nomacro.c
Normal file
@@ -0,0 +1,306 @@
|
||||
|
||||
|
||||
#ifdef OPENSSL_NO_MACRO
|
||||
# ifndef OPENSSL_NO_RSA
|
||||
int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *rsa)
|
||||
{
|
||||
return EVP_PKEY_assign(pkey, EVP_PKEY_RSA, (char *)rsa);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_NO_DSA
|
||||
int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *dsa)
|
||||
{
|
||||
return EVP_PKEY_assign(pkey, EVP_PKEY_DSA, (char *)dsa);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_NO_DH
|
||||
int EVP_PKEY_assign_DH(EVP_PKEY *pkey, DH *dh)
|
||||
{
|
||||
return EVP_PKEY_assign(pkey, EVP_PKEY_DH, (char *)dh);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_NO_EC
|
||||
int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *ec_key)
|
||||
{
|
||||
return EVP_PKEY_assign(pkey, EVP_PKEY_EC, (char *)ec_key);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_NO_PAILLIER
|
||||
int EVP_PKEY_assign_PAILLIER(EVP_PKEY *pkey, PAILLIER *paillier)
|
||||
{
|
||||
return EVP_PKEY_assign(pkey, EVP_PKEY_PAILLIER, (char *)paillier);
|
||||
}
|
||||
#endif
|
||||
|
||||
const EVP_MD *EVP_get_digestbynid(int nid)
|
||||
{
|
||||
return EVP_get_digestbyname(OBJ_nid2sn(nid));
|
||||
}
|
||||
|
||||
const EVP_MD *EVP_get_digestbyobj(ASN1_OBJECT *obj)
|
||||
{
|
||||
return EVP_get_digestbynid(OBJ_obj2nid(obj));
|
||||
}
|
||||
|
||||
const EVP_CIPHER *EVP_get_cipherbynid(int nid)
|
||||
{
|
||||
return EVP_get_cipherbyname(OBJ_nid2sn(nid));
|
||||
}
|
||||
|
||||
const EVP_CIPHER *EVP_get_cipherbyobj(ASN1_OBJECT *obj)
|
||||
{
|
||||
return EVP_get_cipherbynid(OBJ_obj2nid(obj));
|
||||
}
|
||||
|
||||
int EVP_MD_nid(const EVP_MD *md)
|
||||
{
|
||||
return EVP_MD_type(md);
|
||||
}
|
||||
|
||||
const char *EVP_MD_name(const EVP_MD *md)
|
||||
{
|
||||
return OBJ_nid2sn(EVP_MD_nid(md));
|
||||
}
|
||||
|
||||
int EVP_MD_CTX_size(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return EVP_MD_size(EVP_MD_CTX_md(ctx));
|
||||
}
|
||||
|
||||
int EVP_MD_CTX_block_size(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return EVP_MD_block_size(EVP_MD_CTX_md(ctx));
|
||||
}
|
||||
|
||||
int EVP_MD_CTX_type(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return EVP_MD_type(EVP_MD_CTX_md(ctx));
|
||||
}
|
||||
|
||||
const char *EVP_CIPHER_name(const EVP_CIPHER *cipher)
|
||||
{
|
||||
return OBJ_nid2sn(EVP_CIPHER_nid(cipher));
|
||||
}
|
||||
|
||||
int EVP_CIPHER_mode(const EVP_CIPHER *cipher)
|
||||
{
|
||||
return (EVP_CIPHER_flags(cipher) & EVP_CIPH_MODE);
|
||||
}
|
||||
|
||||
int EVP_CIPHER_CTX_type(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
return EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(ctx));
|
||||
}
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
int EVP_CIPHER_CTX_flags(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
return EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(ctx));
|
||||
}
|
||||
# endif
|
||||
|
||||
int EVP_CIPHER_CTX_mode(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
return EVP_CIPHER_mode(EVP_CIPHER_CTX_cipher(ctx));
|
||||
}
|
||||
|
||||
long EVP_ENCODE_LENGTH(long l)
|
||||
{
|
||||
return (((l+2)/3*4)+(l/48+1)*2+80);
|
||||
}
|
||||
|
||||
long EVP_DECODE_LENGTH(long l)
|
||||
{
|
||||
return ((l+3)/4*3+80);
|
||||
}
|
||||
|
||||
__owur int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type,
|
||||
ENGINE *impl)
|
||||
{
|
||||
return EVP_DigestInit_ex(ctx, type, impl);
|
||||
}
|
||||
|
||||
__owur int EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type)
|
||||
{
|
||||
return EVP_DigestInit(ctx, type);
|
||||
}
|
||||
|
||||
__owur int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt)
|
||||
{
|
||||
return EVP_DigestUpdate(ctx, d, cnt);
|
||||
}
|
||||
|
||||
__owur int EVP_VerifyInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type,
|
||||
ENGINE *impl)
|
||||
{
|
||||
return EVP_DigestInit_ex(ctx, type, impl);
|
||||
}
|
||||
|
||||
__owur int EVP_VerifyInit(EVP_MD_CTX *ctx, const EVP_MD *type)
|
||||
{
|
||||
return EVP_DigestInit(ctx, type);
|
||||
}
|
||||
|
||||
__owur int EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt)
|
||||
{
|
||||
return EVP_DigestUpdate(ctx, d, cnt);
|
||||
}
|
||||
|
||||
/*__owur*/ int EVP_OpenUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
int *outl, const unsigned char *in, int inl)
|
||||
{
|
||||
return EVP_DecryptUpdate(ctx, out, outl, in, inl);
|
||||
}
|
||||
|
||||
/*__owur*/ int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
int *outl, const unsigned char *in, int inl)
|
||||
{
|
||||
return EVP_EncryptUpdate(ctx, out, outl, in, inl);
|
||||
}
|
||||
|
||||
__owur int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt)
|
||||
{
|
||||
return EVP_DigestUpdate(ctx, d, cnt);
|
||||
}
|
||||
|
||||
__owur int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt)
|
||||
{
|
||||
return EVP_DigestUpdate(ctx, d, cnt);
|
||||
}
|
||||
|
||||
long BIO_get_md(BIO *bio, const EVP_MD **pmd)
|
||||
{
|
||||
return BIO_ctrl(bio,BIO_C_GET_MD,0,(char *)pmd);
|
||||
}
|
||||
|
||||
long BIO_get_md_ctx(BIO *bio, EVP_MD_CTX **pmctx)
|
||||
{
|
||||
return BIO_ctrl(bio,BIO_C_GET_MD_CTX,0,(char *)pmctx);
|
||||
}
|
||||
|
||||
long BIO_set_md_ctx(BIO *bio, EVP_MD_CTX *mctx)
|
||||
{
|
||||
return BIO_ctrl(bio,BIO_C_SET_MD_CTX,0,(char *)mctx);
|
||||
}
|
||||
|
||||
long BIO_get_cipher_status(BIO *bio)
|
||||
{
|
||||
return BIO_ctrl(bio,BIO_C_GET_CIPHER_STATUS,0,NULL);
|
||||
}
|
||||
|
||||
long BIO_get_cipher_ctx(BIO *bio, EVP_CIPHER_CTX *pcctx)
|
||||
{
|
||||
return BIO_ctrl(bio,BIO_C_GET_CIPHER_CTX,0,(char *)pcctx)
|
||||
}
|
||||
|
||||
int EVP_add_cipher_alias(int type, const char *alias)
|
||||
{
|
||||
return OBJ_NAME_add(alias,
|
||||
OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS, type);
|
||||
}
|
||||
|
||||
int EVP_add_digest_alias(int type, const char *alias)
|
||||
{
|
||||
return OBJ_NAME_add(alias,
|
||||
OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS, type);
|
||||
}
|
||||
|
||||
int EVP_delete_cipher_alias(const char *alias)
|
||||
{
|
||||
return OBJ_NAME_remove(alias,
|
||||
OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
|
||||
}
|
||||
|
||||
int EVP_delete_digest_alias(const char *alias)
|
||||
{
|
||||
return OBJ_NAME_remove(alias,
|
||||
OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
|
||||
}
|
||||
|
||||
EVP_MD_CTX *EVP_MD_CTX_create(void)
|
||||
{
|
||||
return EVP_MD_CTX_new();
|
||||
}
|
||||
int EVP_MD_CTX_init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return EVP_MD_CTX_reset(ctx);
|
||||
}
|
||||
|
||||
void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
|
||||
{
|
||||
EVP_MD_CTX_free(ctx);
|
||||
}
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
int EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
return EVP_CIPHER_CTX_reset(ctx);
|
||||
}
|
||||
|
||||
int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
return EVP_CIPHER_CTX_reset(ctx);
|
||||
}
|
||||
# endif
|
||||
|
||||
int OPENSSL_add_all_algorithms_conf(void)
|
||||
{
|
||||
return OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS
|
||||
| OPENSSL_INIT_LOAD_CONFIG, NULL);
|
||||
}
|
||||
|
||||
int OPENSSL_add_all_algorithms_noconf(void)
|
||||
{
|
||||
return OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
|
||||
}
|
||||
|
||||
int OpenSSL_add_all_algorithms(void)
|
||||
{
|
||||
# ifdef OPENSSL_LOAD_CONF
|
||||
return OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS
|
||||
| OPENSSL_INIT_LOAD_CONFIG, NULL);
|
||||
# else
|
||||
return OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
|
||||
# endif
|
||||
}
|
||||
|
||||
int OpenSSL_add_all_ciphers(void)
|
||||
{
|
||||
return OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL);
|
||||
}
|
||||
|
||||
int OPENSSL_add_all_digests(void)
|
||||
{
|
||||
return OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);
|
||||
}
|
||||
|
||||
void OPENSSL_cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md)
|
||||
{
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,
|
||||
EVP_PKEY_CTRL_MD, 0, (void *)md);
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **pmd)
|
||||
{
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,
|
||||
EVP_PKEY_CTRL_GET_MD, 0, (void *)pmd);
|
||||
}
|
||||
|
||||
int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, const unsigned char *key, int keylen)
|
||||
{
|
||||
return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_KEYGEN,
|
||||
EVP_PKEY_CTRL_SET_MAC_KEY, len, (void *)key);
|
||||
}
|
||||
#endif
|
||||
@@ -38,6 +38,7 @@ static const EVP_PBE_CTL builtin_pbe[] = {
|
||||
|
||||
{EVP_PBE_TYPE_OUTER, NID_id_pbkdf2, -1, -1, PKCS5_v2_PBKDF2_keyivgen},
|
||||
|
||||
#ifndef OPENSSL_NO_PKCS12
|
||||
{EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And128BitRC4,
|
||||
NID_rc4, NID_sha1, PKCS12_PBE_keyivgen},
|
||||
{EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And40BitRC4,
|
||||
@@ -50,6 +51,7 @@ static const EVP_PBE_CTL builtin_pbe[] = {
|
||||
NID_rc2_cbc, NID_sha1, PKCS12_PBE_keyivgen},
|
||||
{EVP_PBE_TYPE_OUTER, NID_pbe_WithSHA1And40BitRC2_CBC,
|
||||
NID_rc2_40_cbc, NID_sha1, PKCS12_PBE_keyivgen},
|
||||
#endif
|
||||
|
||||
{EVP_PBE_TYPE_OUTER, NID_pbes2, -1, -1, PKCS5_v2_PBE_keyivgen},
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/md4.h>
|
||||
# include <openssl/rsa.h>
|
||||
# include "internal/evp_int.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#if !defined(OPENSSL_NO_MD5)
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_SHA)
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
@@ -16,7 +18,8 @@
|
||||
# include <openssl/sha.h>
|
||||
# include "internal/cryptlib.h"
|
||||
# include "internal/evp_int.h"
|
||||
# include <openssl/rsa.h>
|
||||
//# include <openssl/rsa.h>
|
||||
// try no rsa if md5_sha1 ok?
|
||||
|
||||
struct md5_sha1_ctx {
|
||||
MD5_CTX md5;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/rsa.h>
|
||||
# include "internal/evp_int.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
|
||||
@@ -150,20 +150,24 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
|
||||
if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {
|
||||
if (vctx) {
|
||||
r = ctx->pctx->pmeth->verifyctx(ctx->pctx, sig, siglen, ctx);
|
||||
} else
|
||||
} else {
|
||||
r = EVP_DigestFinal_ex(ctx, md, &mdlen);
|
||||
}
|
||||
} else {
|
||||
EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
|
||||
if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))
|
||||
if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx)) {
|
||||
return -1;
|
||||
}
|
||||
if (vctx) {
|
||||
r = tmp_ctx->pctx->pmeth->verifyctx(tmp_ctx->pctx,
|
||||
sig, siglen, tmp_ctx);
|
||||
} else
|
||||
} else {
|
||||
r = EVP_DigestFinal_ex(tmp_ctx, md, &mdlen);
|
||||
}
|
||||
EVP_MD_CTX_free(tmp_ctx);
|
||||
}
|
||||
if (vctx || !r)
|
||||
if (vctx || !r) {
|
||||
return r;
|
||||
}
|
||||
return EVP_PKEY_verify(ctx->pctx, sig, siglen, md, mdlen);
|
||||
}
|
||||
|
||||
75
crypto/evp/names2.c
Normal file
75
crypto/evp/names2.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <internal/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include "internal/evp_int.h"
|
||||
|
||||
// 不同的cipher属性不同,似乎不能像MD那样简单处理
|
||||
const EVP_CIPHER *EVP_get_default_cipher(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* use MD5 as default:
|
||||
* X509_REQ_to_X509 x509_r2x.c
|
||||
* X509_issuer_and_serial_hash x509_cmp.c
|
||||
* X509_NAME_hash_old x509_cmp.c
|
||||
* PEM_ASN1_write_bio pem_lib.c
|
||||
*/
|
||||
const EVP_MD *EVP_get_default_digest(void)
|
||||
{
|
||||
#if !defined(OPENSSL_NO_MD5)
|
||||
return EVP_md5();
|
||||
#elif !defined(OPENSSL_NO_SHA)
|
||||
return EVP_sha1();
|
||||
#elif !defined(OPENSSL_NO_SM3)
|
||||
return EVP_sm3();
|
||||
#elif !defined(OPENSSL_NO_RIPEMD)
|
||||
return EVP_rmd160();
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cipher_name_len(const EVP_CIPHER *cipher, const char *from,
|
||||
const char *to, void *x)
|
||||
{
|
||||
*((int *)x) += strlen(EVP_CIPHER_name(cipher));
|
||||
}
|
||||
|
||||
static void cipher_name(const EVP_CIPHER *cipher, const char *from,
|
||||
const char *to, void *x)
|
||||
{
|
||||
strcat((char *)x, EVP_CIPHER_name(cipher));
|
||||
}
|
||||
|
||||
char *EVP_get_ciphernames(int aliases)
|
||||
{
|
||||
char *ret = NULL;
|
||||
int len = 0;
|
||||
EVP_CIPHER_do_all_sorted(cipher_name_len, &len);
|
||||
|
||||
ret = OPENSSL_zalloc(len);
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EVP_CIPHER_do_all_sorted(cipher_name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *EVP_get_digestnames(int aliases)
|
||||
{
|
||||
return "sm3:sha1:sha256";
|
||||
}
|
||||
@@ -121,6 +121,7 @@ int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
|
||||
return 1;
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_NO_SHA
|
||||
int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
|
||||
const unsigned char *salt, int saltlen, int iter,
|
||||
int keylen, unsigned char *out)
|
||||
@@ -128,15 +129,20 @@ int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
|
||||
return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, EVP_sha1(),
|
||||
keylen, out);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef DO_TEST
|
||||
main()
|
||||
{
|
||||
unsigned char out[4];
|
||||
unsigned char salt[] = { 0x12, 0x34, 0x56, 0x78 };
|
||||
# ifndef OPENSSL_NO_SHA
|
||||
PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out);
|
||||
fprintf(stderr, "Out %02X %02X %02X %02X\n",
|
||||
out[0], out[1], out[2], out[3]);
|
||||
# else
|
||||
fprintf(stderr, "PKCS5_PBKDF2_HMAC_SHA1() disabled\n");
|
||||
# endif
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
@@ -57,11 +57,15 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/rsa.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
# include <openssl/rsa.h>
|
||||
#endif
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/sm2.h>
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
# include <openssl/sm2.h>
|
||||
#endif
|
||||
|
||||
int EVP_PKEY_decrypt_old(unsigned char *key, const unsigned char *ek, int ekl,
|
||||
EVP_PKEY *priv)
|
||||
@@ -80,9 +84,11 @@ int EVP_PKEY_decrypt_old(unsigned char *key, const unsigned char *ek, int ekl,
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
siz = ekl;
|
||||
if (!(ctx = EVP_PKEY_CTX_new(priv, NULL))
|
||||
|| !EVP_PKEY_decrypt_init(ctx)
|
||||
|| !EVP_PKEY_CTX_set_ec_enc_type(ctx, NID_sm_scheme)
|
||||
|| !EVP_PKEY_CTX_set_ec_scheme(ctx, NID_sm_scheme)
|
||||
|| !EVP_PKEY_CTX_set_ec_encrypt_param(ctx, NID_sm3)
|
||||
|| !EVP_PKEY_decrypt(ctx, key, &siz, ek, ekl)) {
|
||||
EVPerr(EVP_F_EVP_PKEY_DECRYPT_OLD, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
|
||||
@@ -57,11 +57,15 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/rsa.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
# include <openssl/rsa.h>
|
||||
#endif
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/sm2.h>
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
# include <openssl/sm2.h>
|
||||
#endif
|
||||
|
||||
int EVP_PKEY_encrypt_old(unsigned char *out, const unsigned char *in,
|
||||
int inlen, EVP_PKEY *pkey)
|
||||
@@ -82,23 +86,14 @@ int EVP_PKEY_encrypt_old(unsigned char *out, const unsigned char *in,
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_NO_SM2
|
||||
if (!(ctx = EVP_PKEY_CTX_new(pkey, NULL))) {
|
||||
EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_encrypt_init(ctx)) {
|
||||
EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD, ERR_R_EVP_LIB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
size = inlen + EVP_PKEY_size(pkey);
|
||||
if (!EVP_PKEY_encrypt(ctx, out, &size, in, inlen)) {
|
||||
/* hope the caller has prepared enough buffer for `out`
|
||||
* because this function has no idea of the out length */
|
||||
if (!(ctx = EVP_PKEY_CTX_new(pkey, NULL))
|
||||
|| !EVP_PKEY_encrypt_init(ctx)
|
||||
|| !EVP_PKEY_CTX_set_ec_scheme(ctx, NID_sm_scheme)
|
||||
|| !EVP_PKEY_CTX_set_ec_encrypt_param(ctx, NID_sm3)
|
||||
|| !EVP_PKEY_encrypt(ctx, NULL, &size, in, inlen)
|
||||
|| !EVP_PKEY_encrypt(ctx, out, &size, in, inlen)) {
|
||||
EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,18 @@
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/paillier.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
# include <openssl/rsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
# include <openssl/dsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
# include <openssl/dh.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_PAILLIER
|
||||
# include <openssl/paillier.h>
|
||||
#endif
|
||||
#include <openssl/engine.h>
|
||||
|
||||
#include "internal/asn1_int.h"
|
||||
|
||||
@@ -34,12 +34,12 @@ int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
|
||||
if (!priv)
|
||||
return 1;
|
||||
|
||||
if (EVP_PKEY_id(priv) != EVP_PKEY_RSA) {
|
||||
EVPerr(EVP_F_EVP_OPENINIT, EVP_R_PUBLIC_KEY_NOT_RSA);
|
||||
if (EVP_PKEY_id(priv) != EVP_PKEY_RSA && EVP_PKEY_id(priv) != EVP_PKEY_EC) {
|
||||
EVPerr(EVP_F_EVP_OPENINIT, EVP_R_PUBLIC_KEY_NOT_RSA_OR_EC);
|
||||
goto err;
|
||||
}
|
||||
|
||||
size = EVP_PKEY_size(priv);
|
||||
size = EVP_PKEY_size(priv) >= ekl ? EVP_PKEY_size(priv) : ekl;
|
||||
key = OPENSSL_malloc(size + 2);
|
||||
if (key == NULL) {
|
||||
/* ERROR */
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
@@ -165,6 +165,16 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
|
||||
uint32_t *X, *V, *T;
|
||||
uint64_t i, Blen, Vlen;
|
||||
size_t allocsize;
|
||||
const EVP_MD *md;
|
||||
|
||||
#ifndef OPENSSL_NO_SHA
|
||||
md = EVP_sha256();
|
||||
#elif !defined(OPENSSL_NO_SM3)
|
||||
md = EVP_sm3();
|
||||
#else
|
||||
EVPerr(EVP_F_EVP_PBE_SCRYPT, EVP_R_NO_AVAIABLE_DIGEST);
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
/* Sanity check parameters */
|
||||
/* initial check, r,p must be non zero, N >= 2 and a power of 2 */
|
||||
@@ -230,14 +240,14 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
|
||||
X = (uint32_t *)(B + Blen);
|
||||
T = X + 32 * r;
|
||||
V = T + 32 * r;
|
||||
if (PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, 1, EVP_sha256(),
|
||||
if (PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, 1, md,
|
||||
Blen, B) == 0)
|
||||
goto err;
|
||||
|
||||
for (i = 0; i < p; i++)
|
||||
scryptROMix(B + 128 * r * i, r, N, X, T, V);
|
||||
|
||||
if (PKCS5_PBKDF2_HMAC(pass, passlen, B, Blen, 1, EVP_sha256(),
|
||||
if (PKCS5_PBKDF2_HMAC(pass, passlen, B, Blen, 1, md,
|
||||
keylen, key) == 0)
|
||||
goto err;
|
||||
rv = 1;
|
||||
|
||||
Reference in New Issue
Block a user