mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-18 02:43:40 +08:00
speed-update
This commit is contained in:
26
apps/speed.c
26
apps/speed.c
@@ -148,7 +148,7 @@
|
||||
#define BUFSIZE (1024*16+1)
|
||||
#define MAX_MISALIGNMENT 63
|
||||
|
||||
#define ALGOR_NUM 33
|
||||
#define ALGOR_NUM 34
|
||||
#define SIZE_NUM 6
|
||||
#define PRIME_NUM 3
|
||||
#define RSA_NUM 7
|
||||
@@ -298,7 +298,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", "zuc"
|
||||
"sm3", "sms4 cbc", "zuc", "zuc256"
|
||||
};
|
||||
|
||||
static double results[ALGOR_NUM][SIZE_NUM];
|
||||
@@ -484,6 +484,7 @@ OPTIONS speed_options[] = {
|
||||
#define D_SM3 30
|
||||
#define D_CBC_SMS4 31
|
||||
#define D_ZUC 32
|
||||
#define D_ZUC256 33
|
||||
static OPT_PAIR doit_choices[] = {
|
||||
#ifndef OPENSSL_NO_MD2
|
||||
{"md2", D_MD2},
|
||||
@@ -562,6 +563,7 @@ static OPT_PAIR doit_choices[] = {
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_ZUC
|
||||
{"zuc", D_ZUC},
|
||||
{"zuc256", D_ZUC256},
|
||||
#endif
|
||||
{NULL}
|
||||
};
|
||||
@@ -1573,6 +1575,7 @@ int speed_main(int argc, char **argv)
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_ZUC
|
||||
ZUC_KEY zuc_ks;
|
||||
ZUC256_KEY zuc256_ks;
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_BF
|
||||
BF_KEY bf_ks;
|
||||
@@ -2073,6 +2076,7 @@ int speed_main(int argc, char **argv)
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_ZUC
|
||||
ZUC_set_key(&zuc_ks, key16, iv);
|
||||
ZUC256_set_key(&zuc256_ks, key32, iv);
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RC4
|
||||
RC4_set_key(&rc4_ks, 16, key16);
|
||||
@@ -2135,6 +2139,7 @@ int speed_main(int argc, char **argv)
|
||||
c[D_SM3][0] = count;
|
||||
c[D_CBC_SMS4][0] = count;
|
||||
c[D_ZUC][0] = count;
|
||||
c[D_ZUC256][0] = count;
|
||||
|
||||
for (i = 1; i < SIZE_NUM; i++) {
|
||||
long l0, l1;
|
||||
@@ -2177,6 +2182,7 @@ int speed_main(int argc, char **argv)
|
||||
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;
|
||||
c[D_ZUC256][i] = c[D_ZUC256][i - 1] * l0 / l1;
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_NO_RSA
|
||||
@@ -2696,6 +2702,22 @@ int speed_main(int argc, char **argv)
|
||||
print_result(D_ZUC, testnum, count, d);
|
||||
}
|
||||
}
|
||||
if (doit[D_ZUC256]) {
|
||||
if (async_jobs > 0) {
|
||||
BIO_printf(bio_err, "Async mode is not supported with %s\n",
|
||||
names[D_ZUC256]);
|
||||
doit[D_ZUC256] = 0;
|
||||
}
|
||||
for (testnum = 0; testnum < SIZE_NUM && async_init == 0; testnum++) {
|
||||
print_message(names[D_ZUC256], c[D_ZUC256][testnum], lengths[testnum]);
|
||||
Time_F(START);
|
||||
for (count = 0, run = 1; COND(c[D_ZUC256][testnum]); count++)
|
||||
ZUC256_generate_keystream(&zuc256_ks, lengths[testnum]/4,
|
||||
(unsigned int *)loopargs[0].buf);
|
||||
d = Time_F(STOP);
|
||||
print_result(D_ZUC256, testnum, count, d);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_RC2
|
||||
if (doit[D_CBC_RC2]) {
|
||||
|
||||
@@ -50,8 +50,6 @@
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/sm9.h>
|
||||
#include <openssl/ec_type1.h>
|
||||
#include <openssl/bn_hash.h>
|
||||
#include "sm9_lcl.h"
|
||||
|
||||
|
||||
|
||||
@@ -166,6 +166,7 @@ static int fp2_equ(const fp2_t a, const fp2_t b)
|
||||
return !BN_cmp(a[0], b[0]) && !BN_cmp(a[1], b[1]);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp2_equ_hex(const fp2_t a, const char *str[2], BN_CTX *ctx)
|
||||
{
|
||||
fp2_t t;
|
||||
@@ -173,7 +174,9 @@ static int fp2_equ_hex(const fp2_t a, const char *str[2], BN_CTX *ctx)
|
||||
fp2_set_hex(t, str);
|
||||
return fp2_equ(a, t);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp2_add_word(fp2_t r, const fp2_t a, unsigned long b, const BIGNUM *p, BN_CTX *ctx)
|
||||
{
|
||||
BIGNUM *w = NULL;
|
||||
@@ -187,6 +190,7 @@ static int fp2_add_word(fp2_t r, const fp2_t a, unsigned long b, const BIGNUM *p
|
||||
BN_free(w);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp2_add(fp2_t r, const fp2_t a, const fp2_t b, const BIGNUM *p, BN_CTX *ctx)
|
||||
{
|
||||
@@ -426,11 +430,13 @@ static int fp2_inv(fp2_t r, const fp2_t a, const BIGNUM *p, BN_CTX *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp2_div(fp2_t r, const fp2_t a, const fp2_t b, const BIGNUM *p, BN_CTX *ctx)
|
||||
{
|
||||
return fp2_inv(r, b, p, ctx)
|
||||
&& fp2_mul(r, a, r, p, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp2_to_bin(const fp2_t a, unsigned char to[64])
|
||||
{
|
||||
@@ -446,6 +452,7 @@ static int fp2_from_bin(fp2_t a, const unsigned char from[64])
|
||||
&& BN_bin2bn(from + 32, 32, a[0]);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp2_test(const BIGNUM *p, BN_CTX *ctx)
|
||||
{
|
||||
const char *_a[] = {
|
||||
@@ -561,6 +568,7 @@ static int fp2_test(const BIGNUM *p, BN_CTX *ctx)
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp4_init(fp4_t a, BN_CTX *ctx)
|
||||
{
|
||||
@@ -580,11 +588,13 @@ static void fp4_cleanup(fp4_t a)
|
||||
fp2_cleanup(a[1]);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static void fp4_clear_cleanup(fp4_t a)
|
||||
{
|
||||
fp2_clear_cleanup(a[0]);
|
||||
fp2_clear_cleanup(a[1]);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp4_print(const fp4_t a)
|
||||
{
|
||||
@@ -672,6 +682,7 @@ static int fp4_equ(const fp4_t a, const fp4_t b)
|
||||
&& fp2_equ(a[1], b[1]);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp4_equ_hex(const fp4_t a, const char *str[4], BN_CTX *ctx)
|
||||
{
|
||||
fp4_t t;
|
||||
@@ -679,6 +690,7 @@ static int fp4_equ_hex(const fp4_t a, const char *str[4], BN_CTX *ctx)
|
||||
fp4_set_hex(t, str);
|
||||
return fp4_equ(a, t);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp4_to_bin(const fp4_t a, unsigned char to[128])
|
||||
{
|
||||
@@ -863,6 +875,7 @@ static int fp4_inv(fp4_t r, const fp4_t a, const BIGNUM *p, BN_CTX *ctx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp4_test(const BIGNUM *p, BN_CTX *ctx)
|
||||
{
|
||||
const char *_a[] = {
|
||||
@@ -999,6 +1012,7 @@ static int fp4_test(const BIGNUM *p, BN_CTX *ctx)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int fp12_init(fp12_t a, BN_CTX *ctx)
|
||||
{
|
||||
@@ -1021,12 +1035,14 @@ void fp12_cleanup(fp12_t a)
|
||||
fp4_cleanup(a[2]);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static void fp12_clear_cleanup(fp12_t a)
|
||||
{
|
||||
fp4_clear_cleanup(a[0]);
|
||||
fp4_clear_cleanup(a[1]);
|
||||
fp4_clear_cleanup(a[2]);
|
||||
}
|
||||
#endif
|
||||
|
||||
int fp12_print(const fp12_t a)
|
||||
{
|
||||
@@ -1036,6 +1052,7 @@ int fp12_print(const fp12_t a)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp12_is_zero(const fp12_t a)
|
||||
{
|
||||
return fp4_is_zero(a[0])
|
||||
@@ -1056,6 +1073,7 @@ static void fp12_set_zero(fp12_t r)
|
||||
fp4_set_zero(r[1]);
|
||||
fp4_set_zero(r[2]);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp12_set_one(fp12_t r)
|
||||
{
|
||||
@@ -1071,12 +1089,14 @@ static int fp12_copy(fp12_t r, const fp12_t a)
|
||||
&& fp4_copy(r[2], a[2]);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp12_set(fp12_t r, const fp4_t a0, const fp4_t a1, const fp4_t a2)
|
||||
{
|
||||
return fp4_copy(r[0], a0)
|
||||
&& fp4_copy(r[1], a1)
|
||||
&& fp4_copy(r[2], a2);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp12_set_hex(fp12_t r, const char *str[12])
|
||||
{
|
||||
@@ -1085,12 +1105,14 @@ static int fp12_set_hex(fp12_t r, const char *str[12])
|
||||
&& fp4_set_hex(r[2], str + 8);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp12_set_fp4(fp12_t r, const fp4_t a)
|
||||
{
|
||||
fp4_set_zero(r[1]);
|
||||
fp4_set_zero(r[2]);
|
||||
return fp4_copy(r[0], a);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp12_set_fp2(fp12_t r, const fp2_t a)
|
||||
{
|
||||
@@ -1106,6 +1128,7 @@ static int fp12_set_bn(fp12_t r, const BIGNUM *a)
|
||||
return fp4_set_bn(r[0], a);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp12_set_word(fp12_t r, unsigned long a)
|
||||
{
|
||||
fp4_set_zero(r[1]);
|
||||
@@ -1119,6 +1142,7 @@ static int fp12_set_u(fp12_t r)
|
||||
fp4_set_zero(r[2]);
|
||||
return fp4_set_u(r[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp12_set_v(fp12_t r)
|
||||
{
|
||||
@@ -1127,12 +1151,14 @@ static int fp12_set_v(fp12_t r)
|
||||
return fp4_set_v(r[0]);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp12_set_w(fp12_t r)
|
||||
{
|
||||
fp4_set_zero(r[0]);
|
||||
fp4_set_zero(r[2]);
|
||||
return fp4_set_one(r[1]);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fp12_set_w_sqr(fp12_t r)
|
||||
{
|
||||
@@ -1148,6 +1174,7 @@ static int fp12_equ(const fp12_t a, const fp12_t b)
|
||||
&& fp4_equ(a[2], b[2]);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp12_equ_hex(const fp12_t a, const char *str[12], BN_CTX *ctx)
|
||||
{
|
||||
fp12_t t;
|
||||
@@ -1155,6 +1182,7 @@ static int fp12_equ_hex(const fp12_t a, const char *str[12], BN_CTX *ctx)
|
||||
fp12_set_hex(t, str);
|
||||
return fp12_equ(a, t);
|
||||
}
|
||||
#endif
|
||||
|
||||
int fp12_to_bin(const fp12_t a, unsigned char to[384])
|
||||
{
|
||||
@@ -1165,14 +1193,13 @@ int fp12_to_bin(const fp12_t a, unsigned char to[384])
|
||||
|
||||
static int fp12_from_bin(fp4_t a, const unsigned char from[384])
|
||||
{
|
||||
return fp4_from_bin(a[2], from)
|
||||
&& fp4_from_bin(a[1], from + 128)
|
||||
&& fp4_from_bin(a[0], from + 256);
|
||||
return fp4_from_bin(&a[2], from)
|
||||
&& fp4_from_bin(&a[1], from + 128)
|
||||
&& fp4_from_bin(&a[0], from + 256);
|
||||
}
|
||||
|
||||
static int fp12_add(fp12_t r, const fp12_t a, const fp12_t b, const BIGNUM *p, BN_CTX *ctx)
|
||||
{
|
||||
|
||||
return fp4_add(r[0], a[0], b[0], p, ctx)
|
||||
&& fp4_add(r[1], a[1], b[1], p, ctx)
|
||||
&& fp4_add(r[2], a[2], b[2], p, ctx);
|
||||
@@ -1443,6 +1470,8 @@ int fp12_pow(fp12_t r, const fp12_t a, const BIGNUM *k, const BIGNUM *p, BN_CTX
|
||||
}
|
||||
|
||||
fp12_copy(r, t);
|
||||
|
||||
fp12_cleanup(t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1479,6 +1508,7 @@ static int fp12_fast_expo_p2(fp12_t r, const fp12_t a, const BIGNUM *p, BN_CTX *
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int fp12_test(const BIGNUM *p, BN_CTX *ctx)
|
||||
{
|
||||
const char *_a[] = {
|
||||
@@ -1762,6 +1792,7 @@ static int fp12_test(const BIGNUM *p, BN_CTX *ctx)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int point_init(point_t *P, BN_CTX *ctx)
|
||||
{
|
||||
@@ -2195,6 +2226,7 @@ int point_mul_generator(point_t *R, const BIGNUM *k, const BIGNUM *p, BN_CTX *ct
|
||||
return point_mul(R, k, &G, p, ctx);
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int point_test(const BIGNUM *p, BN_CTX *ctx)
|
||||
{
|
||||
const char *_G[] = {
|
||||
@@ -2295,6 +2327,7 @@ static int point_test(const BIGNUM *p, BN_CTX *ctx)
|
||||
//fp12_cleanup(y);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int eval_tangent(fp12_t r, const point_t *T, const BIGNUM *xP, const BIGNUM *yP,
|
||||
const BIGNUM *p, BN_CTX *ctx)
|
||||
@@ -2445,6 +2478,8 @@ static int final_expo(fp12_t r, const fp12_t a, const BIGNUM *k, const BIGNUM *p
|
||||
}
|
||||
}
|
||||
fp12_copy(r, t);
|
||||
|
||||
fp12_cleanup(t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2503,6 +2538,9 @@ static int fast_final_expo(fp12_t r, const fp12_t a, const BIGNUM *k, const BIGN
|
||||
}
|
||||
}
|
||||
fp12_copy(r, t);
|
||||
|
||||
fp12_cleanup(t);
|
||||
fp12_cleanup(t0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2663,6 +2701,7 @@ int rate_pairing(fp12_t r, const point_t *Q, const EC_POINT *P, BN_CTX *ctx)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if SM9_TEST
|
||||
static int rate_test(void)
|
||||
{
|
||||
const char *Ppubs_str[] = {
|
||||
@@ -2712,6 +2751,7 @@ static int rate_test(void)
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* for SM9 sign, the (xP, yP) is the fixed generator of E(Fp)
|
||||
*/
|
||||
|
||||
@@ -51,8 +51,6 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/sm9.h>
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/ec_type1.h>
|
||||
#include <openssl/bn_gfp2.h>
|
||||
#include "sm9_lcl.h"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user