mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-13 03:46:26 +08:00
jni api
This commit is contained in:
@@ -103,8 +103,8 @@ sm2_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
|
||||
sm2_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
|
||||
sm2_enc.o: ../../include/openssl/sm2.h ../../include/openssl/sm3.h
|
||||
sm2_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
sm2_enc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h sm2.h
|
||||
sm2_enc.o: sm2_enc.c
|
||||
sm2_enc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
|
||||
sm2_enc.o: ../o_str.h sm2_enc.c
|
||||
sm2_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
sm2_err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
|
||||
sm2_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
|
||||
@@ -228,6 +228,7 @@ void ERR_load_SM2_strings(void);
|
||||
# define SM2_F_SM2_CIPHERTEXT_VALUE_PRINT 103
|
||||
# define SM2_F_SM2_CIPHERTEXT_VALUE_SIZE 104
|
||||
# define SM2_F_SM2_COMPUTE_ID_DIGEST 105
|
||||
# define SM2_F_SM2_COMPUTE_ID_DIGEST_EX 127
|
||||
# define SM2_F_SM2_DECRYPT 106
|
||||
# define SM2_F_SM2_DO_DECRYPT 107
|
||||
# define SM2_F_SM2_DO_ENCRYPT 108
|
||||
|
||||
@@ -79,6 +79,7 @@ static ERR_STRING_DATA SM2_str_functs[] = {
|
||||
{ERR_FUNC(SM2_F_SM2_CIPHERTEXT_VALUE_PRINT), "SM2_CIPHERTEXT_VALUE_print"},
|
||||
{ERR_FUNC(SM2_F_SM2_CIPHERTEXT_VALUE_SIZE), "SM2_CIPHERTEXT_VALUE_size"},
|
||||
{ERR_FUNC(SM2_F_SM2_COMPUTE_ID_DIGEST), "SM2_compute_id_digest"},
|
||||
{ERR_FUNC(SM2_F_SM2_COMPUTE_ID_DIGEST_EX), "SM2_COMPUTE_ID_DIGEST_EX"},
|
||||
{ERR_FUNC(SM2_F_SM2_DECRYPT), "SM2_decrypt"},
|
||||
{ERR_FUNC(SM2_F_SM2_DO_DECRYPT), "SM2_do_decrypt"},
|
||||
{ERR_FUNC(SM2_F_SM2_DO_ENCRYPT), "SM2_do_encrypt"},
|
||||
|
||||
@@ -58,7 +58,7 @@ int SM2_KAP_CTX_init(SM2_KAP_CTX *ctx, EC_KEY *ec_key,
|
||||
{
|
||||
int ret = 0;
|
||||
int w;
|
||||
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ctx->id_dgst_md = EVP_sm3();
|
||||
@@ -90,7 +90,7 @@ int SM2_KAP_CTX_init(SM2_KAP_CTX *ctx, EC_KEY *ec_key,
|
||||
SM2err(SM2_F_SM2_KAP_CTX_INIT, ERR_R_EC_LIB);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
if (!SM2_compute_id_digest(ctx->id_dgst_md, ctx->remote_id_dgst,
|
||||
&ctx->remote_id_dgstlen, remote_pubkey)) {
|
||||
SM2err(SM2_F_SM2_KAP_CTX_INIT, 0);
|
||||
@@ -155,97 +155,6 @@ void SM2_KAP_CTX_cleanup(SM2_KAP_CTX *ctx)
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
#if 0
|
||||
int SM2_update_key(EC_KEY *ec_key, EC_POINT **point)
|
||||
{
|
||||
EC_KEY *tmp = NULL;
|
||||
BIGNUM *d = EC_KEY_get0_private_key(ec_key);
|
||||
|
||||
|
||||
if (!(tmp = EC_KEY_new())) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EC_KEY_set_group(tmp, EC_KEY_get0_group(ec_key))) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EC_KEY_generate_key(tmp)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EC_KEY_get_affine_coordinates(tmp, x, y)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* convert x to x' */
|
||||
|
||||
if (**point == NULL) {
|
||||
*point = EC_POINT_dup(EC_KEY_get0_public_key(ec_key), EC_KEY_get0_group(ec_key));
|
||||
} else {
|
||||
EC_POINT_copy(*point, EC_KEY_get0_public_key(ec_key), EC_KEY_get0_group(ec_key));
|
||||
}
|
||||
|
||||
end:
|
||||
EC_KEY_free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SM2_update_public_key(EC_KEY *ec_key, const EC_POINT *pub_key)
|
||||
{
|
||||
EC_GROUP *group;
|
||||
|
||||
|
||||
group = EC_KEY_get0_group(ec_key);
|
||||
|
||||
|
||||
|
||||
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) {
|
||||
if (!EC_POINT_get_affine_coordinates_GFp(group, pub_key, x, NULL, bn_ctx)) {
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
if (!EC_POINT_get_affine_coordinates_GF2m(group, pub_key, x, NULL, bn_ctx)) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
if (!BN_nnmod(x, x, ctx->two_pow_w, bn_ctx)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!BN_add(x, x, ctx->two_pow_w)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!BN_mod_mul(ctx->t, x, r, ctx->order, ctx->bn_ctx)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EC_POINT_mul(group, point, NULL, point, x, ctx->bn_ctx)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!EC_POINT_add(group, pubkey, pubkey, point, bn_ctx)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SM2_derive_key(void *out, size_t outlen,
|
||||
const EC_POINT *pub_key, EC_KEY *ec_key,
|
||||
void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen))
|
||||
{
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* FIXME: ephem_point_len should be both input and output */
|
||||
int SM2_KAP_prepare(SM2_KAP_CTX *ctx, unsigned char *ephem_point,
|
||||
size_t *ephem_point_len)
|
||||
@@ -306,7 +215,7 @@ int SM2_KAP_prepare(SM2_KAP_CTX *ctx, unsigned char *ephem_point,
|
||||
* w = ceil(keybits / 2) - 1
|
||||
* x = 2^w + (x and (2^w - 1)) = 2^w + (x mod 2^w)
|
||||
* t = (d + x * r) mod n
|
||||
* t = (h * t) mod n
|
||||
* t = (h * t) mod n
|
||||
*/
|
||||
|
||||
if (!ctx->t) {
|
||||
@@ -377,7 +286,7 @@ int SM2_KAP_compute_key(SM2_KAP_CTX *ctx, const unsigned char *remote_point,
|
||||
unsigned int len, bnlen;
|
||||
size_t klen = keylen;
|
||||
|
||||
|
||||
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
|
||||
if (!(x = BN_new())) {
|
||||
|
||||
@@ -199,6 +199,14 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SM2_compute_id_digest_ex(const EVP_MD *md,
|
||||
unsigned char *dgst, size_t dgstlen,
|
||||
const char *id, size_t idlen, EC_KEY *ec_key)
|
||||
{
|
||||
SM2err(SM2_F_SM2_COMPUTE_ID_DIGEST_EX, ERR_R_SM2_LIB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO: review this function again.
|
||||
int SM2_compute_id_digest(const EVP_MD *md, unsigned char *dgst,
|
||||
unsigned int *dgstlen, EC_KEY *ec_key)
|
||||
@@ -209,7 +217,7 @@ int SM2_compute_id_digest(const EVP_MD *md, unsigned char *dgst,
|
||||
unsigned char idbits[2];
|
||||
int pkdatalen;
|
||||
char *id;
|
||||
|
||||
|
||||
if ((pkdatalen = sm2_get_public_key_data(pkdata, ec_key)) < 0) {
|
||||
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
|
||||
goto err;
|
||||
@@ -272,7 +280,7 @@ int SM2_compute_message_digest(const EVP_MD *id_md, const EVP_MD *msg_md,
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!SM2_compute_id_digest(id_md, buf, &len, ec_key)) {
|
||||
if (!SM2_compute_id_digest(id_md, buf, &len, ec_key)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -300,7 +308,7 @@ int SM2_digest(const void *msg, size_t msglen, unsigned char *dgst,
|
||||
{
|
||||
const EVP_MD *id_md = EVP_sm3();
|
||||
const EVP_MD *msg_md = EVP_sm3();
|
||||
|
||||
|
||||
return SM2_compute_message_digest(id_md, msg_md,
|
||||
msg, msglen, dgst, dgstlen, ec_key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user