mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-12 00:43:38 +08:00
more sm. tests
This commit is contained in:
42
Makefile
42
Makefile
@@ -11,11 +11,11 @@ SHLIB_VERSION_NUMBER=1.0.0
|
||||
SHLIB_VERSION_HISTORY=
|
||||
SHLIB_MAJOR=1
|
||||
SHLIB_MINOR=0.0
|
||||
SHLIB_EXT=
|
||||
PLATFORM=dist
|
||||
OPTIONS= no-ec_nistp_64_gcc_128 no-gmp no-jpake no-krb5 no-libunbound no-md2 no-rc5 no-rfc3779 no-sctp no-shared no-ssl-trace no-store no-unit-test no-zlib no-zlib-dynamic static-engine
|
||||
CONFIGURE_ARGS=dist
|
||||
SHLIB_TARGET=
|
||||
SHLIB_EXT=.$(SHLIB_MAJOR).$(SHLIB_MINOR).dylib
|
||||
PLATFORM=darwin64-x86_64-cc
|
||||
OPTIONS=--prefix=/usr/local/ --openssldir=/usr/local/openssl/ no-ec_nistp_64_gcc_128 no-gmp no-jpake no-krb5 no-libunbound no-md2 no-rc5 no-rfc3779 no-sctp no-shared no-ssl-trace no-store no-unit-test no-zlib no-zlib-dynamic static-engine
|
||||
CONFIGURE_ARGS=darwin64-x86_64-cc --prefix=/usr/local/ --openssldir=/usr/local/openssl/
|
||||
SHLIB_TARGET=darwin-shared
|
||||
|
||||
# HERE indicates where this Makefile lives. This can be used to indicate
|
||||
# where sub-Makefiles are expected to be. Currently has very limited usage,
|
||||
@@ -26,10 +26,10 @@ HERE=.
|
||||
# for, say, /usr/ and yet have everything installed to /tmp/somedir/usr/.
|
||||
# Normally it is left empty.
|
||||
INSTALL_PREFIX=
|
||||
INSTALLTOP=/usr/local/ssl
|
||||
INSTALLTOP=/usr/local
|
||||
|
||||
# Do not edit this manually. Use Configure --openssldir=DIR do change this!
|
||||
OPENSSLDIR=/usr/local/ssl
|
||||
OPENSSLDIR=/usr/local/openssl
|
||||
|
||||
# NO_IDEA - Define to build without the IDEA algorithm
|
||||
# NO_RC4 - Define to build without the RC4 algorithm
|
||||
@@ -60,9 +60,9 @@ OPENSSLDIR=/usr/local/ssl
|
||||
# PKCS1_CHECK - pkcs1 tests.
|
||||
|
||||
CC= cc
|
||||
CFLAG= -O
|
||||
CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
|
||||
DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_LIBUNBOUND -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_SSL_TRACE -DOPENSSL_NO_STORE -DOPENSSL_NO_UNIT_TEST
|
||||
PEX_LIBS=
|
||||
PEX_LIBS= -Wl,-search_paths_first
|
||||
EX_LIBS=
|
||||
EXE_EXT=
|
||||
ARFLAGS=
|
||||
@@ -88,23 +88,23 @@ ASFLAG=$(CFLAG)
|
||||
PROCESSOR=
|
||||
|
||||
# CPUID module collects small commonly used assembler snippets
|
||||
CPUID_OBJ= mem_clr.o
|
||||
BN_ASM= bn_asm.o
|
||||
EC_ASM=
|
||||
CPUID_OBJ= x86_64cpuid.o
|
||||
BN_ASM= x86_64-gcc.o x86_64-mont.o x86_64-mont5.o x86_64-gf2m.o rsaz_exp.o rsaz-x86_64.o rsaz-avx2.o
|
||||
EC_ASM= ecp_nistz256.o ecp_nistz256-x86_64.o
|
||||
DES_ENC= des_enc.o fcrypt_b.o
|
||||
AES_ENC= aes_core.o aes_cbc.o
|
||||
AES_ENC= aes-x86_64.o vpaes-x86_64.o bsaes-x86_64.o aesni-x86_64.o aesni-sha1-x86_64.o aesni-sha256-x86_64.o aesni-mb-x86_64.o
|
||||
BF_ENC= bf_enc.o
|
||||
CAST_ENC= c_enc.o
|
||||
RC4_ENC= rc4_enc.o rc4_skey.o
|
||||
RC5_ENC= rc5_enc.o
|
||||
MD5_ASM_OBJ=
|
||||
SHA1_ASM_OBJ=
|
||||
MD5_ASM_OBJ= md5-x86_64.o
|
||||
SHA1_ASM_OBJ= sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o sha1-mb-x86_64.o sha256-mb-x86_64.o
|
||||
RMD160_ASM_OBJ=
|
||||
WP_ASM_OBJ= wp_block.o
|
||||
CMLL_ENC= camellia.o cmll_misc.o cmll_cbc.o
|
||||
MODES_ASM_OBJ=
|
||||
WP_ASM_OBJ= wp-x86_64.o
|
||||
CMLL_ENC= cmll-x86_64.o cmll_misc.o
|
||||
MODES_ASM_OBJ= ghash-x86_64.o aesni-gcm-x86_64.o
|
||||
ENGINES_ASM_OBJ=
|
||||
PERLASM_SCHEME=
|
||||
PERLASM_SCHEME= macosx
|
||||
|
||||
# KRB5 stuff
|
||||
KRB5_INCLUDES=
|
||||
@@ -178,8 +178,8 @@ LIBS= libcrypto.a libssl.a
|
||||
SHARED_CRYPTO=libcrypto$(SHLIB_EXT)
|
||||
SHARED_SSL=libssl$(SHLIB_EXT)
|
||||
SHARED_LIBS=
|
||||
SHARED_LIBS_LINK_EXTS=
|
||||
SHARED_LDFLAGS=
|
||||
SHARED_LIBS_LINK_EXTS=.$(SHLIB_MAJOR).dylib .dylib
|
||||
SHARED_LDFLAGS=-arch x86_64 -dynamiclib
|
||||
|
||||
GENERAL= Makefile
|
||||
BASENAME= gmssl
|
||||
|
||||
42
Makefile.bak
42
Makefile.bak
@@ -11,11 +11,11 @@ SHLIB_VERSION_NUMBER=1.0.0
|
||||
SHLIB_VERSION_HISTORY=
|
||||
SHLIB_MAJOR=1
|
||||
SHLIB_MINOR=0.0
|
||||
SHLIB_EXT=.$(SHLIB_MAJOR).$(SHLIB_MINOR).dylib
|
||||
PLATFORM=darwin64-x86_64-cc
|
||||
OPTIONS=--prefix=/usr/local/ --openssldir=/usr/local/openssl/ no-ec_nistp_64_gcc_128 no-gmp no-jpake no-krb5 no-libunbound no-md2 no-rc5 no-rfc3779 no-sctp no-shared no-ssl-trace no-store no-unit-test no-zlib no-zlib-dynamic static-engine
|
||||
CONFIGURE_ARGS=darwin64-x86_64-cc --prefix=/usr/local/ --openssldir=/usr/local/openssl/
|
||||
SHLIB_TARGET=darwin-shared
|
||||
SHLIB_EXT=
|
||||
PLATFORM=dist
|
||||
OPTIONS= no-ec_nistp_64_gcc_128 no-gmp no-jpake no-krb5 no-libunbound no-md2 no-rc5 no-rfc3779 no-sctp no-shared no-ssl-trace no-store no-unit-test no-zlib no-zlib-dynamic static-engine
|
||||
CONFIGURE_ARGS=dist
|
||||
SHLIB_TARGET=
|
||||
|
||||
# HERE indicates where this Makefile lives. This can be used to indicate
|
||||
# where sub-Makefiles are expected to be. Currently has very limited usage,
|
||||
@@ -26,10 +26,10 @@ HERE=.
|
||||
# for, say, /usr/ and yet have everything installed to /tmp/somedir/usr/.
|
||||
# Normally it is left empty.
|
||||
INSTALL_PREFIX=
|
||||
INSTALLTOP=/usr/local
|
||||
INSTALLTOP=/usr/local/ssl
|
||||
|
||||
# Do not edit this manually. Use Configure --openssldir=DIR do change this!
|
||||
OPENSSLDIR=/usr/local/openssl
|
||||
OPENSSLDIR=/usr/local/ssl
|
||||
|
||||
# NO_IDEA - Define to build without the IDEA algorithm
|
||||
# NO_RC4 - Define to build without the RC4 algorithm
|
||||
@@ -60,9 +60,9 @@ OPENSSLDIR=/usr/local/openssl
|
||||
# PKCS1_CHECK - pkcs1 tests.
|
||||
|
||||
CC= cc
|
||||
CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
|
||||
CFLAG= -O
|
||||
DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_LIBUNBOUND -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_SSL_TRACE -DOPENSSL_NO_STORE -DOPENSSL_NO_UNIT_TEST
|
||||
PEX_LIBS= -Wl,-search_paths_first
|
||||
PEX_LIBS=
|
||||
EX_LIBS=
|
||||
EXE_EXT=
|
||||
ARFLAGS=
|
||||
@@ -88,23 +88,23 @@ ASFLAG=$(CFLAG)
|
||||
PROCESSOR=
|
||||
|
||||
# CPUID module collects small commonly used assembler snippets
|
||||
CPUID_OBJ= x86_64cpuid.o
|
||||
BN_ASM= x86_64-gcc.o x86_64-mont.o x86_64-mont5.o x86_64-gf2m.o rsaz_exp.o rsaz-x86_64.o rsaz-avx2.o
|
||||
EC_ASM= ecp_nistz256.o ecp_nistz256-x86_64.o
|
||||
CPUID_OBJ= mem_clr.o
|
||||
BN_ASM= bn_asm.o
|
||||
EC_ASM=
|
||||
DES_ENC= des_enc.o fcrypt_b.o
|
||||
AES_ENC= aes-x86_64.o vpaes-x86_64.o bsaes-x86_64.o aesni-x86_64.o aesni-sha1-x86_64.o aesni-sha256-x86_64.o aesni-mb-x86_64.o
|
||||
AES_ENC= aes_core.o aes_cbc.o
|
||||
BF_ENC= bf_enc.o
|
||||
CAST_ENC= c_enc.o
|
||||
RC4_ENC= rc4_enc.o rc4_skey.o
|
||||
RC5_ENC= rc5_enc.o
|
||||
MD5_ASM_OBJ= md5-x86_64.o
|
||||
SHA1_ASM_OBJ= sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o sha1-mb-x86_64.o sha256-mb-x86_64.o
|
||||
MD5_ASM_OBJ=
|
||||
SHA1_ASM_OBJ=
|
||||
RMD160_ASM_OBJ=
|
||||
WP_ASM_OBJ= wp-x86_64.o
|
||||
CMLL_ENC= cmll-x86_64.o cmll_misc.o
|
||||
MODES_ASM_OBJ= ghash-x86_64.o aesni-gcm-x86_64.o
|
||||
WP_ASM_OBJ= wp_block.o
|
||||
CMLL_ENC= camellia.o cmll_misc.o cmll_cbc.o
|
||||
MODES_ASM_OBJ=
|
||||
ENGINES_ASM_OBJ=
|
||||
PERLASM_SCHEME= macosx
|
||||
PERLASM_SCHEME=
|
||||
|
||||
# KRB5 stuff
|
||||
KRB5_INCLUDES=
|
||||
@@ -178,8 +178,8 @@ LIBS= libcrypto.a libssl.a
|
||||
SHARED_CRYPTO=libcrypto$(SHLIB_EXT)
|
||||
SHARED_SSL=libssl$(SHLIB_EXT)
|
||||
SHARED_LIBS=
|
||||
SHARED_LIBS_LINK_EXTS=.$(SHLIB_MAJOR).dylib .dylib
|
||||
SHARED_LDFLAGS=-arch x86_64 -dynamiclib
|
||||
SHARED_LIBS_LINK_EXTS=
|
||||
SHARED_LDFLAGS=
|
||||
|
||||
GENERAL= Makefile
|
||||
BASENAME= gmssl
|
||||
|
||||
@@ -210,8 +210,6 @@ int MAIN(int argc, char **argv)
|
||||
if (!pkey)
|
||||
goto end;
|
||||
|
||||
printf("GMSSL %s %d\n", __FILE__, __LINE__);
|
||||
|
||||
if (!noout) {
|
||||
if (outformat == FORMAT_PEM) {
|
||||
if (pubout)
|
||||
|
||||
@@ -93,6 +93,7 @@ typedef struct {
|
||||
int enc_type;
|
||||
int dh_type;
|
||||
union {
|
||||
void *ptr;
|
||||
ECIES_PARAMS *ecies;
|
||||
SM2_ENC_PARAMS *sm2;
|
||||
} enc_param;
|
||||
@@ -114,9 +115,10 @@ static int pkey_ec_init(EVP_PKEY_CTX *ctx)
|
||||
dctx->kdf_outlen = 0;
|
||||
dctx->kdf_ukm = NULL;
|
||||
dctx->kdf_ukmlen = 0;
|
||||
dctx->sign_type = NID_secg_scheme;
|
||||
dctx->enc_type = NID_secg_scheme;
|
||||
dctx->dh_type = NID_secg_scheme;
|
||||
dctx->sign_type = NID_sm_scheme;
|
||||
dctx->enc_type = NID_sm_scheme;
|
||||
dctx->dh_type = NID_sm_scheme;
|
||||
dctx->enc_param.ptr = NULL;
|
||||
|
||||
ctx->data = dctx;
|
||||
|
||||
@@ -200,6 +202,8 @@ static int pkey_ec_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
|
||||
type = NID_sha1;
|
||||
else if (dctx->sign_type == NID_sm_scheme)
|
||||
type = NID_sm3;
|
||||
else
|
||||
type = NID_undef;
|
||||
|
||||
if (dctx->sign_type == NID_secg_scheme) {
|
||||
ret = ECDSA_sign(type, dgst, dgstlen, sig, &len, ec_key);
|
||||
@@ -227,7 +231,7 @@ static int pkey_ec_verify(EVP_PKEY_CTX *ctx,
|
||||
else
|
||||
type = NID_sha1;
|
||||
|
||||
if (dctx->sign_type == NID_sm2sign)
|
||||
if (dctx->sign_type == NID_sm_scheme)
|
||||
ret = SM2_verify(type, dgst, dgstlen, sig, siglen, ec_key);
|
||||
else
|
||||
ret = ECDSA_verify(type, dgst, dgstlen, sig, siglen, ec_key);
|
||||
@@ -235,6 +239,15 @@ static int pkey_ec_verify(EVP_PKEY_CTX *ctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int int_update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
if (!EVP_DigestUpdate(ctx, data, count))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int pkey_ec_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
|
||||
{
|
||||
EC_PKEY_CTX *dctx = ctx->data;
|
||||
@@ -243,8 +256,11 @@ static int pkey_ec_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
|
||||
unsigned char zid[EVP_MAX_MD_SIZE];
|
||||
unsigned int zidlen = sizeof(zid);
|
||||
|
||||
if (dctx->sign_type == NID_sm2sign) {
|
||||
// the reason might be we need to init mctx->udpate
|
||||
|
||||
|
||||
if (dctx->sign_type == NID_sm_scheme) {
|
||||
/*
|
||||
if (!SM2_compute_id_digest(md, zid, &zidlen, ec_key)) {
|
||||
ECerr(EC_F_PKEY_SM2_SIGNCTX_INIT, ERR_R_SM2_LIB);
|
||||
return 0;
|
||||
@@ -253,8 +269,11 @@ static int pkey_ec_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
|
||||
ECerr(EC_F_PKEY_SM2_SIGNCTX_INIT, ERR_R_EVP_LIB);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//ctx->update = int_update;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -282,12 +301,15 @@ static int pkey_ec_signctx(EVP_PKEY_CTX *ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dctx->sign_type == NID_sm2sign)
|
||||
if (dctx->sign_type == NID_sm_scheme)
|
||||
ret = SM2_sign(type, dgst, dgstlen, sig, &len, ec_key);
|
||||
else
|
||||
else if (dctx->sign_type == NID_secg_scheme)
|
||||
ret = ECDSA_sign(type, dgst, dgstlen, sig, &len, ec_key);
|
||||
else
|
||||
ret = 0;
|
||||
|
||||
*siglen = (size_t)len;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -301,7 +323,7 @@ static int pkey_ec_verifyctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
|
||||
unsigned int zidlen;
|
||||
|
||||
|
||||
if (dctx->sign_type == NID_sm2sign) {
|
||||
if (dctx->sign_type == NID_sm_scheme) {
|
||||
|
||||
zidlen = sizeof(zid);
|
||||
if (!SM2_compute_id_digest(md, zid, &zidlen, ec_key)) {
|
||||
@@ -320,47 +342,52 @@ end:
|
||||
static int pkey_ec_verifyctx(EVP_PKEY_CTX *ctx,
|
||||
const unsigned char *sig, int siglen, EVP_MD_CTX *mctx)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char dgst[EVP_MAX_MD_SIZE];
|
||||
unsigned int dgstlen;
|
||||
EC_PKEY_CTX *ec_ctx = ctx->data;
|
||||
EC_PKEY_CTX *dctx = ctx->data;
|
||||
EC_KEY *ec_key = ctx->pkey->pkey.ec;
|
||||
int type = ec_ctx->md ? EVP_MD_type(ec_ctx->md) : NID_sm3;
|
||||
int type = dctx->md ? EVP_MD_type(dctx->md) : NID_sm3;
|
||||
|
||||
dgstlen = sizeof(dgst);
|
||||
if (!EVP_DigestFinal_ex(mctx, dgst, &dgstlen)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return SM2_verify(type, dgst, dgstlen, sig, siglen, ec_key);
|
||||
|
||||
switch (dctx->sign_type) {
|
||||
case NID_sm_scheme:
|
||||
ret = SM2_verify(type, dgst, dgstlen, sig, siglen, ec_key);
|
||||
break;
|
||||
case NID_secg_scheme:
|
||||
ret = ECDSA_verify(type, dgst, dgstlen, sig, siglen, ec_key);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int pkey_ec_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen)
|
||||
{
|
||||
int ret;
|
||||
int ret = 0;
|
||||
EC_PKEY_CTX *dctx = ctx->data;
|
||||
EC_KEY *ec_key = ctx->pkey->pkey.ec;
|
||||
ECIES_PARAMS *params = NULL;
|
||||
|
||||
if (dctx->enc_type == NID_sm2encrypt) {
|
||||
ret = SM2_encrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
} else if (dctx->enc_type == NID_ecies_recommendedParameters) {
|
||||
ret = ECIES_encrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
|
||||
switch (dctx->enc_type) {
|
||||
case NID_sm2encrypt:
|
||||
ret = SM2_encrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
case NID_sm_scheme:
|
||||
if (dctx->enc_param.sm2) {
|
||||
ret = SM2_encrypt(dctx->enc_param.sm2, out, outlen, in, inlen, ec_key);
|
||||
} else {
|
||||
ret = SM2_encrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
break;
|
||||
case NID_ecies_recommendedParameters:
|
||||
ret = ECIES_encrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
case NID_secg_scheme:
|
||||
if (dctx->enc_param.ecies) {
|
||||
ret = ECIES_encrypt(dctx->enc_param.ecies, out, outlen, in, inlen, ec_key);
|
||||
} else {
|
||||
ret = ECIES_encrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
break;
|
||||
case NID_ecies_specifiedParameters:
|
||||
//we need to get ECIES_PARAMS from context
|
||||
ret = ECIES_encrypt(params, out, outlen, in, inlen, ec_key);
|
||||
break;
|
||||
default:
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -373,10 +400,21 @@ static int pkey_ec_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen
|
||||
EC_PKEY_CTX *dctx = ctx->data;
|
||||
EC_KEY *ec_key = ctx->pkey->pkey.ec;
|
||||
|
||||
if (dctx->enc_type == NID_sm2encrypt) {
|
||||
ret = SM2_encrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
} else {
|
||||
ret = ECIES_decrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
switch (dctx->enc_type) {
|
||||
case NID_sm_scheme:
|
||||
if (dctx->enc_param.sm2) {
|
||||
ret = SM2_decrypt(dctx->enc_param.sm2, out, outlen, in, inlen, ec_key);
|
||||
} else {
|
||||
ret = SM2_decrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
break;
|
||||
case NID_secg_scheme:
|
||||
if (dctx->enc_param.ecies) {
|
||||
ret = ECIES_decrypt(dctx->enc_param.ecies, out, outlen, in, inlen, ec_key);
|
||||
} else {
|
||||
ret = ECIES_decrypt_with_recommended(out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -528,10 +528,10 @@ int ECIES_PARAMS_init_with_recommended(ECIES_PARAMS *param)
|
||||
return 0;
|
||||
}
|
||||
param->kdf_nid = NID_undef;
|
||||
param->kdf_md = EVP_sha256();
|
||||
param->kdf_md = EVP_sha1(); //FIXME: EVP_sha256() will error
|
||||
param->sym_cipher = EVP_aes_128_cbc();
|
||||
param->mac_nid = NID_undef;
|
||||
param->mac_md = EVP_sha256();
|
||||
param->mac_nid = NID_hmac_full_ecies;
|
||||
param->mac_md = EVP_sha1(); //FIXME: EVP_sha256() need test
|
||||
param->mac_cipher = NULL;
|
||||
return 1;
|
||||
}
|
||||
@@ -555,4 +555,3 @@ int ECIES_decrypt_with_recommended(unsigned char *out, size_t *outlen,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -155,6 +155,11 @@ static ERR_STRING_DATA ERR_str_libraries[] = {
|
||||
{ERR_PACK(ERR_LIB_FIPS, 0, 0), "FIPS routines"},
|
||||
{ERR_PACK(ERR_LIB_CMS, 0, 0), "CMS routines"},
|
||||
{ERR_PACK(ERR_LIB_HMAC, 0, 0), "HMAC routines"},
|
||||
# ifndef OPENSSL_NO_GMSSL
|
||||
{ERR_PACK(ERR_LIB_ECIES, 0, 0), "ECIES routines"},
|
||||
{ERR_PACK(ERR_LIB_SM2, 0, 0), "SM2 routines"},
|
||||
{ERR_PACK(ERR_LIB_SKF, 0, 0), "SKF routines"},
|
||||
# endif
|
||||
{0, NULL},
|
||||
};
|
||||
|
||||
|
||||
@@ -197,8 +197,11 @@ typedef struct err_state_st {
|
||||
# define ERR_LIB_TS 47
|
||||
# define ERR_LIB_HMAC 48
|
||||
# define ERR_LIB_JPAKE 49
|
||||
# ifndef OPENSSL_NO_GMSSL
|
||||
# define ERR_LIB_ECIES 50
|
||||
# define ERR_LIB_SM2 51
|
||||
# define ERR_LIB_SKF 52
|
||||
# endif
|
||||
|
||||
# define ERR_LIB_USER 128
|
||||
|
||||
@@ -235,8 +238,11 @@ typedef struct err_state_st {
|
||||
# define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),__FILE__,__LINE__)
|
||||
# define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__)
|
||||
# define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__)
|
||||
# ifndef OPENSSL_NO_GMSSL
|
||||
# define ECIESerr(f,r) ERR_PUT_error(ERR_LIB_ECIES,(f),(r),__FILE__,__LINE__)
|
||||
# define SM2err(f, r) ERR_PUT_error(ERR_LIB_SM2,(f),(r),__FILE__,__LINE__)
|
||||
# define SM2err(f,r) ERR_PUT_error(ERR_LIB_SM2,(f),(r),__FILE__,__LINE__)
|
||||
# define SKFerr(f,r) ERR_PUT_error(ERR_LIB_SKF,(f),(r),__FILE__,__LINE__)
|
||||
# endif
|
||||
|
||||
/*
|
||||
* Borland C seems too stupid to be able to shift and do longs in the
|
||||
@@ -293,8 +299,11 @@ typedef struct err_state_st {
|
||||
# define ERR_R_ECDH_LIB ERR_LIB_ECDH/* 43 */
|
||||
# define ERR_R_STORE_LIB ERR_LIB_STORE/* 44 */
|
||||
# define ERR_R_TS_LIB ERR_LIB_TS/* 45 */
|
||||
# ifndef OPENSSL_NO_GMSSL
|
||||
# define ERR_R_ECIES_LIB ERR_LIB_ECIES/* 50 */
|
||||
# define ERR_R_SM2_LIB ERR_LIB_SM2/* 51 */
|
||||
# define ERR_R_SKF_LIB ERR_LIB_SKF/* 52 */
|
||||
# endif
|
||||
|
||||
# define ERR_R_NESTED_ASN1_ERROR 58
|
||||
# define ERR_R_BAD_ASN1_OBJECT_HEADER 59
|
||||
|
||||
@@ -107,6 +107,9 @@
|
||||
#ifndef OPENSSL_NO_JPAKE
|
||||
# include <openssl/jpake.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_GMSSL
|
||||
# include <openssl/sm2.h>
|
||||
#endif
|
||||
|
||||
void ERR_load_crypto_strings(void)
|
||||
{
|
||||
@@ -164,5 +167,9 @@ void ERR_load_crypto_strings(void)
|
||||
# ifndef OPENSSL_NO_JPAKE
|
||||
ERR_load_JPAKE_strings();
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_GMSSL
|
||||
ERR_load_ECIES_strings();
|
||||
ERR_load_SM2_strings();
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ L TS crypto/ts/ts.h crypto/ts/ts_err.c
|
||||
L HMAC crypto/hmac/hmac.h crypto/hmac/hmac_err.c
|
||||
L CMS crypto/cms/cms.h crypto/cms/cms_err.c
|
||||
L JPAKE crypto/jpake/jpake.h crypto/jpake/jpake_err.c
|
||||
L ECIES crypto/ecies/ecies.h crypto/ecies/ecies_err.c
|
||||
L SM2 crypto/sm2/sm2.h crypto/sm2/sm2_err.c
|
||||
L SKF crypto/skf/skf.h crypto/skf/skf_err.c
|
||||
|
||||
# additional header files to be scanned for function names
|
||||
L NONE crypto/x509/x509_vfy.h NONE
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* demo/gmssl/sm3.c */
|
||||
/* crypto/evp/m_btc.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2014 - 2015 The GmSSL Project. All rights reserved.
|
||||
* Copyright (c) 2014 - 2016 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
|
||||
@@ -46,64 +46,72 @@
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* This module is to support crypto-currency such as Bitcoin
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "cryptlib.h"
|
||||
|
||||
#ifndef OPENSSL_NO_GMSSL
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/ripemd.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
int ret = -1;
|
||||
FILE *fp = stdin;
|
||||
unsigned char buf[1024];
|
||||
size_t len;
|
||||
const EVP_MD *md;
|
||||
EVP_MD_CTX mdctx;
|
||||
unsigned char dgst[EVP_MAX_MD_SIZE];
|
||||
unsigned int dgstlen, i;
|
||||
|
||||
if (argc == 2) {
|
||||
if (!(fp = fopen(argv[1], "r"))) {
|
||||
fprintf(stderr, "open file %s failed\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
OpenSSL_add_all_digests();
|
||||
if (!(md = EVP_get_digestbyname("sm3"))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_DigestInit(&mdctx, md)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
while ((len = fread(buf, 1, sizeof(buf), fp))) {
|
||||
if (!EVP_DigestUpdate(&mdctx, buf, len)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
if (!EVP_DigestFinal(&mdctx, dgst, &dgstlen)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i = 0; i < dgstlen; i++) {
|
||||
printf("%02x", dgst[i]);
|
||||
}
|
||||
printf("\n");
|
||||
ret = 0;
|
||||
|
||||
end:
|
||||
fclose(fp);
|
||||
EVP_cleanup();
|
||||
return ret;
|
||||
SHA256_Init(ctx->md_data->sha256);
|
||||
RIPEMD_Init(ctx->md_data->rmd160);
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *in, size_t inlen)
|
||||
{
|
||||
SHA256_Update(ctx, in, inlen);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return sm3_final(ctx->md_data, md);
|
||||
}
|
||||
|
||||
static const EVP_MD sm3_md = {
|
||||
NID_btchash,
|
||||
NID_sm2sign_with_sm3,
|
||||
SM3_DIGEST_LENGTH,
|
||||
0,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
(evp_sign_method *)SM2_sign,
|
||||
(evp_verify_method *)SM2_verify,
|
||||
{EVP_PKEY_EC, 0, 0, 0},
|
||||
SM3_BLOCK_SIZE,
|
||||
sizeof(EVP_MD *) + sizeof(sm3_ctx_t),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_btc160(void)
|
||||
{
|
||||
return &btc160_md;
|
||||
}
|
||||
|
||||
const EVP_MD *EVP_btc256(void)
|
||||
{
|
||||
return &btc256_md;
|
||||
}
|
||||
|
||||
const EVP_MD *EVP_sm3_rmd160(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* crypto/sms4/sms4.h */
|
||||
/* crypto/evp/m_sm3.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2014 - 2015 The GmSSL Project. All rights reserved.
|
||||
*
|
||||
|
||||
@@ -62,12 +62,12 @@
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#define NUM_NID 1040
|
||||
#define NUM_SN 1016
|
||||
#define NUM_LN 1016
|
||||
#define NUM_OBJ 954
|
||||
#define NUM_NID 1044
|
||||
#define NUM_SN 1020
|
||||
#define NUM_LN 1020
|
||||
#define NUM_OBJ 958
|
||||
|
||||
static const unsigned char lvalues[6721]={
|
||||
static const unsigned char lvalues[6753]={
|
||||
0x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */
|
||||
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */
|
||||
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */
|
||||
@@ -1016,6 +1016,10 @@ static const unsigned char lvalues[6721]={
|
||||
0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D,0x03,0x02,/* [6700] OBJ_sm2encrypt_specifiedParameters */
|
||||
0x2B,0x81,0x04,0x01, /* [6710] OBJ_secg_scheme */
|
||||
0x2A,0x81,0x1C,0xCF,0x55,0x01, /* [6714] OBJ_sm_scheme */
|
||||
0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x78, /* [6720] OBJ_sm2sign_with_sha512 */
|
||||
0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x79, /* [6728] OBJ_sm2sign_with_sha224 */
|
||||
0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x7A, /* [6736] OBJ_sm2sign_with_sha384 */
|
||||
0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x7B, /* [6744] OBJ_sm2sign_with_rmd160 */
|
||||
};
|
||||
|
||||
static const ASN1_OBJECT nid_objs[NUM_NID]={
|
||||
@@ -2683,6 +2687,14 @@ static const ASN1_OBJECT nid_objs[NUM_NID]={
|
||||
{"secg-scheme","secg-scheme",NID_secg_scheme,4,&(lvalues[6710]),0},
|
||||
{"sm-scheme","sm-scheme",NID_sm_scheme,6,&(lvalues[6714]),0},
|
||||
{"CBC-MAC","cbc-mac",NID_cbc_mac,0,NULL,0},
|
||||
{"SM2Sign-with-SHA511","sm2sign-with-sha512",NID_sm2sign_with_sha512,
|
||||
8,&(lvalues[6720]),0},
|
||||
{"SM2Sign-with-SHA224","sm2sign-with-sha224",NID_sm2sign_with_sha224,
|
||||
8,&(lvalues[6728]),0},
|
||||
{"SM2Sign-with-SHA384","sm2sign-with-sha384",NID_sm2sign_with_sha384,
|
||||
8,&(lvalues[6736]),0},
|
||||
{"SM2Sign-with-RMD160","sm2sign-with-rmd160",NID_sm2sign_with_rmd160,
|
||||
8,&(lvalues[6744]),0},
|
||||
};
|
||||
|
||||
static const unsigned int sn_objs[NUM_SN]={
|
||||
@@ -2875,8 +2887,12 @@ static const unsigned int sn_objs[NUM_SN]={
|
||||
1019, /* "SM1-CFB" */
|
||||
1016, /* "SM1-ECB" */
|
||||
1018, /* "SM1-OFB" */
|
||||
1043, /* "SM2Sign-with-RMD160" */
|
||||
974, /* "SM2Sign-with-SHA1" */
|
||||
1041, /* "SM2Sign-with-SHA224" */
|
||||
975, /* "SM2Sign-with-SHA256" */
|
||||
1042, /* "SM2Sign-with-SHA384" */
|
||||
1040, /* "SM2Sign-with-SHA511" */
|
||||
973, /* "SM2Sign-with-SM3" */
|
||||
962, /* "SM3" */
|
||||
1006, /* "SM5" */
|
||||
@@ -4647,8 +4663,12 @@ static const unsigned int ln_objs[NUM_LN]={
|
||||
971, /* "sm2keyagreement" */
|
||||
958, /* "sm2p256v1" */
|
||||
970, /* "sm2sign" */
|
||||
1043, /* "sm2sign-with-rmd160" */
|
||||
974, /* "sm2sign-with-sha1" */
|
||||
1041, /* "sm2sign-with-sha224" */
|
||||
975, /* "sm2sign-with-sha256" */
|
||||
1042, /* "sm2sign-with-sha384" */
|
||||
1040, /* "sm2sign-with-sha512" */
|
||||
973, /* "sm2sign-with-sm3" */
|
||||
962, /* "sm3" */
|
||||
1006, /* "sm5" */
|
||||
@@ -5189,6 +5209,10 @@ static const unsigned int obj_objs[NUM_OBJ]={
|
||||
973, /* OBJ_sm2sign_with_sm3 1 2 156 10197 1 501 */
|
||||
974, /* OBJ_sm2sign_with_sha1 1 2 156 10197 1 502 */
|
||||
975, /* OBJ_sm2sign_with_sha256 1 2 156 10197 1 503 */
|
||||
1040, /* OBJ_sm2sign_with_sha512 1 2 156 10197 1 504 */
|
||||
1041, /* OBJ_sm2sign_with_sha224 1 2 156 10197 1 505 */
|
||||
1042, /* OBJ_sm2sign_with_sha384 1 2 156 10197 1 506 */
|
||||
1043, /* OBJ_sm2sign_with_rmd160 1 2 156 10197 1 507 */
|
||||
1000, /* OBJ_zuc 1 2 156 10197 1 800 */
|
||||
776, /* OBJ_seed_ecb 1 2 410 200004 1 3 */
|
||||
777, /* OBJ_seed_cbc 1 2 410 200004 1 4 */
|
||||
|
||||
@@ -4473,6 +4473,26 @@
|
||||
#define NID_sm2sign_with_sha256 975
|
||||
#define OBJ_sm2sign_with_sha256 OBJ_sm_scheme,503L
|
||||
|
||||
#define SN_sm2sign_with_sha512 "SM2Sign-with-SHA511"
|
||||
#define LN_sm2sign_with_sha512 "sm2sign-with-sha512"
|
||||
#define NID_sm2sign_with_sha512 1040
|
||||
#define OBJ_sm2sign_with_sha512 OBJ_sm_scheme,504L
|
||||
|
||||
#define SN_sm2sign_with_sha224 "SM2Sign-with-SHA224"
|
||||
#define LN_sm2sign_with_sha224 "sm2sign-with-sha224"
|
||||
#define NID_sm2sign_with_sha224 1041
|
||||
#define OBJ_sm2sign_with_sha224 OBJ_sm_scheme,505L
|
||||
|
||||
#define SN_sm2sign_with_sha384 "SM2Sign-with-SHA384"
|
||||
#define LN_sm2sign_with_sha384 "sm2sign-with-sha384"
|
||||
#define NID_sm2sign_with_sha384 1042
|
||||
#define OBJ_sm2sign_with_sha384 OBJ_sm_scheme,506L
|
||||
|
||||
#define SN_sm2sign_with_rmd160 "SM2Sign-with-RMD160"
|
||||
#define LN_sm2sign_with_rmd160 "sm2sign-with-rmd160"
|
||||
#define NID_sm2sign_with_rmd160 1043
|
||||
#define OBJ_sm2sign_with_rmd160 OBJ_sm_scheme,507L
|
||||
|
||||
#define SN_zuc "ZUC"
|
||||
#define LN_zuc "zuc"
|
||||
#define NID_zuc 1000
|
||||
|
||||
@@ -1037,3 +1037,7 @@ sm2encrypt_specifiedParameters 1036
|
||||
secg_scheme 1037
|
||||
sm_scheme 1038
|
||||
cbc_mac 1039
|
||||
sm2sign_with_sha512 1040
|
||||
sm2sign_with_sha224 1041
|
||||
sm2sign_with_sha384 1042
|
||||
sm2sign_with_rmd160 1043
|
||||
|
||||
@@ -1439,6 +1439,10 @@ sm-scheme 401 2 : HMAC-SM3 : hmac-sm3
|
||||
sm-scheme 501 : SM2Sign-with-SM3 : sm2sign-with-sm3
|
||||
sm-scheme 502 : SM2Sign-with-SHA1 : sm2sign-with-sha1
|
||||
sm-scheme 503 : SM2Sign-with-SHA256 : sm2sign-with-sha256
|
||||
sm-scheme 504 : SM2Sign-with-SHA511 : sm2sign-with-sha512
|
||||
sm-scheme 505 : SM2Sign-with-SHA224 : sm2sign-with-sha224
|
||||
sm-scheme 506 : SM2Sign-with-SHA384 : sm2sign-with-sha384
|
||||
sm-scheme 507 : SM2Sign-with-RMD160 : sm2sign-with-rmd160
|
||||
|
||||
# GmSSL ZUC OID
|
||||
sm-scheme 800 : ZUC : zuc
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
/* OpenSSL was configured with the following options: */
|
||||
#ifndef OPENSSL_SYSNAME_MACOSX
|
||||
# define OPENSSL_SYSNAME_MACOSX
|
||||
#endif
|
||||
#ifndef OPENSSL_DOING_MAKEDEPEND
|
||||
|
||||
|
||||
@@ -47,6 +50,9 @@ extern "C" {
|
||||
|
||||
#endif /* OPENSSL_DOING_MAKEDEPEND */
|
||||
|
||||
#ifndef OPENSSL_THREADS
|
||||
# define OPENSSL_THREADS
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DYNAMIC_ENGINE
|
||||
# define OPENSSL_NO_DYNAMIC_ENGINE
|
||||
#endif
|
||||
@@ -94,6 +100,8 @@ extern "C" {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define OPENSSL_CPUID_OBJ
|
||||
|
||||
/* crypto/opensslconf.h.in */
|
||||
|
||||
/* Generate 80386 code? */
|
||||
@@ -101,8 +109,8 @@ extern "C" {
|
||||
|
||||
#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
|
||||
#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
|
||||
#define ENGINESDIR "/usr/local/ssl/lib/engines"
|
||||
#define OPENSSLDIR "/usr/local/ssl"
|
||||
#define ENGINESDIR "/usr/local/lib/engines"
|
||||
#define OPENSSLDIR "/usr/local/openssl"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -140,7 +148,7 @@ extern "C" {
|
||||
* This enables code handling data aligned at natural CPU word
|
||||
* boundary. See crypto/rc4/rc4_enc.c for further details.
|
||||
*/
|
||||
#undef RC4_CHUNK
|
||||
#define RC4_CHUNK unsigned long
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -148,7 +156,7 @@ extern "C" {
|
||||
/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
|
||||
* %20 speed up (longs are 8 bytes, int's are 4). */
|
||||
#ifndef DES_LONG
|
||||
#define DES_LONG unsigned long
|
||||
#define DES_LONG unsigned int
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -159,9 +167,9 @@ extern "C" {
|
||||
/* Should we define BN_DIV2W here? */
|
||||
|
||||
/* Only one for the following should be defined */
|
||||
#undef SIXTY_FOUR_BIT_LONG
|
||||
#define SIXTY_FOUR_BIT_LONG
|
||||
#undef SIXTY_FOUR_BIT
|
||||
#define THIRTY_TWO_BIT
|
||||
#undef THIRTY_TWO_BIT
|
||||
#endif
|
||||
|
||||
#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
|
||||
@@ -203,7 +211,7 @@ extern "C" {
|
||||
/* Unroll the inner loop, this sometimes helps, sometimes hinders.
|
||||
* Very mucy CPU dependant */
|
||||
#ifndef DES_UNROLL
|
||||
#undef DES_UNROLL
|
||||
#define DES_UNROLL
|
||||
#endif
|
||||
|
||||
/* These default values were supplied by
|
||||
|
||||
@@ -89,10 +89,8 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
|
||||
return NULL;
|
||||
p = data;
|
||||
|
||||
fprintf(stderr, "GMSSL: %s %d: nm = %s\n", __FILE__, __LINE__, nm);
|
||||
if (strcmp(nm, PEM_STRING_PKCS8INF) == 0) {
|
||||
PKCS8_PRIV_KEY_INFO *p8inf;
|
||||
fprintf(stderr, "GMSSL: %s %d\n", __FILE__, __LINE__);
|
||||
p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
|
||||
if (!p8inf)
|
||||
goto p8err;
|
||||
@@ -108,7 +106,6 @@ fprintf(stderr, "GMSSL: %s %d\n", __FILE__, __LINE__);
|
||||
X509_SIG *p8;
|
||||
int klen;
|
||||
char psbuf[PEM_BUFSIZE];
|
||||
fprintf(stderr, "GMSSL: %s %d\n", __FILE__, __LINE__);
|
||||
p8 = d2i_X509_SIG(NULL, &p, len);
|
||||
if (!p8)
|
||||
goto p8err;
|
||||
@@ -134,20 +131,14 @@ fprintf(stderr, "GMSSL: %s %d\n", __FILE__, __LINE__);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
} else if ((slen = pem_check_suffix(nm, "PRIVATE KEY")) > 0) {
|
||||
const EVP_PKEY_ASN1_METHOD *ameth;
|
||||
fprintf(stderr, "GMSSL: %s %d\n", __FILE__, __LINE__);
|
||||
fprintf(stderr, "GMSSL: %s %d: slen = %d\n", __FILE__, __LINE__, slen);
|
||||
|
||||
ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);
|
||||
|
||||
OPENSSL_assert(ameth != NULL);
|
||||
|
||||
if (!ameth || !ameth->old_priv_decode)
|
||||
goto p8err;
|
||||
fprintf(stderr, "GMSSL: %s %d: type id = %d\n", __FILE__, __LINE__, ameth->pkey_id);
|
||||
ret = d2i_PrivateKey(ameth->pkey_id, x, &p, len);
|
||||
OPENSSL_assert(ret != NULL);
|
||||
}
|
||||
fprintf(stderr, "GMSSL: %s %d\n", __FILE__, __LINE__);
|
||||
p8err:
|
||||
if (ret == NULL)
|
||||
PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, ERR_R_ASN1_LIB);
|
||||
@@ -155,7 +146,6 @@ fprintf(stderr, "GMSSL: %s %d\n", __FILE__, __LINE__);
|
||||
OPENSSL_free(nm);
|
||||
OPENSSL_cleanse(data, len);
|
||||
OPENSSL_free(data);
|
||||
fprintf(stderr, "GMSSL: %s %d\n", __FILE__, __LINE__);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* crypto/skf/skf.h */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2014 - 2015 The GmSSL Project. All rights reserved.
|
||||
*
|
||||
@@ -53,7 +54,6 @@
|
||||
#define HEADER_SKF_H
|
||||
|
||||
|
||||
/* Algorithms */
|
||||
#define SGD_SM1_ECB 0x00000101
|
||||
#define SGD_SM1_CBC 0x00000102
|
||||
#define SGD_SM1_CFB 0x00000104
|
||||
@@ -114,13 +114,13 @@ typedef HANDLE HCONTAINER;
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#define DEVAPI __stdcall
|
||||
#define DEVAPI __stdcall
|
||||
#else
|
||||
#define DEVAPI
|
||||
#define DEVAPI
|
||||
#endif
|
||||
|
||||
#ifndef ADMIN_TYPE
|
||||
#define ADMIN_TYPE 0
|
||||
#ifndef ADMIN_TYPE
|
||||
#define ADMIN_TYPE 0
|
||||
#endif
|
||||
|
||||
#ifndef USER_TYPE
|
||||
@@ -219,8 +219,10 @@ typedef struct Struct_ECCSIGNATUREBLOB {
|
||||
BYTE s[ECC_MAX_XCOORDINATE_BITS_LEN/8];
|
||||
} ECCSIGNATUREBLOB, *PECCSIGNATUREBLOB;
|
||||
|
||||
#ifndef SKF_NO_GMSSL
|
||||
#define SKF_NO_PADDING 0
|
||||
#define SKF_PKCS5_PADDING 1
|
||||
#endif
|
||||
|
||||
typedef struct Struct_BLOCKCIPHERPARAM {
|
||||
BYTE IV[MAX_IV_LEN];
|
||||
@@ -249,55 +251,74 @@ typedef struct Struct_FILEATTRIBUTE {
|
||||
ULONG DEVAPI SKF_WaitForDevEvent(LPSTR szDevName,
|
||||
ULONG *pulDevNameLen,
|
||||
ULONG *pulEvent);
|
||||
|
||||
ULONG DEVAPI SKF_CancelWaitForDevEvent();
|
||||
|
||||
ULONG DEVAPI SKF_EnumDev(BOOL bPresent,
|
||||
LPSTR szNameList,
|
||||
ULONG *pulSize);
|
||||
|
||||
ULONG DEVAPI SKF_ConnectDev(LPSTR szName,
|
||||
DEVHANDLE *phDev);
|
||||
|
||||
ULONG DEVAPI SKF_DisConnectDev(DEVHANDLE hDev);
|
||||
|
||||
#ifndef SKF_NO_GMSSL
|
||||
#define DEV_ABSENT_STATE 0x00000000
|
||||
#define DEV_PRESENT_STATE 0x00000001
|
||||
#define DEV_UNKNOW_STATE 0x00000010
|
||||
#endif
|
||||
|
||||
ULONG DEVAPI SKF_GetDevState(LPSTR szDevName,
|
||||
ULONG *pulDevState);
|
||||
|
||||
ULONG DEVAPI SKF_SetLabel(DEVHANDLE hDev,
|
||||
LPSTR szLabel);
|
||||
|
||||
ULONG DEVAPI SKF_GetDevInfo(DEVHANDLE hDev,
|
||||
DEVINFO *pDevInfo);
|
||||
|
||||
ULONG DEVAPI SKF_LockDev(DEVHANDLE hDev,
|
||||
ULONG ulTimeOut);
|
||||
|
||||
ULONG DEVAPI SKF_UnlockDev(DEVHANDLE hDev);
|
||||
|
||||
ULONG DEVAPI SKF_Transmit(DEVHANDLE hDev,
|
||||
BYTE *pbCommand,
|
||||
ULONG ulCommandLen,
|
||||
BYTE *pbData,
|
||||
ULONG *pulDataLen);
|
||||
|
||||
ULONG DEVAPI SKF_ChangeDevAuthKey(DEVHANDLE hDev,
|
||||
BYTE *pbKeyValue,
|
||||
ULONG ulKeyLen);
|
||||
|
||||
ULONG DEVAPI SKF_DevAuth(DEVHANDLE hDev,
|
||||
BYTE *pbAuthData,
|
||||
ULONG ulLen);
|
||||
|
||||
ULONG DEVAPI SKF_ChangePIN(HAPPLICATION hApplication,
|
||||
ULONG ulPINType,
|
||||
LPSTR szOldPin,
|
||||
LPSTR szNewPin,
|
||||
ULONG *pulRetryCount);
|
||||
|
||||
LONG DEVAPI SKF_GetPINInfo(HAPPLICATION hApplication,
|
||||
ULONG ulPINType,
|
||||
ULONG *pulMaxRetryCount,
|
||||
ULONG *pulRemainRetryCount,
|
||||
BOOL *pbDefaultPin);
|
||||
|
||||
ULONG DEVAPI SKF_VerifyPIN(HAPPLICATION hApplication,
|
||||
ULONG ulPINType,
|
||||
LPSTR szPIN,
|
||||
ULONG *pulRetryCount);
|
||||
|
||||
ULONG DEVAPI SKF_UnblockPIN(HAPPLICATION hApplication,
|
||||
LPSTR szAdminPIN,
|
||||
LPSTR szNewUserPIN,
|
||||
ULONG *pulRetryCount);
|
||||
|
||||
ULONG DEVAPI SKF_ClearSecureState(HAPPLICATION hApplication);
|
||||
|
||||
ULONG DEVAPI SKF_CreateApplication(DEVHANDLE hDev,
|
||||
@@ -308,14 +329,18 @@ ULONG DEVAPI SKF_CreateApplication(DEVHANDLE hDev,
|
||||
DWORD dwUserPinRetryCount,
|
||||
DWORD dwCreateFileRights,
|
||||
HAPPLICATION *phApplication);
|
||||
|
||||
ULONG DEVAPI SKF_EnumApplication(DEVHANDLE hDev,
|
||||
LPSTR szAppName,
|
||||
ULONG *pulSize);
|
||||
|
||||
ULONG DEVAPI SKF_DeleteApplication(DEVHANDLE hDev,
|
||||
LPSTR szAppName);
|
||||
|
||||
ULONG DEVAPI SKF_OpenApplication(DEVHANDLE hDev,
|
||||
LPSTR szAppName,
|
||||
HAPPLICATION *phApplication);
|
||||
|
||||
ULONG DEVAPI SKF_CloseApplication(HAPPLICATION hApplication);
|
||||
|
||||
ULONG DEVAPI SKF_CreateFile(HAPPLICATION hApplication,
|
||||
@@ -323,20 +348,25 @@ ULONG DEVAPI SKF_CreateFile(HAPPLICATION hApplication,
|
||||
ULONG ulFileSize,
|
||||
ULONG ulReadRights,
|
||||
ULONG ulWriteRights);
|
||||
|
||||
ULONG DEVAPI SKF_DeleteFile(HAPPLICATION hApplication,
|
||||
LPSTR szFileName);
|
||||
|
||||
ULONG DEVAPI SKF_EnumFiles(HAPPLICATION hApplication,
|
||||
LPSTR szFileList,
|
||||
ULONG *pulSize);
|
||||
|
||||
ULONG DEVAPI SKF_GetFileInfo(HAPPLICATION hApplication,
|
||||
LPSTR szFileName,
|
||||
FILEATTRIBUTE *pFileInfo);
|
||||
|
||||
ULONG DEVAPI SKF_ReadFile(HAPPLICATION hApplication,
|
||||
LPSTR szFileName,
|
||||
ULONG ulOffset,
|
||||
ULONG ulSize,
|
||||
BYTE *pbOutData,
|
||||
ULONG *pulOutLen);
|
||||
|
||||
ULONG DEVAPI SKF_WriteFile(HAPPLICATION hApplication,
|
||||
LPSTR szFileName,
|
||||
ULONG ulOffset,
|
||||
@@ -346,19 +376,26 @@ ULONG DEVAPI SKF_WriteFile(HAPPLICATION hApplication,
|
||||
ULONG DEVAPI SKF_CreateContainer(HAPPLICATION hApplication,
|
||||
LPSTR szContainerName,
|
||||
HCONTAINER *phContainer);
|
||||
|
||||
ULONG DEVAPI SKF_DeleteContainer(HAPPLICATION hApplication,
|
||||
LPSTR szContainerName);
|
||||
|
||||
ULONG DEVAPI SKF_EnumContainer(HAPPLICATION hApplication,
|
||||
LPSTR szContainerName,
|
||||
ULONG *pulSize);
|
||||
|
||||
ULONG DEVAPI SKF_OpenContainer(HAPPLICATION hApplication,
|
||||
LPSTR szContainerName,
|
||||
HCONTAINER *phContainer);
|
||||
|
||||
ULONG DEVAPI SKF_CloseContainer(HCONTAINER hContainer);
|
||||
|
||||
#ifndef SKF_NO_GMSSL
|
||||
#define CONTAINER_TYPE_UNDEF 0
|
||||
#define CONTAINER_TYPE_RSA 1
|
||||
#define CONTAINER_TYPE_ECC 2
|
||||
#endif
|
||||
|
||||
ULONG DEVAPI SKF_GetContainerType(HCONTAINER hContainer,
|
||||
ULONG *pulContainerType);
|
||||
|
||||
@@ -377,46 +414,52 @@ ULONG DEVAPI SKF_ExportPublicKey(HCONTAINER hContainer,
|
||||
BYTE *pbBlob,
|
||||
ULONG *pulBlobLen);
|
||||
|
||||
|
||||
|
||||
ULONG DEVAPI SKF_GenRandom(DEVHANDLE hDev,
|
||||
BYTE *pbRandom,
|
||||
ULONG ulRandomLen);
|
||||
|
||||
ULONG DEVAPI SKF_GenExtRSAKey(DEVHANDLE hDev,
|
||||
ULONG ulBitsLen,
|
||||
RSAPRIVATEKEYBLOB *pBlob);
|
||||
|
||||
ULONG DEVAPI SKF_GenRSAKeyPair(HCONTAINER hContainer,
|
||||
ULONG ulBitsLen,
|
||||
RSAPUBLICKEYBLOB *pBlob);
|
||||
|
||||
ULONG DEVAPI SKF_ImportRSAKeyPair(HCONTAINER hContainer,
|
||||
ULONG ulSymAlgId,
|
||||
BYTE *pbWrappedKey,
|
||||
BYTE *pbWrappedKey,
|
||||
ULONG ulWrappedKeyLen,
|
||||
BYTE *pbEncryptedData,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG ulEncryptedDataLen);
|
||||
|
||||
ULONG DEVAPI SKF_RSASignData(HCONTAINER hContainer,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbSignature,
|
||||
ULONG *pulSignLen);
|
||||
|
||||
ULONG DEVAPI SKF_RSAVerify(DEVHANDLE hDev,
|
||||
RSAPUBLICKEYBLOB *pRSAPubKeyBlob,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbSignature,
|
||||
ULONG ulSignLen);
|
||||
|
||||
ULONG DEVAPI SKF_RSAExportSessionKey(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
RSAPUBLICKEYBLOB *pPubKey,
|
||||
BYTE *pbData,
|
||||
ULONG *pulDataLen,
|
||||
RSAPUBLICKEYBLOB *pPubKey,
|
||||
BYTE *pbData,
|
||||
ULONG *pulDataLen,
|
||||
HANDLE *phSessionKey);
|
||||
|
||||
ULONG DEVAPI SKF_ExtRSAPubKeyOperation(DEVHANDLE hDev,
|
||||
RSAPUBLICKEYBLOB *pRSAPubKeyBlob,
|
||||
BYTE *pbInput,
|
||||
ULONG ulInputLen,
|
||||
BYTE *pbOutput,
|
||||
BYTE *pbInput,
|
||||
ULONG ulInputLen,
|
||||
BYTE *pbOutput,
|
||||
ULONG *pulOutputLen);
|
||||
|
||||
ULONG DEVAPI SKF_ExtRSAPriKeyOperation(DEVHANDLE hDev,
|
||||
RSAPRIVATEKEYBLOB *pRSAPriKeyBlob,
|
||||
BYTE *pbInput,
|
||||
@@ -427,44 +470,50 @@ ULONG DEVAPI SKF_ExtRSAPriKeyOperation(DEVHANDLE hDev,
|
||||
ULONG DEVAPI SKF_GenECCKeyPair(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
ECCPUBLICKEYBLOB *pBlob);
|
||||
|
||||
ULONG DEVAPI SKF_ImportECCKeyPair(HCONTAINER hContainer,
|
||||
PENVELOPEDKEYBLOB pEnvelopedKeyBlob);
|
||||
ENVELOPEDKEYBLOB *pEnvelopedKeyBlob);
|
||||
|
||||
ULONG DEVAPI SKF_ECCSignData(HCONTAINER hContainer,
|
||||
BYTE *pbDigest,
|
||||
ULONG ulDigestLen,
|
||||
PECCSIGNATUREBLOB pSignature);
|
||||
ECCSIGNATUREBLOB *pSignature);
|
||||
|
||||
ULONG DEVAPI SKF_ECCVerify(DEVHANDLE hDev,
|
||||
ECCPUBLICKEYBLOB* pECCPubKeyBlob,
|
||||
BYTE *pbData,
|
||||
ECCPUBLICKEYBLOB *pECCPubKeyBlob,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
PECCSIGNATUREBLOB pSignature);
|
||||
ULONG DEVAPI SKF_ECCExportSessionKey(HCONTAINER hContainer,
|
||||
ECCSIGNATUREBLOB *pSignature);
|
||||
|
||||
ULONG DEVAPI SKF_ECCExportSessionKey(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
ECCPUBLICKEYBLOB *pPubKey,
|
||||
PECCCIPHERBLOB pData,
|
||||
ECCPUBLICKEYBLOB *pPubKey,
|
||||
ECCCIPHERBLOB *pData,
|
||||
HANDLE *phSessionKey);
|
||||
ULONG DEVAPI SKF_ExtECCEncrypt(DEVHANDLE hDev,
|
||||
|
||||
ULONG DEVAPI SKF_ExtECCEncrypt(DEVHANDLE hDev,
|
||||
ECCPUBLICKEYBLOB *pECCPubKeyBlob,
|
||||
BYTE *pbPlainText,
|
||||
ULONG ulPlainTextLen,
|
||||
PECCCIPHERBLOB pCipherText);
|
||||
ECCCIPHERBLOB *pCipherText);
|
||||
|
||||
ULONG DEVAPI SKF_ExtECCDecrypt(DEVHANDLE hDev,
|
||||
ECCPRIVATEKEYBLOB *pECCPriKeyBlob,
|
||||
PECCCIPHERBLOB pCipherText,
|
||||
ECCCIPHERBLOB *pCipherText,
|
||||
BYTE *pbPlainText,
|
||||
ULONG *pulPlainTextLen);
|
||||
|
||||
ULONG DEVAPI SKF_ExtECCSign(DEVHANDLE hDev,
|
||||
ECCPRIVATEKEYBLOB *pECCPriKeyBlob,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
PECCSIGNATUREBLOB pSignature);
|
||||
ULONG DEVAPI SKF_ExtECCVerify(DEVHANDLE hDev,
|
||||
ECCSIGNATUREBLOB *pSignature);
|
||||
|
||||
ULONG DEVAPI SKF_ExtECCVerify(DEVHANDLE hDev,
|
||||
ECCPUBLICKEYBLOB *pECCPubKeyBlob,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
PECCSIGNATUREBLOB pSignature);
|
||||
ECCSIGNATUREBLOB *pSignature);
|
||||
|
||||
ULONG DEVAPI SKF_GenerateAgreementDataWithECC(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
@@ -472,6 +521,7 @@ ULONG DEVAPI SKF_GenerateAgreementDataWithECC(HCONTAINER hContainer,
|
||||
BYTE *pbID,
|
||||
ULONG ulIDLen,
|
||||
HANDLE *phAgreementHandle);
|
||||
|
||||
ULONG DEVAPI SKF_GenerateAgreementDataAndKeyWithECC(HANDLE hContainer,
|
||||
ULONG ulAlgId,
|
||||
ECCPUBLICKEYBLOB *pSponsorECCPubKeyBlob,
|
||||
@@ -482,6 +532,7 @@ ULONG DEVAPI SKF_GenerateAgreementDataAndKeyWithECC(HANDLE hContainer,
|
||||
BYTE *pbSponsorID,
|
||||
ULONG ulSponsorIDLen,
|
||||
HANDLE *phKeyHandle);
|
||||
|
||||
ULONG DEVAPI SKF_GenerateKeyWithECC(HANDLE hAgreementHandle,
|
||||
ECCPUBLICKEYBLOB *pECCPubKeyBlob,
|
||||
ECCPUBLICKEYBLOB *pTempECCPubKeyBlob,
|
||||
@@ -489,12 +540,12 @@ ULONG DEVAPI SKF_GenerateKeyWithECC(HANDLE hAgreementHandle,
|
||||
ULONG ulIDLen,
|
||||
HANDLE *phKeyHandle);
|
||||
|
||||
|
||||
ULONG DEVAPI SKF_ImportSessionKey(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
BYTE *pbWrapedData,
|
||||
ULONG ulWrapedLen,
|
||||
HANDLE *phKey);
|
||||
|
||||
ULONG DEVAPI SKF_SetSymmKey(DEVHANDLE hDev,
|
||||
BYTE *pbKey,
|
||||
ULONG ulAlgID,
|
||||
@@ -502,31 +553,38 @@ ULONG DEVAPI SKF_SetSymmKey(DEVHANDLE hDev,
|
||||
|
||||
ULONG DEVAPI SKF_EncryptInit(HANDLE hKey,
|
||||
BLOCKCIPHERPARAM EncryptParam);
|
||||
|
||||
ULONG DEVAPI SKF_Encrypt(HANDLE hKey,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG *pulEncryptedLen);
|
||||
|
||||
ULONG DEVAPI SKF_EncryptUpdate(HANDLE hKey,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG *pulEncryptedLen);
|
||||
|
||||
ULONG DEVAPI SKF_EncryptFinal(HANDLE hKey,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG *pulEncryptedDataLen);
|
||||
|
||||
ULONG DEVAPI SKF_DecryptInit(HANDLE hKey,
|
||||
BLOCKCIPHERPARAM DecryptParam);
|
||||
|
||||
ULONG DEVAPI SKF_Decrypt(HANDLE hKey,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG ulEncryptedLen,
|
||||
BYTE *pbData,
|
||||
ULONG *pulDataLen);
|
||||
|
||||
ULONG DEVAPI SKF_DecryptUpdate(HANDLE hKey,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG ulEncryptedLen,
|
||||
BYTE *pbData,
|
||||
ULONG *pulDataLen);
|
||||
|
||||
ULONG DEVAPI SKF_DecryptFinal(HANDLE hKey,
|
||||
BYTE *pbDecryptedData,
|
||||
ULONG *pulDecryptedDataLen);
|
||||
@@ -534,32 +592,39 @@ ULONG DEVAPI SKF_DecryptFinal(HANDLE hKey,
|
||||
ULONG DEVAPI SKF_DigestInit(DEVHANDLE hDev,
|
||||
ULONG ulAlgID,
|
||||
ECCPUBLICKEYBLOB *pPubKey,
|
||||
unsigned char *pucID,
|
||||
BYTE *pbID,
|
||||
ULONG ulIDLen,
|
||||
HANDLE *phHash);
|
||||
|
||||
ULONG DEVAPI SKF_Digest(HANDLE hHash,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbHashData,
|
||||
BYTE *pbHashData,
|
||||
ULONG *pulHashLen);
|
||||
|
||||
ULONG DEVAPI SKF_DigestUpdate(HANDLE hHash,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen);
|
||||
|
||||
ULONG DEVAPI SKF_DigestFinal(HANDLE hHash,
|
||||
BYTE *pHashData,
|
||||
ULONG *pulHashLen);
|
||||
|
||||
ULONG DEVAPI SKF_MacInit(HANDLE hKey,
|
||||
BLOCKCIPHERPARAM *pMacParam,
|
||||
HANDLE *phMac);
|
||||
|
||||
ULONG DEVAPI SKF_Mac(HANDLE hMac,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbMacData,
|
||||
ULONG *pulMacLen);
|
||||
ULONG DEVAPI SKF_MacUpdate(HANDLE hMac,
|
||||
|
||||
ULONG DEVAPI SKF_MacUpdate(HANDLE hMac,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen);
|
||||
ULONG DEVAPI SKF_MacFinal(HANDLE hMac,
|
||||
|
||||
ULONG DEVAPI SKF_MacFinal(HANDLE hMac,
|
||||
BYTE *pbMacData,
|
||||
ULONG *pulMacDataLen);
|
||||
|
||||
@@ -594,7 +659,8 @@ ULONG DEVAPI SKF_CloseHandle(HANDLE hHandle);
|
||||
#define SAR_RSAENCERR 0x0A000018
|
||||
#define SAR_RSADECERR 0x0A000019
|
||||
#define SAR_HASHNOTEQUALERR 0x0A00001A
|
||||
#define SAR_KEYNOTFOUNTERR 0x0A00001B /* NOT FOUNT? */
|
||||
#define SAR_KEYNOTFOUNTERR 0x0A00001B
|
||||
#define SAR_KEYNOTFOUNDERR 0x0A00001B
|
||||
#define SAR_CERTNOTFOUNTERR 0x0A00001C
|
||||
#define SAR_NOTEXPORTERR 0x0A00001D
|
||||
#define SAR_DECRYPTPADERR 0x0A00001E
|
||||
@@ -1,3 +1,54 @@
|
||||
/* engines/skf/skf_dummy.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2015-2016 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 "skf.h"
|
||||
133
crypto/skf/skf_err2.c
Normal file
133
crypto/skf/skf_err2.c
Normal file
@@ -0,0 +1,133 @@
|
||||
#include "skf/skf.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* about the filename err2: this is manually written err file
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int skf_err2openssl(int err)
|
||||
{
|
||||
switch (err) {
|
||||
case SAR_OK: return SKF_R_SAR_OK;
|
||||
case SAR_FAIL: return SKF_R_SAR_FAIL;
|
||||
case SAR_UNKNOWNERR: return SKF_R_
|
||||
case SAR_NOTSUPPORTYETERR: return SKF_R_
|
||||
case SAR_FILEERR: return SKF_R_
|
||||
case SAR_INVALIDHANDLEERR: return SKF_R_
|
||||
case SAR_INVALIDPARAMERR: return SKF_R_
|
||||
case SAR_READFILEERR: return SKF_R_
|
||||
case SAR_WRITEFILEERR: return SKF_R_
|
||||
case SAR_NAMELENERR: return SKF_R_
|
||||
case SAR_KEYUSAGEERR: return SKF_R_
|
||||
case SAR_MODULUSLENERR: return SKF_R_
|
||||
case SAR_NOTINITIALIZEERR: return SKF_R_
|
||||
case SAR_OBJERR: return SKF_R_
|
||||
case SAR_MEMORYERR: return SKF_R_
|
||||
case SAR_TIMEOUTERR: return SKF_R_
|
||||
case SAR_INDATALENERR: return SKF_R_
|
||||
case SAR_INDATAERR: return SKF_R_
|
||||
case SAR_GENRANDERR: return SKF_R_
|
||||
case SAR_HASHOBJERR: return SKF_R_
|
||||
case SAR_HASHERR: return SKF_R_
|
||||
case SAR_GENRSAKEYERR: return SKF_R_
|
||||
case SAR_RSAMODULUSLENERR: return SKF_R_
|
||||
case SAR_CSPIMPRTPUBKEYERR: return SKF_R_
|
||||
case SAR_RSAENCERR: return SKF_R_
|
||||
case SAR_RSADECERR: return SKF_R_
|
||||
case SAR_HASHNOTEQUALERR: return SKF_R_
|
||||
case SAR_KEYNOTFOUNTERR: return SKF_R_
|
||||
case SAR_CERTNOTFOUNTERR: return SKF_R_
|
||||
case SAR_NOTEXPORTERR: return SKF_R_
|
||||
case SAR_DECRYPTPADERR: return SKF_R_
|
||||
case SAR_MACLENERR: return SKF_R_
|
||||
case SAR_BUFFER_TOO_SMALL: return SKF_R_
|
||||
case SAR_KEYINFOTYPEERR: return SKF_R_
|
||||
case SAR_NOT_EVENTERR: return SKF_R_
|
||||
case SAR_DEVICE_REMOVED: return SKF_R_
|
||||
case SAR_PIN_INCORRECT: return SKF_R_
|
||||
case SAR_PIN_LOCKED: return SKF_R_
|
||||
case SAR_PIN_INVALID: return SKF_R_
|
||||
case SAR_PIN_LEN_RANGE: return SKF_R_
|
||||
case SAR_USER_ALREADY_LOGGED_IN: return SKF_R_
|
||||
case SAR_USER_PIN_NOT_INITIALIZED: return SKF_R_
|
||||
case SAR_USER_TYPE_INVALID: return SKF_R_
|
||||
case SAR_APPLICATION_NAME_INVALID: return SKF_R_
|
||||
case SAR_APPLICATION_EXISTS: return SKF_R_
|
||||
case SAR_USER_NOT_LOGGED_IN: return SKF_R_
|
||||
case SAR_APPLICATION_NOT_EXISTS: return SKF_R_
|
||||
case SAR_FILE_ALREADY_EXIST: return SKF_R_
|
||||
case SAR_NO_ROOM: return SKF_R_
|
||||
case SAR_FILE_NOT_EXIST: return SKF_R_
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
int err_no;
|
||||
char *err_str;
|
||||
} skf_errstr[] = {
|
||||
{ SAR_OK, "Success" },
|
||||
{ SAR_FAIL, "Failure" },
|
||||
{ SAR_UNKNOWNERR, "Unknown error" },
|
||||
{ SAR_NOTSUPPORTYETERR, "Not supported" },
|
||||
{ SAR_FILEERR, "File error" },
|
||||
{ SAR_INVALIDHANDLEERR, "Invalid handler" },
|
||||
{ SAR_INVALIDPARAMERR, "Invalid parameter" },
|
||||
{ SAR_READFILEERR, "Read file error" },
|
||||
{ SAR_WRITEFILEERR "Write file error" },
|
||||
{ SAR_NAMELENERR, "Name length error" },
|
||||
{ SAR_KEYUSAGEERR, "Key usage error" },
|
||||
{ SAR_MODULUSLENERR, "Modulus length error" },
|
||||
{ SAR_NOTINITIALIZEERR, "Not initialized" },
|
||||
{ SAR_OBJERR, "Object error" },
|
||||
{ SAR_MEMORYERR, "Memory error" },
|
||||
{ SAR_TIMEOUTERR, "Time out" },
|
||||
{ SAR_INDATALENERR, "Input data length error" },
|
||||
{ SAR_INDATAERR, "Input data error" },
|
||||
{ SAR_GENRANDERR, "Generate randomness error" },
|
||||
{ SAR_HASHOBJERR, "Hash object error" },
|
||||
{ SAR_HASHERR, "Hash error" },
|
||||
{ SAR_GENRSAKEYERR, "Genenerate RSA key error" },
|
||||
{ SAR_RSAMODULUSLENERR, "RSA modulus length error" },
|
||||
{ SAR_CSPIMPRTPUBKEYERR, "CSP import public key error" },
|
||||
{ SAR_RSAENCERR, "RSA encryption error" },
|
||||
{ SAR_RSADECERR, "RSA decryption error" },
|
||||
{ SAR_HASHNOTEQUALERR, "Hash not equal" },
|
||||
{ SAR_KEYNOTFOUNTERR, "Key not found" },
|
||||
{ SAR_CERTNOTFOUNTERR, "Certificate not found" },
|
||||
{ SAR_NOTEXPORTERR, "Not exported" },
|
||||
{ SAR_DECRYPTPADERR, "Decrypt pad error" },
|
||||
{ SAR_MACLENERR, "MAC length error" },
|
||||
{ SAR_BUFFER_TOO_SMALL, "Buffer too small" },
|
||||
{ SAR_KEYINFOTYPEERR, "Key info type error" },
|
||||
{ SAR_NOT_EVENTERR, "No event error" },
|
||||
{ SAR_DEVICE_REMOVED "Device removed" },
|
||||
{ SAR_PIN_INCORRECT, "PIN incorrect" },
|
||||
{ SAR_PIN_LOCKED, "PIN locked" },
|
||||
{ SAR_PIN_INVALID, "PIN invalid" },
|
||||
{ SAR_PIN_LEN_RANGE, "PIN length error" },
|
||||
{ SAR_USER_ALREADY_LOGGED_IN, "User already logged in" },
|
||||
{ SAR_USER_PIN_NOT_INITIALIZED, "User PIN not initialized" },
|
||||
{ SAR_USER_TYPE_INVALID, "User type invalid" },
|
||||
{ SAR_APPLICATION_NAME_INVALID, "Application name invalid" },
|
||||
{ SAR_APPLICATION_EXISTS, "Application already exist" },
|
||||
{ SAR_USER_NOT_LOGGED_IN, "User not logged in" },
|
||||
{ SAR_APPLICATION_NOT_EXISTS, "Application not exist" },
|
||||
{ SAR_FILE_ALREADY_EXIST, "File already exist" },
|
||||
{ SAR_NO_ROOM, "No file space" },
|
||||
{ SAR_FILE_NOT_EXIST, "File not exist" }
|
||||
};
|
||||
|
||||
|
||||
LPSTR DEVAPI SKF_GetErrorString(ULONG ulError)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
722
crypto/skf/skf_gmssl.c
Normal file
722
crypto/skf/skf_gmssl.c
Normal file
@@ -0,0 +1,722 @@
|
||||
/* engines/skf/skf_gmssl.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2015-2016 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.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* this should be the SKF soft-token based on GmSSL libcrypto.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "skf.h"
|
||||
|
||||
#define DEV_NAME "skf-soft-token"
|
||||
#define DEV_NAME_LIST DEV_NAME"\0"
|
||||
#define APP_NAME "default-app"
|
||||
#define APP_NAME_LIST APP_NAME"\0"
|
||||
#define CONTAINER_NAME "container0"
|
||||
#define CONTAINER_NAME_LIST CONTAINER_NAME"\0"
|
||||
|
||||
|
||||
ULONG DEVAPI SKF_WaitForDevEvent(LPSTR szDevName,
|
||||
ULONG *pulDevNameLen, ULONG *pulEvent)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_CancelWaitForDevEvent()
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_EnumDev(BOOL bPresent,
|
||||
LPSTR szNameList,
|
||||
ULONG *pulSize)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ConnectDev(LPSTR szName,
|
||||
DEVHANDLE *phDev)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DisConnectDev(DEVHANDLE hDev)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GetDevState(LPSTR szDevName,
|
||||
ULONG *pulDevState)
|
||||
{
|
||||
if (!pulDevState) {
|
||||
return SAR_INVALIDPARAMERR;
|
||||
}
|
||||
*pulDevState = DEV_PRESENT_STATE;
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_SetLabel(DEVHANDLE hDev,
|
||||
LPSTR szLabel)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GetDevInfo(DEVHANDLE hDev,
|
||||
DEVINFO *pDevInfo)
|
||||
{
|
||||
DEVINFO devInfo;
|
||||
|
||||
bzero(&devInfo, sizeof(DEVINFO));
|
||||
devInfo.Version.major = 1;
|
||||
devInfo.Version.minor = 0;
|
||||
strcpy((char *)&devInfo.Manufacturer, "GmSSL Project (http://gmssl.org)");
|
||||
strcpy((char *)&devInfo.Issuer, "GmSSL Project (http://gmssl.org)");
|
||||
strcpy((char *)&devInfo.Label, "SKF Softotken");
|
||||
strcpy((char *)&devInfo.SerialNumber, "000001");
|
||||
devInfo.HWVersion.major = 1;
|
||||
devInfo.HWVersion.minor = 0;
|
||||
devInfo.FirmwareVersion.major = 1;
|
||||
devInfo.FirmwareVersion.minor = 0;
|
||||
devInfo.AlgSymCap = 0x0000041F;
|
||||
devInfo.AlgAsymCap = 0x00030700;
|
||||
devInfo.AlgHashCap = 0x00000007;
|
||||
devInfo.DevAuthAlgId = SGD_SM4_CBC;
|
||||
devInfo.TotalSpace = 0;
|
||||
devInfo.FreeSpace = 0;
|
||||
devInfo.MaxECCBufferSize = 0; /* FIXME: max inlen of ECC encrypt */
|
||||
devInfo.MaxBufferSize = 0; /* FIXME: max inlen of SM4 encrypt */
|
||||
|
||||
memcpy(pDevInfo, &devInfo, sizeof(DEVINFO));
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_LockDev(DEVHANDLE hDev,
|
||||
ULONG ulTimeOut)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_UnlockDev(DEVHANDLE hDev)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_Transmit(DEVHANDLE hDev,
|
||||
BYTE *pbCommand,
|
||||
ULONG ulCommandLen,
|
||||
BYTE *pbData,
|
||||
ULONG *pulDataLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ChangeDevAuthKey(DEVHANDLE hDev,
|
||||
BYTE *pbKeyValue,
|
||||
ULONG ulKeyLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DevAuth(DEVHANDLE hDev,
|
||||
BYTE *pbAuthData,
|
||||
ULONG ulLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ChangePIN(HAPPLICATION hApplication,
|
||||
ULONG ulPINType,
|
||||
LPSTR szOldPin,
|
||||
LPSTR szNewPin,
|
||||
ULONG *pulRetryCount)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
LONG DEVAPI SKF_GetPINInfo(HAPPLICATION hApplication,
|
||||
ULONG ulPINType,
|
||||
ULONG *pulMaxRetryCount,
|
||||
ULONG *pulRemainRetryCount,
|
||||
BOOL *pbDefaultPin)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_VerifyPIN(HAPPLICATION hApplication,
|
||||
ULONG ulPINType,
|
||||
LPSTR szPIN,
|
||||
ULONG *pulRetryCount)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_UnblockPIN(HAPPLICATION hApplication,
|
||||
LPSTR szAdminPIN,
|
||||
LPSTR szNewUserPIN,
|
||||
ULONG *pulRetryCount)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ClearSecureState(HAPPLICATION hApplication)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_CreateApplication(DEVHANDLE hDev,
|
||||
LPSTR szAppName,
|
||||
LPSTR szAdminPin,
|
||||
DWORD dwAdminPinRetryCount,
|
||||
LPSTR szUserPin,
|
||||
DWORD dwUserPinRetryCount,
|
||||
DWORD dwCreateFileRights,
|
||||
HAPPLICATION *phApplication)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_EnumApplication(DEVHANDLE hDev,
|
||||
LPSTR szAppName,
|
||||
ULONG *pulSize)
|
||||
{
|
||||
if (!szAppName) {
|
||||
*pulSize = sizeof(APP_NAME_LIST);
|
||||
return SAR_OK;
|
||||
}
|
||||
if (*pulSize < sizeof(APP_NAME_LIST)) {
|
||||
return SAR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
memcpy(szAppName, APP_NAME_LIST, sizeof(APP_NAME_LIST));
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DeleteApplication(DEVHANDLE hDev,
|
||||
LPSTR szAppName)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_OpenApplication(DEVHANDLE hDev,
|
||||
LPSTR szAppName,
|
||||
HAPPLICATION *phApplication)
|
||||
{
|
||||
if (!phApplication) {
|
||||
return SAR_INVALIDPARAMERR;
|
||||
}
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_CloseApplication(HAPPLICATION hApplication)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_CreateFile(HAPPLICATION hApplication,
|
||||
LPSTR szFileName,
|
||||
ULONG ulFileSize,
|
||||
ULONG ulReadRights,
|
||||
ULONG ulWriteRights)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DeleteFile(HAPPLICATION hApplication,
|
||||
LPSTR szFileName)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_EnumFiles(HAPPLICATION hApplication,
|
||||
LPSTR szFileList,
|
||||
ULONG *pulSize)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GetFileInfo(HAPPLICATION hApplication,
|
||||
LPSTR szFileName,
|
||||
FILEATTRIBUTE *pFileInfo)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ReadFile(HAPPLICATION hApplication,
|
||||
LPSTR szFileName,
|
||||
ULONG ulOffset,
|
||||
ULONG ulSize,
|
||||
BYTE * pbOutData,
|
||||
ULONG *pulOutLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_WriteFile(HAPPLICATION hApplication,
|
||||
LPSTR szFileName,
|
||||
ULONG ulOffset,
|
||||
BYTE *pbData,
|
||||
ULONG ulSize)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_CreateContainer(HAPPLICATION hApplication,
|
||||
LPSTR szContainerName,
|
||||
HCONTAINER *phContainer)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DeleteContainer(HAPPLICATION hApplication,
|
||||
LPSTR szContainerName)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_EnumContainer(HAPPLICATION hApplication,
|
||||
LPSTR szContainerName,
|
||||
ULONG *pulSize)
|
||||
{
|
||||
if (!pulSize) {
|
||||
return SAR_INVALIDPARAMERR;
|
||||
}
|
||||
if (!szContainerName) {
|
||||
*pulSize = sizeof(CONTAINER_NAME_LIST);
|
||||
return SAR_OK;
|
||||
}
|
||||
if (*pulSize < sizeof(CONTAINER_NAME_LIST)) {
|
||||
return SAR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
memcpy(szContainerName, CONTAINER_NAME_LIST, sizeof(CONTAINER_NAME_LIST));
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_OpenContainer(HAPPLICATION hApplication,
|
||||
LPSTR szContainerName,
|
||||
HCONTAINER *phContainer)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_CloseContainer(HCONTAINER hContainer)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GetContainerType(HCONTAINER hContainer,
|
||||
ULONG *pulContainerType)
|
||||
{
|
||||
if (!pulContainerType) {
|
||||
return SAR_INVALIDPARAMERR;
|
||||
}
|
||||
*pulContainerType = CONTAINER_TYPE_ECC;
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ImportCertificate(HCONTAINER hContainer,
|
||||
BOOL bSignFlag,
|
||||
BYTE *pbCert,
|
||||
ULONG ulCertLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ExportCertificate(HCONTAINER hContainer,
|
||||
BOOL bSignFlag,
|
||||
BYTE* pbCert,
|
||||
ULONG *pulCertLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GenRandom(DEVHANDLE hDev,
|
||||
BYTE *pbRandom,
|
||||
ULONG ulRandomLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GenExtRSAKey(DEVHANDLE hDev,
|
||||
ULONG ulBitsLen,
|
||||
RSAPRIVATEKEYBLOB *pBlob)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GenRSAKeyPair(HCONTAINER hContainer,
|
||||
ULONG ulBitsLen,
|
||||
RSAPUBLICKEYBLOB *pBlob)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ImportRSAKeyPair(HCONTAINER hContainer,
|
||||
ULONG ulSymAlgId,
|
||||
BYTE *pbWrappedKey,
|
||||
ULONG ulWrappedKeyLen,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG ulEncryptedDataLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_RSASignData(HCONTAINER hContainer,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbSignature,
|
||||
ULONG *pulSignLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_RSAVerify(DEVHANDLE hDev,
|
||||
RSAPUBLICKEYBLOB *pRSAPubKeyBlob,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbSignature,
|
||||
ULONG ulSignLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_RSAExportSessionKey(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
RSAPUBLICKEYBLOB *pPubKey,
|
||||
BYTE *pbData,
|
||||
ULONG *pulDataLen,
|
||||
HANDLE *phSessionKey)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ExtRSAPubKeyOperation(DEVHANDLE hDev,
|
||||
RSAPUBLICKEYBLOB *pRSAPubKeyBlob,
|
||||
BYTE *pbInput,
|
||||
ULONG ulInputLen,
|
||||
BYTE *pbOutput,
|
||||
ULONG *pulOutputLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ExtRSAPriKeyOperation(DEVHANDLE hDev,
|
||||
RSAPRIVATEKEYBLOB *pRSAPriKeyBlob,
|
||||
BYTE *pbInput,
|
||||
ULONG ulInputLen,
|
||||
BYTE *pbOutput,
|
||||
ULONG *pulOutputLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GenECCKeyPair(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
ECCPUBLICKEYBLOB *pBlob)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ImportECCKeyPair(HCONTAINER hContainer,
|
||||
PENVELOPEDKEYBLOB pEnvelopedKeyBlob)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ECCSignData(HCONTAINER hContainer,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
PECCSIGNATUREBLOB pSignature)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ECCVerify(DEVHANDLE hDev,
|
||||
ECCPUBLICKEYBLOB *pECCPubKeyBlob,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
PECCSIGNATUREBLOB pSignature)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ECCExportSessionKey(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
ECCPUBLICKEYBLOB *pPubKey,
|
||||
PECCCIPHERBLOB pData,
|
||||
HANDLE *phSessionKey)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ExtECCEncrypt(DEVHANDLE hDev,
|
||||
ECCPUBLICKEYBLOB *pECCPubKeyBlob,
|
||||
BYTE *pbPlainText,
|
||||
ULONG ulPlainTextLen,
|
||||
PECCCIPHERBLOB pCipherText)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ExtECCDecrypt(DEVHANDLE hDev,
|
||||
ECCPRIVATEKEYBLOB *pECCPriKeyBlob,
|
||||
PECCCIPHERBLOB pCipherText,
|
||||
BYTE *pbPlainText,
|
||||
ULONG *pulPlainTextLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ExtECCSign(DEVHANDLE hDev,
|
||||
ECCPRIVATEKEYBLOB *pECCPriKeyBlob,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
PECCSIGNATUREBLOB pSignature)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ExtECCVerify(DEVHANDLE hDev,
|
||||
ECCPUBLICKEYBLOB *pECCPubKeyBlob,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
PECCSIGNATUREBLOB pSignature)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GenerateAgreementDataWithECC(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
ECCPUBLICKEYBLOB *pTempECCPubKeyBlob,
|
||||
BYTE *pbID,
|
||||
ULONG ulIDLen,
|
||||
HANDLE *phAgreementHandle)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GenerateAgreementDataAndKeyWithECC(HANDLE hContainer,
|
||||
ULONG ulAlgId,
|
||||
ECCPUBLICKEYBLOB *pSponsorECCPubKeyBlob,
|
||||
ECCPUBLICKEYBLOB *pSponsorTempECCPubKeyBlob,
|
||||
ECCPUBLICKEYBLOB *pTempECCPubKeyBlob,
|
||||
BYTE *pbID,
|
||||
ULONG ulIDLen,
|
||||
BYTE *pbSponsorID,
|
||||
ULONG ulSponsorIDLen,
|
||||
HANDLE *phKeyHandle)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_GenerateKeyWithECC(HANDLE hAgreementHandle,
|
||||
ECCPUBLICKEYBLOB *pECCPubKeyBlob,
|
||||
ECCPUBLICKEYBLOB *pTempECCPubKeyBlob,
|
||||
BYTE *pbID,
|
||||
ULONG ulIDLen,
|
||||
HANDLE *phKeyHandle)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ExportPublicKey(HCONTAINER hContainer,
|
||||
BOOL bSignFlag,
|
||||
BYTE* pbBlob,
|
||||
ULONG* pulBlobLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_ImportSessionKey(HCONTAINER hContainer,
|
||||
ULONG ulAlgId,
|
||||
BYTE *pbWrapedData,
|
||||
ULONG ulWrapedLen,
|
||||
HANDLE *phKey)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_SetSymmKey(DEVHANDLE hDev,
|
||||
BYTE *pbKey,
|
||||
ULONG ulAlgID,
|
||||
HANDLE *phKey)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_EncryptInit(HANDLE hKey,
|
||||
BLOCKCIPHERPARAM EncryptParam)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_Encrypt(HANDLE hKey,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG *pulEncryptedLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_EncryptUpdate(HANDLE hKey,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG *pulEncryptedLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_EncryptFinal(HANDLE hKey,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG *pulEncryptedDataLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DecryptInit(HANDLE hKey,
|
||||
BLOCKCIPHERPARAM DecryptParam)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_Decrypt(HANDLE hKey,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG ulEncryptedLen,
|
||||
BYTE *pbData,
|
||||
ULONG *pulDataLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DecryptUpdate(HANDLE hKey,
|
||||
BYTE *pbEncryptedData,
|
||||
ULONG ulEncryptedLen,
|
||||
BYTE *pbData,
|
||||
ULONG *pulDataLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DecryptFinal(HANDLE hKey,
|
||||
BYTE *pbDecryptedData,
|
||||
ULONG *pulDecryptedDataLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DigestInit(DEVHANDLE hDev,
|
||||
ULONG ulAlgID,
|
||||
ECCPUBLICKEYBLOB *pPubKey,
|
||||
BYTE *pucID,
|
||||
ULONG ulIDLen,
|
||||
HANDLE *phHash)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_Digest(HANDLE hHash,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbHashData,
|
||||
ULONG *pulHashLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DigestUpdate(HANDLE hHash,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_DigestFinal(HANDLE hHash,
|
||||
BYTE *pHashData,
|
||||
ULONG *pulHashLen)
|
||||
{
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_MacInit(HANDLE hKey,
|
||||
BLOCKCIPHERPARAM *pMacParam,
|
||||
HANDLE *phMac)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_Mac(HANDLE hMac,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen,
|
||||
BYTE *pbMacData,
|
||||
ULONG *pulMacLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_MacUpdate(HANDLE hMac,
|
||||
BYTE *pbData,
|
||||
ULONG ulDataLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_MacFinal(HANDLE hMac,
|
||||
BYTE *pbMacData,
|
||||
ULONG *pulMacDataLen)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
ULONG DEVAPI SKF_CloseHandle(HANDLE hHandle)
|
||||
{
|
||||
return SAR_NOTSUPPORTYETERR;
|
||||
}
|
||||
|
||||
135
crypto/skf/skf_lcl.h
Normal file
135
crypto/skf/skf_lcl.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/* crypto/skf/skf.h */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2016 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.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_SKF_H
|
||||
#define HEADER_SKF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
int EC_KEY_set_ECCPUBLICKEYBLOB(EC_KEY *ec_key, const ECCPUBLICKEYBLOB *blob);
|
||||
int EC_KEY_get_ECCPUBLICKEYBLOB(EC_KEY *ec_key, ECCPUBLICKEYBLOB *blob);
|
||||
int EC_KEY_set_ECCPRIVATEKEYBLOB(EC_KEY *ec_key, const ECCPRIVATEKEYBLOB *blob)
|
||||
int EC_KEY_get_ECCPRIVATEKEYBLOB(EC_KEY *ec_key, ECCPRIVATEKEYBLOB *blob);
|
||||
|
||||
int SM2_CIPHERTEXT_VALUE_set_ECCCIPHERBLOB(SM2_CIPHERTEXT_VALUE *cv,
|
||||
const ECCCIPHERBLOB *blob);
|
||||
int SM2_CIPHERTEXT_VALUE_get_ECCCIPHERBLOB(const SM2_CIPHERTEXT_VALUE *a,
|
||||
void *out, size_t *outlen);
|
||||
int ECDSA_SIG_to_SKF_ECCSIGNATUREBLOB(const ECDSA_SIG *sig,
|
||||
const EC_GROUP *group, void *out, size_t *outlen);
|
||||
|
||||
int RSA_set_RSAPUBLICKEYBLOB(RSA *rsa, const RSAPUBLICKEYBLOB *blob);
|
||||
int RSA_get_RSAPUBLICKEYBLOB(RSA *rsa, RSAPUBLICKEYBLOB *blob);
|
||||
int RSA_set_RSAPRIVATEKEYBLOB(RSA *rsa, const RSAPRIVATEKEYBLOB *blob);
|
||||
int RSA_to_RSAPRIVATEKEYBLOB(RSA *rsa, RSAPRIVATEKEYBLOB *blob);
|
||||
|
||||
|
||||
|
||||
#define SAR_OK 0x00000000
|
||||
#define SAR_FAIL 0x0A000001
|
||||
#define SAR_UNKNOWNERR 0x0A000002
|
||||
#define SAR_NOTSUPPORTYETERR 0x0A000003
|
||||
#define SAR_FILEERR 0x0A000004
|
||||
#define SAR_INVALIDHANDLEERR 0x0A000005
|
||||
#define SAR_INVALIDPARAMERR 0x0A000006
|
||||
#define SAR_READFILEERR 0x0A000007
|
||||
#define SAR_WRITEFILEERR 0x0A000008
|
||||
#define SAR_NAMELENERR 0x0A000009
|
||||
#define SAR_KEYUSAGEERR 0x0A00000A
|
||||
#define SAR_MODULUSLENERR 0x0A00000B
|
||||
#define SAR_NOTINITIALIZEERR 0x0A00000C
|
||||
#define SAR_OBJERR 0x0A00000D
|
||||
#define SAR_MEMORYERR 0x0A00000E
|
||||
#define SAR_TIMEOUTERR 0x0A00000F
|
||||
#define SAR_INDATALENERR 0x0A000010
|
||||
#define SAR_INDATAERR 0x0A000011
|
||||
#define SAR_GENRANDERR 0x0A000012
|
||||
#define SAR_HASHOBJERR 0x0A000013
|
||||
#define SAR_HASHERR 0x0A000014
|
||||
#define SAR_GENRSAKEYERR 0x0A000015
|
||||
#define SAR_RSAMODULUSLENERR 0x0A000016
|
||||
#define SAR_CSPIMPRTPUBKEYERR 0x0A000017
|
||||
#define SAR_RSAENCERR 0x0A000018
|
||||
#define SAR_RSADECERR 0x0A000019
|
||||
#define SAR_HASHNOTEQUALERR 0x0A00001A
|
||||
#define SAR_KEYNOTFOUNTERR 0x0A00001B
|
||||
#define SAR_KEYNOTFOUNDERR 0x0A00001B
|
||||
#define SAR_CERTNOTFOUNTERR 0x0A00001C
|
||||
#define SAR_NOTEXPORTERR 0x0A00001D
|
||||
#define SAR_DECRYPTPADERR 0x0A00001E
|
||||
#define SAR_MACLENERR 0x0A00001F
|
||||
#define SAR_BUFFER_TOO_SMALL 0x0A000020
|
||||
#define SAR_KEYINFOTYPEERR 0x0A000021
|
||||
#define SAR_NOT_EVENTERR 0x0A000022
|
||||
#define SAR_DEVICE_REMOVED 0x0A000023
|
||||
#define SAR_PIN_INCORRECT 0x0A000024
|
||||
#define SAR_PIN_LOCKED 0x0A000025
|
||||
#define SAR_PIN_INVALID 0x0A000026
|
||||
#define SAR_PIN_LEN_RANGE 0x0A000027
|
||||
#define SAR_USER_ALREADY_LOGGED_IN 0x0A000028
|
||||
#define SAR_USER_PIN_NOT_INITIALIZED 0x0A000029
|
||||
#define SAR_USER_TYPE_INVALID 0x0A00002A
|
||||
#define SAR_APPLICATION_NAME_INVALID 0x0A00002B
|
||||
#define SAR_APPLICATION_EXISTS 0x0A00002C
|
||||
#define SAR_USER_NOT_LOGGED_IN 0x0A00002D
|
||||
#define SAR_APPLICATION_NOT_EXISTS 0x0A00002E
|
||||
#define SAR_FILE_ALREADY_EXIST 0x0A00002F
|
||||
#define SAR_NO_ROOM 0x0A000030
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
285
crypto/skf/skf_types.c
Normal file
285
crypto/skf/skf_types.c
Normal file
@@ -0,0 +1,285 @@
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
#include <openssl/sm2.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include "skf.h"
|
||||
|
||||
int EC_KEY_set_ECCPUBLICKEYBLOB(EC_KEY *ec_key, const ECCPUBLICKEYBLOB *blob)
|
||||
{
|
||||
int ret = 0;
|
||||
int nbytes;
|
||||
BIGNUM *x = NULL;
|
||||
BIGNUM *y = NULL;
|
||||
|
||||
if (blob->BitLen != EC_GROUP_get_degree(EC_KEY_get0_group(ec_key))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nbytes = (blob->BitLen + 7)/8;
|
||||
|
||||
if (!(x = BN_bin2bn(blob->XCoordinate, nbytes, NULL))) {
|
||||
goto end;
|
||||
}
|
||||
if (!(y = BN_bin2bn(blob->YCoordinate, nbytes, NULL))) {
|
||||
goto end;
|
||||
}
|
||||
if (!EC_KEY_set_public_key_affine_coordinates(ec_key, x, y)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
BN_free(x);
|
||||
BN_free(y);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int EC_KEY_get_ECCPUBLICKEYBLOB(EC_KEY *ec_key, ECCPUBLICKEYBLOB *blob)
|
||||
{
|
||||
int ret = 0;
|
||||
int nbytes;
|
||||
BIGNUM *x = NULL;
|
||||
BIGNUM *y = NULL;
|
||||
BN_CTX *bn_ctx = NULL;
|
||||
const EC_GROUP *group = EC_KEY_get0_group(ec_key);
|
||||
const EC_POINT *point = EC_KEY_get0_public_key(ec_key);
|
||||
|
||||
nbytes = (EC_GROUP_get_degree(group) + 7)/8;
|
||||
if (nbyte > ECC_MAX_MODULUS_BITS_LEN/8) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
x = BN_new();
|
||||
y = BN_new();
|
||||
bn_ctx = BN_CTX_new();
|
||||
if (!x || !y || !bn_ctx) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) {
|
||||
if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, bn_ctx)) {
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, bn_ctx)) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
bzero(blob, sizeof(*blob));
|
||||
blob->BitLen = EC_GROUP_get_degree(group);
|
||||
if (!BN_bn2bin(x, blob->XCoordinate + nbytes - BN_num_bytes(x))) {
|
||||
goto end;
|
||||
}
|
||||
if (!BN_bn2bin(y, blob->YCoordinate + nbytes - BN_num_bytes(y))) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
BN_free(x);
|
||||
BN_free(y);
|
||||
BN_CTX_free(bn_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int EC_KEY_set_ECCPRIVATEKEYBLOB(EC_KEY *ec_key, const ECCPRIVATEKEYBLOB *blob)
|
||||
{
|
||||
int ret = 0;
|
||||
int nbytes;
|
||||
BIGNUM *d = NULL;
|
||||
|
||||
/* is this corrent ?
|
||||
* because the key length sometimes will be less than field length
|
||||
*/
|
||||
if (blob->BitLen != EC_GROUP_get_degree(EC_KEY_get0_group(ec_key))) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
nbytes = (blob->BitLen + 7)/8;
|
||||
if (!(d = BN_bin2bn(data->PrivateKey, nbytes, NULL))) {
|
||||
goto end;
|
||||
}
|
||||
if (!EC_KEY_set_private_key(ec_key, d)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
BN_clear_free(d);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int EC_KEY_get_ECCPRIVATEKEYBLOB(EC_KEY *ec_key, ECCPRIVATEKEYBLOB *blob)
|
||||
{
|
||||
int ret = 0;
|
||||
int nbytes;
|
||||
BIGNUM *order = BN_new();
|
||||
BIGNUM *d = EC_KEY_get0_private_key(ec_key);
|
||||
|
||||
if (!order) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!d) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!EC_GROUP_get_order(EC_KEY_get0_group(ec_key), order, NULL)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
nbytes = BN_num_bytes(order);
|
||||
if (nbytes > ECC_MAX_MODULUS_BITS_LEN/8) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
BN_bn2bin(d, blob->PrivateKey + nbytes - BN_num_bytes(d));
|
||||
|
||||
ret = 1;
|
||||
|
||||
end:
|
||||
BN_free(order);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SM2_CIPHERTEXT_VALUE_set_ECCCIPHERBLOB(SM2_CIPHERTEXT_VALUE *cv,
|
||||
const ECCCIPHERBLOB *blob)
|
||||
{
|
||||
SM2_CIPHERTEXT_VALUE *ret = NULL;
|
||||
const ECCCIPHERBLOB *data = (const ECCCIPHERBLOB *)blob;
|
||||
BIGNUM *x = NULL;
|
||||
BIGNUM *y = NULL;
|
||||
|
||||
if (bloblen < sizeof(ECCCIPHERBLOB)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(ret = OPENSSL_malloc(sizeof(SM2_CIPHERTEXT_VALUE)))) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
int SM2_CIPHERTEXT_VALUE_get_ECCCIPHERBLOB(const SM2_CIPHERTEXT_VALUE *a,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
int ret = 0;
|
||||
BIGNUM *x = NULL;
|
||||
BIGNUM *y = NULL;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ECDSA_SIG *ECDSA_SIG_new_from_SKF_ECCSIGNATUREBLOB(
|
||||
const EC_GROUP *group, const void *blob, size_t bloblen)
|
||||
{
|
||||
ECDSA_SIG *ret = NULL;
|
||||
int bnlen;
|
||||
const ECCSIGNATUREBLOB *data = blob;
|
||||
|
||||
if (bloblen != sizeof(ECCSIGNATUREBLOB)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bnlen = (EC_GROUP_get_degree(group) + 7)/8;
|
||||
|
||||
if (!(ret = ECDSA_SIG_new())) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->r = BN_bin2bn(data->r, bnlen, NULL);
|
||||
ret->s = BN_bin2bn(data->s, bnlen, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ECDSA_SIG_to_SKF_ECCSIGNATUREBLOB(const ECDSA_SIG *sig,
|
||||
const EC_GROUP *group, void *out, size_t *outlen)
|
||||
{
|
||||
int bnlen;
|
||||
ECCSIGNATUREBLOB *data = out;
|
||||
|
||||
if (!out) {
|
||||
if (!outlen) {
|
||||
return 0;
|
||||
}
|
||||
*outlen = sizeof(ECCSIGNATUREBLOB);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bnlen = (EC_GROUP_get_degree(group) + 7)/8;
|
||||
*outlen = sizeof(ECCSIGNATUREBLOB);
|
||||
|
||||
BN_bn2bin(sig->r, data->r + bnlen - BN_num_bytes(sig->r));
|
||||
BN_bn2bin(sig->s, data->s + bnlen - BN_num_bytes(sig->s));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int RSA_set_RSAPUBLICKEYBLOB(RSA *rsa, const RSAPUBLICKEYBLOB *blob)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (!(rsa->n = BN_bin2bn(blob->Modulus, blob->BitLen/8, NULL))) {
|
||||
goto end;
|
||||
}
|
||||
if (!(rsa->e = BN_bin2bn(blob->PublicExponent, blob->BitLen/8, NULL))) {
|
||||
goto end;
|
||||
}
|
||||
if (!RSA_check_key(rsa)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RSA_get_RSAPUBLICKEYBLOB(RSA *rsa, RSAPUBLICKEYBLOB *blob)
|
||||
{
|
||||
int ret = 0;
|
||||
int nbytes;
|
||||
|
||||
if (!rsa->n || !rsa->e) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
nbytes = BN_num_bytes(rsa->n);
|
||||
|
||||
BN_bn2bin(rsa->n, blob->Modulus + bnlen - BN_num_bytes(rsa->n));
|
||||
BN_bn2bin(rsa->e, blob->PublicExponent + bnlen - BN_num_bytes(rsa->e));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RSA_set_RSAPRIVATEKEYBLOB(RSA *rsa, const RSAPRIVATEKEYBLOB *blob)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (!blob->AlgID) {
|
||||
goto end;
|
||||
}
|
||||
if (!blob->BitLen) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
rsa->n = BN_bin2bn(blob->Modulus, MAX_RSA_MODULUS_LEN, NULL);
|
||||
rsa->e = BN_bin2bn(blob->PublicExponent, MAX_RSA_EXPONENT_LEN, NULL);
|
||||
rsa->d = BN_bin2bn(blob->Prime1, bnlen, NULL);
|
||||
rsa->p = BN_bin2bn(blob->Prime2, bnlen, NULL);
|
||||
rsa->dmp1 = BN_bin2bn(blob->Prime1Exponent, bnlen, NULL);
|
||||
rsa->dmq1 = BN_bin2bn(blob->Prime2Exponent, bnlen, NULL);
|
||||
rsa->iqmp = BN_bin2bn(blob->Coefficient, bnlen, NULL);
|
||||
|
||||
}
|
||||
|
||||
int RSA_get_RSAPRIVATEKEYBLOB(RSA *rsa, RSAPRIVATEKEYBLOB *blob)
|
||||
{
|
||||
int ret = 0;
|
||||
RSAPRIVATEKEYBLOB *blob = out;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,55 @@
|
||||
/* engines/skf/skftest.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2015-2016 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 <stdlib.h>
|
||||
@@ -115,26 +115,25 @@ SM2_CIPHERTEXT_VALUE *d2i_SM2_CIPHERTEXT_VALUE(SM2_CIPHERTEXT_VALUE **c,
|
||||
int SM2_CIPHERTEXT_VALUE_print(BIO *out, const EC_GROUP *ec_group,
|
||||
const SM2_CIPHERTEXT_VALUE *cv, int indent, unsigned long flags);
|
||||
|
||||
/* FIXME: we should provide optional return value */
|
||||
|
||||
SM2_CIPHERTEXT_VALUE *SM2_do_encrypt(const SM2_ENC_PARAMS *params,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key);
|
||||
//FIXME: output first, and change ECIES
|
||||
int SM2_do_decrypt(const SM2_ENC_PARAMS *params,
|
||||
const SM2_CIPHERTEXT_VALUE *cv, unsigned char *out, size_t *outlen,
|
||||
EC_KEY *ec_key);
|
||||
int SM2_encrypt(const SM2_ENC_PARAMS *params,
|
||||
const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
|
||||
int SM2_decrypt(const SM2_ENC_PARAMS *params,
|
||||
const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
|
||||
int SM2_encrypt_with_recommended(const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
|
||||
int SM2_decrypt_with_recommended(const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
|
||||
int SM2_encrypt_elgamal(const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
|
||||
int SM2_decrypt_elgamal(const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
|
||||
int SM2_encrypt(const SM2_ENC_PARAMS *params, unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key);
|
||||
int SM2_decrypt(const SM2_ENC_PARAMS *params, unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key);
|
||||
int SM2_encrypt_with_recommended(unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key);
|
||||
int SM2_decrypt_with_recommended(unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key);
|
||||
int SM2_encrypt_elgamal(unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key);
|
||||
int SM2_decrypt_elgamal(unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key);
|
||||
|
||||
int SM2_compute_message_digest(const EVP_MD *id_md, const EVP_MD *msg_md,
|
||||
const void *msg, size_t msglen, unsigned char *dgst,
|
||||
@@ -252,6 +251,7 @@ void ERR_load_SM2_strings(void);
|
||||
#define SM2_R_BUFFER_TOO_SMALL 108
|
||||
#define SM2_R_SM2_KAP_NOT_INITED 109
|
||||
#define SM2_R_RANDOM_NUMBER_GENERATION_FAILED 110
|
||||
#define SM2_R_ERROR 111
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -68,15 +68,20 @@ int SM2_CIPHERTEXT_VALUE_size(const EC_GROUP *group,
|
||||
EC_KEY *ec_key = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
|
||||
if (!(ec_key = EC_KEY_new())) {
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_SIZE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EC_KEY_set_group(ec_key, group)) {
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_SIZE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EC_KEY_generate_key(ec_key)) {
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_SIZE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
len += EC_POINT_point2oct(group, EC_KEY_get0_public_key(ec_key),
|
||||
params->point_form, NULL, 0, NULL);
|
||||
len += mlen;
|
||||
@@ -107,11 +112,13 @@ int SM2_CIPHERTEXT_VALUE_encode(const SM2_CIPHERTEXT_VALUE *cv,
|
||||
size_t ptlen, cvlen;
|
||||
|
||||
if (!bn_ctx) {
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_ENCODE, SM2_R_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(ptlen = EC_POINT_point2oct(ec_group, cv->ephem_point,
|
||||
params->point_form, NULL, 0, bn_ctx))) {
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_ENCODE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
cvlen = ptlen + cv->ciphertext_size + cv->mactag_size;
|
||||
@@ -122,11 +129,13 @@ int SM2_CIPHERTEXT_VALUE_encode(const SM2_CIPHERTEXT_VALUE *cv,
|
||||
goto end;
|
||||
|
||||
} else if (*buflen < cvlen) {
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_ENCODE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(ptlen = EC_POINT_point2oct(ec_group, cv->ephem_point,
|
||||
params->point_form, buf, *buflen, bn_ctx))) {
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_ENCODE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
buf += ptlen;
|
||||
@@ -158,17 +167,17 @@ SM2_CIPHERTEXT_VALUE *SM2_CIPHERTEXT_VALUE_decode(
|
||||
}
|
||||
|
||||
if (!(fixlen = SM2_CIPHERTEXT_VALUE_size(ec_group, params, 0))) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_DECODE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (buflen <= fixlen) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_DECODE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(ret = OPENSSL_malloc(sizeof(SM2_CIPHERTEXT_VALUE)))) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_DECODE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -176,14 +185,13 @@ SM2_CIPHERTEXT_VALUE *SM2_CIPHERTEXT_VALUE_decode(
|
||||
ret->ciphertext_size = buflen - fixlen;
|
||||
ret->ciphertext = OPENSSL_malloc(ret->ciphertext_size);
|
||||
if (!ret->ephem_point || !ret->ciphertext) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_DECODE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
ptlen = fixlen - SM2_ENC_PARAMS_mactag_size(params);
|
||||
if (!EC_POINT_oct2point(ec_group, ret->ephem_point, buf, ptlen, bn_ctx)) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
ERR_print_errors_fp(stdout);
|
||||
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_DECODE, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -242,8 +250,9 @@ end:
|
||||
}
|
||||
|
||||
int SM2_encrypt(const SM2_ENC_PARAMS *params,
|
||||
unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key)
|
||||
EC_KEY *ec_key)
|
||||
{
|
||||
int ret = 0;
|
||||
const EC_GROUP *ec_group = EC_KEY_get0_group(ec_key);
|
||||
@@ -251,6 +260,7 @@ int SM2_encrypt(const SM2_ENC_PARAMS *params,
|
||||
int len;
|
||||
|
||||
if (!(len = SM2_CIPHERTEXT_VALUE_size(ec_group, params, inlen))) {
|
||||
SM2err(SM2_F_SM2_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -263,9 +273,11 @@ int SM2_encrypt(const SM2_ENC_PARAMS *params,
|
||||
}
|
||||
|
||||
if (!(cv = SM2_do_encrypt(params, in, inlen, ec_key))) {
|
||||
SM2err(SM2_F_SM2_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!SM2_CIPHERTEXT_VALUE_encode(cv, ec_group, params, out, outlen)) {
|
||||
SM2err(SM2_F_SM2_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -293,6 +305,7 @@ SM2_CIPHERTEXT_VALUE *SM2_do_encrypt(const SM2_ENC_PARAMS *params,
|
||||
int nbytes;
|
||||
unsigned char dgst[EVP_MAX_MD_SIZE];
|
||||
unsigned int dgstlen;
|
||||
int mactag_size;
|
||||
size_t len;
|
||||
int i;
|
||||
|
||||
@@ -305,6 +318,7 @@ SM2_CIPHERTEXT_VALUE *SM2_do_encrypt(const SM2_ENC_PARAMS *params,
|
||||
|
||||
/* init ciphertext_value */
|
||||
if (!(cv = OPENSSL_malloc(sizeof(SM2_CIPHERTEXT_VALUE)))) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
bzero(cv, sizeof(SM2_CIPHERTEXT_VALUE));
|
||||
@@ -312,6 +326,7 @@ SM2_CIPHERTEXT_VALUE *SM2_do_encrypt(const SM2_ENC_PARAMS *params,
|
||||
cv->ciphertext = OPENSSL_malloc(inlen);
|
||||
cv->ciphertext_size = inlen;
|
||||
if (!cv->ephem_point || !cv->ciphertext) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -322,14 +337,17 @@ SM2_CIPHERTEXT_VALUE *SM2_do_encrypt(const SM2_ENC_PARAMS *params,
|
||||
bn_ctx = BN_CTX_new();
|
||||
md_ctx = EVP_MD_CTX_create();
|
||||
if (!point || !n || !h || !k || !bn_ctx || !md_ctx) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* init ec domain parameters */
|
||||
if (!EC_GROUP_get_order(ec_group, n, bn_ctx)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EC_GROUP_get_cofactor(ec_group, h, bn_ctx)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
nbytes = (EC_GROUP_get_degree(ec_group) + 7) / 8;
|
||||
@@ -344,23 +362,28 @@ SM2_CIPHERTEXT_VALUE *SM2_do_encrypt(const SM2_ENC_PARAMS *params,
|
||||
|
||||
/* A2: C1 = [k]G = (x1, y1) */
|
||||
if (!EC_POINT_mul(ec_group, cv->ephem_point, k, NULL, NULL, bn_ctx)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* A3: check [h]P_B != O */
|
||||
if (!EC_POINT_mul(ec_group, point, NULL, pub_key, h, bn_ctx)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (EC_POINT_is_at_infinity(ec_group, point)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* A4: compute ECDH [k]P_B = (x2, y2) */
|
||||
if (!EC_POINT_mul(ec_group, point, NULL, pub_key, k, bn_ctx)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!(len = EC_POINT_point2oct(ec_group, point,
|
||||
POINT_CONVERSION_UNCOMPRESSED, buf, sizeof(buf), bn_ctx))) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
OPENSSL_assert(len == nbytes * 2 + 1);
|
||||
@@ -387,31 +410,38 @@ SM2_CIPHERTEXT_VALUE *SM2_do_encrypt(const SM2_ENC_PARAMS *params,
|
||||
cv->ciphertext[i] ^= in[i];
|
||||
}
|
||||
|
||||
if (params->mactag_size) {
|
||||
mactag_size = SM2_ENC_PARAMS_mactag_size(params);
|
||||
if (mactag_size) {
|
||||
|
||||
/* A7: C3 = Hash(x2 || M || y2) */
|
||||
if (!EVP_DigestInit_ex(md_ctx, params->mac_md, NULL)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(md_ctx, buf + 1, nbytes)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(md_ctx, in, inlen)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(md_ctx, buf + 1 + nbytes, nbytes)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(md_ctx, dgst, &dgstlen)) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* GmSSL specific: reduce mactag size */
|
||||
if (params->mactag_size > dgstlen) {
|
||||
if (mactag_size > dgstlen) {
|
||||
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
cv->mactag_size = params->mactag_size;
|
||||
cv->mactag_size = mactag_size;
|
||||
memcpy(cv->mactag, dgst, cv->mactag_size);
|
||||
}
|
||||
|
||||
@@ -434,8 +464,9 @@ end:
|
||||
}
|
||||
|
||||
int SM2_decrypt(const SM2_ENC_PARAMS *params,
|
||||
unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key)
|
||||
EC_KEY *ec_key)
|
||||
{
|
||||
int ret = 0;
|
||||
const EC_GROUP *ec_group = EC_KEY_get0_group(ec_key);
|
||||
@@ -443,11 +474,11 @@ int SM2_decrypt(const SM2_ENC_PARAMS *params,
|
||||
int len;
|
||||
|
||||
if (!(len = SM2_CIPHERTEXT_VALUE_size(ec_group, params, 0))) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
SM2err(SM2_F_SM2_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (inlen <= len) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
SM2err(SM2_F_SM2_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -455,16 +486,16 @@ int SM2_decrypt(const SM2_ENC_PARAMS *params,
|
||||
*outlen = inlen - len;
|
||||
return 1;
|
||||
} else if (*outlen < inlen - len) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
SM2err(SM2_F_SM2_DECRYPT, SM2_R_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(cv = SM2_CIPHERTEXT_VALUE_decode(ec_group, params, in, inlen))) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
SM2err(SM2_F_SM2_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!SM2_do_decrypt(params, cv, out, outlen, ec_key)) {
|
||||
fprintf(stderr, "%s %d\n", __FILE__, __LINE__);
|
||||
SM2err(SM2_F_SM2_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -490,14 +521,17 @@ int SM2_do_decrypt(const SM2_ENC_PARAMS *params,
|
||||
unsigned char buf[(OPENSSL_ECC_MAX_FIELD_BITS + 7)/4 + 1];
|
||||
unsigned char mac[EVP_MAX_MD_SIZE];
|
||||
unsigned int maclen;
|
||||
int mactag_size;
|
||||
int nbytes;
|
||||
size_t size;
|
||||
int i;
|
||||
|
||||
if (!ec_group || !pri_key) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!kdf) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -506,6 +540,7 @@ int SM2_do_decrypt(const SM2_ENC_PARAMS *params,
|
||||
return 1;
|
||||
}
|
||||
if (*outlen < cv->ciphertext_size) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -516,32 +551,39 @@ int SM2_do_decrypt(const SM2_ENC_PARAMS *params,
|
||||
bn_ctx = BN_CTX_new();
|
||||
md_ctx = EVP_MD_CTX_create();
|
||||
if (!point || !n || !h || !bn_ctx || !md_ctx) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* init ec domain parameters */
|
||||
if (!EC_GROUP_get_order(ec_group, n, bn_ctx)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EC_GROUP_get_cofactor(ec_group, h, bn_ctx)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
nbytes = (EC_GROUP_get_degree(ec_group) + 7) / 8;
|
||||
|
||||
/* B2: check [h]C1 != O */
|
||||
if (!EC_POINT_mul(ec_group, point, NULL, cv->ephem_point, h, bn_ctx)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (EC_POINT_is_at_infinity(ec_group, point)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* B3: compute ECDH [d]C1 = (x2, y2) */
|
||||
if (!EC_POINT_mul(ec_group, point, NULL, cv->ephem_point, pri_key, bn_ctx)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!(size = EC_POINT_point2oct(ec_group, point,
|
||||
POINT_CONVERSION_UNCOMPRESSED, buf, sizeof(buf), bn_ctx))) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
OPENSSL_assert(size == 1 + nbytes * 2);
|
||||
@@ -558,31 +600,39 @@ int SM2_do_decrypt(const SM2_ENC_PARAMS *params,
|
||||
}
|
||||
*outlen = cv->ciphertext_size;
|
||||
|
||||
if (params->mactag_size) {
|
||||
mactag_size = SM2_ENC_PARAMS_mactag_size(params);
|
||||
if (mactag_size) {
|
||||
|
||||
/* B6: check Hash(x2 || M || y2) == C3 */
|
||||
if (!EVP_DigestInit_ex(md_ctx, params->mac_md, NULL)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(md_ctx, buf + 1, nbytes)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(md_ctx, out, *outlen)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestUpdate(md_ctx, buf + 1 + nbytes, nbytes)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(md_ctx, mac, &maclen)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* GmSSL specific */
|
||||
if (params->mactag_size > maclen) {
|
||||
if (mactag_size > maclen) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
if (cv->mactag_size != params->mactag_size ||
|
||||
if (cv->mactag_size != mactag_size ||
|
||||
memcmp(mac, cv->mactag, cv->mactag_size)) {
|
||||
SM2err(SM2_F_SM2_DO_DECRYPT, SM2_R_ERROR);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
@@ -610,41 +660,41 @@ int SM2_ENC_PARAMS_init_with_recommended(SM2_ENC_PARAMS *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SM2_encrypt_with_recommended(const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key)
|
||||
int SM2_encrypt_with_recommended(unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key)
|
||||
{
|
||||
SM2_ENC_PARAMS params;
|
||||
SM2_ENC_PARAMS_init_with_recommended(¶ms);
|
||||
return SM2_encrypt(¶ms, in, inlen, out, outlen, ec_key);
|
||||
return SM2_encrypt(¶ms, out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
|
||||
int SM2_decrypt_with_recommended(const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key)
|
||||
int SM2_decrypt_with_recommended(unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key)
|
||||
{
|
||||
SM2_ENC_PARAMS params;
|
||||
SM2_ENC_PARAMS_init_with_recommended(¶ms);
|
||||
return SM2_decrypt(¶ms, in, inlen, out, outlen, ec_key);
|
||||
return SM2_decrypt(¶ms, out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
|
||||
int SM2_encrypt_elgamal(const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key)
|
||||
int SM2_encrypt_elgamal(unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key)
|
||||
{
|
||||
SM2_ENC_PARAMS params;
|
||||
params.kdf_md = EVP_sm3();
|
||||
params.mac_md = EVP_sm3();
|
||||
params.mactag_size = 0;
|
||||
params.point_form = POINT_CONVERSION_COMPRESSED;
|
||||
return SM2_encrypt(¶ms, in, inlen, out, outlen, ec_key);
|
||||
return SM2_encrypt(¶ms, out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
|
||||
int SM2_decrypt_elgamal(const unsigned char *in, size_t inlen,
|
||||
unsigned char *out, size_t *outlen, EC_KEY *ec_key)
|
||||
int SM2_decrypt_elgamal(unsigned char *out, size_t *outlen,
|
||||
const unsigned char *in, size_t inlen, EC_KEY *ec_key)
|
||||
{
|
||||
SM2_ENC_PARAMS params;
|
||||
params.kdf_md = EVP_sm3();
|
||||
params.mac_md = EVP_sm3();
|
||||
params.mactag_size = 0;
|
||||
params.point_form = POINT_CONVERSION_COMPRESSED;
|
||||
return SM2_decrypt(¶ms, in, inlen, out, outlen, ec_key);
|
||||
return SM2_decrypt(¶ms, out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ static ERR_STRING_DATA SM2_str_reasons[] = {
|
||||
{ERR_REASON(SM2_R_BUFFER_TOO_SMALL), "buffer too small"},
|
||||
{ERR_REASON(SM2_R_SM2_KAP_NOT_INITED), "KAP not inited"},
|
||||
{ERR_REASON(SM2_R_RANDOM_NUMBER_GENERATION_FAILED), "random number generation failed"},
|
||||
{ERR_REASON(SM2_R_ERROR), "Error"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -479,6 +479,7 @@ int SM2_sign_ex(int type, const unsigned char *dgst, int dgstlen,
|
||||
int SM2_sign(int type, const unsigned char *dgst, int dgstlen,
|
||||
unsigned char *sig, unsigned int *siglen, EC_KEY *ec_key)
|
||||
{
|
||||
fprintf(stderr, "%s %d %s() executed\n", __FILE__, __LINE__, __FUNCTION__);
|
||||
return SM2_sign_ex(type, dgst, dgstlen, sig, siglen, NULL, NULL, ec_key);
|
||||
}
|
||||
|
||||
@@ -491,6 +492,8 @@ int SM2_verify(int type, const unsigned char *dgst, int dgstlen,
|
||||
int derlen = -1;
|
||||
int ret = -1;
|
||||
|
||||
fprintf(stderr, "%s %d %s() executed\n", __FILE__, __LINE__, __FUNCTION__);
|
||||
|
||||
if (!(s = ECDSA_SIG_new())) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -337,8 +337,8 @@ int test_sm2_enc(const EC_GROUP *group,
|
||||
}
|
||||
|
||||
buflen = sizeof(buf);
|
||||
if (!SM2_encrypt(kdf_md, mac_md, point_form,
|
||||
(const unsigned char *)M, strlen(M), buf, &buflen, ec_key)) {
|
||||
if (!SM2_encrypt_with_recommended((const unsigned char *)M, strlen(M),
|
||||
buf, &buflen, ec_key)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
@@ -355,8 +355,7 @@ int test_sm2_enc(const EC_GROUP *group,
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
if (!SM2_decrypt(kdf_md, mac_md, point_form, buf, buflen,
|
||||
msg, &msglen, ec_key)) {
|
||||
if (!SM2_decrypt_with_recommended(buf, buflen, msg, &msglen, ec_key)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
@@ -625,7 +624,7 @@ int test_sm2_test_vector()
|
||||
printf("sm2 kap p256 passed\n");
|
||||
}
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
/* ZA will not pass! */
|
||||
if (!test_sm2_kap(
|
||||
sm2b257test,
|
||||
@@ -663,6 +662,567 @@ end:
|
||||
}
|
||||
|
||||
|
||||
EVP_PKEY *genpkey(int curve_nid, BIO *out, int verbose)
|
||||
{
|
||||
int ok = 0;
|
||||
EVP_PKEY *ret = NULL;
|
||||
EVP_PKEY_CTX *pkctx = NULL;
|
||||
|
||||
if (!(pkctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL))) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_keygen_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pkctx, curve_nid)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_keygen(pkctx, &ret)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose > 1) {
|
||||
EVP_PKEY_print_private(out, ret, 4, NULL);
|
||||
BIO_printf(out, "\n");
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
end:
|
||||
if (!ok && ret) {
|
||||
EVP_PKEY_free(ret);
|
||||
ret = NULL;
|
||||
}
|
||||
EVP_PKEY_CTX_free(pkctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_evp_pkey_sign(EVP_PKEY *pkey, int do_sm2, int verbose)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY_CTX *pkctx = NULL;
|
||||
int type = do_sm2 ? NID_sm_scheme : NID_secg_scheme;
|
||||
unsigned char dgst[EVP_MAX_MD_SIZE] = "hello world";
|
||||
size_t dgstlen;
|
||||
unsigned char sig[256];
|
||||
size_t siglen;
|
||||
|
||||
|
||||
if (!(pkctx = EVP_PKEY_CTX_new(pkey, NULL))) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* EVP_PKEY_sign() */
|
||||
|
||||
if (!EVP_PKEY_sign_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_CTX_set_ec_sign_type(pkctx, type)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
dgstlen = 32;
|
||||
bzero(sig, sizeof(sig));
|
||||
siglen = sizeof(sig);
|
||||
if (!EVP_PKEY_sign(pkctx, sig, &siglen, dgst, dgstlen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose > 1) {
|
||||
size_t i;
|
||||
printf("signature (%zu bytes) = ", siglen);
|
||||
for (i = 0; i < siglen; i++) {
|
||||
printf("%02X", sig[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_verify_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_CTX_set_ec_sign_type(pkctx, type)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_verify(pkctx, sig, siglen, dgst, dgstlen) != SM2_VERIFY_SUCCESS) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
printf("test %s signing passed\n", OBJ_nid2sn(type));
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
EVP_PKEY_CTX_free(pkctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_evp_pkey_encrypt(EVP_PKEY *pkey, int do_sm2, int verbose)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY_CTX *pkctx = NULL;
|
||||
int type = do_sm2 ? NID_sm_scheme : NID_secg_scheme;
|
||||
unsigned char msg[] = "hello world this is the message";
|
||||
size_t msglen = sizeof(msg);
|
||||
unsigned char cbuf[512];
|
||||
size_t cbuflen = sizeof(cbuf);
|
||||
unsigned char mbuf[512];
|
||||
size_t mbuflen = sizeof(mbuf);
|
||||
int len;
|
||||
unsigned int ulen;
|
||||
|
||||
if (!(pkctx = EVP_PKEY_CTX_new(pkey, NULL))) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* EVP_PKEY_encrypt() */
|
||||
|
||||
if (!EVP_PKEY_encrypt_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_CTX_set_ec_enc_type(pkctx, type)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
cbuflen = sizeof(cbuf);
|
||||
if (!EVP_PKEY_encrypt(pkctx, cbuf, &cbuflen, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose > 1) {
|
||||
size_t i;
|
||||
printf("ciphertext (%zu bytes) = ", cbuflen);
|
||||
for (i = 0; i < cbuflen; i++) {
|
||||
printf("%02X", cbuf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_decrypt_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_CTX_set_ec_enc_type(pkctx, type)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
bzero(mbuf, sizeof(mbuf));
|
||||
mbuflen = sizeof(mbuf);
|
||||
if (!EVP_PKEY_decrypt(pkctx, mbuf, &mbuflen, cbuf, cbuflen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose > 1) {
|
||||
printf("original message = %s\n", msg);
|
||||
printf("decrypted message = %s\n", mbuf);
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
printf("test %s encryption passed\n", OBJ_nid2sn(type));
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
EVP_PKEY_CTX_free(pkctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_evp_pkey_encrypt_old(EVP_PKEY *pkey, int verbose)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char msg[] = "hello world this is the message";
|
||||
size_t msglen = sizeof(msg);
|
||||
unsigned char cbuf[512];
|
||||
size_t cbuflen = sizeof(cbuf);
|
||||
unsigned char mbuf[512];
|
||||
size_t mbuflen = sizeof(mbuf);
|
||||
|
||||
int len;
|
||||
|
||||
if ((len = EVP_PKEY_encrypt_old(cbuf, msg, (int)msglen, pkey)) <= 0) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose > 1) {
|
||||
int i;
|
||||
printf("ciphertext (%d bytes) = ", len);
|
||||
for (i = 0; i < len; i++) {
|
||||
printf("%02X", cbuf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
bzero(mbuf, sizeof(mbuf));
|
||||
if ((len = EVP_PKEY_decrypt_old(mbuf, cbuf, len, pkey)) <= 0) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose > 1) {
|
||||
printf("original message = %s\n", msg);
|
||||
printf("decrypted message = %s\n", mbuf);
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
printf("EVP_PKEY_encrypt_old() passed!\n");
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_evp_sign(EVP_PKEY *pkey, const EVP_MD *md, int verbose)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_MD_CTX *mdctx = NULL;
|
||||
unsigned char msg[] = "hello world this is the message";
|
||||
size_t msglen = sizeof(msg);
|
||||
unsigned char sig[256];
|
||||
unsigned int siglen = (unsigned int)sizeof(sig);
|
||||
unsigned int i;
|
||||
|
||||
if (!(mdctx = EVP_MD_CTX_create())) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_SignInit_ex(mdctx, md, NULL)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_SignUpdate(mdctx, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_SignFinal(mdctx, sig, &siglen, pkey)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose > 1) {
|
||||
size_t i;
|
||||
printf("signature (%u bytes) = ", siglen);
|
||||
for (i = 0; i < siglen; i++) {
|
||||
printf("%02X", sig[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (!EVP_VerifyInit_ex(mdctx, md, NULL)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_VerifyUpdate(mdctx, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (EVP_VerifyFinal(mdctx, sig, siglen, pkey) != SM2_VERIFY_SUCCESS) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
printf("EVP_SignInit/Update/Final() passed\n");
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
end:
|
||||
EVP_MD_CTX_destroy(mdctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_evp_digestsign(EVP_PKEY *pkey, int do_sm2, const EVP_MD *md, int verbose)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_MD_CTX *mdctx = NULL;
|
||||
EVP_PKEY_CTX *pkctx;
|
||||
int type = do_sm2 ? NID_sm_scheme : NID_secg_scheme;
|
||||
unsigned char msg[] = "hello world this is the message";
|
||||
size_t msglen = sizeof(msg);
|
||||
unsigned char sig[256];
|
||||
size_t siglen = (unsigned int)sizeof(sig);
|
||||
|
||||
if (!(mdctx = EVP_MD_CTX_create())) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
pkctx = NULL;
|
||||
if (!EVP_DigestSignInit(mdctx, &pkctx, md, NULL, pkey)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_CTX_set_ec_sign_type(pkctx, type)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_DigestSignUpdate(mdctx, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
siglen = sizeof(sig);
|
||||
if (!EVP_DigestSignFinal(mdctx, sig, &siglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
pkctx = NULL;
|
||||
if (!EVP_DigestVerifyInit(mdctx, &pkctx, md, NULL, pkey)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_CTX_set_ec_sign_type(pkctx, type)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_DigestVerifyUpdate(mdctx, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_DigestVerifyFinal(mdctx, sig, siglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
printf("EVP_DigestSignInit/Update/Final() passed\n");
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
EVP_MD_CTX_destroy(mdctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define NUM_PKEYS 3
|
||||
#define MAX_PKEY_SIZE 256
|
||||
|
||||
int test_evp_seal(int curve_id, const EVP_CIPHER *cipher, BIO *out, int verbose)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey[NUM_PKEYS] = {0};
|
||||
EVP_CIPHER_CTX *cctx = NULL;
|
||||
unsigned char iv[16];
|
||||
unsigned char ek[NUM_PKEYS][MAX_PKEY_SIZE];
|
||||
int ekl[NUM_PKEYS];
|
||||
unsigned char msg1[] = "Hello ";
|
||||
unsigned char msg2[] = "World!";
|
||||
unsigned char cbuf[256];
|
||||
unsigned char mbuf[256];
|
||||
unsigned char *p;
|
||||
int len, clen, mlen, i;
|
||||
|
||||
|
||||
for (i = 0; i < NUM_PKEYS; i++) {
|
||||
pkey[i] = genpkey(curve_id, out, verbose);
|
||||
ekl[i] = MAX_PKEY_SIZE;
|
||||
}
|
||||
RAND_bytes(iv, sizeof(iv));
|
||||
|
||||
if (!(cctx = EVP_CIPHER_CTX_new())) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (NUM_PKEYS != EVP_SealInit(cctx, cipher, ek, ekl, iv, pkey, NUM_PKEYS)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose > 1) {
|
||||
for (i = 0; i < NUM_PKEYS; i++) {
|
||||
int j;
|
||||
BIO_printf(out, "ek[i] (%d-byte) = ", ekl[i]);
|
||||
for (j = 0; j < ekl[i]; j++) {
|
||||
BIO_printf(out, "%02X", ek[i][j]);
|
||||
}
|
||||
BIO_printf(out, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
p = cbuf;
|
||||
len = sizeof(cbuf);
|
||||
if (!EVP_SealUpdate(cctx, p, &len, msg1, sizeof(msg1)-1)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
p += len;
|
||||
|
||||
len = sizeof(cbuf) - (p - cbuf);
|
||||
if (!EVP_SealUpdate(cctx, p, &len, msg2, sizeof(msg2)-1)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
p += len;
|
||||
|
||||
len = sizeof(cbuf) - (p - cbuf);
|
||||
if (!EVP_SealFinal(cctx, p, &len)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
p += len;
|
||||
|
||||
clen = p - cbuf;
|
||||
|
||||
if (verbose > 1) {
|
||||
BIO_printf(out, "ciphertext (%d-byte) = ", clen);
|
||||
for (i = 0; i < clen; i++) {
|
||||
BIO_printf(out, "%02X", cbuf[i]);
|
||||
}
|
||||
BIO_printf(out, "\n");
|
||||
}
|
||||
|
||||
if (!EVP_OpenInit(cctx, cipher, ek[0], ekl[0], iv, pkey[0])) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
bzero(mbuf, sizeof(mbuf));
|
||||
p = mbuf;
|
||||
len = sizeof(mbuf);
|
||||
|
||||
if (!EVP_OpenUpdate(cctx, p, &len, cbuf, clen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
p += len;
|
||||
len = sizeof(mbuf) - len;
|
||||
|
||||
if (!EVP_OpenFinal(cctx, p, &len)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
p += len;
|
||||
|
||||
mlen = p - mbuf;
|
||||
|
||||
if (verbose > 1) {
|
||||
BIO_printf(out, "message = %s%s\n", (char *)msg1, (char *)msg2);
|
||||
BIO_printf(out, "message = %s\n", (char *)mbuf);
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
BIO_printf(out, "EVP_SealInit/Update/Final() passed!\n");
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
end:
|
||||
EVP_CIPHER_CTX_free(cctx);
|
||||
for (i = 0; i < NUM_PKEYS; i++) {
|
||||
EVP_PKEY_free(pkey[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_sm2_evp(int verbose)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
BIO *out = NULL;
|
||||
int curve_id = NID_sm2p256v1;
|
||||
const EVP_MD *md = EVP_sm3();
|
||||
const EVP_CIPHER *cipher = EVP_sms4_cbc();
|
||||
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
out = BIO_new_fp(stderr, BIO_NOCLOSE);
|
||||
|
||||
if (!(pkey = genpkey(curve_id, out, verbose))) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* test sm2sign */
|
||||
if (!test_evp_pkey_sign(pkey, 1, verbose)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* test ecdsa */
|
||||
if (!test_evp_pkey_sign(pkey, 0, verbose)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* test sm2encrypt */
|
||||
if (!test_evp_pkey_encrypt(pkey, 1, verbose)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* test ecies */
|
||||
if (!test_evp_pkey_encrypt(pkey, 0, verbose)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* test ec default encrypt */
|
||||
if (!test_evp_pkey_encrypt_old(pkey, verbose)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* test ec default sign */
|
||||
if (!test_evp_sign(pkey, md, verbose)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* test seal/open */
|
||||
if (!test_evp_seal(curve_id, cipher, out, verbose)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
end:
|
||||
if (ret != 1) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
EVP_PKEY_free(pkey);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = -1;
|
||||
@@ -688,30 +1248,11 @@ int main(int argc, char **argv)
|
||||
if (!test_sm2_test_vector()) {
|
||||
goto err;
|
||||
}
|
||||
/*
|
||||
if (!test_sm2_evp_pkey_sign()) {
|
||||
|
||||
if (!test_sm2_evp(2)) {
|
||||
goto err;
|
||||
}
|
||||
if (!test_sm2_evp_pkey_encrypt()) {
|
||||
goto err;
|
||||
}
|
||||
if (!test_sm2_evp_pkey_derive()) {
|
||||
goto err;
|
||||
}
|
||||
if (!test_sm2_evp_sign()) {
|
||||
goto err;
|
||||
}
|
||||
if (!test_sm2_evp_digestsign()) {
|
||||
goto err;
|
||||
}
|
||||
if (!test_sm2_evp_encrypt_old()) {
|
||||
goto err;
|
||||
}
|
||||
if (!test_sm2_evp_seal()) {
|
||||
goto err;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
ret =0;
|
||||
err:
|
||||
if (ret)
|
||||
|
||||
13
demos/gmssl/cert.pem
Normal file
13
demos/gmssl/cert.pem
Normal file
@@ -0,0 +1,13 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIB9jCCAZ2gAwIBAgIJAI6saFfpzqpLMAoGCCqGSM49BAMCMFgxCzAJBgNVBAYT
|
||||
AkNOMQwwCgYDVQQIDANQS1UxDDAKBgNVBAcMA1BLVTEMMAoGA1UECgwDUEtVMQ0w
|
||||
CwYDVQQLDARERFNTMRAwDgYDVQQDDAdERFNTLUFTMB4XDTE2MDUxODExNTgyMVoX
|
||||
DTI2MDUxNjExNTgyMVowWDELMAkGA1UEBhMCQ04xDDAKBgNVBAgMA1BLVTEMMAoG
|
||||
A1UEBwwDUEtVMQwwCgYDVQQKDANQS1UxDTALBgNVBAsMBEREU1MxEDAOBgNVBAMM
|
||||
B0REU1MtQVMwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAATFBdPQp/tqJHjfL+eZ
|
||||
Jv1tUCMFpWCzoskQgDImhLP8+snkNSmZhRtHeerUr8oP6FtWAPnhUzwMOVb4JcNC
|
||||
CYSbo1AwTjAdBgNVHQ4EFgQUCz8gNn0NMxyIW/gRF13zl6ExeLUwHwYDVR0jBBgw
|
||||
FoAUCz8gNn0NMxyIW/gRF13zl6ExeLUwDAYDVR0TBAUwAwEB/zAKBggqhkjOPQQD
|
||||
AgNHADBEAiARFx9dY1LE+ELs/SWIkMLxbikA3P4YE0JZZkAmXZVo/gIgEs8G6fJw
|
||||
8AEbDwMcMiLLyJ7RhcUhEX+oj3Ibm8JgQXo=
|
||||
-----END CERTIFICATE-----
|
||||
@@ -1,41 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
#gmssl=/usr/local/bin/gmssl
|
||||
|
||||
gmssl=../../apps/gmssl
|
||||
paramfile=ecparam.pem
|
||||
keyfile=eckey.pem
|
||||
pubkeyfile=ecpubkey.pem
|
||||
pkeyopt="-pkeyopt ec_paramgen_curve:sm2p256v1"
|
||||
|
||||
|
||||
#echo -n abc | $gmssl dgst -sm3
|
||||
#echo -n abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd | gmssl dgst -sm3
|
||||
|
||||
$gmssl version
|
||||
$gmssl ecparam -list_curves | grep sm2
|
||||
$gmssl ecparam -text -noout -name sm2p256v1 -param_enc explicit
|
||||
#$gmssl version
|
||||
#$gmssl ecparam -list_curves | grep sm2
|
||||
#$gmssl ecparam -text -noout -name sm2p256v1 -param_enc explicit
|
||||
#$gmssl genpkey -genparam -algorithm EC -out sm2p256v1.pem -pkeyopt ec_paramgen_curve:sm2p256v1 -pkeyopt ec_param_enc:named_curve
|
||||
$gmssl genpkey -algorithm EC -out sm2key.pem -pkeyopt ec_paramgen_curve:sm2p256v1 -pkeyopt ec_param_enc:named_curve
|
||||
#$gmssl pkey -text -noout -in sm2key.pem
|
||||
#$gmssl pkey -in sm2key.pem -pubout -out sm2pubkey.pem
|
||||
#$gmssl pkey -text -noout -pubin -in $pubkeyfile
|
||||
#echo hello | $gmssl pkeyutl -sign -inkey sm2key.pem -pkeyopt ec_sign_algor:sm2 > sm2sig.der
|
||||
#echo hello | $gmssl pkeyutl -verify -inkey sm2key.pem -sigfile sm2sig.der -pkeyopt ec_sign_algor:sm2
|
||||
#echo hello | $gmssl pkeyutl -encrypt -inkey sm2key.pem -pkeyopt ec_encrypt_algor:sm2 > sm2ciphertext.bin
|
||||
#cat sm2ciphertext.bin | $gmssl pkeyutl -decrypt -inkey sm2key.pem -pkeyopt ec_encrypt_algor:sm2
|
||||
|
||||
gmssl genpkey -genparam -algorithm EC -out sm2p256v1.pem \
|
||||
-pkeyopt ec_paramgen_curve:sm2p256v1 \
|
||||
-pkeyopt ec_param_enc:named_curve
|
||||
|
||||
gmssl genpkey -algorithm EC -out sm2key.pem \
|
||||
-pkeyopt ec_paramgen_curve:sm2p256v1 \
|
||||
-pkeyopt ec_param_enc:named_curve
|
||||
|
||||
# print private key
|
||||
#gmssl pkey -text -noout -in sm2key.pem
|
||||
|
||||
# export public key
|
||||
gmssl pkey -in sm2key.pem -pubout -out sm2pubkey.pem
|
||||
#gmssl pkey -text -noout -pubin -in $pubkeyfile
|
||||
|
||||
echo hello | gmssl pkeyutl -sign -inkey sm2key.pem -pkeyopt ec_sign_algor:sm2 > sm2sig.der
|
||||
|
||||
|
||||
echo hello | \
|
||||
gmssl pkeyutl -verify -inkey sm2key.pem \
|
||||
-sigfile sm2sig.der -pkeyopt ec_sign_algor:sm2
|
||||
|
||||
|
||||
$gmssl req -new -x509 -days 3650 -key sm2key.pem -out cert.pem -pkeyopt ec_sign_algor:sm2
|
||||
#$gmssl x509 -text -noout -in $DIR/cacert.pem
|
||||
|
||||
38
demos/gmssl/listciphers.c
Normal file
38
demos/gmssl/listciphers.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char *names[] = {
|
||||
"sms4-ecb",
|
||||
"sms4-cbc",
|
||||
"sms4-cfb",
|
||||
"sms4-ofb",
|
||||
"sms4-ctr",
|
||||
};
|
||||
const EVP_CIPHER *cipher;
|
||||
|
||||
OpenSSL_add_all_ciphers();
|
||||
|
||||
printf("%s new ciphers:\n\n", OPENSSL_VERSION_TEXT);
|
||||
|
||||
for (i = 0; i < sizeof(names)/sizeof(names[i]); i++) {
|
||||
if (!(cipher = EVP_get_cipherbyname(names[i]))) {
|
||||
fprintf(stderr, "cipher \"%s\" is not supported\n", names[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf(" cipher nid : %d\n", EVP_CIPHER_nid(cipher));
|
||||
printf(" cipher name : %s\n", EVP_CIPHER_name(cipher));
|
||||
printf(" block size : %d\n", EVP_CIPHER_block_size(cipher));
|
||||
printf(" key length : %d\n", EVP_CIPHER_key_length(cipher));
|
||||
printf(" iv length : %d\n", EVP_CIPHER_iv_length(cipher));
|
||||
printf(" flags : 0x%016lx\n", EVP_CIPHER_flags(cipher));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,355 +0,0 @@
|
||||
/* demo/gmssl/sm2.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2015-2016 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 <strings.h>
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/sm2.h>
|
||||
|
||||
#define NUM_PKEYS 4
|
||||
|
||||
int main()
|
||||
{
|
||||
int ret = -1;
|
||||
int verbose = 0;
|
||||
BIO *out = NULL;
|
||||
|
||||
int id = EVP_PKEY_SM2;
|
||||
const EVP_MD *md = EVP_sm3();
|
||||
ENGINE *engine = NULL;
|
||||
|
||||
EVP_PKEY_CTX *pkctx = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
EVP_MD_CTX *mdctx = NULL;
|
||||
EVP_CIPHER_CTX *cpctx = NULL;
|
||||
|
||||
unsigned char dgst[EVP_MAX_MD_SIZE] = "hello world";
|
||||
size_t dgstlen = 32;
|
||||
unsigned char sig[256];
|
||||
size_t siglen = sizeof(sig);
|
||||
|
||||
unsigned char msg[] = "hello world this is the message";
|
||||
size_t msglen = sizeof(msg);
|
||||
unsigned char cbuf[512];
|
||||
size_t cbuflen = sizeof(cbuf);
|
||||
unsigned char mbuf[512];
|
||||
size_t mbuflen = sizeof(mbuf);
|
||||
|
||||
int len;
|
||||
unsigned int ulen;
|
||||
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
out = BIO_new_fp(stdout, BIO_NOCLOSE);
|
||||
|
||||
if (!(pkctx = EVP_PKEY_CTX_new_id(id, engine))) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_keygen_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_keygen(pkctx, &pkey)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
EVP_PKEY_CTX_free(pkctx);
|
||||
|
||||
if (0) {
|
||||
EVP_PKEY_print_public(out, pkey, 4, NULL);
|
||||
BIO_printf(out, "\n");
|
||||
EVP_PKEY_print_private(out, pkey, 4, NULL);
|
||||
BIO_printf(out, "\n");
|
||||
}
|
||||
|
||||
if (!(pkctx = EVP_PKEY_CTX_new(pkey, engine))) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* EVP_PKEY_sign() */
|
||||
|
||||
if (!EVP_PKEY_sign_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
bzero(sig, sizeof(sig));
|
||||
siglen = sizeof(sig);
|
||||
dgstlen = 32;
|
||||
|
||||
if (!EVP_PKEY_sign(pkctx, sig, &siglen, dgst, dgstlen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
size_t i;
|
||||
printf("signature (%zu bytes) = ", siglen);
|
||||
for (i = 0; i < siglen; i++) {
|
||||
printf("%02X", sig[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_verify_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_verify(pkctx, sig, siglen, dgst, dgstlen) != SM2_VERIFY_SUCCESS) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
printf("signature verification success!\n");
|
||||
}
|
||||
|
||||
/* EVP_PKEY_encrypt() */
|
||||
|
||||
if (!EVP_PKEY_encrypt_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
cbuflen = sizeof(cbuf);
|
||||
if (!EVP_PKEY_encrypt(pkctx, cbuf, &cbuflen, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
size_t i;
|
||||
printf("ciphertext (%zu bytes) = ", cbuflen);
|
||||
for (i = 0; i < cbuflen; i++) {
|
||||
printf("%02X", cbuf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_decrypt_init(pkctx)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
bzero(mbuf, sizeof(mbuf));
|
||||
mbuflen = sizeof(mbuf);
|
||||
if (!EVP_PKEY_decrypt(pkctx, mbuf, &mbuflen, cbuf, cbuflen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
printf("original message = %s\n", msg);
|
||||
printf("decrypted message = %s\n", mbuf);
|
||||
}
|
||||
|
||||
|
||||
/* EVP_PKEY_encrypt_old */
|
||||
|
||||
|
||||
if ((len = EVP_PKEY_encrypt_old(cbuf, msg, (int)msglen, pkey)) <= 0) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
int i;
|
||||
printf("ciphertext (%d bytes) = ", len);
|
||||
for (i = 0; i < len; i++) {
|
||||
printf("%02X", cbuf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
bzero(mbuf, sizeof(mbuf));
|
||||
if ((len = EVP_PKEY_decrypt_old(mbuf, cbuf, len, pkey)) <= 0) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
printf("original message = %s\n", msg);
|
||||
printf("decrypted message = %s\n", mbuf);
|
||||
}
|
||||
|
||||
if (!(mdctx = EVP_MD_CTX_create())) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
/* EVP_SignInit_ex/Update/Final_ex */
|
||||
|
||||
if (!EVP_SignInit_ex(mdctx, EVP_sm3(), engine)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_SignUpdate(mdctx, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_SignFinal(mdctx, sig, &ulen, pkey)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
siglen = ulen;
|
||||
|
||||
if (verbose) {
|
||||
size_t i;
|
||||
printf("signature (%zu bytes) = ", siglen);
|
||||
for (i = 0; i < siglen; i++) {
|
||||
printf("%02X", sig[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (!EVP_VerifyInit_ex(mdctx, EVP_sm3(), engine)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_VerifyUpdate(mdctx, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (EVP_VerifyFinal(mdctx, sig, ulen, pkey) != SM2_VERIFY_SUCCESS) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
/* EVP_DigestSignInit/Update/Final() */
|
||||
// FIXME: return values might be different, not just 1 or 0
|
||||
if (!EVP_DigestSignInit(mdctx, &pkctx, md, engine, pkey)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_DigestSignUpdate(mdctx, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
siglen = sizeof(sig);
|
||||
if (!EVP_DigestSignFinal(mdctx, sig, &siglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
pkctx = NULL;
|
||||
if (!EVP_DigestVerifyInit(mdctx, &pkctx, md, engine, pkey)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_DigestVerifyUpdate(mdctx, msg, msglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_DigestVerifyFinal(mdctx, sig, siglen)) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
/* EVP_SealInit/Update/Final() EVP_OpenInit/Update/Final() */
|
||||
/*
|
||||
EVP_PKEY *pk[NUM_PKEYS] = {0};
|
||||
unsigned char iv[16];
|
||||
unsigned char ek[NUM_PKEYS][256];
|
||||
int eklen[NUM_PKEYS];
|
||||
|
||||
RAND_pseudo_bytes(iv, sizeof(iv));
|
||||
|
||||
int i;
|
||||
for (i = 0; i < NUM_PKEYS; i++) {
|
||||
}
|
||||
|
||||
if (!(cpctx = EVP_CIPHER_CTX_new())) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_SealInit(cpctx, cipher, ek, &ekl, iv, pubk, npubk)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_SealUpdate(cpctx, msg, msglen)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EVP_SealFinal(cpctx, cbuf, (int *)&cbuflen)) {
|
||||
goto end;
|
||||
}
|
||||
*/
|
||||
|
||||
printf("test success!\n");
|
||||
ret = 1;
|
||||
end:
|
||||
ERR_print_errors_fp(stderr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
5
demos/gmssl/sm2key.pem
Normal file
5
demos/gmssl/sm2key.pem
Normal file
@@ -0,0 +1,5 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQg2MM/g28XAEne6VG/
|
||||
cPYUhVq8H0D/5igtUw9CUaxr2KWhRANCAAQdCrdYHfnyeFhcFQuyRrCxuGH1/bnS
|
||||
wDKinlLUFyVa72SlAz5tBaA4TPY2m5259/55lTkdVkq6gtvyW7L/VFTg
|
||||
-----END PRIVATE KEY-----
|
||||
120
demos/gmssl/sm2selfsign.c
Normal file
120
demos/gmssl/sm2selfsign.c
Normal file
@@ -0,0 +1,120 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
int mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days);
|
||||
|
||||
int main()
|
||||
{
|
||||
BIO *bio_err;
|
||||
X509 *x509 = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
|
||||
|
||||
mkit(&x509, &pkey, 512, 0, 365);
|
||||
|
||||
EC_KEY_print_fp(stdout, pkey->pkey.ec, 0);
|
||||
X509_print_fp(stdout, x509);
|
||||
|
||||
PEM_write_PrivateKey(stdout, pkey, NULL, NULL, 0, NULL, NULL);
|
||||
PEM_write_X509(stdout, x509);
|
||||
|
||||
X509_free(x509);
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
CRYPTO_mem_leaks(bio_err);
|
||||
BIO_free(bio_err);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days)
|
||||
{
|
||||
X509 *x;
|
||||
EVP_PKEY *pk;
|
||||
EC_KEY *ec_key;
|
||||
X509_NAME *name = NULL;
|
||||
X509_NAME_ENTRY *ne = NULL;
|
||||
X509_EXTENSION *ex = NULL;
|
||||
|
||||
if ((pkeyp == NULL) || (*pkeyp == NULL)) {
|
||||
if ((pk = EVP_PKEY_new()) == NULL) {
|
||||
abort();
|
||||
return (0);
|
||||
}
|
||||
} else
|
||||
pk = *pkeyp;
|
||||
|
||||
if ((x509p == NULL) || (*x509p == NULL)) {
|
||||
if ((x = X509_new()) == NULL)
|
||||
goto err;
|
||||
} else {
|
||||
x = *x509p;
|
||||
}
|
||||
|
||||
|
||||
ec_key = EC_KEY_new_by_curve_name(NID_sm2p256v1);
|
||||
EC_KEY_generate_key(ec_key);
|
||||
|
||||
if (!EVP_PKEY_assign_EC_KEY(pk, ec_key)) {
|
||||
abort();
|
||||
goto err;
|
||||
}
|
||||
ec_key = NULL;
|
||||
|
||||
X509_set_version(x, 3);
|
||||
ASN1_INTEGER_set(X509_get_serialNumber(x), serial);
|
||||
X509_gmtime_adj(X509_get_notBefore(x), 0);
|
||||
X509_gmtime_adj(X509_get_notAfter(x), (long)60 * 60 * 24 * days);
|
||||
X509_set_pubkey(x, pk);
|
||||
|
||||
name = X509_get_subject_name(x);
|
||||
|
||||
/*
|
||||
* This function creates and adds the entry, working out the correct
|
||||
* string type and performing checks on its length. Normally we'd check
|
||||
* the return value for errors...
|
||||
*/
|
||||
X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, "UK", -1, -1, 0);
|
||||
X509_NAME_add_entry_by_txt(name, "CN",
|
||||
MBSTRING_ASC, "OpenSSL Group", -1, -1, 0);
|
||||
|
||||
X509_set_issuer_name(x, name);
|
||||
|
||||
/*
|
||||
* Add extension using V3 code: we can set the config file as NULL
|
||||
* because we wont reference any other sections. We can also set the
|
||||
* context to NULL because none of these extensions below will need to
|
||||
* access it.
|
||||
*/
|
||||
|
||||
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_netscape_cert_type, "server");
|
||||
X509_add_ext(x, ex, -1);
|
||||
X509_EXTENSION_free(ex);
|
||||
|
||||
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_netscape_comment,
|
||||
"example comment extension");
|
||||
X509_add_ext(x, ex, -1);
|
||||
X509_EXTENSION_free(ex);
|
||||
|
||||
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_netscape_ssl_server_name,
|
||||
"www.openssl.org");
|
||||
|
||||
X509_add_ext(x, ex, -1);
|
||||
X509_EXTENSION_free(ex);
|
||||
|
||||
|
||||
if (!X509_sign(x, pk, EVP_sm3()))
|
||||
goto err;
|
||||
|
||||
*x509p = x;
|
||||
*pkeyp = pk;
|
||||
return (1);
|
||||
err:
|
||||
return (0);
|
||||
}
|
||||
211
engines/e_skf.c
211
engines/e_skf.c
@@ -1,5 +1,52 @@
|
||||
/*
|
||||
* The SKF ENGINE will be released when EC_KEY_METHOD is avaiable
|
||||
/* engines/e_skf.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2015-2016 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>
|
||||
@@ -22,6 +69,10 @@ static DEVHANDLE skf_dev_handle = NULL;
|
||||
static HAPPLICATION skf_app_handle = NULL;
|
||||
static HCONTAINER skf_container_handle = NULL;
|
||||
|
||||
static int authkey_set = 0;
|
||||
static unsigned char authkey[16];
|
||||
static int userpin_set = 0;
|
||||
static char userpin[64];
|
||||
|
||||
static int skf_init(ENGINE *e);
|
||||
static int skf_finish(ENGINE *e);
|
||||
@@ -29,20 +80,58 @@ static int skf_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
|
||||
static int skf_destroy(ENGINE *e);
|
||||
|
||||
|
||||
#define SKF_CMD_LIST_DEVS ENGINE_CMD_BASE
|
||||
#define SKF_CMD_SO_PATH ENGINE_CMD_BASE
|
||||
#define SKF_CMD_OPEN_DEV (ENGINE_CMD_BASE + 1)
|
||||
#define SKF_CMD_DEV_AUTH (ENGINE_CMD_BASE + 2)
|
||||
#define SKF_CMD_OPEN_APP (ENGINE_CMD_BASE + 3)
|
||||
#define SKF_CMD_VERIFY_PIN (ENGINE_CMD_BASE + 4)
|
||||
#define SKF_CMD_OPEN_CONTAINER (ENGINE_CMD_BASE + 5)
|
||||
|
||||
static const ENGINE_CMD_DEFN skf_cmd_defns[] = {
|
||||
{SKF_CMD_SO_PATH,
|
||||
"SO_PATH",
|
||||
"Specifies the path to the vendor's SKF shared library",
|
||||
ENGINE_CMD_FLAG_STRING},
|
||||
{SKF_CMD_OPEN_DEV,
|
||||
"OPEN_DEVICE",
|
||||
"Open SKF device with device name",
|
||||
ENGINE_CMD_FLAG_STRING},
|
||||
{SKF_CMD_DEV_AUTH,
|
||||
"DEV_AUTH",
|
||||
"Device authentication with authentication key",
|
||||
ENGINE_CMD_FLAG_STRING},
|
||||
{SKF_CMD_OPEN_APP,
|
||||
"OPEN_APP",
|
||||
"Open application with specified name",
|
||||
{SKF_CMD_VERIFY_PIN,
|
||||
"VERIFY_PIN",
|
||||
"Specifies user's PIN of the application to open",
|
||||
ENGINE_CMD_FLAG_STRING},
|
||||
{SKF_CMD_OPEN_CONTAINER,
|
||||
"OPEN_CONTAINER",
|
||||
"Open container wtith specified name",
|
||||
ENGINE_CMD_FLAG_STRING},
|
||||
{0, NULL, NULL, 0}
|
||||
};
|
||||
|
||||
|
||||
|
||||
static int skf_open_container(const char *dev,
|
||||
const unsigned char *authkey, size_t authkeylen,
|
||||
const char *app, const char *pin,
|
||||
const char *container, HCONTAINER *phContainer)
|
||||
int set_authkey(const char *authkey_hex)
|
||||
{
|
||||
ULONG rv;
|
||||
DEVINFO devInfo;
|
||||
DEVHANDLE hDev = NULL;
|
||||
HAPPLICATION hApp = NULL;
|
||||
HCONTAINER hContainer = NULL;
|
||||
// convert the
|
||||
}
|
||||
|
||||
int set_userpin(const char *pin)
|
||||
{
|
||||
if (strlen(pin) > sizeof(userpin)) {
|
||||
return 0;
|
||||
}
|
||||
strcpy(userpin, pin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_dev(const char *devname)
|
||||
{
|
||||
if ((rv = SKF_ConnectDev(dev, &hDev)) != SAR_OK) {
|
||||
goto end;
|
||||
}
|
||||
@@ -63,13 +152,22 @@ static int skf_open_container(const char *dev,
|
||||
goto end;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_app(const char *appname)
|
||||
{
|
||||
if ((rv = SKF_OpenApplication(hDev, appName, &hApp)) != SAR_OK) {
|
||||
goto end;
|
||||
}
|
||||
if ((rv = SKF_VerifyPIN(hApp, USER_TYPE, pin, &retryCount)) != SAR_OK) {
|
||||
goto end;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int open_container(const char *containername)
|
||||
{
|
||||
if ((rv = SKF_OpenContainer(hApp, containerName, &hContainer)) != SAR_OK) {
|
||||
goto end;
|
||||
}
|
||||
@@ -79,11 +177,27 @@ static int skf_open_container(const char *dev,
|
||||
if (containerType != CONTAINER_TYPE_ECC) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int skf_engine_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
|
||||
{
|
||||
switch (cmd) {
|
||||
case SKF_CMD_OPEN_DEV:
|
||||
return open_dev(p);
|
||||
case SKF_CMD_DEV_AUTH:
|
||||
return dev_auth(p);
|
||||
case SKF_CMD_OPEN_APP:
|
||||
return open_app(p);
|
||||
case SKF_CMD_VERIFY_PIN:
|
||||
return verify_pin(p);
|
||||
case SKF_CMD_OPEN_CONTAINER:
|
||||
return open_container(p);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static EVP_PKEY *skf_load_pubkey(ENGINE *e, const char *key_id,
|
||||
UI_METHOD *ui_method, void *callback_data)
|
||||
@@ -470,12 +584,30 @@ static int skf_digests(ENGINE *e, const EVP_MD **digest, const int **nids, int n
|
||||
}
|
||||
|
||||
|
||||
static int skf_rsa_sign(int type, const unsigned char *m, unsigned int mlen,
|
||||
unsigned char *sig, unsigned int *siglen, const RSA *rsa)
|
||||
{
|
||||
int ret = 0;
|
||||
ULONG rv;
|
||||
BYTE *pbData = (BYTE *)m;
|
||||
ULONG ulDataLen = (ULONG)mlen;
|
||||
BYTE signature[256];
|
||||
ULONG ulSigLen;
|
||||
|
||||
if ((rv = SKF_RSASignData(hContainer, pbData, ulDataLen,
|
||||
signature, &ulSigLen)) != SAR_OK) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static RSA_METHOD skf_rsa = {
|
||||
"SKF RSA method",
|
||||
skf_rsa_pub_enc,
|
||||
NULL,
|
||||
NULL,
|
||||
skf_rsa_priv_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
@@ -483,11 +615,52 @@ static RSA_METHOD skf_rsa = {
|
||||
RSA_FLAG_SIGN_VER,
|
||||
NULL,
|
||||
skf_rsa_sign,
|
||||
skf_rsa_verify,
|
||||
NULL
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
static ECDSA_SIG *skf_sm2_do_sign(const unsigned char *dgst, int dgstlen,
|
||||
const BIGNUM *a, const BIGNUM *b, EC_KEY *ec_key)
|
||||
{
|
||||
ECDSA_SIG *ret = NULL;
|
||||
ULONG rv;
|
||||
BYTE *pbDigest = (BYTE *)dgst;
|
||||
ULONG ulDigestLen = (ULONG)dgstlen,
|
||||
ECCSIGNATUREBLOB sigBlob;
|
||||
int ok = 0;
|
||||
|
||||
OPENSSL_assert(!a);
|
||||
OPENSSL_assert(!b);
|
||||
|
||||
if ((rv = SKF_ECCSignData(hContainer, pbDigest, ulDigestLen, &sigBlob)) != SAR_OK) {
|
||||
goto end;
|
||||
}
|
||||
if (!(ret = ECDSA_SIG_new())) {
|
||||
goto end;
|
||||
}
|
||||
if (!ECDSA_SIG_set_ECCSIGNATUREBLOB(group, ret, &sigBlob)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
end:
|
||||
if (!ok && ret) {
|
||||
ECDSA_SIG_free(ret);
|
||||
ret = NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ECDSA_METHOD skf_sm2sign = {
|
||||
"SKF ECDSA method (SM2 signature)",
|
||||
skf_sm2_do_sign,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
#ifdef OPENSSL_NO_DYNAMIC_ENGINE
|
||||
static ENGINE *engine_skf(void)
|
||||
@@ -536,6 +709,8 @@ static int bind(ENGINE *e, const char *id)
|
||||
!ENGINE_set_digests(e, skf_digests) ||
|
||||
!ENGINE_set_ciphers(e, skf_ciphers) ||
|
||||
!ENGINE_set_load_pubkey_function(e, skf_load_pubkey) ||
|
||||
!ENGINE_set_ECDSA(e, &skf_sm2sign) ||
|
||||
!ENGINE_set_RSA(e, &skf_rsa) ||
|
||||
!ENGINE_set_RAND(e, &skf_random)) {
|
||||
|
||||
return 0;
|
||||
|
||||
32
ssl/gm_lib.c
32
ssl/gm_lib.c
@@ -356,38 +356,6 @@ OPENSSL_GLOBAL SSL_CIPHER gm1_ciphers[] = {
|
||||
128,
|
||||
},
|
||||
|
||||
/* Cipher 13 (GmSSL specific) */
|
||||
{
|
||||
1,
|
||||
GM1_TXT_ECDHE_SM2_SM4_SM3,
|
||||
GM1_CK_ECDHE_SM2_SM4_SM3,
|
||||
SSL_kEECDH,
|
||||
SSL_aSM2,
|
||||
SSL_SM4,
|
||||
SSL_SM3,
|
||||
SSL_GMV1,
|
||||
SSL_NOT_EXP|SSL_HIGH,
|
||||
SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
|
||||
128,
|
||||
128,
|
||||
},
|
||||
|
||||
/* Cipher 14, (GmSSL Specific) */
|
||||
{
|
||||
1,
|
||||
GM1_TXT_SM2_SM4_SM3,
|
||||
GM1_CK_SM2_SM4_SM3,
|
||||
SSL_kSM2,
|
||||
SSL_aSM2,
|
||||
SSL_SM4,
|
||||
SSL_SM3,
|
||||
SSL_GMV1,
|
||||
SSL_NOT_EXP|SSL_HIGH,
|
||||
SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
|
||||
128,
|
||||
128,
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int gm1_num_ciphers(void)
|
||||
|
||||
35
ssl/s3_lib.c
35
ssl/s3_lib.c
@@ -2891,6 +2891,41 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[] = {
|
||||
256},
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_GMSSL
|
||||
/* (GmSSL specific) */
|
||||
{
|
||||
1,
|
||||
GM1_TXT_ECDHE_SM2_SM4_SM3,
|
||||
GM1_CK_ECDHE_SM2_SM4_SM3,
|
||||
SSL_kEECDH,
|
||||
SSL_aSM2,
|
||||
SSL_SM4,
|
||||
SSL_SM3,
|
||||
SSL_TLSV1_2,
|
||||
SSL_NOT_EXP|SSL_HIGH,
|
||||
SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
|
||||
128,
|
||||
128,
|
||||
},
|
||||
|
||||
/* (GmSSL Specific) */
|
||||
{
|
||||
1,
|
||||
GM1_TXT_SM2_SM4_SM3,
|
||||
GM1_CK_SM2_SM4_SM3,
|
||||
SSL_kSM2,
|
||||
SSL_aSM2,
|
||||
SSL_SM4,
|
||||
SSL_SM3,
|
||||
SSL_TLSV1_2,
|
||||
SSL_NOT_EXP|SSL_HIGH,
|
||||
SSL_HANDSHAKE_MAC_DEFAULT|TLS1_PRF,
|
||||
128,
|
||||
128,
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* end of list */
|
||||
};
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
# Perl c_rehash script, scan all files in a directory
|
||||
# and add symbolic links to their hash values.
|
||||
|
||||
my $dir = "/usr/local/ssl";
|
||||
my $prefix = "/usr/local/ssl";
|
||||
my $dir = "/usr/local/openssl";
|
||||
my $prefix = "/usr/local";
|
||||
|
||||
my $openssl = $ENV{OPENSSL} || "openssl";
|
||||
my $pwd;
|
||||
|
||||
Reference in New Issue
Block a user