Update sm2 and zuc

This commit is contained in:
Zhi Guan
2019-01-12 11:56:06 +08:00
parent 3dfae969d9
commit 4bab277911
14 changed files with 8517 additions and 5415 deletions

View File

@@ -306,6 +306,9 @@ static FUNCTION functions[] = {
#ifndef OPENSSL_NO_SMS4
{ FT_cipher, "sms4-cfb", enc_main, enc_options },
#endif
#ifndef OPENSSL_NO_ZUC
{ FT_cipher, "zuc", enc_main, enc_options },
#endif
#ifndef OPENSSL_NO_AES
{ FT_cipher, "aes-128-cbc", enc_main, enc_options },
#endif

View File

@@ -118,7 +118,7 @@ my %cipher_disabler = (
cast5 => "cast",
);
foreach my $cmd (
"sms4", "sms4-cbc", "sms4-ecb", "sms4-ofb", "sms4-cfb",
"sms4", "sms4-cbc", "sms4-ecb", "sms4-ofb", "sms4-cfb", "zuc",
"aes-128-cbc", "aes-128-ecb",
"aes-192-cbc", "aes-192-ecb",
"aes-256-cbc", "aes-256-ecb",

View File

@@ -122,6 +122,9 @@
#ifndef OPENSSL_NO_SMS4
# include <openssl/sms4.h>
#endif
#ifndef OPENSSL_NO_ZUC
# include <openssl/zuc.h>
#endif
#ifndef OPENSSL_NO_SM9
# include <openssl/sm9.h>
#endif
@@ -145,7 +148,7 @@
#define BUFSIZE (1024*16+1)
#define MAX_MISALIGNMENT 63
#define ALGOR_NUM 32
#define ALGOR_NUM 33
#define SIZE_NUM 6
#define PRIME_NUM 3
#define RSA_NUM 7
@@ -294,7 +297,7 @@ static const char *names[ALGOR_NUM] = {
"camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc",
"evp", "sha256", "sha512", "whirlpool",
"aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash",
"sm3", "sms4 cbc"
"sm3", "sms4 cbc", "zuc"
};
static double results[ALGOR_NUM][SIZE_NUM];
@@ -479,6 +482,7 @@ OPTIONS speed_options[] = {
#define D_GHASH 29
#define D_SM3 30
#define D_CBC_SMS4 31
#define D_ZUC 32
static OPT_PAIR doit_choices[] = {
#ifndef OPENSSL_NO_MD2
{"md2", D_MD2},
@@ -554,6 +558,9 @@ static OPT_PAIR doit_choices[] = {
#ifndef OPENSSL_NO_SMS4
{"sms4-cbc", D_CBC_SMS4},
{"sms4", D_CBC_SMS4},
#endif
#ifndef OPENSSL_NO_ZUC
{"zuc", D_ZUC},
#endif
{NULL}
};
@@ -1188,10 +1195,11 @@ static int SM2_encrypt_loop(void *args)
size_t *sm2cipherlen = &tempargs->cipherlen;
int ret, count;
for (count = 0; COND(sm2enc_c[testnum][0]); count++) {
ret = SM2_encrypt(NID_sm3, buf, 32, sm2cipher,
*sm2cipherlen = BUFSIZE;
ret = SM2_encrypt(NID_sm3, buf, 32, sm2cipher,
sm2cipherlen, sm2[testnum]);
if (ret == 0) {
BIO_printf(bio_err, "SM2 sign failure\n");
BIO_printf(bio_err, "SM2 encrypt failure\n");
ERR_print_errors(bio_err);
count = -1;
break;
@@ -1494,6 +1502,9 @@ int speed_main(int argc, char **argv)
#ifndef OPENSSL_NO_SMS4
sms4_key_t sms4_ks;
#endif
#ifndef OPENSSL_NO_ZUC
ZUC_KEY zuc_ks;
#endif
#ifndef OPENSSL_NO_BF
BF_KEY bf_ks;
#endif
@@ -1985,6 +1996,9 @@ int speed_main(int argc, char **argv)
#ifndef OPENSSL_NO_SMS4
sms4_set_encrypt_key(&sms4_ks, key16);
#endif
#ifndef OPENSSL_NO_ZUC
ZUC_set_key(&zuc_ks, key16, iv);
#endif
#ifndef OPENSSL_NO_RC4
RC4_set_key(&rc4_ks, 16, key16);
#endif
@@ -2045,6 +2059,7 @@ int speed_main(int argc, char **argv)
c[D_GHASH][0] = count;
c[D_SM3][0] = count;
c[D_CBC_SMS4][0] = count;
c[D_ZUC][0] = count;
for (i = 1; i < SIZE_NUM; i++) {
long l0, l1;
@@ -2086,6 +2101,7 @@ int speed_main(int argc, char **argv)
c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
c[D_CBC_SMS4][i] = c[D_CBC_SMS4][i - 1] * l0 / l1;
c[D_ZUC][i] = c[D_ZUC][i - 1] * l0 / l1;
}
# ifndef OPENSSL_NO_RSA
@@ -2588,6 +2604,24 @@ int speed_main(int argc, char **argv)
}
}
#endif
#ifndef OPENSSL_NO_ZUC
if (doit[D_ZUC]) {
if (async_jobs > 0) {
BIO_printf(bio_err, "Async mode is not supported with %s\n",
names[D_ZUC]);
doit[D_ZUC] = 0;
}
for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
print_message(names[D_ZUC], c[D_ZUC][testnum], lengths[testnum]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_ZUC][testnum]); count++)
ZUC_generate_keystream(&zuc_ks, lengths[testnum]/4,
(unsigned int *)loopargs[0].buf);
d = Time_F(STOP);
print_result(D_ZUC, testnum, count, d);
}
}
#endif
#ifndef OPENSSL_NO_RC2
if (doit[D_CBC_RC2]) {
if (async_jobs > 0) {
@@ -3160,6 +3194,7 @@ int speed_main(int argc, char **argv)
EC_KEY_precompute_mult(loopargs[i].sm2[testnum], NULL);
/* Perform SM2 encryption test */
EC_KEY_generate_key(loopargs[i].sm2[testnum]);
loopargs[i].cipherlen = BUFSIZE;
st = SM2_encrypt(NID_sm3, loopargs[i].buf, 32, loopargs[i].buf2,
&loopargs[i].cipherlen, loopargs[i].sm2[testnum]);
if (st == 0)