Clean SM2 and SM3

This commit is contained in:
Zhi Guan
2019-06-15 23:42:35 +08:00
parent 934a66ec36
commit cfcffd03d0
7 changed files with 5123 additions and 5346 deletions

View File

@@ -1,3 +1,3 @@
LIBS=../../libcrypto
SOURCE[../../libcrypto]=sm2_err.c sm2_asn1.c sm2_id.c sm2_sign.c sm2_enc.c \
sm2_oct.c sm2_exch.c sm2_kmeth.c sm2_cosign.c
sm2_oct.c sm2_exch.c sm2_kmeth.c

View File

@@ -142,71 +142,3 @@ int i2d_SM2CiphertextValue_fp(FILE *fp, SM2CiphertextValue *a)
return ASN1_item_i2d_fp(ASN1_ITEM_rptr(SM2CiphertextValue), fp, a);
}
#endif
ASN1_SEQUENCE(SM2_COSIGNER1_SHARE) = {
ASN1_SIMPLE(SM2_COSIGNER1_SHARE, a, BIGNUM),
ASN1_SIMPLE(SM2_COSIGNER1_SHARE, b, BIGNUM)
} ASN1_SEQUENCE_END(SM2_COSIGNER1_SHARE)
IMPLEMENT_ASN1_FUNCTIONS(SM2_COSIGNER1_SHARE)
IMPLEMENT_ASN1_DUP_FUNCTION(SM2_COSIGNER1_SHARE)
ASN1_SEQUENCE(SM2_COSIGNER2_SHARE) = {
ASN1_SIMPLE(SM2_COSIGNER2_SHARE, a, BIGNUM),
ASN1_SIMPLE(SM2_COSIGNER2_SHARE, b, BIGNUM)
} ASN1_SEQUENCE_END(SM2_COSIGNER2_SHARE)
IMPLEMENT_ASN1_FUNCTIONS(SM2_COSIGNER2_SHARE)
IMPLEMENT_ASN1_DUP_FUNCTION(SM2_COSIGNER2_SHARE)
ASN1_SEQUENCE(SM2_COSIGNER1_PROOF) = {
ASN1_SIMPLE(SM2_COSIGNER1_PROOF, a, BIGNUM),
ASN1_SIMPLE(SM2_COSIGNER1_PROOF, b, BIGNUM)
} ASN1_SEQUENCE_END(SM2_COSIGNER1_PROOF)
IMPLEMENT_ASN1_FUNCTIONS(SM2_COSIGNER1_PROOF)
IMPLEMENT_ASN1_DUP_FUNCTION(SM2_COSIGNER1_PROOF)
ASN1_SEQUENCE(SM2_COSIGNER2_PROOF) = {
ASN1_SIMPLE(SM2_COSIGNER2_PROOF, a, BIGNUM),
ASN1_SIMPLE(SM2_COSIGNER2_PROOF, b, BIGNUM)
} ASN1_SEQUENCE_END(SM2_COSIGNER2_PROOF)
IMPLEMENT_ASN1_FUNCTIONS(SM2_COSIGNER2_PROOF)
IMPLEMENT_ASN1_DUP_FUNCTION(SM2_COSIGNER2_PROOF)
int i2d_SM2_COSIGNER1_SHARE_bio(BIO *bp, SM2_COSIGNER1_SHARE *a)
{
return ASN1_item_i2d_bio(ASN1_ITEM_rptr(SM2_COSIGNER1_SHARE), bp, a);
}
SM2_COSIGNER1_SHARE *d2i_SM2_COSIGNER1_SHARE_bio(BIO *bp, SM2_COSIGNER1_SHARE **a)
{
return ASN1_item_d2i_bio(ASN1_ITEM_rptr(SM2_COSIGNER1_SHARE), bp, a);
}
int i2d_SM2_COSIGNER2_SHARE_bio(BIO *bp, SM2_COSIGNER2_SHARE *a)
{
return ASN1_item_i2d_bio(ASN1_ITEM_rptr(SM2_COSIGNER2_SHARE), bp, a);
}
SM2_COSIGNER2_SHARE *d2i_SM2_COSIGNER2_SHARE_bio(BIO *bp, SM2_COSIGNER2_SHARE **a)
{
return ASN1_item_d2i_bio(ASN1_ITEM_rptr(SM2_COSIGNER2_SHARE), bp, a);
}
int i2d_SM2_COSIGNER1_PROOF_bio(BIO *bp, SM2_COSIGNER1_PROOF *a)
{
return ASN1_item_i2d_bio(ASN1_ITEM_rptr(SM2_COSIGNER1_PROOF), bp, a);
}
SM2_COSIGNER1_PROOF *d2i_SM2_COSIGNER1_PROOF_bio(BIO *bp, SM2_COSIGNER1_PROOF **a)
{
return ASN1_item_d2i_bio(ASN1_ITEM_rptr(SM2_COSIGNER1_PROOF), bp, a);
}
int i2d_SM2_COSIGNER2_PROOF_bio(BIO *bp, SM2_COSIGNER2_PROOF *a)
{
return ASN1_item_i2d_bio(ASN1_ITEM_rptr(SM2_COSIGNER2_PROOF), bp, a);
}
SM2_COSIGNER2_PROOF *d2i_SM2_COSIGNER2_PROOF_bio(BIO *bp, SM2_COSIGNER2_PROOF **a)
{
return ASN1_item_d2i_bio(ASN1_ITEM_rptr(SM2_COSIGNER2_PROOF), bp, a);
}

View File

@@ -1,90 +0,0 @@
/* ====================================================================
* Copyright (c) 2015 - 2019 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include <string.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/sm2.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/obj_mac.h>
#include <openssl/paillier.h>
#include "../ec/ec_lcl.h"
#include "sm2_lcl.h"
SM2_COSIGNER1_SHARE *SM2_cosigner1_setup(BIGNUM **k1, EC_KEY *ec_key, PAILLIER *pk)
{
SM2err(SM2_F_SM2_COSIGNER1_SETUP, SM2_R_NOT_IMPLEMENTED);
return NULL;
}
SM2_COSIGNER2_SHARE *SM2_cosigner2_setup(const SM2_COSIGNER1_SHARE *s1, BIGNUM **k2, EC_KEY *ec_key, PAILLIER *pk)
{
SM2err(SM2_F_SM2_COSIGNER2_SETUP, SM2_R_NOT_IMPLEMENTED);
return NULL;
}
SM2_COSIGNER1_PROOF *SM2_cosigner1_generate_proof(EC_KEY *ec_key, PAILLIER *pk)
{
SM2err(SM2_F_SM2_COSIGNER1_GENERATE_PROOF, SM2_R_NOT_IMPLEMENTED);
return NULL;
}
SM2_COSIGNER2_PROOF *SM2_cosigner2_generate_proof(EC_KEY *ec_key, PAILLIER *pk)
{
SM2err(SM2_F_SM2_COSIGNER2_GENERATE_PROOF, SM2_R_NOT_IMPLEMENTED);
return NULL;
}
ECDSA_SIG *SM2_cosigner1_generate_signature(EC_KEY *ec_key, PAILLIER *pk)
{
SM2err(SM2_F_SM2_COSIGNER1_GENERATE_SIGNATURE, SM2_R_NOT_IMPLEMENTED);
return NULL;
}

View File

@@ -46,10 +46,6 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
/* This implementation is a very straitforward implementaton of the SM3
* specification without any optimization tricks. It is also designed
* as a standalone module that can be ported.
*/
#include <string.h>
#include <openssl/sm3.h>
@@ -148,7 +144,6 @@ void sm3_compress(uint32_t digest[8], const unsigned char block[64])
uint32_t SS1, SS2, TT1, TT2;
int j;
for (j = 0; j < 16; j++)
W[j] = cpu_to_be32(pblock[j]);
@@ -210,18 +205,3 @@ void sm3(const unsigned char *msg, size_t msglen,
memset(&ctx, 0, sizeof(sm3_ctx_t));
}
#define DATA_ORDER_IS_BIG_ENDIAN
#define HASH_LONG SM3_LONG
#define HASH_CTX SM3_CTX
#define HASH_CBLOCK SM3_CBLOCK