uint8_t e_byte = 0;
hash = EVP_MD_CTX_new();
- ctx = BN_CTX_new();
+ ctx = BN_CTX_new_ex(ec_key_get_libctx(key));
if (hash == NULL || ctx == NULL) {
SM2err(SM2_F_SM2_COMPUTE_Z_DIGEST, ERR_R_MALLOC_FAILURE);
goto done;
const int md_size = EVP_MD_size(digest);
uint8_t *z = NULL;
BIGNUM *e = NULL;
+ EVP_MD *fetched_digest = NULL;
+ OPENSSL_CTX *libctx = ec_key_get_libctx(key);
+ const char *propq = ec_key_get0_propq(key);
if (md_size < 0) {
SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, SM2_R_INVALID_DIGEST);
goto done;
}
- if (!sm2_compute_z_digest(z, digest, id, id_len, key)) {
+ fetched_digest = EVP_MD_fetch(libctx, EVP_MD_name(digest), propq);
+ if (fetched_digest == NULL) {
+ SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, ERR_R_INTERNAL_ERROR);
+ goto done;
+ }
+
+ if (!sm2_compute_z_digest(z, fetched_digest, id, id_len, key)) {
/* SM2err already called */
goto done;
}
- if (!EVP_DigestInit(hash, digest)
+ if (!EVP_DigestInit(hash, fetched_digest)
|| !EVP_DigestUpdate(hash, z, md_size)
|| !EVP_DigestUpdate(hash, msg, msg_len)
/* reuse z buffer to hold H(Z || M) */
SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, ERR_R_INTERNAL_ERROR);
done:
+ EVP_MD_free(fetched_digest);
OPENSSL_free(z);
EVP_MD_CTX_free(hash);
return e;
BIGNUM *s = NULL;
BIGNUM *x1 = NULL;
BIGNUM *tmp = NULL;
+ OPENSSL_CTX *libctx = ec_key_get_libctx(key);
kG = EC_POINT_new(group);
- ctx = BN_CTX_new();
+ ctx = BN_CTX_new_ex(libctx);
if (kG == NULL || ctx == NULL) {
SM2err(SM2_F_SM2_SIG_GEN, ERR_R_MALLOC_FAILURE);
goto done;
}
for (;;) {
- if (!BN_priv_rand_range(k, order)) {
+ if (!BN_priv_rand_range_ex(k, order, ctx)) {
SM2err(SM2_F_SM2_SIG_GEN, ERR_R_INTERNAL_ERROR);
goto done;
}
BIGNUM *x1 = NULL;
const BIGNUM *r = NULL;
const BIGNUM *s = NULL;
+ OPENSSL_CTX *libctx = ec_key_get_libctx(key);
- ctx = BN_CTX_new();
+ ctx = BN_CTX_new_ex(libctx);
pt = EC_POINT_new(group);
if (ctx == NULL || pt == NULL) {
SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_MALLOC_FAILURE);
}
s = sm2_sig_gen(eckey, e);
+ if (s == NULL) {
+ SM2err(SM2_F_SM2_SIGN, ERR_R_INTERNAL_ERROR);
+ goto done;
+ }
sigleni = i2d_ECDSA_SIG(s, &sig);
if (sigleni < 0) {