mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-08 15:04:46 +08:00
@@ -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)
|
||||
|
||||
|
||||
@@ -1,3 +1,51 @@
|
||||
/* ====================================================================
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/*
|
||||
* Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
@@ -472,6 +520,19 @@ static int ec_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
|
||||
X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
|
||||
}
|
||||
return 1;
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
case ASN1_PKEY_CTRL_PKCS7_ENCRYPT:
|
||||
if (arg1 == 0) {
|
||||
X509_ALGOR *alg = NULL;
|
||||
PKCS7_RECIP_INFO_get0_alg(arg2, &alg);
|
||||
if (alg) {
|
||||
X509_ALGOR_set0(alg, OBJ_nid2obj(NID_sm2encrypt_with_sm3), V_ASN1_NULL, 0);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_CMS
|
||||
case ASN1_PKEY_CTRL_CMS_SIGN:
|
||||
if (arg1 == 0) {
|
||||
|
||||
@@ -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"},
|
||||
@@ -178,6 +182,7 @@ static ERR_STRING_DATA EC_str_functs[] = {
|
||||
{ERR_FUNC(EC_F_EC_KEY_SIMPLE_CHECK_KEY), "ec_key_simple_check_key"},
|
||||
{ERR_FUNC(EC_F_EC_KEY_SIMPLE_OCT2PRIV), "ec_key_simple_oct2priv"},
|
||||
{ERR_FUNC(EC_F_EC_KEY_SIMPLE_PRIV2OCT), "ec_key_simple_priv2oct"},
|
||||
{ERR_FUNC(EC_F_EC_KEY_SPLIT), "EC_KEY_split"},
|
||||
{ERR_FUNC(EC_F_EC_POINTS_MAKE_AFFINE), "EC_POINTs_make_affine"},
|
||||
{ERR_FUNC(EC_F_EC_POINT_ADD), "EC_POINT_add"},
|
||||
{ERR_FUNC(EC_F_EC_POINT_CMP), "EC_POINT_cmp"},
|
||||
@@ -329,6 +334,7 @@ static ERR_STRING_DATA EC_str_reasons[] = {
|
||||
"invalid sm2 kap checksum length"},
|
||||
{ERR_REASON(EC_R_INVALID_SM2_KAP_CHECKSUM_VALUE),
|
||||
"invalid sm2 kap checksum value"},
|
||||
{ERR_REASON(EC_R_INVALID_SPLIT_PARAMETER), "invalid split parameter"},
|
||||
{ERR_REASON(EC_R_INVALID_TRINOMIAL_BASIS), "invalid trinomial basis"},
|
||||
{ERR_REASON(EC_R_INVALID_TYPE1CURVE), "invalid type1curve"},
|
||||
{ERR_REASON(EC_R_INVALID_TYPE1_CURVE), "invalid type1 curve"},
|
||||
|
||||
@@ -250,6 +250,8 @@ int ec_key_simple_generate_key(EC_KEY *eckey)
|
||||
|
||||
int ec_key_simple_generate_public_key(EC_KEY *eckey)
|
||||
{
|
||||
if (eckey->pub_key == NULL)
|
||||
eckey->pub_key = EC_POINT_new(eckey->group);
|
||||
return EC_POINT_mul(eckey->group, eckey->pub_key, eckey->priv_key, NULL,
|
||||
NULL, NULL);
|
||||
}
|
||||
@@ -637,3 +639,107 @@ int EC_KEY_can_sign(const EC_KEY *eckey)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define EC_KEY_MIN_SHARES 2
|
||||
#define EC_KEY_MAX_SHARES 5
|
||||
|
||||
STACK_OF(EC_KEY) *EC_KEY_split(EC_KEY *ec_key, int k, int n)
|
||||
{
|
||||
STACK_OF(EC_KEY) *ret = NULL;
|
||||
STACK_OF(EC_KEY) *keys = NULL;
|
||||
STACK_OF(BIGNUM) *as = NULL;
|
||||
const BIGNUM *order;
|
||||
const BIGNUM *d;
|
||||
EC_KEY *key = NULL; /* for stack */
|
||||
BIGNUM *a = NULL; /* for stack */
|
||||
BIGNUM *fx = NULL;
|
||||
BIGNUM *ax = NULL;
|
||||
BN_CTX *bn_ctx = NULL;
|
||||
int i, x, xpow;
|
||||
|
||||
if (!(d = EC_KEY_get0_private_key(ec_key))
|
||||
|| !(order = EC_GROUP_get0_order(EC_KEY_get0_group(ec_key)))) {
|
||||
ECerr(EC_F_EC_KEY_SPLIT, EC_R_INVALID_PRIVATE_KEY);
|
||||
return NULL;
|
||||
}
|
||||
if (k < EC_KEY_MIN_SHARES || k > n || n > EC_KEY_MAX_SHARES) {
|
||||
ECerr(EC_F_EC_KEY_SPLIT, EC_R_INVALID_SPLIT_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(keys = sk_EC_KEY_new_null())
|
||||
|| !(as = sk_BIGNUM_new_null())
|
||||
|| !(fx = BN_new())
|
||||
|| !(ax = BN_new())
|
||||
|| !(bn_ctx = BN_CTX_new())) {
|
||||
ECerr(EC_F_EC_KEY_SPLIT, ERR_R_MALLOC_FAILURE);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* a_i = rand(1, order), i = 0 .. k-1 */
|
||||
for (i = 0; i < k; i++) {
|
||||
if (!(a = BN_new())) {
|
||||
ECerr(EC_F_EC_KEY_SPLIT, ERR_R_MALLOC_FAILURE);
|
||||
goto end;
|
||||
}
|
||||
|
||||
do {
|
||||
if (!BN_rand_range(a, order)) {
|
||||
ECerr(EC_F_EC_KEY_SPLIT, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
} while (BN_is_zero(a));
|
||||
|
||||
if (!sk_BIGNUM_push(as, a)) {
|
||||
ECerr(EC_F_EC_KEY_SPLIT, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
a = NULL;
|
||||
}
|
||||
|
||||
/* f(x) = d + a_0 * x^1 + ... + a_{k-1} * x^k, x = 1 .. n */
|
||||
for (x = 1; x <= n; x++) {
|
||||
if (!(key = EC_KEY_dup(ec_key))
|
||||
|| !BN_copy(fx, d)) {
|
||||
ECerr(EC_F_EC_KEY_SPLIT, ERR_R_MALLOC_FAILURE);
|
||||
goto end;
|
||||
}
|
||||
|
||||
xpow = x;
|
||||
for (i = 0; i < k; i++) {
|
||||
if (!BN_copy(ax, sk_BIGNUM_value(as, i))
|
||||
|| !BN_mul_word(ax, xpow)
|
||||
|| !BN_mod_add(fx, fx, ax, order, bn_ctx)) {
|
||||
ECerr(EC_F_EC_KEY_SPLIT, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
xpow *= x;
|
||||
}
|
||||
|
||||
if (!EC_KEY_set_private_key(key, fx)
|
||||
|| !sk_EC_KEY_push(keys, key)) {
|
||||
ECerr(EC_F_EC_KEY_SPLIT, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
key = NULL;
|
||||
}
|
||||
|
||||
ret = keys;
|
||||
keys = NULL;
|
||||
|
||||
end:
|
||||
sk_EC_KEY_free(keys);
|
||||
sk_BIGNUM_free(as);
|
||||
EC_KEY_free(key);
|
||||
BN_free(a);
|
||||
BN_free(fx);
|
||||
BN_free(ax);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,51 @@
|
||||
/* ====================================================================
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/*
|
||||
* Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
@@ -540,6 +588,14 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
case EVP_PKEY_CTRL_CMS_SIGN:
|
||||
return 1;
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
case EVP_PKEY_CTRL_PKCS7_ENCRYPT:
|
||||
case EVP_PKEY_CTRL_PKCS7_DECRYPT:
|
||||
case EVP_PKEY_CTRL_CMS_DECRYPT:
|
||||
case EVP_PKEY_CTRL_CMS_ENCRYPT:
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return -2;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
2
crypto/ecrs/build.info
Normal file
2
crypto/ecrs/build.info
Normal file
@@ -0,0 +1,2 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=ecrs_err.c ecrs_asn1.c ecrs_lib.c
|
||||
65
crypto/ecrs/ecrs_asn1.c
Normal file
65
crypto/ecrs/ecrs_asn1.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2014 - 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 <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/ecrs.h>
|
||||
#include "./ecrs_lcl.h"
|
||||
|
||||
ASN1_SEQUENCE(ECRS_SIG) = {
|
||||
ASN1_SIMPLE(ECRS_SIG, s, BIGNUM),
|
||||
ASN1_SEQUENCE_OF(ECRS_SIG, c, BIGNUM),
|
||||
} ASN1_SEQUENCE_END(ECRS_SIG)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(ECRS_SIG)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(ECRS_SIG)
|
||||
|
||||
int ECRS_size(const EC_KEY *ec_key, int n)
|
||||
{
|
||||
return 128 * n;
|
||||
}
|
||||
52
crypto/ecrs/ecrs_err.c
Normal file
52
crypto/ecrs/ecrs_err.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* 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
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ecrs.h>
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
# define ERR_FUNC(func) ERR_PACK(ERR_LIB_ECRS,func,0)
|
||||
# define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECRS,0,reason)
|
||||
|
||||
static ERR_STRING_DATA ECRS_str_functs[] = {
|
||||
{ERR_FUNC(ECRS_F_ECRS_DO_SIGN), "ECRS_do_sign"},
|
||||
{ERR_FUNC(ECRS_F_ECRS_DO_VERIFY), "ECRS_do_verify"},
|
||||
{ERR_FUNC(ECRS_F_ECRS_SIGN), "ECRS_sign"},
|
||||
{ERR_FUNC(ECRS_F_ECRS_VERIFY), "ECRS_verify"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA ECRS_str_reasons[] = {
|
||||
{ERR_REASON(ECRS_R_EC_KEY_NOT_MATCH), "ec key not match"},
|
||||
{ERR_REASON(ECRS_R_INVALID_DIGEST_ALGOR), "invalid digest algor"},
|
||||
{ERR_REASON(ECRS_R_NO_SIGNING_KEY), "no signing key"},
|
||||
{ERR_REASON(ECRS_R_PARSE_SIGNATURE_FAILURE), "parse signature failure"},
|
||||
{ERR_REASON(ECRS_R_PUBLIC_KEYS_NOT_MATCH), "public keys not match"},
|
||||
{ERR_REASON(ECRS_R_PUBLIC_KEYS_NOT_MATCH_SIG),
|
||||
"public keys not match sig"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
int ERR_load_ECRS_strings(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
if (ERR_func_error_string(ECRS_str_functs[0].error) == NULL) {
|
||||
ERR_load_strings(0, ECRS_str_functs);
|
||||
ERR_load_strings(0, ECRS_str_reasons);
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
56
crypto/ecrs/ecrs_lcl.h
Normal file
56
crypto/ecrs/ecrs_lcl.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 <openssl/bn.h>
|
||||
#include <openssl/stack.h>
|
||||
|
||||
struct ECRS_SIG_st {
|
||||
BIGNUM *s;
|
||||
STACK_OF(BIGNUM) *c;
|
||||
};
|
||||
|
||||
411
crypto/ecrs/ecrs_lib.c
Normal file
411
crypto/ecrs/ecrs_lib.c
Normal file
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
* 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 <openssl/err.h>
|
||||
#include <openssl/ecrs.h>
|
||||
#include "./ecrs_lcl.h"
|
||||
|
||||
|
||||
ECRS_SIG *ECRS_do_sign(const EVP_MD *md, const unsigned char *dgst,
|
||||
int dgstlen, STACK_OF(EC_KEY) *pub_keys, EC_KEY *ec_key)
|
||||
{
|
||||
ECRS_SIG *ret = NULL;
|
||||
ECRS_SIG *sig = NULL;
|
||||
const EC_GROUP *group;
|
||||
const BIGNUM *order;
|
||||
BIGNUM *ck = NULL; /* ref of STACK_OF(BIGNUM) elements, dont free */
|
||||
BIGNUM *a = NULL;
|
||||
BIGNUM *c = NULL;
|
||||
BIGNUM *z = NULL;
|
||||
BN_CTX *bn_ctx = NULL;
|
||||
EC_POINT *R = NULL;
|
||||
EC_POINT *T = NULL;
|
||||
EVP_MD_CTX *mctx = NULL;
|
||||
int form = POINT_CONVERSION_UNCOMPRESSED;
|
||||
unsigned char buf[512];
|
||||
unsigned char *p = buf;
|
||||
unsigned int ulen;
|
||||
size_t siz;
|
||||
int len, i;
|
||||
|
||||
group = EC_KEY_get0_group(ec_key);
|
||||
order = EC_GROUP_get0_order(group);
|
||||
|
||||
if (!(sig = ECRS_SIG_new())
|
||||
|| !(sig->s = BN_new())
|
||||
|| !(sig->c = sk_BIGNUM_new(NULL))
|
||||
|| !(a = BN_new())
|
||||
|| !(c = BN_new())
|
||||
|| !(z = BN_new())
|
||||
|| !(bn_ctx = BN_CTX_new())
|
||||
|| !(R = EC_POINT_new(group))
|
||||
|| !(T = EC_POINT_new(group))
|
||||
|| !(mctx = EVP_MD_CTX_new())) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_MALLOC_FAILURE);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* hash update ECParameters */
|
||||
if (!(len = i2d_ECPKParameters(group, &p))) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestInit_ex(mctx, md, NULL)
|
||||
|| !EVP_DigestUpdate(mctx, buf, len)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* a = rand(1, order) */
|
||||
do {
|
||||
if (!BN_rand_range(a, order)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
} while (BN_is_zero(a));
|
||||
|
||||
/* R = [a]G */
|
||||
if (!EC_POINT_mul(group, R, a, NULL, NULL, bn_ctx)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i = 0; i < sk_EC_KEY_num(pub_keys); i++) {
|
||||
const EC_KEY *pub_key = sk_EC_KEY_value(pub_keys, i);
|
||||
const EC_POINT *Pi = EC_KEY_get0_public_key(pub_key);
|
||||
BIGNUM *ci;
|
||||
|
||||
/* check P_i */
|
||||
if (EC_GROUP_cmp(EC_KEY_get0_group(pub_key), group, bn_ctx) != 0) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ECRS_R_EC_KEY_NOT_MATCH);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* hash update P_i = (x_i, y_i) */
|
||||
if (!(siz = EC_POINT_point2oct(group, Pi, form, buf,
|
||||
sizeof(buf), bn_ctx))) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(mctx, buf + 1, siz - 1)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* create c_i */
|
||||
if (!(ci = BN_new())) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_MALLOC_FAILURE);
|
||||
goto end;
|
||||
}
|
||||
sk_BIGNUM_push(sig->c, ci);
|
||||
|
||||
/* find signer's public key */
|
||||
if (EC_POINT_cmp(group, Pi, EC_KEY_get0_public_key(ec_key),
|
||||
bn_ctx) == 0) {
|
||||
if (ck) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_ECRS_LIB);
|
||||
goto end;
|
||||
}
|
||||
ck = ci;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* c_i = rand(1, order) */
|
||||
do {
|
||||
if (!BN_rand_range(ci, order)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
} while (BN_is_zero(ci));
|
||||
|
||||
/* R = R + [c_i]P_i */
|
||||
if (!EC_POINT_mul(group, T, NULL, Pi, ci, bn_ctx)
|
||||
|| !EC_POINT_add(group, R, R, T, bn_ctx)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* z = z + c_i */
|
||||
if (!BN_mod_add(z, z, ci, order, bn_ctx)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
/* no signing private key found */
|
||||
if (!ck) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ECRS_R_NO_SIGNING_KEY);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* hash update dgst and R */
|
||||
if (!(siz = EC_POINT_point2oct(group, R, form, buf, sizeof(buf),
|
||||
bn_ctx))) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(mctx, dgst, dgstlen)
|
||||
|| !EVP_DigestUpdate(mctx, buf + 1, siz - 1)
|
||||
|| !EVP_DigestFinal_ex(mctx, buf, &ulen)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* c = hash({Pi}, Hash(m), R) mod #G */
|
||||
if (!BN_bin2bn(buf, ulen, c)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* c_k = c - (c_0 + ... + c_{k-1} + c_{k+1} + ... + c_{n-1}) mod #G */
|
||||
if (!BN_mod_sub(ck, c, z, order, bn_ctx)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* sig->s = a - c_k * x_k mod #G */
|
||||
if (!BN_mod_mul(sig->s, ck, EC_KEY_get0_private_key(ec_key), order, bn_ctx)
|
||||
|| !BN_mod_sub(sig->s, a, sig->s, order, bn_ctx)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_SIGN, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = sig;
|
||||
sig = NULL;
|
||||
|
||||
end:
|
||||
ECRS_SIG_free(sig);
|
||||
BN_free(a);
|
||||
BN_free(c);
|
||||
BN_CTX_free(bn_ctx);
|
||||
EC_POINT_free(R);
|
||||
EC_POINT_free(T);
|
||||
EVP_MD_CTX_free(mctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify(m, sig=(s, c_0, ..., c_{n-1}, {P_i}):
|
||||
* R = [s]G + [c_0]P_0 + ... + [c_{n-1}]P_{n-1}
|
||||
* c = c_0 + ... + c_{n-1}
|
||||
* h = Hash({P_i}, Hash(m), R)
|
||||
* return c =?= h
|
||||
*/
|
||||
int ECRS_do_verify(const EVP_MD *md, const unsigned char *dgst, int dgstlen,
|
||||
const ECRS_SIG *sig, STACK_OF(EC_KEY) *pub_keys)
|
||||
{
|
||||
int ret = -1;
|
||||
const EC_GROUP *group = NULL;
|
||||
const BIGNUM *order = NULL;
|
||||
BIGNUM *c = NULL;
|
||||
BIGNUM *h = NULL;
|
||||
BN_CTX *bn_ctx = NULL;
|
||||
EC_POINT *R = NULL;
|
||||
EC_POINT *T = NULL;
|
||||
EVP_MD_CTX *mctx = NULL;
|
||||
int form = POINT_CONVERSION_UNCOMPRESSED;
|
||||
unsigned char buf[512];
|
||||
unsigned char *p = buf;
|
||||
unsigned int ulen;
|
||||
size_t siz;
|
||||
int len, i;
|
||||
|
||||
if (sk_BIGNUM_num(sig->c) != sk_EC_KEY_num(pub_keys)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ECRS_R_PUBLIC_KEYS_NOT_MATCH_SIG);
|
||||
return -1;
|
||||
}
|
||||
|
||||
group = EC_KEY_get0_group(sk_EC_KEY_value(pub_keys, 0));
|
||||
order = EC_GROUP_get0_order(group);
|
||||
|
||||
if (!(c = BN_new())
|
||||
|| !(h = BN_new())
|
||||
|| !(bn_ctx = BN_CTX_new())
|
||||
|| !(R = EC_POINT_new(group))
|
||||
|| !(T = EC_POINT_new(group))
|
||||
|| !(mctx = EVP_MD_CTX_new())) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_MALLOC_FAILURE);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* hash update ECParameters */
|
||||
|
||||
/* hash update ECParameters */
|
||||
if (!(len = i2d_ECPKParameters(group, &p))) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestInit_ex(mctx, md, NULL)
|
||||
|| !EVP_DigestUpdate(mctx, buf, len)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* R = [s]G */
|
||||
if (!EC_POINT_mul(group, R, sig->s, NULL, NULL, bn_ctx)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i = 0; i < sk_BIGNUM_num(sig->c); i++) {
|
||||
EC_KEY *ec_key = sk_EC_KEY_value(pub_keys, i);
|
||||
const EC_POINT *Pi = EC_KEY_get0_public_key(ec_key);
|
||||
BIGNUM *ci = sk_BIGNUM_value(sig->c, i);
|
||||
|
||||
/* check Pi */
|
||||
if (EC_GROUP_cmp(EC_KEY_get0_group(ec_key), group, bn_ctx) != 0) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ECRS_R_PUBLIC_KEYS_NOT_MATCH);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* hash update P_i = (x_i, y_i) */
|
||||
if (!(siz = EC_POINT_point2oct(group, Pi, form, buf,
|
||||
sizeof(buf), bn_ctx))) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(mctx, buf + 1, siz - 1)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* R = R + [c_i]P_i */
|
||||
if (!EC_POINT_mul(group, T, NULL, Pi, ci, bn_ctx)
|
||||
|| !EC_POINT_add(group, R, R, T, bn_ctx)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* c = c + c_i mod #G */
|
||||
if (!BN_mod_add(c, c, ci, order, bn_ctx)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
/* hash update dgst and R */
|
||||
if (!(siz = EC_POINT_point2oct(group, R, form, buf, sizeof(buf),
|
||||
bn_ctx))) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(mctx, dgst, dgstlen)
|
||||
|| !EVP_DigestUpdate(mctx, buf + 1, siz - 1)
|
||||
|| !EVP_DigestFinal_ex(mctx, buf, &ulen)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_EVP_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* h = hash({Pi}, Hash(m), R) mod #G */
|
||||
if (!BN_bin2bn(buf, ulen, h)) {
|
||||
ECRSerr(ECRS_F_ECRS_DO_VERIFY, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
//FIXME: h mod #G */
|
||||
|
||||
if (BN_cmp(h, c) == 0)
|
||||
ret = 1;
|
||||
else
|
||||
ret = 0;
|
||||
|
||||
|
||||
end:
|
||||
BN_free(c);
|
||||
BN_free(h);
|
||||
BN_CTX_free(bn_ctx);
|
||||
EC_POINT_free(R);
|
||||
EC_POINT_free(T);
|
||||
EVP_MD_CTX_free(mctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ECRS_sign(int type, const unsigned char *dgst, int dgstlen,
|
||||
unsigned char *sig, unsigned int *siglen, STACK_OF(EC_KEY) *pub_keys,
|
||||
EC_KEY *ec_key)
|
||||
{
|
||||
const EVP_MD *md;
|
||||
ECRS_SIG *s = NULL;
|
||||
|
||||
if (!(md = EVP_get_digestbynid(type))) {
|
||||
ECRSerr(ECRS_F_ECRS_SIGN, ECRS_R_INVALID_DIGEST_ALGOR);
|
||||
return 0;
|
||||
}
|
||||
if (!(s = ECRS_do_sign(md, dgst, dgstlen, pub_keys, ec_key))) {
|
||||
ECRSerr(ECRS_F_ECRS_SIGN, ERR_R_ECRS_LIB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*siglen = i2d_ECRS_SIG(s, &sig);
|
||||
ECRS_SIG_free(s);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ECRS_verify(int type, const unsigned char *dgst, int dgstlen,
|
||||
const unsigned char *sig, int siglen, STACK_OF(EC_KEY) *pub_keys)
|
||||
{
|
||||
const EVP_MD *md;
|
||||
ECRS_SIG *s = NULL;
|
||||
const unsigned char *p = sig;
|
||||
int ret = -1;
|
||||
|
||||
if (!(s = d2i_ECRS_SIG(NULL, &p, siglen))) {
|
||||
ECRSerr(ECRS_F_ECRS_VERIFY, ECRS_R_PARSE_SIGNATURE_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (p != sig + siglen) {
|
||||
ECRSerr(ECRS_F_ECRS_VERIFY, ECRS_R_PARSE_SIGNATURE_FAILURE);
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = ECRS_do_verify(md, dgst, dgstlen, s, pub_keys);
|
||||
|
||||
end:
|
||||
ECRS_SIG_free(s);
|
||||
return ret;
|
||||
}
|
||||
@@ -74,6 +74,7 @@ static ERR_STRING_DATA ERR_str_libraries[] = {
|
||||
{ERR_PACK(ERR_LIB_SKF, 0, 0), "SKF routines"},
|
||||
{ERR_PACK(ERR_LIB_SOF, 0, 0), "SOF routines"},
|
||||
{ERR_PACK(ERR_LIB_BASE58, 0, 0), "BASE58 routines"},
|
||||
{ERR_PACK(ERR_LIB_ECRS, 0, 0), "ECRS routines"},
|
||||
{0, NULL},
|
||||
};
|
||||
|
||||
@@ -133,6 +134,7 @@ static ERR_STRING_DATA ERR_str_reasons[] = {
|
||||
{ERR_R_SKF_LIB, "SKF lib"},
|
||||
{ERR_R_SOF_LIB, "SOF lib"},
|
||||
{ERR_R_BASE58_LIB, "BASE58 lib"},
|
||||
{ERR_R_ECRS_LIB, "ECRS lib"},
|
||||
|
||||
{ERR_R_NESTED_ASN1_ERROR, "nested asn1 error"},
|
||||
{ERR_R_MISSING_ASN1_EOS, "missing asn1 eos"},
|
||||
|
||||
@@ -108,6 +108,9 @@
|
||||
#ifndef OPENSSL_NO_BASE58
|
||||
# include <openssl/base58.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_ECRS
|
||||
# include <openssl/ecrs.h>
|
||||
#endif
|
||||
|
||||
|
||||
int err_load_crypto_strings_int(void)
|
||||
@@ -218,6 +221,9 @@ int err_load_crypto_strings_int(void)
|
||||
# ifndef OPENSSL_NO_BASE58
|
||||
ERR_load_BASE58_strings() == 0 ||
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_ECRS
|
||||
ERR_load_ECRS_strings() == 0 ||
|
||||
# endif
|
||||
#endif
|
||||
ERR_load_KDF_strings() == 0)
|
||||
return 0;
|
||||
|
||||
@@ -50,6 +50,7 @@ L SDF include/openssl/gmsdf.h crypto/sdf/sdf_err.c
|
||||
L SKF include/openssl/gmskf.h crypto/skf/skf_err.c
|
||||
L SOF include/openssl/gmsof.h crypto/sof/sof_err.c
|
||||
L BASE58 include/openssl/base58.h crypto/base58/base58_err.c
|
||||
L ECRS include/openssl/ecrs.h crypto/ecrs/ecrs_err.c
|
||||
|
||||
# additional header files to be scanned for function names
|
||||
L NONE crypto/x509/x509_vfy.h NONE
|
||||
|
||||
@@ -1,3 +1,51 @@
|
||||
/* ====================================================================
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
@@ -14,6 +62,9 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
# include <openssl/sm2.h>
|
||||
#endif
|
||||
|
||||
static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
|
||||
void *value);
|
||||
@@ -105,6 +156,13 @@ static int pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri,
|
||||
if (EVP_PKEY_encrypt_init(pctx) <= 0)
|
||||
goto err;
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
if (OBJ_obj2nid(ri->key_enc_algor->algorithm) == NID_sm2encrypt_with_sm3) {
|
||||
EVP_PKEY_CTX_set_ec_scheme(pctx, NID_sm_scheme);
|
||||
EVP_PKEY_CTX_set_ec_encrypt_param(pctx, NID_sm3);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT,
|
||||
EVP_PKEY_CTRL_PKCS7_ENCRYPT, 0, ri) <= 0) {
|
||||
PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, PKCS7_R_CTRL_ERROR);
|
||||
@@ -152,6 +210,13 @@ static int pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen,
|
||||
if (EVP_PKEY_decrypt_init(pctx) <= 0)
|
||||
goto err;
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
if (OBJ_obj2nid(ri->key_enc_algor->algorithm) == NID_sm2encrypt_with_sm3) {
|
||||
EVP_PKEY_CTX_set_ec_scheme(pctx, NID_sm_scheme);
|
||||
EVP_PKEY_CTX_set_ec_encrypt_param(pctx, NID_sm3);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DECRYPT,
|
||||
EVP_PKEY_CTRL_PKCS7_DECRYPT, 0, ri) <= 0) {
|
||||
PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, PKCS7_R_CTRL_ERROR);
|
||||
@@ -832,6 +897,12 @@ int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
|
||||
if (EVP_DigestSignInit(mctx, &pctx, md, NULL, si->pkey) <= 0)
|
||||
goto err;
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
if (OBJ_obj2nid(si->digest_enc_alg->algorithm) == NID_sm2sign_with_sm3) {
|
||||
EVP_PKEY_CTX_set_ec_scheme(pctx, NID_sm_scheme);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
|
||||
EVP_PKEY_CTRL_PKCS7_SIGN, 0, si) <= 0) {
|
||||
PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR);
|
||||
@@ -940,6 +1011,9 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
|
||||
STACK_OF(X509_ATTRIBUTE) *sk;
|
||||
BIO *btmp;
|
||||
EVP_PKEY *pkey;
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
EVP_PKEY_CTX *pctx;
|
||||
#endif
|
||||
|
||||
mdc_tmp = EVP_MD_CTX_new();
|
||||
if (mdc_tmp == NULL) {
|
||||
@@ -985,6 +1059,13 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
|
||||
if (!EVP_MD_CTX_copy_ex(mdc_tmp, mdc))
|
||||
goto err;
|
||||
|
||||
os = si->enc_digest;
|
||||
pkey = X509_get0_pubkey(x509);
|
||||
if (!pkey) {
|
||||
ret = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
sk = si->auth_attr;
|
||||
if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0)) {
|
||||
unsigned char md_dat[EVP_MAX_MD_SIZE], *abuf = NULL;
|
||||
@@ -1007,9 +1088,15 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!EVP_VerifyInit_ex(mdc_tmp, EVP_get_digestbynid(md_type), NULL))
|
||||
if (!EVP_DigestVerifyInit(mdc_tmp, &pctx,
|
||||
EVP_get_digestbynid(md_type), NULL, pkey)) {
|
||||
goto err;
|
||||
|
||||
}
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
if (OBJ_obj2nid(si->digest_enc_alg->algorithm) == NID_sm2sign_with_sm3) {
|
||||
EVP_PKEY_CTX_set_ec_scheme(pctx, NID_sm_scheme);
|
||||
}
|
||||
#endif
|
||||
alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
|
||||
ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY));
|
||||
if (alen <= 0) {
|
||||
@@ -1017,20 +1104,13 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
|
||||
ret = -1;
|
||||
goto err;
|
||||
}
|
||||
if (!EVP_VerifyUpdate(mdc_tmp, abuf, alen))
|
||||
if (!EVP_DigestVerifyUpdate(mdc_tmp, abuf, alen))
|
||||
goto err;
|
||||
|
||||
OPENSSL_free(abuf);
|
||||
}
|
||||
|
||||
os = si->enc_digest;
|
||||
pkey = X509_get0_pubkey(x509);
|
||||
if (!pkey) {
|
||||
ret = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
i = EVP_VerifyFinal(mdc_tmp, os->data, os->length, pkey);
|
||||
i = EVP_DigestVerifyFinal(mdc_tmp, os->data, os->length);
|
||||
if (i <= 0) {
|
||||
PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, PKCS7_R_SIGNATURE_FAILURE);
|
||||
ret = -1;
|
||||
|
||||
@@ -1,3 +1,51 @@
|
||||
/* ====================================================================
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
@@ -146,6 +194,9 @@ PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert,
|
||||
|| !add_cipher_smcap(smcap, NID_aes_192_cbc, -1)
|
||||
|| !add_cipher_smcap(smcap, NID_aes_128_cbc, -1)
|
||||
|| !add_cipher_smcap(smcap, NID_des_ede3_cbc, -1)
|
||||
#ifndef OPENSSL_NO_SMS4
|
||||
|| !add_cipher_smcap(smcap, NID_sms4_cbc, -1)
|
||||
#endif
|
||||
|| !add_cipher_smcap(smcap, NID_rc2_cbc, 128)
|
||||
|| !add_cipher_smcap(smcap, NID_rc2_cbc, 64)
|
||||
|| !add_cipher_smcap(smcap, NID_des_cbc, -1)
|
||||
|
||||
@@ -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