|
122 | 122 | #ifndef OPENSSL_NO_SMS4 |
123 | 123 | # include <openssl/sms4.h> |
124 | 124 | #endif |
| 125 | +#ifndef OPENSSL_NO_ZUC |
| 126 | +# include <openssl/zuc.h> |
| 127 | +#endif |
125 | 128 | #ifndef OPENSSL_NO_SM9 |
126 | 129 | # include <openssl/sm9.h> |
127 | 130 | #endif |
|
145 | 148 | #define BUFSIZE (1024*16+1) |
146 | 149 | #define MAX_MISALIGNMENT 63 |
147 | 150 |
|
148 | | -#define ALGOR_NUM 32 |
| 151 | +#define ALGOR_NUM 33 |
149 | 152 | #define SIZE_NUM 6 |
150 | 153 | #define PRIME_NUM 3 |
151 | 154 | #define RSA_NUM 7 |
@@ -294,7 +297,7 @@ static const char *names[ALGOR_NUM] = { |
294 | 297 | "camellia-128 cbc", "camellia-192 cbc", "camellia-256 cbc", |
295 | 298 | "evp", "sha256", "sha512", "whirlpool", |
296 | 299 | "aes-128 ige", "aes-192 ige", "aes-256 ige", "ghash", |
297 | | - "sm3", "sms4 cbc" |
| 300 | + "sm3", "sms4 cbc", "zuc" |
298 | 301 | }; |
299 | 302 |
|
300 | 303 | static double results[ALGOR_NUM][SIZE_NUM]; |
@@ -479,6 +482,7 @@ OPTIONS speed_options[] = { |
479 | 482 | #define D_GHASH 29 |
480 | 483 | #define D_SM3 30 |
481 | 484 | #define D_CBC_SMS4 31 |
| 485 | +#define D_ZUC 32 |
482 | 486 | static OPT_PAIR doit_choices[] = { |
483 | 487 | #ifndef OPENSSL_NO_MD2 |
484 | 488 | {"md2", D_MD2}, |
@@ -554,6 +558,9 @@ static OPT_PAIR doit_choices[] = { |
554 | 558 | #ifndef OPENSSL_NO_SMS4 |
555 | 559 | {"sms4-cbc", D_CBC_SMS4}, |
556 | 560 | {"sms4", D_CBC_SMS4}, |
| 561 | +#endif |
| 562 | +#ifndef OPENSSL_NO_ZUC |
| 563 | + {"zuc", D_ZUC}, |
557 | 564 | #endif |
558 | 565 | {NULL} |
559 | 566 | }; |
@@ -1188,10 +1195,11 @@ static int SM2_encrypt_loop(void *args) |
1188 | 1195 | size_t *sm2cipherlen = &tempargs->cipherlen; |
1189 | 1196 | int ret, count; |
1190 | 1197 | for (count = 0; COND(sm2enc_c[testnum][0]); count++) { |
1191 | | - ret = SM2_encrypt(NID_sm3, buf, 32, sm2cipher, |
| 1198 | + *sm2cipherlen = BUFSIZE; |
| 1199 | + ret = SM2_encrypt(NID_sm3, buf, 32, sm2cipher, |
1192 | 1200 | sm2cipherlen, sm2[testnum]); |
1193 | 1201 | if (ret == 0) { |
1194 | | - BIO_printf(bio_err, "SM2 sign failure\n"); |
| 1202 | + BIO_printf(bio_err, "SM2 encrypt failure\n"); |
1195 | 1203 | ERR_print_errors(bio_err); |
1196 | 1204 | count = -1; |
1197 | 1205 | break; |
@@ -1494,6 +1502,9 @@ int speed_main(int argc, char **argv) |
1494 | 1502 | #ifndef OPENSSL_NO_SMS4 |
1495 | 1503 | sms4_key_t sms4_ks; |
1496 | 1504 | #endif |
| 1505 | +#ifndef OPENSSL_NO_ZUC |
| 1506 | + ZUC_KEY zuc_ks; |
| 1507 | +#endif |
1497 | 1508 | #ifndef OPENSSL_NO_BF |
1498 | 1509 | BF_KEY bf_ks; |
1499 | 1510 | #endif |
@@ -1985,6 +1996,9 @@ int speed_main(int argc, char **argv) |
1985 | 1996 | #ifndef OPENSSL_NO_SMS4 |
1986 | 1997 | sms4_set_encrypt_key(&sms4_ks, key16); |
1987 | 1998 | #endif |
| 1999 | +#ifndef OPENSSL_NO_ZUC |
| 2000 | + ZUC_set_key(&zuc_ks, key16, iv); |
| 2001 | +#endif |
1988 | 2002 | #ifndef OPENSSL_NO_RC4 |
1989 | 2003 | RC4_set_key(&rc4_ks, 16, key16); |
1990 | 2004 | #endif |
@@ -2045,6 +2059,7 @@ int speed_main(int argc, char **argv) |
2045 | 2059 | c[D_GHASH][0] = count; |
2046 | 2060 | c[D_SM3][0] = count; |
2047 | 2061 | c[D_CBC_SMS4][0] = count; |
| 2062 | + c[D_ZUC][0] = count; |
2048 | 2063 |
|
2049 | 2064 | for (i = 1; i < SIZE_NUM; i++) { |
2050 | 2065 | long l0, l1; |
@@ -2086,6 +2101,7 @@ int speed_main(int argc, char **argv) |
2086 | 2101 | c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1; |
2087 | 2102 | c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1; |
2088 | 2103 | c[D_CBC_SMS4][i] = c[D_CBC_SMS4][i - 1] * l0 / l1; |
| 2104 | + c[D_ZUC][i] = c[D_ZUC][i - 1] * l0 / l1; |
2089 | 2105 | } |
2090 | 2106 |
|
2091 | 2107 | # ifndef OPENSSL_NO_RSA |
@@ -2588,6 +2604,24 @@ int speed_main(int argc, char **argv) |
2588 | 2604 | } |
2589 | 2605 | } |
2590 | 2606 | #endif |
| 2607 | +#ifndef OPENSSL_NO_ZUC |
| 2608 | + if (doit[D_ZUC]) { |
| 2609 | + if (async_jobs > 0) { |
| 2610 | + BIO_printf(bio_err, "Async mode is not supported with %s\n", |
| 2611 | + names[D_ZUC]); |
| 2612 | + doit[D_ZUC] = 0; |
| 2613 | + } |
| 2614 | + for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) { |
| 2615 | + print_message(names[D_ZUC], c[D_ZUC][testnum], lengths[testnum]); |
| 2616 | + Time_F(START); |
| 2617 | + for (count = 0, run = 1; COND(c[D_ZUC][testnum]); count++) |
| 2618 | + ZUC_generate_keystream(&zuc_ks, lengths[testnum]/4, |
| 2619 | + (unsigned int *)loopargs[0].buf); |
| 2620 | + d = Time_F(STOP); |
| 2621 | + print_result(D_ZUC, testnum, count, d); |
| 2622 | + } |
| 2623 | + } |
| 2624 | +#endif |
2591 | 2625 | #ifndef OPENSSL_NO_RC2 |
2592 | 2626 | if (doit[D_CBC_RC2]) { |
2593 | 2627 | if (async_jobs > 0) { |
@@ -3160,6 +3194,7 @@ int speed_main(int argc, char **argv) |
3160 | 3194 | EC_KEY_precompute_mult(loopargs[i].sm2[testnum], NULL); |
3161 | 3195 | /* Perform SM2 encryption test */ |
3162 | 3196 | EC_KEY_generate_key(loopargs[i].sm2[testnum]); |
| 3197 | + loopargs[i].cipherlen = BUFSIZE; |
3163 | 3198 | st = SM2_encrypt(NID_sm3, loopargs[i].buf, 32, loopargs[i].buf2, |
3164 | 3199 | &loopargs[i].cipherlen, loopargs[i].sm2[testnum]); |
3165 | 3200 | if (st == 0) |
|
0 commit comments