#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);
#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);
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
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
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
/* 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);
* 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);
/*
* 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);
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();
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;
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)
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)
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" */
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)
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;
{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}
};
#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)
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;
}
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);
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;
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)
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;
goto done;
}
- s = SM2_sig_gen(eckey, e);
+ s = sm2_sig_gen(eckey, e);
sigleni = i2d_ECDSA_SIG(s, &sig);
if (sigleni < 0) {
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;
goto done;
}
- ret = SM2_sig_verify(eckey, s, e);
+ ret = sm2_sig_verify(eckey, s, e);
done:
OPENSSL_free(der);
#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)
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);
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;
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;
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))
|| !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 */