Revert "Merge branch 'master' of https://github.com/guanzhi/GmSSL"

This reverts commit 7897604408, reversing
changes made to 6c122e31a6.
This commit is contained in:
Zhi Guan
2019-05-24 10:46:55 +08:00
parent 7897604408
commit 246867fd2b
15 changed files with 11 additions and 266 deletions

View File

@@ -202,7 +202,6 @@ typedef struct loopargs_st {
#ifndef OPENSSL_NO_SM9
SM9PublicParameters *sm9mpk[SM9_NUM];
SM9PrivateKey *sm9sk[SM9_NUM];
SM9MasterSecret *sm9mst[SM9_NUM];
#endif
EVP_CIPHER_CTX *ctx;
HMAC_CTX *hctx;
@@ -1123,91 +1122,23 @@ static long sm9sign_c[SM9_NUM][2];
static int SM9_sign_loop(void *args)
{
loopargs_t *tempargs = *(loopargs_t **)args;
unsigned char *buf = tempargs->buf;
SM9PrivateKey **sm9 = tempargs->sm9sk;
unsigned char *sm9sig = tempargs->buf2;
unsigned int *sm9siglen = &tempargs->siglen;
int ret, count;
for (count = 0; COND(sm9sign_c[testnum][0]); count++) {
ret = SM9_sign(NID_sm3, buf, 32, sm9sig, sm9siglen, sm9[testnum]);
if (ret == 0) {
BIO_printf(bio_err, "SM9 sign failure\n");
ERR_print_errors(bio_err);
count = -1;
break;
}
}
return count;
return 1;
}
static char* sm9verify_id = "sm9_verify";
static size_t sm9verify_idlen = 10;
static int SM9_verify_loop(void *args)
{
loopargs_t *tempargs = *(loopargs_t **)args;
unsigned char *buf = tempargs->buf;
SM9PublicParameters **sm9 = tempargs->sm9mpk;
unsigned char *sm9sig = tempargs->buf2;
unsigned int sm9siglen = tempargs->siglen;
int ret, count;
for (count = 0; COND(sm9sign_c[testnum][1]); count++) {
ret = SM9_verify(NID_sm3, buf, 32, sm9sig, sm9siglen, sm9[testnum], sm9verify_id, sm9verify_idlen);
if (ret != 1) {
BIO_printf(bio_err, "SM9 verify failure\n");
ERR_print_errors(bio_err);
count = -1;
break;
}
}
return count;
return 1;
}
static long sm9enc_c[SM9_NUM][2];
static char* sm9enc_id = "sm9_enc";
static size_t sm9enc_idlen = 7;
static int SM9_encrypt_loop(void *args)
{
loopargs_t *tempargs = *(loopargs_t **)args;
unsigned char *buf = tempargs->buf;
SM9PublicParameters **sm9 = tempargs->sm9mpk;
unsigned char *sm9cipher = tempargs->buf2;
size_t *sm9cipherlen = &tempargs->cipherlen;
int ret, count;
for (count = 0; COND(sm9enc_c[testnum][0]); count++) {
*sm9cipherlen = BUFSIZE;
ret = SM9_encrypt(NID_sm3, buf, 32, sm9cipher,
sm9cipherlen, sm9[testnum], sm9enc_id, sm9enc_idlen);
if (ret == 0) {
BIO_printf(bio_err, "SM9 encrypt failure\n");
ERR_print_errors(bio_err);
count = -1;
break;
}
}
return count;
return 1;
}
static int SM9_decrypt_loop(void *args)
{
loopargs_t *tempargs = *(loopargs_t **)args;
unsigned char *buf = tempargs->buf;
SM9PrivateKey **sm9 = tempargs->sm9sk;
unsigned char *sm9cipher = tempargs->buf2;
size_t sm9cipherlen = tempargs->cipherlen;
int ret, count;
for (count = 0; COND(sm9enc_c[testnum][0]); count++) {
size_t len = sm9cipherlen;
ret = SM9_decrypt(NID_sm3, sm9cipher, sm9cipherlen,
buf, &len, sm9[testnum]);
if (ret == 0) {
BIO_printf(bio_err, "SM9 decrypt failure\n");
ERR_print_errors(bio_err);
count = -1;
break;
}
}
return count;
return 1;
}
#endif
@@ -1708,12 +1639,6 @@ int speed_main(int argc, char **argv)
static const int test_sm9_curves_bits[SM9_NUM] = {
256,
};
static const int test_sm9_scheme[SM9_NUM] = {
NID_sm9sign,
};
static const int test_sm9_hash1[SM9_NUM] = {
NID_sm9hash1_with_sm3,
};
int sm9sign_doit[SM9_NUM] = { 0 };
int sm9enc_doit[SM9_NUM] = { 0 };
#endif
@@ -3334,181 +3259,7 @@ int speed_main(int argc, char **argv)
#endif /* OPENSSL_NO_SM2 */
#ifndef OPENSSL_NO_SM9
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
}
for (testnum = 0; testnum < SM9_NUM; testnum++) {
int st = 1;
if (!sm9sign_doit[testnum])
continue; /* Ignore Curve */
for (i = 0; i < loopargs_len; i++) {
loopargs[i].sm9mst[testnum] = SM9_generate_master_secret(test_sm9_curves[testnum],
test_sm9_scheme[testnum], test_sm9_hash1[testnum]);
if (loopargs[i].sm9mst[testnum] == NULL) {
st = 0;
break;
}
}
if (st == 0) {
BIO_printf(bio_err, "SM9 failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
for (i = 0; i < loopargs_len; i++) {
/* Perform SM9 signature test */
loopargs[i].sm9sk[testnum] = SM9_extract_private_key(loopargs[i].sm9mst[testnum], sm9verify_id, sm9verify_idlen);
st = SM9_sign(NID_sm3, loopargs[i].buf, 32, loopargs[i].buf2,
&loopargs[i].siglen, loopargs[i].sm9sk[testnum]);
if (st == 0)
break;
}
if (st == 0) {
BIO_printf(bio_err,
"SM9 sign failure. No SM9 sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("sign", "sm9",
sm9sign_c[testnum][0],
test_sm9_curves_bits[testnum], ECDSA_SECONDS);
Time_F(START);
count = run_benchmark(async_jobs, SM9_sign_loop, loopargs);
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R7:%ld:%d:%.2f\n" :
"%ld %d bit SM9 signs in %.2fs \n",
count, test_sm9_curves_bits[testnum], d);
sm9sign_results[testnum][0] = d / (double)count;
rsa_count = count;
}
/* Perform SM9 verification test */
for (i = 0; i < loopargs_len; i++) {
loopargs[i].sm9mpk[testnum] = SM9_extract_public_parameters(loopargs[i].sm9mst[testnum]);
st = SM9_verify(NID_sm3, loopargs[i].buf, 32, loopargs[i].buf2,
loopargs[i].siglen, loopargs[i].sm9mpk[testnum], sm9verify_id, sm9verify_idlen);
if (st != 1)
break;
}
if (st != 1) {
BIO_printf(bio_err,
"SM9 verify failure. No SM9 verify will be done.\n");
ERR_print_errors(bio_err);
sm9sign_doit[testnum] = 0;
} else {
pkey_print_message("verify", "sm9",
sm9sign_c[testnum][1],
test_sm9_curves_bits[testnum], ECDSA_SECONDS);
Time_F(START);
count = run_benchmark(async_jobs, SM9_verify_loop, loopargs);
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R8:%ld:%d:%.2f\n"
: "%ld %d bit SM9 verify in %.2fs\n",
count, test_sm9_curves_bits[testnum], d);
sm9sign_results[testnum][1] = d / (double)count;
}
if (rsa_count <= 1) {
/* if longer than 10s, don't do any more */
for (testnum++; testnum < SM9_NUM; testnum++)
sm9sign_doit[testnum] = 0;
}
}
}
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
}
for (testnum = 0; testnum < SM9_NUM; testnum++) {
int st = 1;
if (!sm9enc_doit[testnum])
continue;
for (i = 0; i < loopargs_len; i++) {
loopargs[i].sm9mst[testnum] = SM9_generate_master_secret(test_sm9_curves[testnum],
test_sm9_scheme[testnum], test_sm9_hash1[testnum]);
if (loopargs[i].sm9mst[testnum] == NULL) {
st = 0;
break;
}
}
if (st == 0) {
BIO_printf(bio_err, "SM9 failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
for (i = 0; i < loopargs_len; i++) {
/* these 2 lines should be modified ? */
/*if (!nopre)
EC_KEY_precompute_mult(loopargs[i].sm9[testnum], NULL);*/
/* Perform SM9 encryption test */
loopargs[i].sm9mpk[testnum] = SM9_extract_public_parameters(loopargs[i].sm9mst[testnum]);
loopargs[i].cipherlen = BUFSIZE;
st = SM9_encrypt(NID_sm3, loopargs[i].buf, 32, loopargs[i].buf2,
&loopargs[i].cipherlen, loopargs[i].sm9mpk[testnum], sm9enc_id, sm9enc_idlen);
if (st == 0)
break;
}
if (st == 0) {
BIO_printf(bio_err,
"SM9 encryption failure. No SM9 encryption will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("encrypt", "sm9",
sm9enc_c[testnum][0],
test_sm9_curves_bits[testnum], ECDSA_SECONDS);
Time_F(START);
count = run_benchmark(async_jobs, SM9_encrypt_loop, loopargs);
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R7:%ld:%d:%.2f\n" :
"%ld %d bit SM9 encrypt in %.2fs \n",
count, test_sm9_curves_bits[testnum], d);
sm9enc_results[testnum][0] = d / (double)count;
rsa_count = count;
}
/* Perform SM9 verification test */
for (i = 0; i < loopargs_len; i++) {
loopargs[i].sm9sk[testnum] = SM9_extract_private_key(loopargs[i].sm9mst[testnum], sm9enc_id, sm9enc_idlen);
size_t len = loopargs[i].cipherlen;
st = SM9_decrypt(NID_sm3, loopargs[i].buf2, loopargs[i].cipherlen,
loopargs[i].buf, &len, loopargs[i].sm9sk[testnum]);
if (st == 0)
break;
}
if (st != 1) {
BIO_printf(bio_err,
"SM9 decrypt failure. No SM9 decrypt will be done.\n");
ERR_print_errors(bio_err);
sm9enc_doit[testnum] = 0;
} else {
pkey_print_message("decrypt", "sm9",
sm9enc_c[testnum][1],
test_sm9_curves_bits[testnum], ECDSA_SECONDS);
Time_F(START);
count = run_benchmark(async_jobs, SM9_decrypt_loop, loopargs);
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R8:%ld:%d:%.2f\n"
: "%ld %d bit SM9 decrypt in %.2fs\n",
count, test_sm9_curves_bits[testnum], d);
sm9enc_results[testnum][1] = d / (double)count;
}
if (rsa_count <= 1) {
/* if longer than 10s, don't do any more */
for (testnum++; testnum < SM9_NUM; testnum++)
sm9sign_doit[testnum] = 0;
}
}
}
//FIXME: this is the core code,
#endif /* OPENSSL_NO_SM9 */
#ifndef NO_FORK
@@ -3779,7 +3530,6 @@ int speed_main(int argc, char **argv)
for (k = 0; k < SM9_NUM; k++) {
SM9PublicParameters_free(loopargs[i].sm9mpk[k]);
SM9PrivateKey_free(loopargs[i].sm9sk[k]);
SM9MasterSecret_free(loopargs[i].sm9mst[k]);
}
#endif
}

0
crypto/sm9/sm9_asn1.c Normal file → Executable file
View File

0
crypto/sm9/sm9_enc.c Normal file → Executable file
View File

0
crypto/sm9/sm9_err.c Normal file → Executable file
View File

0
crypto/sm9/sm9_exch.c Normal file → Executable file
View File

3
crypto/sm9/sm9_keygen.c Normal file → Executable file
View File

@@ -304,8 +304,7 @@ SM9_KEY *SM9_MASTER_KEY_extract_key(SM9_MASTER_KEY *master,
sk = NULL;
end:
SM9PrivateKey_free(sk);
EC_GROUP_clear_free(group);
EC_GROUP_free(group);
if (ctx) {
BN_CTX_end(ctx);
}

0
crypto/sm9/sm9_lib.c Normal file → Executable file
View File

0
crypto/sm9/sm9_params.c Normal file → Executable file
View File

0
crypto/sm9/sm9_pmeth.c Normal file → Executable file
View File

View File

@@ -2659,7 +2659,6 @@ int rate_pairing(fp12_t r, const point_t *Q, const EC_POINT *P, BN_CTX *ctx)
BN_free(xP);
BN_free(yP);
EC_GROUP_clear_free(group);
return ret;
}

0
crypto/sm9/sm9_setup.c Normal file → Executable file
View File

6
crypto/sm9/sm9_sign.c Normal file → Executable file
View File

@@ -198,8 +198,6 @@ end:
BN_free(r);
point_cleanup(&Ppubs);
fp12_cleanup(w);
BN_CTX_end(bn_ctx);
BN_CTX_free(bn_ctx);
return ret;
}
@@ -357,7 +355,9 @@ end:
point_cleanup(&P);
fp12_cleanup(w);
fp12_cleanup(u);
BN_CTX_end(bn_ctx);
if (bn_ctx) {
BN_CTX_end(bn_ctx);
}
BN_CTX_free(bn_ctx);
return ret;
}

View File

@@ -58,7 +58,6 @@ package gmssl
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/engine.h>
#include <openssl/objects.h>
#include <openssl/opensslconf.h>
@@ -70,8 +69,8 @@ import "C"
import (
"fmt"
"runtime"
"unsafe"
"runtime"
)
type Certificate struct {

View File

@@ -49,9 +49,8 @@
package sm3
import (
"gmssl"
"hash"
"github.com/guanzhi/GmSSL/go/gmssl"
)
type digest struct {

View File

@@ -425,7 +425,6 @@ end:
if (inbuf) (*env)->ReleaseByteArrayElements(env, in, (jbyte *)inbuf, JNI_ABORT);
if (ivbuf) (*env)->ReleaseByteArrayElements(env, iv, (jbyte *)ivbuf, JNI_ABORT);
EVP_CIPHER_CTX_free(cctx);
OPENSSL_free(outbuf);
return ret;
}