fast SMS4 with Intel AVX2/KNC-NI

This commit is contained in:
Zhi Guan
2016-05-09 09:20:02 +02:00
parent addcac4896
commit 8c0439e7d6
83 changed files with 3536 additions and 5882 deletions

View File

@@ -345,4 +345,10 @@ const EVP_CIPHER *EVP_sms4_wrap(void)
}
//TODO: EVP_sms4_256_xxx();
#endif

View File

@@ -254,6 +254,14 @@ typedef int evp_verify_method(int type, const unsigned char *m,
# define EVP_PKEY_ECDSA_method EVP_PKEY_NULL_method
# endif
# ifndef OPENSSL_NO_SM2
# define EVP_PKEY_SM2_method (evp_sign_method *)SM2_sign, \
(evp_verify_method *)SM2_verify, \
{EVP_PKEY_SM2,0,0,0}
# else
# define EVP_PKEY_SM2_method EVP_PKEY_NULL_method
# endif
# ifndef OPENSSL_NO_RSA
# define EVP_PKEY_RSA_method (evp_sign_method *)RSA_sign, \
(evp_verify_method *)RSA_verify, \

View File

@@ -227,3 +227,15 @@ int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
return 1;
return 0;
}
#ifndef OPENSSL_NO_GMSSL
int EVP_PKEY_ec_to_sm2(EVP_PKEY *pkey, int only_sm2_curve)
{
return 0;
}
int EVP_PKEY_sm2_to_ec(EVP_PKEY *pkey)
{
return 0;
}
#endif

View File

@@ -87,8 +87,6 @@ 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)
@@ -98,22 +96,21 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
return 0;
} else {
if (ctx->pctx->pmeth->signctx_init) {
if (ctx->pctx->pmeth->signctx_init(ctx->pctx, ctx) <= 0)
if (ctx->pctx->pmeth->signctx_init(ctx->pctx, ctx) <= 0) {
fprintf(stderr, "error %s %d\n", __FILE__, __LINE__);
return 0;
}
ctx->pctx->operation = EVP_PKEY_OP_SIGNCTX;
} 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;

View File

@@ -85,7 +85,7 @@ static const EVP_MD sm3_md = {
final,
NULL,
NULL,
EVP_PKEY_RSA_method,
EVP_PKEY_SM2_method,
SM3_BLOCK_SIZE,
sizeof(EVP_MD *) + sizeof(sm3_ctx_t),
};

View File

@@ -101,10 +101,10 @@ int EVP_PKEY_decrypt_old(unsigned char *out, const unsigned char *in, int inlen,
return 0;
}
if (!EVP_PKEY_encrypt_init(ctx)) {
if (!EVP_PKEY_decrypt_init(ctx)) {
goto end;
}
if (!EVP_PKEY_encrypt(ctx, out, &outlen, in, inlen)) {
if (!EVP_PKEY_decrypt(ctx, out, &outlen, in, inlen)) {
goto end;
}

View File

@@ -80,6 +80,10 @@
#include "asn1_locl.h"
#ifndef OPENSSL_NO_GMSSL
#include "../ec/ec_lcl.h"
#endif
static void EVP_PKEY_free_it(EVP_PKEY *x);
int EVP_PKEY_bits(EVP_PKEY *pkey)
@@ -206,7 +210,6 @@ EVP_PKEY *EVP_PKEY_new(void)
* Setup a public key ASN1 method and ENGINE from a NID or a string. If pkey
* is NULL just return 1 or 0 if the algorithm exists.
*/
static int pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
{
const EVP_PKEY_ASN1_METHOD *ameth;
@@ -247,6 +250,7 @@ static int pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
pkey->type = pkey->ameth->pkey_id;
pkey->save_type = type;
}
return 1;
}
@@ -345,6 +349,7 @@ int EVP_PKEY_set1_SM2(EVP_PKEY *pkey, EC_KEY *key)
EC_KEY *EVP_PKEY_get1_SM2(EVP_PKEY *pkey)
{
/* FIXME: reconsider the SM2 and EC_KEY relationship */
if (pkey->type != EVP_PKEY_SM2) {
EVPerr(EVP_F_EVP_PKEY_GET1_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);//FIXME:errno
return NULL;