Add new EC/SM2 API

This commit is contained in:
Zhi Guan
2019-02-28 17:49:37 +08:00
parent bf4c6920d9
commit 5b90476864
14 changed files with 6220 additions and 5435 deletions

View File

@@ -142,3 +142,71 @@ 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);
}

90
crypto/sm2/sm2_cosign.c Normal file
View File

@@ -0,0 +1,90 @@
/* ====================================================================
* 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

@@ -1,6 +1,6 @@
/*
* Generated by util/mkerr.pl DO NOT EDIT
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -23,6 +23,14 @@ static ERR_STRING_DATA SM2_str_functs[] = {
{ERR_FUNC(SM2_F_O2I_SM2CIPHERTEXTVALUE), "o2i_SM2CiphertextValue"},
{ERR_FUNC(SM2_F_SM2CIPHERTEXTVALUE_SIZE), "SM2CiphertextValue_size"},
{ERR_FUNC(SM2_F_SM2_CIPHERTEXT_SIZE), "SM2_ciphertext_size"},
{ERR_FUNC(SM2_F_SM2_COSIGNER1_GENERATE_PROOF),
"SM2_cosigner1_generate_proof"},
{ERR_FUNC(SM2_F_SM2_COSIGNER1_GENERATE_SIGNATURE),
"SM2_cosigner1_generate_signature"},
{ERR_FUNC(SM2_F_SM2_COSIGNER1_SETUP), "SM2_cosigner1_setup"},
{ERR_FUNC(SM2_F_SM2_COSIGNER2_GENERATE_PROOF),
"SM2_cosigner2_generate_proof"},
{ERR_FUNC(SM2_F_SM2_COSIGNER2_SETUP), "SM2_cosigner2_setup"},
{ERR_FUNC(SM2_F_SM2_DECRYPT), "SM2_decrypt"},
{ERR_FUNC(SM2_F_SM2_DO_DECRYPT), "SM2_do_decrypt"},
{ERR_FUNC(SM2_F_SM2_DO_ENCRYPT), "SM2_do_encrypt"},
@@ -47,6 +55,7 @@ static ERR_STRING_DATA SM2_str_reasons[] = {
{ERR_REASON(SM2_R_KDF_FAILURE), "kdf failure"},
{ERR_REASON(SM2_R_MISSING_PARAMETERS), "missing parameters"},
{ERR_REASON(SM2_R_NEED_NEW_SETUP_VALUES), "need new setup values"},
{ERR_REASON(SM2_R_NOT_IMPLEMENTED), "not implemented"},
{ERR_REASON(SM2_R_PLAINTEXT_TOO_LONG), "plaintext too long"},
{ERR_REASON(SM2_R_RANDOM_NUMBER_GENERATION_FAILED),
"random number generation failed"},

View File

@@ -98,3 +98,24 @@ struct sm2_kap_ctx_st {
int SM2_ciphertext_size(const EC_KEY *ec_key, size_t inlen);
struct SM2_COSIGNER1_SHARE_st {
BIGNUM *a;
BIGNUM *b;
};
struct SM2_COSIGNER2_SHARE_st {
BIGNUM *a;
BIGNUM *b;
};
struct SM2_COSIGNER1_PROOF_st {
BIGNUM *a;
BIGNUM *b;
};
struct SM2_COSIGNER2_PROOF_st {
BIGNUM *a;
BIGNUM *b;
};