mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-07 21:53:41 +08:00
first step of v2 final release
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=sm9_lib.c sm9_err.c sm9_asn1.c sm9_params.c \
|
||||
sm9_setup.c sm9_keygen.c sm9_sign.c sm9_enc.c sm9_kap.c
|
||||
sm9_setup.c sm9_keygen.c sm9_sign.c sm9_enc.c sm9_exch.c
|
||||
|
||||
@@ -87,6 +87,12 @@ ASN1_SEQUENCE(SM9PrivateKey) = {
|
||||
IMPLEMENT_ASN1_FUNCTIONS(SM9PrivateKey)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(SM9PrivateKey)
|
||||
|
||||
ASN1_SEQUENCE(SM9PublicKey) = {
|
||||
ASN1_SIMPLE(SM9PublicKey, publicPoint, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(SM9PublicKey)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(SM9PublicKey)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(SM9PublicKey)
|
||||
|
||||
ASN1_SEQUENCE(SM9Ciphertext) = {
|
||||
ASN1_SIMPLE(SM9Ciphertext, pointC1, ASN1_OCTET_STRING),
|
||||
ASN1_SIMPLE(SM9Ciphertext, c2, ASN1_OCTET_STRING),
|
||||
@@ -102,3 +108,7 @@ ASN1_SEQUENCE(SM9Signature) = {
|
||||
IMPLEMENT_ASN1_FUNCTIONS(SM9Signature)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(SM9Signature)
|
||||
|
||||
int SM9PublicKey_gmtls_encode(SM9PublicKey *pk, unsigned char key[1024])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -107,6 +107,13 @@ static int SM9PublicParameters_get_point_size(SM9PublicParameters *mpk,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SM9_wrap_key_ex(SM9PublicParameters *mpk, size_t keylen,
|
||||
unsigned char *outkey, unsigned char *outcipher, size_t *outcipherlen,
|
||||
SM9PublicKey *pk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SM9_wrap_key(SM9PublicParameters *mpk, size_t keylen,
|
||||
unsigned char *outkey, unsigned char *outcipher, size_t *outcipherlen,
|
||||
const char *id, size_t idlen)
|
||||
@@ -308,6 +315,14 @@ end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SM9_unwrap_key_ex(SM9PublicParameters *mpk, size_t keylen,
|
||||
const unsigned char *incipher, size_t incipherlen,
|
||||
unsigned char *outkey,
|
||||
SM9PublicKey *pk, SM9PrivateKey *sk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SM9_unwrap_key(SM9PublicParameters *mpk, size_t keylen,
|
||||
const unsigned char *incipher, size_t incipherlen,
|
||||
unsigned char *outkey,
|
||||
@@ -791,6 +806,14 @@ end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
SM9Ciphertext *SM9_do_encrypt_ex(SM9PublicParameters *mpk,
|
||||
const SM9EncParameters *encparams,
|
||||
const unsigned char *in, size_t inlen,
|
||||
SM9PublicKey *pk)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SM9Ciphertext *SM9_do_encrypt(SM9PublicParameters *mpk,
|
||||
const SM9EncParameters *encparams,
|
||||
const unsigned char *in, size_t inlen,
|
||||
@@ -1012,6 +1035,14 @@ static int SM9Ciphertext_size(SM9PublicParameters *mpk,
|
||||
*outlen = inlen + 4096;
|
||||
}
|
||||
|
||||
int SM9_encrypt_ex(SM9PublicParameters *mpk, const SM9EncParameters *encparams,
|
||||
const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen,
|
||||
SM9PublicKey *pk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SM9_encrypt(SM9PublicParameters *mpk, const SM9EncParameters *encparams,
|
||||
const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen,
|
||||
@@ -1095,6 +1126,14 @@ static int SM9EncParameters_init_with_recommended(SM9EncParameters *encparams)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SM9_encrypt_with_recommended_ex(SM9PublicParameters *mpk,
|
||||
const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen,
|
||||
SM9PublicKey *pk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SM9_encrypt_with_recommended(SM9PublicParameters *mpk,
|
||||
const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen,
|
||||
@@ -1114,4 +1153,3 @@ int SM9_decrypt_with_recommended(SM9PublicParameters *mpk,
|
||||
SM9EncParameters_init_with_recommended(&encparams);
|
||||
return SM9_decrypt(mpk, &encparams, in, inlen, out, outlen, sk, id, idlen);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,3 +51,23 @@
|
||||
#include <openssl/sm9.h>
|
||||
#include "sm9_lcl.h"
|
||||
|
||||
/*
|
||||
* h = H1(ID_B || hid, N)
|
||||
* Q_B = [h]P1 + P_pub
|
||||
* r_A = rand(1, N-1)
|
||||
* R_A = [r_A]Q_B
|
||||
*/
|
||||
SM9PublicKey *SM9_generate_key_exchange(SM9PublicParameters *mpk,
|
||||
const char *peer_id, size_t peer_idlen, BIGNUM **r)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int SM9_compute_share_key(SM9PublicParameters *mpk,
|
||||
unsigned char *out, size_t *outlen,
|
||||
const char *peer_id, size_t peer_idlen, SM9PublicKey *peer_exch,
|
||||
const char *id, size_t idlen, SM9PublicKey *exch,
|
||||
SM9PrivateKey *sk, int initiator)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -173,3 +173,27 @@ end:
|
||||
EC_POINT_free(point);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SM9PublicKey *SM9_extract_sign_public_key(SM9PublicParameters *mpk,
|
||||
const char *id, size_t idlen)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SM9PublicKey *SM9_extract_exch_public_key(SM9PublicParameters *mpk,
|
||||
const char *id, size_t idlen)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SM9PublicKey *SM9_extract_enc_public_key(SM9PublicParameters *mpk,
|
||||
const char *id, size_t idlen)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SM9PublicKey *SM9PrivateKey_get_public_key(SM9PublicParameters *mpk,
|
||||
SM9PrivateKey *sk)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -54,19 +54,20 @@
|
||||
#include <openssl/sm9.h>
|
||||
|
||||
/* Curve ID */
|
||||
#define SM9_CID_TYPE0CURVE 0x10
|
||||
#define SM9_CID_TYPE1CURVE 0x11
|
||||
#define SM9_CID_TYPE2CURVE 0x12
|
||||
/* 一个字节表示的曲线类型 */
|
||||
#define SM9_CID_TYPE0CURVE 0x10 /* Fp上的常曲线 */
|
||||
#define SM9_CID_TYPE1CURVE 0x11 /* Fp上的超奇异曲线 */
|
||||
#define SM9_CID_TYPE2CURVE 0x12 /* Fp上常曲线及其扭曲线 */
|
||||
|
||||
/* Pairing ID */
|
||||
/* 一个字节表示的双线性对类型 */
|
||||
#define SM9_EID_TATE 0x01
|
||||
#define SM9_EID_WEIL 0x02
|
||||
#define SM9_EID_ATE 0x03
|
||||
#define SM9_EID_RATE 0x04
|
||||
|
||||
#define SM9_MAX_ID_LENGTH 127
|
||||
|
||||
/* not clear what it is */
|
||||
/* 一个字节的签名私钥生成函数标识符 */
|
||||
#define SM9_HID 0xc9
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -95,6 +96,13 @@ struct SM9MasterSecret_st {
|
||||
BIGNUM *masterSecret;
|
||||
};
|
||||
|
||||
/* 签名算法中公钥为G2上的点
|
||||
* 密钥交换和加密中为G1上的点
|
||||
*/
|
||||
struct SM9PublicKey_st {
|
||||
ASN1_OCTET_STRING *publicPoint;
|
||||
};
|
||||
|
||||
struct SM9PrivateKey_st {
|
||||
ASN1_OCTET_STRING *privatePoint;
|
||||
};
|
||||
|
||||
@@ -53,6 +53,18 @@
|
||||
#include <openssl/bn_hash.h>
|
||||
#include "sm9_lcl.h"
|
||||
|
||||
int SM9PrivateKey_get_gmtls_public_key(SM9PublicParameters *mpk,
|
||||
SM9PrivateKey *sk, unsigned char pub_key[1024])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SM9PublicKey_get_gmtls_encoded(SM9PublicParameters *mpk,
|
||||
SM9PublicKey *pk, unsigned char encoded[1024])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SM9_hash1(const EVP_MD *md, BIGNUM **r,
|
||||
const char *id, size_t idlen,
|
||||
unsigned char hid,
|
||||
|
||||
@@ -104,10 +104,7 @@ int SM9_setup_type1curve(const EC_GROUP *group, const EVP_MD *md,
|
||||
}
|
||||
|
||||
/* mpk->beta = 0 */
|
||||
if (!BN_zero(mpk->beta)) {
|
||||
SM9err(SM9_F_SM9_SETUP_TYPE1CURVE, ERR_R_BN_LIB);
|
||||
goto end;
|
||||
}
|
||||
BN_zero(mpk->beta);
|
||||
|
||||
/* mpk->order = group->order */
|
||||
if (!EC_GROUP_get_order(group, mpk->order, bn_ctx)) {
|
||||
|
||||
@@ -55,6 +55,11 @@
|
||||
#include <openssl/bn_gfp2.h>
|
||||
#include "sm9_lcl.h"
|
||||
|
||||
int SM9_signature_size(SM9PublicParameters *mpk)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SM9Signature *SM9_do_sign_type1curve(SM9PublicParameters *mpk,
|
||||
const unsigned char *dgst, size_t dgstlen, SM9PrivateKey *sk)
|
||||
{
|
||||
@@ -226,6 +231,13 @@ SM9Signature *SM9_do_sign(SM9PublicParameters *mpk,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int SM9_do_verify_type1curve_ex(SM9PublicParameters *mpk,
|
||||
const unsigned char *dgst, size_t dgstlen,
|
||||
const SM9Signature *sig, SM9PublicKey *pk)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SM9_do_verify_type1curve(SM9PublicParameters *mpk,
|
||||
const unsigned char *dgst, size_t dgstlen,
|
||||
const SM9Signature *sig, const char *id, size_t idlen)
|
||||
@@ -397,6 +409,13 @@ end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SM9_do_verify_ex(SM9PublicParameters *mpk,
|
||||
const unsigned char *dgst, size_t dgstlen,
|
||||
const SM9Signature *sig, SM9PublicKey *pk)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SM9_do_verify(SM9PublicParameters *mpk,
|
||||
const unsigned char *dgst, size_t dgstlen,
|
||||
const SM9Signature *sig, const char *id, size_t idlen)
|
||||
@@ -472,6 +491,12 @@ end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SM9_verify_ex(SM9PublicParameters *mpk, const unsigned char *dgst,
|
||||
size_t dgstlen, const unsigned char *sig, size_t siglen,
|
||||
SM9PublicKey *pk)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SM9_verify(SM9PublicParameters *mpk, const unsigned char *dgst,
|
||||
size_t dgstlen, const unsigned char *sig, size_t siglen,
|
||||
|
||||
Reference in New Issue
Block a user