mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-29 17:23:38 +08:00
SM2 KAP (Key Agreement Protocol), not tested
This commit is contained in:
92
crypto/evp/a.c
Normal file
92
crypto/evp/a.c
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
/* crypto/evp/e_sms4.c */
|
||||
#include <stdio.h>
|
||||
#include "../cryptlib.h"
|
||||
|
||||
#ifndef OPENSSL_NO_SMS4
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include "evp_locl.h"
|
||||
#include <openssl/sms4.h>
|
||||
#define SMS4_IV_LENGTH SMS4_BLOCK_SIZE
|
||||
|
||||
typedef struct {
|
||||
sms4_key_t ks;
|
||||
} EVP_SMS4_KEY;
|
||||
|
||||
static int sms4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
if (!enc) {
|
||||
if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE)
|
||||
enc = 1;
|
||||
else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE)
|
||||
enc = 1; //encrypt key == decrypt key
|
||||
}
|
||||
|
||||
if (enc)
|
||||
sms4_set_encrypt_key(ctx->cipher_data, key);
|
||||
else sms4_set_decrypt_key(ctx->cipher_data, key);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
static int
|
||||
sms4_cbc_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out, const unsigned char *in, size_t inl)
|
||||
{
|
||||
while (inl >= ((size_t) 1 << (sizeof(long) * 8 - 2))) {
|
||||
sms4_cbc_encrypt(in, out, (long)((size_t) 1 << (sizeof(long) * 8 - 2)), &((EVP_SMS4_KEY *) ctx->cipher_data)->ks, ctx->iv, ctx->encrypt);
|
||||
inl -= ((size_t) 1 << (sizeof(long) * 8 - 2));
|
||||
in += ((size_t) 1 << (sizeof(long) * 8 - 2));
|
||||
out += ((size_t) 1 << (sizeof(long) * 8 - 2));
|
||||
} if (inl)
|
||||
sms4_cbc_encrypt(in, out, (long)inl, &((EVP_SMS4_KEY *) ctx->cipher_data)->ks, ctx->iv, ctx->encrypt);
|
||||
return 1;
|
||||
} static int sms4_cfb128_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out, const unsigned char *in, size_t inl){
|
||||
size_t chunk = ((size_t) 1 << (sizeof(long) * 8 - 2));
|
||||
if (128 == 1)
|
||||
chunk >>= 3;
|
||||
if (inl < chunk)
|
||||
chunk = inl;
|
||||
while (inl && inl >= chunk) {
|
||||
sms4_cfb128_encrypt(in, out, (long)((128 == 1) && !(ctx->flags & 0x2000) ? inl * 8 : inl), &((EVP_SMS4_KEY *) ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt);
|
||||
inl -= chunk;
|
||||
in += chunk;
|
||||
out += chunk;
|
||||
if (inl < chunk)
|
||||
chunk = inl;
|
||||
} return 1;
|
||||
} static int sms4_ecb_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out, const unsigned char *in, size_t inl){
|
||||
size_t i , bl;
|
||||
bl = ctx->cipher->block_size;
|
||||
if (inl < bl)
|
||||
return 1;
|
||||
inl -= bl;
|
||||
for (i = 0; i <= inl; i += bl)
|
||||
sms4_ecb_encrypt(in + i, out + i, &((EVP_SMS4_KEY *) ctx->cipher_data)->ks, ctx->encrypt);
|
||||
return 1;
|
||||
} static int sms4_ofb_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out, const unsigned char *in, size_t inl){
|
||||
while (inl >= ((size_t) 1 << (sizeof(long) * 8 - 2))) {
|
||||
sms4_ofb128_encrypt(in, out, (long)((size_t) 1 << (sizeof(long) * 8 - 2)), &((EVP_SMS4_KEY *) ctx->cipher_data)->ks, ctx->iv, &ctx->num);
|
||||
inl -= ((size_t) 1 << (sizeof(long) * 8 - 2));
|
||||
in += ((size_t) 1 << (sizeof(long) * 8 - 2));
|
||||
out += ((size_t) 1 << (sizeof(long) * 8 - 2));
|
||||
} if (inl)
|
||||
sms4_ofb128_encrypt(in, out, (long)inl, &((EVP_SMS4_KEY *) ctx->cipher_data)->ks, ctx->iv, &ctx->num);
|
||||
return 1;
|
||||
} static const EVP_CIPHER sms4_cbc = {978, 16, 16, 16, 0 | 0x2, sms4_init_key, sms4_cbc_cipher, ((void *)0), sizeof(EVP_SMS4_KEY), ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
|
||||
const EVP_CIPHER *EVP_sms4_cbc(void){
|
||||
return &sms4_cbc;
|
||||
} static const EVP_CIPHER sms4_cfb128 = {982, 1, 16, 16, 0 | 0x3, sms4_init_key, sms4_cfb128_cipher, ((void *)0), sizeof(EVP_SMS4_KEY), ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
|
||||
const EVP_CIPHER *EVP_sms4_cfb128(void){
|
||||
return &sms4_cfb128;
|
||||
} static const EVP_CIPHER sms4_ofb = {981, 1, 16, 16, 0 | 0x4, sms4_init_key, sms4_ofb_cipher, ((void *)0), sizeof(EVP_SMS4_KEY), ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
|
||||
const EVP_CIPHER *EVP_sms4_ofb(void){
|
||||
return &sms4_ofb;
|
||||
} static const EVP_CIPHER sms4_ecb = {977, 16, 16, 0, 0 | 0x1, sms4_init_key, sms4_ecb_cipher, ((void *)0), sizeof(EVP_SMS4_KEY), ((void *)0), ((void *)0), ((void *)0), ((void *)0)};
|
||||
const EVP_CIPHER *
|
||||
EVP_sms4_ecb(void)
|
||||
{
|
||||
return &sms4_ecb;
|
||||
}
|
||||
#endif
|
||||
3
crypto/evp/a.c.BAK
Normal file
3
crypto/evp/a.c.BAK
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
static int sms4_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) {
|
||||
while(inl>=((size_t)1<<(sizeof(long)*8-2))) { sms4_cbc_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), &((EVP_SMS4_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); inl-=((size_t)1<<(sizeof(long)*8-2)); in +=((size_t)1<<(sizeof(long)*8-2)); out+=((size_t)1<<(sizeof(long)*8-2)); } if (inl) sms4_cbc_encrypt(in, out, (long)inl, &((EVP_SMS4_KEY *)ctx->cipher_data)->ks, ctx->iv, ctx->encrypt); return 1;} static int sms4_cfb128_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { size_t chunk=((size_t)1<<(sizeof(long)*8-2)); if (128==1) chunk>>=3; if (inl<chunk) chunk=inl; while(inl && inl>=chunk) { sms4_cfb128_encrypt(in, out, (long)((128==1) && !(ctx->flags & 0x2000) ?inl*8:inl), &((EVP_SMS4_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num, ctx->encrypt); inl-=chunk; in +=chunk; out+=chunk; if(inl<chunk) chunk=inl; } return 1;} static int sms4_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { size_t i, bl; bl = ctx->cipher->block_size; if(inl < bl) return 1; inl -= bl; for(i=0; i <= inl; i+=bl) sms4_ecb_encrypt(in + i, out + i, &((EVP_SMS4_KEY *)ctx->cipher_data)->ks, ctx->encrypt); return 1;} static int sms4_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { while(inl>=((size_t)1<<(sizeof(long)*8-2))) { sms4_ofb128_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), &((EVP_SMS4_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); inl-=((size_t)1<<(sizeof(long)*8-2)); in +=((size_t)1<<(sizeof(long)*8-2)); out+=((size_t)1<<(sizeof(long)*8-2)); } if (inl) sms4_ofb128_encrypt(in, out, (long)inl, &((EVP_SMS4_KEY *)ctx->cipher_data)->ks, ctx->iv, &ctx->num); return 1;} static const EVP_CIPHER sms4_cbc = { 978, 16, 16, 16, 0 | 0x2, sms4_init_key, sms4_cbc_cipher, ((void*)0), sizeof(EVP_SMS4_KEY), ((void*)0), ((void*)0), ((void*)0), ((void*)0) }; const EVP_CIPHER *EVP_sms4_cbc(void) { return &sms4_cbc; } static const EVP_CIPHER sms4_cfb128 = { 982, 1, 16, 16, 0 | 0x3, sms4_init_key, sms4_cfb128_cipher, ((void*)0), sizeof(EVP_SMS4_KEY), ((void*)0), ((void*)0), ((void*)0), ((void*)0) }; const EVP_CIPHER *EVP_sms4_cfb128(void) { return &sms4_cfb128; } static const EVP_CIPHER sms4_ofb = { 981, 1, 16, 16, 0 | 0x4, sms4_init_key, sms4_ofb_cipher, ((void*)0), sizeof(EVP_SMS4_KEY), ((void*)0), ((void*)0), ((void*)0), ((void*)0) }; const EVP_CIPHER *EVP_sms4_ofb(void) { return &sms4_ofb; } static const EVP_CIPHER sms4_ecb = { 977, 16, 16, 0, 0 | 0x1, sms4_init_key, sms4_ecb_cipher, ((void*)0), sizeof(EVP_SMS4_KEY), ((void*)0), ((void*)0), ((void*)0), ((void*)0) }; const EVP_CIPHER *EVP_sms4_ecb(void) { return &sms4_ecb; }
|
||||
@@ -165,9 +165,9 @@ void OpenSSL_add_all_ciphers(void)
|
||||
|
||||
#ifndef OPENSSL_NO_SMS4
|
||||
EVP_add_cipher(EVP_sms4_ecb());
|
||||
//EVP_add_cipher(EVP_sms4_cfb128());
|
||||
//EVP_add_cipher(EVP_sms4_ofb());
|
||||
EVP_add_cipher(EVP_sms4_cbc());
|
||||
EVP_add_cipher(EVP_sms4_ofb());
|
||||
EVP_add_cipher(EVP_sms4_cfb128());
|
||||
EVP_add_cipher_alias(SN_sms4_cbc,"SMS4");
|
||||
EVP_add_cipher_alias(SN_sms4_cbc,"sms4");
|
||||
#endif
|
||||
|
||||
@@ -211,6 +211,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
type = ctx->digest;
|
||||
}
|
||||
#endif
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
if (ctx->digest != type) {
|
||||
if (ctx->digest && ctx->digest->ctx_size)
|
||||
OPENSSL_free(ctx->md_data);
|
||||
@@ -218,6 +219,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {
|
||||
ctx->update = type->update;
|
||||
ctx->md_data = OPENSSL_malloc(type->ctx_size);
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
if (ctx->md_data == NULL) {
|
||||
EVPerr(EVP_F_EVP_DIGESTINIT_EX, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
@@ -229,6 +231,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
#endif
|
||||
if (ctx->pctx) {
|
||||
int r;
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,
|
||||
EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);
|
||||
if (r <= 0 && (r != -2))
|
||||
@@ -245,6 +248,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
return ctx->digest->init(ctx);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,30 +8,197 @@
|
||||
#include "evp_locl.h"
|
||||
#include <openssl/sms4.h>
|
||||
|
||||
static int sms4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv,int enc);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#define SMS4_IV_LENGTH SMS4_BLOCK_SIZE
|
||||
|
||||
typedef struct {
|
||||
sms4_key_t ks;
|
||||
} EVP_SMS4_KEY;
|
||||
|
||||
|
||||
IMPLEMENT_BLOCK_CIPHER(sms4, ks, sms4, EVP_SMS4_KEY, NID_sms4,
|
||||
16, 16, 16, 128, 0, sms4_init_key, 0, 0, 0, 0)
|
||||
} EVP_SMS4_KEY;
|
||||
|
||||
static int sms4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
if(!enc) {
|
||||
if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE) enc = 1;
|
||||
else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE) enc = 1; //encrypt key == decrypt key
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
if (!enc) {
|
||||
if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE)
|
||||
enc = 1;
|
||||
else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE)
|
||||
enc = 1; //encrypt key == decrypt key
|
||||
}
|
||||
|
||||
if (enc)
|
||||
sms4_set_encrypt_key(ctx->cipher_data, key);
|
||||
else //ecb, cbc
|
||||
sms4_set_decrypt_key(ctx->cipher_data, key);
|
||||
else sms4_set_decrypt_key(ctx->cipher_data, key);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
IMPLEMENT_BLOCK_CIPHER(sms4, ks, sms4, EVP_SMS4_KEY, NID_sms4,
|
||||
SMS4_BLOCK_SIZE, SMS4_KEY_LENGTH, SMS4_IV_LENGTH, 128, 0,
|
||||
sms4_init_key, NULL, NULL, NULL, NULL)
|
||||
|
||||
#if 0
|
||||
static int sms4_ctr_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t inlen)
|
||||
{
|
||||
|
||||
unsigned int num = ctx->num;
|
||||
EVP_SMS4_KEY *sms4 = (EVP_SMS4_KEY *)ctx->cipher_data;
|
||||
|
||||
CRYPTO_ctr128_encrypt_ctr32(in, out, inlen, &sms4->ks, ctx->iv, ctx->buf,
|
||||
&num, sms4_ctr_encrypt);
|
||||
|
||||
ctx->num = (size_t)num;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const EVP_CIPHER sms4_ctr = {
|
||||
NID_sms4_ctr,
|
||||
SMS4_BLOCK_SIZE,
|
||||
SMS4_KEY_LENGTH,
|
||||
SMS4_IV_LENGTH,
|
||||
0,
|
||||
sms4_init_key,
|
||||
sms4_ctr_cipher,
|
||||
NULL, /* cleanup() */
|
||||
sizeof(EVP_SMS4_CTX),
|
||||
NULL, /* set_asn1_parameters() */
|
||||
NULL, /* get_asn1_parameters() */
|
||||
NULL, /* ctrl() */
|
||||
NULL /* app_data */
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_sms4_ctr(void)
|
||||
{
|
||||
return &sms4_ctr;
|
||||
}
|
||||
|
||||
static int sms4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
|
||||
int mode;
|
||||
|
||||
mode = ctx->cipher->flags & EVP_CIPH_MODE;
|
||||
if ((mode == EVP_CIPH_ECB_MODE || mode == EVP_CIPH_CBC_MODE) && !enc) {
|
||||
ret = sms4_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
|
||||
sms4->block = (block128_f)sms4_decrypt;
|
||||
sms4->stream.cbc = (mode == EVP_CIPH_CBC_MODE ?
|
||||
(cbc128_f)sms4_cbc_encrypt : NULL);
|
||||
} else {
|
||||
ret = sms4_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
|
||||
sms4->block = (block128_f)sms4_encrypt;
|
||||
|
||||
if (mode == EVP_CIPH_CBC_MODE) {
|
||||
sms4->stream.cbc = (cbc128_f)sms4_cbc_encrypt;
|
||||
} else if (mode == EVP_CIPH_CTR_MODE) {
|
||||
sms4->stream.ctr = (ctr128_f)sms4_ctr32_encrypt_blocks;
|
||||
} else {
|
||||
sms4->stream.cbc = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
sms4_key_t ks;
|
||||
int key_is_inited;
|
||||
int iv_is_inited;
|
||||
GCM128_CONTEXT gcm;
|
||||
unsigned char *iv;
|
||||
int ivlen;
|
||||
int taglen;
|
||||
int iv_gen;
|
||||
ctr128_f ctr;
|
||||
} EVP_SMS4_GCM_CTX;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int sms4_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
|
||||
{
|
||||
|
||||
switch (type) {
|
||||
case EVP_CTRL_INIT:
|
||||
|
||||
|
||||
case EVP_CTRL_GCM_SET_IVLEN:
|
||||
case EVP_CTRL_GCM_SET_TAG:
|
||||
case EVP_CTRL_GCM_GET_TAG:
|
||||
case EVP_CTRL_GCM_SET_IV_FIXED:
|
||||
case EVP_CTRL_GCM_IV_GEN:
|
||||
case EVP_CTRL_GCM_SET_IV_INV:
|
||||
case EVP_CTRL_COPY:
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
double align;
|
||||
sms4_key_t ks;
|
||||
} ks;
|
||||
unsigned char *iv;
|
||||
} EVP_SMS4_WRAP_CTX;
|
||||
|
||||
|
||||
static int sms4_wrap_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int sms4_wrap_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t inlen)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#define WRAP_FLAGS (EVP_CIPH_WRAP_MODE \
|
||||
| EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \
|
||||
| EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_FLAG_DEFAULT_ASN1)
|
||||
|
||||
|
||||
|
||||
const EVP_CIPHER sms4_wrap = {
|
||||
NID_sms4_wrap,
|
||||
SMS4_WRAP_BLOCK_SIZE,
|
||||
SMS4_KEY_LENGTH,
|
||||
SMS4_WRAP_IV_LENGTH,
|
||||
WRAP_FLAGS,
|
||||
sms4_wrap_init_key,
|
||||
sms4_wrap_do_cipher,
|
||||
NULL, /* cleanup() */
|
||||
sizeof(EVP_SMS4_WRAP_CTX),
|
||||
NULL, /* set_asn1_parameters() */
|
||||
NULL, /* get_asn1_parameters() */
|
||||
NULL, /* ctrl() */
|
||||
NULL /* app_data */
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_sms4_wrap(void)
|
||||
{
|
||||
return &sms4_wrap;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -657,6 +657,13 @@ int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
|
||||
int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
|
||||
|
||||
#ifndef OPENSSL_NO_GMSSL
|
||||
int EVP_Encrypt_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outlen,
|
||||
const unsigned char *in, int inlen);
|
||||
int EVP_Decrypt_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outlen,
|
||||
const unsigned char *in, int inlen);
|
||||
#endif
|
||||
|
||||
int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s,
|
||||
EVP_PKEY *pkey);
|
||||
|
||||
@@ -842,6 +849,11 @@ const EVP_CIPHER *EVP_sms4_ecb(void);
|
||||
const EVP_CIPHER *EVP_sms4_cbc(void);
|
||||
const EVP_CIPHER *EVP_sms4_cfb128(void);
|
||||
const EVP_CIPHER *EVP_sms4_ofb128(void);
|
||||
const EVP_CIPHER *EVP_sms4_ctr(void);
|
||||
const EVP_CIPHER *EVP_sms4_ccm(void);
|
||||
const EVP_CIPHER *EVP_sms4_gcm(void);
|
||||
const EVP_CIPHER *EVP_sms4_xts(void);
|
||||
const EVP_CIPHER *EVP_sms4_wrap(void);
|
||||
#define EVP_sm4_ecb EVP_sms4_ecb
|
||||
#define EVP_sm4_cbc EVP_sms4_cbc
|
||||
#define EVP_sm4_cfb128 EVP_sms4_cfb128
|
||||
@@ -1484,6 +1496,11 @@ 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
|
||||
|
||||
@@ -664,3 +664,19 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
|
||||
return in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_GMSSL
|
||||
int EVP_Encrypt_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outlen,
|
||||
const unsigned char *in, int inlen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_Decrypt_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outlen,
|
||||
const unsigned char *in, int inlen)
|
||||
{
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* GMSSL */
|
||||
|
||||
|
||||
@@ -152,6 +152,10 @@ 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}
|
||||
};
|
||||
|
||||
|
||||
0
crypto/evp/m_sha3.c
Normal file
0
crypto/evp/m_sha3.c
Normal file
@@ -87,6 +87,8 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
|
||||
if (ver) {
|
||||
if (ctx->pctx->pmeth->verifyctx_init) {
|
||||
if (ctx->pctx->pmeth->verifyctx_init(ctx->pctx, ctx) <= 0)
|
||||
@@ -102,12 +104,16 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
} else if (EVP_PKEY_sign_init(ctx->pctx) <= 0)
|
||||
return 0;
|
||||
}
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
if (EVP_PKEY_CTX_set_signature_md(ctx->pctx, type) <= 0)
|
||||
return 0;
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
if (pctx)
|
||||
*pctx = ctx->pctx;
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
if (ctx->pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM)
|
||||
return 1;
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
if (!EVP_DigestInit_ex(ctx, type, e))
|
||||
return 0;
|
||||
return 1;
|
||||
|
||||
@@ -7,21 +7,24 @@
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/sm3.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <openssl/rsa.h>
|
||||
#endif
|
||||
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{ return sm3_init(ctx->md_data); }
|
||||
{
|
||||
return sm3_init(ctx->md_data);
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{ return sm3_update(ctx->md_data, data, count); }
|
||||
static int update(EVP_MD_CTX *ctx, const void *in, size_t inlen)
|
||||
{
|
||||
return sm3_update(ctx->md_data, in, inlen);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{ return sm3_final(ctx->md_data, md); }
|
||||
|
||||
static const EVP_MD sm3_md=
|
||||
{
|
||||
return sm3_final(ctx->md_data, md);
|
||||
}
|
||||
|
||||
static const EVP_MD sm3_md = {
|
||||
NID_sm3,
|
||||
NID_sm2sign_with_sm3,
|
||||
SM3_DIGEST_LENGTH,
|
||||
@@ -33,11 +36,12 @@ static const EVP_MD sm3_md=
|
||||
NULL,
|
||||
EVP_PKEY_RSA_method,
|
||||
SM3_BLOCK_SIZE,
|
||||
sizeof(EVP_MD *)+sizeof(sm3_ctx_t),
|
||||
sizeof(EVP_MD *) + sizeof(sm3_ctx_t),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_sm3(void)
|
||||
{
|
||||
return(&sm3_md);
|
||||
return &sm3_md;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user