mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-07 08:56:17 +08:00
Add new EC/SM2 API
This commit is contained in:
@@ -6,7 +6,7 @@ SOURCE[../../libcrypto]=\
|
||||
ecp_nistp224.c ecp_nistp256.c ecp_nistp521.c ecp_nistputil.c \
|
||||
ecp_oct.c ec2_oct.c ec_oct.c ec_kmeth.c ecdh_ossl.c ecdh_kdf.c \
|
||||
ecdsa_ossl.c ecdsa_sign.c ecdsa_vrf.c curve25519.c ecx_meth.c \
|
||||
{- $target{ec_asm_src} -}
|
||||
{- $target{ec_asm_src} -} ecahe.c
|
||||
|
||||
GENERATE[ecp_nistz256-x86.s]=asm/ecp_nistz256-x86.pl $(PERLASM_SCHEME) $(CFLAGS) $(LIB_CFLAGS) $(PROCESSOR)
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ static ERR_STRING_DATA EC_str_functs[] = {
|
||||
{ERR_FUNC(EC_F_D2I_ECPKPARAMETERS), "d2i_ECPKParameters"},
|
||||
{ERR_FUNC(EC_F_D2I_ECPRIVATEKEY), "d2i_ECPrivateKey"},
|
||||
{ERR_FUNC(EC_F_DO_EC_KEY_PRINT), "do_EC_KEY_print"},
|
||||
{ERR_FUNC(EC_F_ECAHE_CIPHERTEXT_SIZE), "ECAHE_ciphertext_size"},
|
||||
{ERR_FUNC(EC_F_ECAHE_DECRYPT), "ECAHE_decrypt"},
|
||||
{ERR_FUNC(EC_F_ECAHE_ENCRYPT), "ECAHE_encrypt"},
|
||||
{ERR_FUNC(EC_F_ECDH_CMS_DECRYPT), "ecdh_cms_decrypt"},
|
||||
{ERR_FUNC(EC_F_ECDH_CMS_SET_SHARED_INFO), "ecdh_cms_set_shared_info"},
|
||||
{ERR_FUNC(EC_F_ECDH_COMPUTE_KEY), "ECDH_compute_key"},
|
||||
@@ -169,6 +172,7 @@ static ERR_STRING_DATA EC_str_functs[] = {
|
||||
{ERR_FUNC(EC_F_EC_KEY_CHECK_KEY), "EC_KEY_check_key"},
|
||||
{ERR_FUNC(EC_F_EC_KEY_COPY), "EC_KEY_copy"},
|
||||
{ERR_FUNC(EC_F_EC_KEY_GENERATE_KEY), "EC_KEY_generate_key"},
|
||||
{ERR_FUNC(EC_F_EC_KEY_MERGE), "EC_KEY_merge"},
|
||||
{ERR_FUNC(EC_F_EC_KEY_NEW_METHOD), "EC_KEY_new_method"},
|
||||
{ERR_FUNC(EC_F_EC_KEY_OCT2PRIV), "EC_KEY_oct2priv"},
|
||||
{ERR_FUNC(EC_F_EC_KEY_PRINT_FP), "EC_KEY_print_fp"},
|
||||
|
||||
@@ -737,3 +737,9 @@ end:
|
||||
BN_CTX_free(bn_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
EC_KEY *EC_KEY_merge(STACK_OF(EC_KEY) *ec_keys)
|
||||
{
|
||||
ECerr(EC_F_EC_KEY_MERGE, EC_R_NOT_IMPLEMENTED);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
456
crypto/ec/ecahe.c
Normal file
456
crypto/ec/ecahe.c
Normal file
@@ -0,0 +1,456 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2016 - 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ecahe.h>
|
||||
|
||||
struct ECAHE_CIPHERTEXT_st {
|
||||
EC_POINT *A;
|
||||
EC_POINT *B;
|
||||
};
|
||||
|
||||
ASN1_SEQUENCE(ECAHE_CIPHERTEXT) = {
|
||||
ASN1_SIMPLE(ECAHE_CIPHERTEXT, A, ASN1_OCTET_STRING),
|
||||
ASN1_SIMPLE(ECAHE_CIPHERTEXT, B, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(ECAHE_CIPHERTEXT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ECAHE_CIPHERTEXT)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(ECAHE_CIPHERTEXT)
|
||||
|
||||
|
||||
#define EC_MAX_PLAINTEXT (65536)
|
||||
|
||||
|
||||
int ECAHE_ciphertext_size(EC_KEY *pk)
|
||||
{
|
||||
ECerr(EC_F_ECAHE_CIPHERTEXT_SIZE, ERR_R_EC_LIB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ECAHE_encrypt(unsigned char *out, size_t *outlen, const BIGNUM *in, EC_KEY *pk)
|
||||
{
|
||||
ECerr(EC_F_ECAHE_ENCRYPT, ERR_R_EC_LIB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ECAHE_decrypt(unsigned long *out, const unsigned char *in, size_t inlen, EC_KEY *sk)
|
||||
{
|
||||
ECerr(EC_F_ECAHE_DECRYPT, ERR_R_EC_LIB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ECAHE_do_encrypt(ECAHE_CIPHERTEXT *c, const BIGNUM *m, EC_KEY *pk)
|
||||
{
|
||||
int ret = -1;
|
||||
const EC_GROUP *group;
|
||||
const EC_POINT *point;
|
||||
BIGNUM *order = NULL;
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *r = NULL;
|
||||
|
||||
OPENSSL_assert(c);
|
||||
OPENSSL_assert(m);
|
||||
OPENSSL_assert(pk);
|
||||
|
||||
if (!(group = EC_KEY_get0_group(pk))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(order = BN_new())) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(ctx = BN_CTX_new())) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EC_GROUP_get_order(group, order, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(r = BN_new())) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
do {
|
||||
if (!BN_rand_range(r, order)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
} while (BN_is_zero(r));
|
||||
|
||||
if (c->A == NULL) {
|
||||
if (!(c->A = EC_POINT_new(group))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
/* c->A = [r]G */
|
||||
if (!EC_POINT_mul(group, c->A, r, NULL, NULL, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (c->B == NULL) {
|
||||
if (!(c->B = EC_POINT_new(group))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(point = EC_KEY_get0_public_key(pk))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
{
|
||||
//EC_POINT *T = EC_POINT_new(group);
|
||||
//EC_POINT_mul(group, T, m, NULL, NULL, ctx);
|
||||
//printf("[m]G = %s\n", EC_POINT_point2hex(group, T, EC_PUBKEY_FORMAT, ctx));
|
||||
}
|
||||
|
||||
/* c->b = [m]G + [r]P */
|
||||
if (!EC_POINT_mul(group, c->B, m, point, r, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
end:
|
||||
if (r) BN_free(r);
|
||||
if (order) BN_free(order);
|
||||
if (ctx) BN_CTX_free(ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* A == [r]G
|
||||
* B == [m]G + [r]P == [m]G + [rd]G
|
||||
* B - [d]A == B - [rd]G == [m]G
|
||||
*/
|
||||
int ECAHE_do_decrypt(BIGNUM *m, const ECAHE_CIPHERTEXT *c, EC_KEY *sk)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
const EC_GROUP *group;
|
||||
const EC_POINT *G;
|
||||
const BIGNUM *d;
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *order = NULL;
|
||||
EC_POINT *point = NULL;
|
||||
EC_POINT *point2 = NULL;
|
||||
unsigned int i;
|
||||
|
||||
OPENSSL_assert(m);
|
||||
OPENSSL_assert(c && c->A && c->B);
|
||||
OPENSSL_assert(sk);
|
||||
|
||||
if (!(group = EC_KEY_get0_group(sk))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(G = EC_GROUP_get0_generator(group))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(d = EC_KEY_get0_private_key(sk))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(ctx = BN_CTX_new())) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(order = BN_new())) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EC_GROUP_get_order(group, order, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(point = EC_POINT_new(group))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!BN_one(order)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* point = [d]A = [rd]G */
|
||||
if (!EC_POINT_mul(group, point, NULL, c->A, d, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* point = -[rd]G */
|
||||
if (!EC_POINT_invert(group, point, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* point = B - [rd]G = [m]G + [rd]G - [rd]G = [m]G */
|
||||
if (!EC_POINT_add(group, point, point, c->B, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
{
|
||||
//printf("[m]G = %s\n", EC_POINT_point2hex(group, point, EC_PUBKEY_FORMAT, ctx));
|
||||
}
|
||||
|
||||
if (!(point2 = EC_POINT_new(group))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EC_POINT_set_to_infinity(group, point2)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i = 0; i < EC_MAX_PLAINTEXT; i++) {
|
||||
|
||||
//printf("%03d ", i);
|
||||
//printf(" %s\n", EC_POINT_point2hex(group, point, EC_PUBKEY_FORMAT, ctx));
|
||||
//printf(" %s\n", EC_POINT_point2hex(group, point2, EC_PUBKEY_FORMAT, ctx));
|
||||
|
||||
if (EC_POINT_cmp(group, point, point2, ctx) == 0) {
|
||||
if (!BN_set_word(m, i)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
//printf("SUCCESS: %d\n", i+1);
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
EC_POINT_add(group, point2, point2, EC_GROUP_get0_generator(group), ctx);
|
||||
}
|
||||
|
||||
|
||||
end:
|
||||
if (ctx) BN_CTX_free(ctx);
|
||||
if (order) BN_free(order);
|
||||
if (point) EC_POINT_free(point);
|
||||
if (point2) EC_POINT_free(point2);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ECAHE_ciphertext_add(ECAHE_CIPHERTEXT *r,
|
||||
const ECAHE_CIPHERTEXT *a, const ECAHE_CIPHERTEXT *b,
|
||||
EC_KEY *pk)
|
||||
{
|
||||
const EC_GROUP *group = EC_KEY_get0_group(pk);
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
if (!(group = EC_KEY_get0_group(pk))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
OPENSSL_assert(a->A);
|
||||
OPENSSL_assert(b->A);
|
||||
OPENSSL_assert(a->B);
|
||||
OPENSSL_assert(b->B);
|
||||
|
||||
if (r->A == NULL) {
|
||||
if (!(r->A = EC_POINT_new(group))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (r->B == NULL) {
|
||||
if (!(r->B = EC_POINT_new(group))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(ctx = BN_CTX_new())) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!EC_POINT_add(group, r->A, a->A, b->A, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
BN_CTX_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!EC_POINT_add(group, r->B, a->B, b->B, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
BN_CTX_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ECAHE_ciphertext_sub(ECAHE_CIPHERTEXT *r,
|
||||
const ECAHE_CIPHERTEXT *a, const ECAHE_CIPHERTEXT *b,
|
||||
EC_KEY *pk)
|
||||
{
|
||||
const EC_GROUP *group = EC_KEY_get0_group(pk);
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
if (!(group = EC_KEY_get0_group(pk))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
OPENSSL_assert(a->A);
|
||||
OPENSSL_assert(b->A);
|
||||
OPENSSL_assert(a->B);
|
||||
OPENSSL_assert(b->B);
|
||||
|
||||
if (ECAHE_ciphertext_neg(r, b, pk) < 0) {
|
||||
fprintf(stderr, "%s (%s %d): ec_ciphertext_neg failed\n",
|
||||
__FUNCTION__, __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!(ctx = BN_CTX_new())) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!EC_POINT_add(group, r->A, r->A, a->A, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
BN_CTX_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!EC_POINT_add(group, r->B, r->B, a->B, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
BN_CTX_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ECAHE_ciphertext_neg(ECAHE_CIPHERTEXT *r, const ECAHE_CIPHERTEXT *a,
|
||||
EC_KEY *pk)
|
||||
{
|
||||
const EC_GROUP *group;
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
OPENSSL_assert(r && a && pk);
|
||||
OPENSSL_assert(a->A);
|
||||
OPENSSL_assert(a->B);
|
||||
|
||||
|
||||
if (!(group = EC_KEY_get0_group(pk))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (r->A)
|
||||
EC_POINT_free(r->A);
|
||||
if (!(r->A = EC_POINT_dup(a->A, group))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (r->B)
|
||||
EC_POINT_free(r->B);
|
||||
if (!(r->B = EC_POINT_dup(a->B, group))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(ctx = BN_CTX_new())) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
return -1;
|
||||
}
|
||||
if (!EC_POINT_invert(group, r->A, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
BN_CTX_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
if (!EC_POINT_invert(group, r->B, ctx)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
BN_CTX_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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
90
crypto/sm2/sm2_cosign.c
Normal 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;
|
||||
}
|
||||
@@ -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"},
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user