提交 2167239a 编写于 作者: M Matt Caswell

Use lowercase for internal SM2 symbols

Reviewed-by: NRichard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6386)
上级 206521a0
......@@ -126,7 +126,7 @@ static int pkey_ec_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
#if defined(OPENSSL_NO_SM2)
return -1;
#else
ret = SM2_sign(type, tbs, tbslen, sig, &sltmp, ec);
ret = sm2_sign(type, tbs, tbslen, sig, &sltmp, ec);
#endif
} else {
ret = ECDSA_sign(type, tbs, tbslen, sig, &sltmp, ec);
......@@ -156,7 +156,7 @@ static int pkey_ec_verify(EVP_PKEY_CTX *ctx,
#if defined(OPENSSL_NO_SM2)
ret = -1;
#else
ret = SM2_verify(type, tbs, tbslen, sig, siglen, ec);
ret = sm2_verify(type, tbs, tbslen, sig, siglen, ec);
#endif
} else {
ret = ECDSA_verify(type, tbs, tbslen, sig, siglen, ec);
......@@ -223,14 +223,14 @@ static int pkey_ecies_encrypt(EVP_PKEY_CTX *ctx,
md_type = NID_sm3;
if (out == NULL) {
if (!SM2_ciphertext_size(ec, EVP_get_digestbynid(md_type), inlen,
if (!sm2_ciphertext_size(ec, EVP_get_digestbynid(md_type), inlen,
outlen))
ret = -1;
else
ret = 1;
}
else {
ret = SM2_encrypt(ec, EVP_get_digestbynid(md_type),
ret = sm2_encrypt(ec, EVP_get_digestbynid(md_type),
in, inlen, out, outlen);
}
# endif
......@@ -263,14 +263,14 @@ static int pkey_ecies_decrypt(EVP_PKEY_CTX *ctx,
md_type = NID_sm3;
if (out == NULL) {
if (!SM2_plaintext_size(ec, EVP_get_digestbynid(md_type), inlen,
if (!sm2_plaintext_size(ec, EVP_get_digestbynid(md_type), inlen,
outlen))
ret = -1;
else
ret = 1;
}
else {
ret = SM2_decrypt(ec, EVP_get_digestbynid(md_type),
ret = sm2_decrypt(ec, EVP_get_digestbynid(md_type),
in, inlen, out, outlen);
}
# endif
......
......@@ -1068,15 +1068,15 @@ SM2_F_PKEY_SM2_CTRL_STR:275:pkey_sm2_ctrl_str
SM2_F_PKEY_SM2_KEYGEN:276:pkey_sm2_keygen
SM2_F_PKEY_SM2_PARAMGEN:277:pkey_sm2_paramgen
SM2_F_PKEY_SM2_SIGN:278:pkey_sm2_sign
SM2_F_SM2_COMPUTE_MSG_HASH:284:SM2_compute_msg_hash
SM2_F_SM2_COMPUTE_USERID_DIGEST:286:SM2_compute_userid_digest
SM2_F_SM2_DECRYPT:279:SM2_decrypt
SM2_F_SM2_ENCRYPT:280:SM2_encrypt
SM2_F_SM2_PLAINTEXT_SIZE:287:SM2_plaintext_size
SM2_F_SM2_SIGN:281:SM2_sign
SM2_F_SM2_SIG_GEN:285:SM2_sig_gen
SM2_F_SM2_SIG_VERIFY:282:SM2_sig_verify
SM2_F_SM2_VERIFY:283:SM2_verify
SM2_F_SM2_COMPUTE_MSG_HASH:284:sm2_compute_msg_hash
SM2_F_SM2_COMPUTE_USERID_DIGEST:286:sm2_compute_userid_digest
SM2_F_SM2_DECRYPT:279:sm2_decrypt
SM2_F_SM2_ENCRYPT:280:sm2_encrypt
SM2_F_SM2_PLAINTEXT_SIZE:287:sm2_plaintext_size
SM2_F_SM2_SIGN:281:sm2_sign
SM2_F_SM2_SIG_GEN:285:sm2_sig_gen
SM2_F_SM2_SIG_VERIFY:282:sm2_sig_verify
SM2_F_SM2_VERIFY:283:sm2_verify
SSL_F_ADD_CLIENT_KEY_SHARE_EXT:438:*
SSL_F_ADD_KEY_SHARE:512:add_key_share
SSL_F_BYTES_TO_CIPHER_LIST:519:bytes_to_cipher_list
......
......@@ -24,7 +24,7 @@ extern "C" {
/* The default user id as specified in GM/T 0009-2012 */
# define SM2_DEFAULT_USERID "1234567812345678"
int SM2_compute_userid_digest(uint8_t *out,
int sm2_compute_userid_digest(uint8_t *out,
const EVP_MD *digest,
const char *user_id, const EC_KEY *key);
......@@ -32,11 +32,11 @@ int SM2_compute_userid_digest(uint8_t *out,
* SM2 signature operation. Computes ZA (user id digest) and then signs
* H(ZA || msg) using SM2
*/
ECDSA_SIG *SM2_do_sign(const EC_KEY *key,
ECDSA_SIG *sm2_do_sign(const EC_KEY *key,
const EVP_MD *digest,
const char *user_id, const uint8_t *msg, size_t msg_len);
int SM2_do_verify(const EC_KEY *key,
int sm2_do_verify(const EC_KEY *key,
const EVP_MD *digest,
const ECDSA_SIG *signature,
const char *user_id, const uint8_t *msg, size_t msg_len);
......@@ -44,32 +44,32 @@ int SM2_do_verify(const EC_KEY *key,
/*
* SM2 signature generation. Assumes input is an SM3 digest
*/
int SM2_sign(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 *eckey);
/*
* SM2 signature verification. Assumes input is an SM3 digest
*/
int SM2_verify(int type, const unsigned char *dgst, int dgstlen,
int sm2_verify(int type, const unsigned char *dgst, int dgstlen,
const unsigned char *sig, int siglen, EC_KEY *eckey);
/*
* SM2 encryption
*/
int SM2_ciphertext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
int sm2_ciphertext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
size_t *ct_size);
int SM2_plaintext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
int sm2_plaintext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
size_t *pt_size);
int SM2_encrypt(const EC_KEY *key,
int sm2_encrypt(const EC_KEY *key,
const EVP_MD *digest,
const uint8_t *msg,
size_t msg_len,
uint8_t *ciphertext_buf, size_t *ciphertext_len);
int SM2_decrypt(const EC_KEY *key,
int sm2_decrypt(const EC_KEY *key,
const EVP_MD *digest,
const uint8_t *ciphertext,
size_t ciphertext_len, uint8_t *ptext_buf, size_t *ptext_len);
......
......@@ -37,7 +37,7 @@ ASN1_SEQUENCE(SM2_Ciphertext) = {
IMPLEMENT_ASN1_FUNCTIONS(SM2_Ciphertext)
static size_t EC_field_size(const EC_GROUP *group)
static size_t ec_field_size(const EC_GROUP *group)
{
/* Is there some simpler way to do this? */
BIGNUM *p = BN_new();
......@@ -59,10 +59,10 @@ static size_t EC_field_size(const EC_GROUP *group)
return field_size;
}
int SM2_plaintext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
int sm2_plaintext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
size_t *pt_size)
{
const size_t field_size = EC_field_size(EC_KEY_get0_group(key));
const size_t field_size = ec_field_size(EC_KEY_get0_group(key));
const int md_size = EVP_MD_size(digest);
size_t overhead;
......@@ -85,10 +85,10 @@ int SM2_plaintext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
return 1;
}
int SM2_ciphertext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
int sm2_ciphertext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
size_t *ct_size)
{
const size_t field_size = EC_field_size(EC_KEY_get0_group(key));
const size_t field_size = ec_field_size(EC_KEY_get0_group(key));
const int md_size = EVP_MD_size(digest);
if (field_size == 0 || md_size < 0)
......@@ -98,7 +98,7 @@ int SM2_ciphertext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
return 1;
}
int SM2_encrypt(const EC_KEY *key,
int sm2_encrypt(const EC_KEY *key,
const EVP_MD *digest,
const uint8_t *msg,
size_t msg_len, uint8_t *ciphertext_buf, size_t *ciphertext_len)
......@@ -121,7 +121,7 @@ int SM2_encrypt(const EC_KEY *key,
uint8_t *msg_mask = NULL;
uint8_t *x2y2 = NULL;
uint8_t *C3 = NULL;
const size_t field_size = EC_field_size(group);
const size_t field_size = ec_field_size(group);
const size_t C3_size = EVP_MD_size(digest);
/* NULL these before any "goto done" */
......@@ -250,7 +250,7 @@ int SM2_encrypt(const EC_KEY *key,
return rc;
}
int SM2_decrypt(const EC_KEY *key,
int sm2_decrypt(const EC_KEY *key,
const EVP_MD *digest,
const uint8_t *ciphertext,
size_t ciphertext_len, uint8_t *ptext_buf, size_t *ptext_len)
......@@ -265,7 +265,7 @@ int SM2_decrypt(const EC_KEY *key,
BIGNUM *y2 = NULL;
uint8_t *x2y2 = NULL;
uint8_t *computed_C3 = NULL;
const size_t field_size = EC_field_size(group);
const size_t field_size = ec_field_size(group);
const int hash_size = EVP_MD_size(digest);
uint8_t *msg_mask = NULL;
const uint8_t *C2 = NULL;
......
......@@ -20,16 +20,16 @@ static const ERR_STRING_DATA SM2_str_functs[] = {
{ERR_PACK(ERR_LIB_SM2, SM2_F_PKEY_SM2_PARAMGEN, 0), "pkey_sm2_paramgen"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_PKEY_SM2_SIGN, 0), "pkey_sm2_sign"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_COMPUTE_MSG_HASH, 0),
"SM2_compute_msg_hash"},
"sm2_compute_msg_hash"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_COMPUTE_USERID_DIGEST, 0),
"SM2_compute_userid_digest"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_DECRYPT, 0), "SM2_decrypt"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_ENCRYPT, 0), "SM2_encrypt"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_PLAINTEXT_SIZE, 0), "SM2_plaintext_size"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_SIGN, 0), "SM2_sign"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_SIG_GEN, 0), "SM2_sig_gen"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_SIG_VERIFY, 0), "SM2_sig_verify"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_VERIFY, 0), "SM2_verify"},
"sm2_compute_userid_digest"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_DECRYPT, 0), "sm2_decrypt"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_ENCRYPT, 0), "sm2_encrypt"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_PLAINTEXT_SIZE, 0), "sm2_plaintext_size"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_SIGN, 0), "sm2_sign"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_SIG_GEN, 0), "sm2_sig_gen"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_SIG_VERIFY, 0), "sm2_sig_verify"},
{ERR_PACK(ERR_LIB_SM2, SM2_F_SM2_VERIFY, 0), "sm2_verify"},
{0, NULL}
};
......
......@@ -17,7 +17,7 @@
#include <openssl/bn.h>
#include <string.h>
static BIGNUM *SM2_compute_msg_hash(const EVP_MD *digest,
static BIGNUM *sm2_compute_msg_hash(const EVP_MD *digest,
const EC_KEY *key,
const char *user_id,
const uint8_t *msg, size_t msg_len)
......@@ -37,7 +37,7 @@ static BIGNUM *SM2_compute_msg_hash(const EVP_MD *digest,
goto done;
}
if (!SM2_compute_userid_digest(za, digest, user_id, key)) {
if (!sm2_compute_userid_digest(za, digest, user_id, key)) {
/* SM2err already called */
goto done;
}
......@@ -61,7 +61,7 @@ static BIGNUM *SM2_compute_msg_hash(const EVP_MD *digest,
return e;
}
static ECDSA_SIG *SM2_sig_gen(const EC_KEY *key, const BIGNUM *e)
static ECDSA_SIG *sm2_sig_gen(const EC_KEY *key, const BIGNUM *e)
{
const BIGNUM *dA = EC_KEY_get0_private_key(key);
const EC_GROUP *group = EC_KEY_get0_group(key);
......@@ -163,7 +163,7 @@ static ECDSA_SIG *SM2_sig_gen(const EC_KEY *key, const BIGNUM *e)
return sig;
}
static int SM2_sig_verify(const EC_KEY *key, const ECDSA_SIG *sig,
static int sm2_sig_verify(const EC_KEY *key, const ECDSA_SIG *sig,
const BIGNUM *e)
{
int ret = 0;
......@@ -241,27 +241,27 @@ static int SM2_sig_verify(const EC_KEY *key, const ECDSA_SIG *sig,
return ret;
}
ECDSA_SIG *SM2_do_sign(const EC_KEY *key,
ECDSA_SIG *sm2_do_sign(const EC_KEY *key,
const EVP_MD *digest,
const char *user_id, const uint8_t *msg, size_t msg_len)
{
BIGNUM *e = NULL;
ECDSA_SIG *sig = NULL;
e = SM2_compute_msg_hash(digest, key, user_id, msg, msg_len);
e = sm2_compute_msg_hash(digest, key, user_id, msg, msg_len);
if (e == NULL) {
/* SM2err already called */
goto done;
}
sig = SM2_sig_gen(key, e);
sig = sm2_sig_gen(key, e);
done:
BN_free(e);
return sig;
}
int SM2_do_verify(const EC_KEY *key,
int sm2_do_verify(const EC_KEY *key,
const EVP_MD *digest,
const ECDSA_SIG *sig,
const char *user_id, const uint8_t *msg, size_t msg_len)
......@@ -269,20 +269,20 @@ int SM2_do_verify(const EC_KEY *key,
BIGNUM *e = NULL;
int ret = 0;
e = SM2_compute_msg_hash(digest, key, user_id, msg, msg_len);
e = sm2_compute_msg_hash(digest, key, user_id, msg, msg_len);
if (e == NULL) {
/* SM2err already called */
goto done;
}
ret = SM2_sig_verify(key, sig, e);
ret = sm2_sig_verify(key, sig, e);
done:
BN_free(e);
return ret;
}
int SM2_sign(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 *eckey)
{
BIGNUM *e = NULL;
......@@ -301,7 +301,7 @@ int SM2_sign(int type, const unsigned char *dgst, int dgstlen,
goto done;
}
s = SM2_sig_gen(eckey, e);
s = sm2_sig_gen(eckey, e);
sigleni = i2d_ECDSA_SIG(s, &sig);
if (sigleni < 0) {
......@@ -318,7 +318,7 @@ int SM2_sign(int type, const unsigned char *dgst, int dgstlen,
return ret;
}
int SM2_verify(int type, const unsigned char *dgst, int dgstlen,
int sm2_verify(int type, const unsigned char *dgst, int dgstlen,
const unsigned char *sig, int sig_len, EC_KEY *eckey)
{
ECDSA_SIG *s = NULL;
......@@ -355,7 +355,7 @@ int SM2_verify(int type, const unsigned char *dgst, int dgstlen,
goto done;
}
ret = SM2_sig_verify(eckey, s, e);
ret = sm2_sig_verify(eckey, s, e);
done:
OPENSSL_free(der);
......
......@@ -16,7 +16,7 @@
#include <openssl/bn.h>
#include <string.h>
int SM2_compute_userid_digest(uint8_t *out,
int sm2_compute_userid_digest(uint8_t *out,
const EVP_MD *digest,
const char *user_id,
const EC_KEY *key)
......
......@@ -161,7 +161,7 @@ static int test_sm2_crypt(const EC_GROUP *group,
if (!TEST_ptr(pt)
|| !TEST_true(EC_POINT_mul(group, pt, priv, NULL, NULL, NULL))
|| !TEST_true(EC_KEY_set_public_key(key, pt))
|| !TEST_true(SM2_ciphertext_size(key, digest, msg_len, &ctext_len)))
|| !TEST_true(sm2_ciphertext_size(key, digest, msg_len, &ctext_len)))
goto done;
ctext = OPENSSL_zalloc(ctext_len);
......@@ -169,7 +169,7 @@ static int test_sm2_crypt(const EC_GROUP *group,
goto done;
start_fake_rand(k_hex);
if (!TEST_true(SM2_encrypt(key, digest, (const uint8_t *)message, msg_len,
if (!TEST_true(sm2_encrypt(key, digest, (const uint8_t *)message, msg_len,
ctext, &ctext_len))) {
restore_rand();
goto done;
......@@ -179,13 +179,13 @@ static int test_sm2_crypt(const EC_GROUP *group,
if (!TEST_mem_eq(ctext, ctext_len, expected, ctext_len))
goto done;
if (!TEST_true(SM2_plaintext_size(key, digest, ctext_len, &ptext_len))
if (!TEST_true(sm2_plaintext_size(key, digest, ctext_len, &ptext_len))
|| !TEST_int_eq(ptext_len, msg_len))
goto done;
recovered = OPENSSL_zalloc(ptext_len);
if (!TEST_ptr(recovered)
|| !TEST_true(SM2_decrypt(key, digest, ctext, ctext_len, recovered, &recovered_len))
|| !TEST_true(sm2_decrypt(key, digest, ctext, ctext_len, recovered, &recovered_len))
|| !TEST_int_eq(recovered_len, msg_len)
|| !TEST_mem_eq(recovered, recovered_len, message, msg_len))
goto done;
......@@ -284,7 +284,7 @@ static int test_sm2_sign(const EC_GROUP *group,
goto done;
start_fake_rand(k_hex);
sig = SM2_do_sign(key, EVP_sm3(), userid, (const uint8_t *)message, msg_len);
sig = sm2_do_sign(key, EVP_sm3(), userid, (const uint8_t *)message, msg_len);
restore_rand();
if (!TEST_ptr(sig))
......@@ -298,7 +298,7 @@ static int test_sm2_sign(const EC_GROUP *group,
|| !TEST_BN_eq(s, sig_s))
goto done;
ok = SM2_do_verify(key, EVP_sm3(), sig, userid, (const uint8_t *)message,
ok = sm2_do_verify(key, EVP_sm3(), sig, userid, (const uint8_t *)message,
msg_len);
/* We goto done whether this passes or fails */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册