我正在尝试使用客户引擎实现 ECDSA,但在 EVP_DigestSignFinal(mdctx, sig, slen)) 这一行遇到错误。谁能指导我。
引擎部分-->
EVP_PKEY_meth_set_sign(dasync_ec, dasync_ec_signinit,
dasync_ec_sign);
static int dasync_ec_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)
{
static int (*psign)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen);
if (psign == NULL)
EVP_PKEY_meth_get_sign(dasync_ec_orig, NULL, &psign);
return psign(ctx,sig,siglen,tbs,tbslen);
}
测试端-->
EVP_MD_CTX *mdctx=NULL;
EVP_PKEY *pkey = EVP_PKEY_new();
EC_KEY *eckey=NULL;
eckey=EC_KEY_new();
size_t *slen;
EVP_PKEY_assign_EC_KEY(pkey,eckey);
if(!(mdctx = EVP_MD_CTX_create()))
goto err;
if(1 != EVP_DigestSignInit(mdctx, NULL, EVP_sha256(), my_engine, pkey))
goto err;
if(1 != EVP_DigestSignUpdate(mdctx, msg, strlen(msg)))
goto err;
if(1 != EVP_DigestSignFinal(mdctx, NULL, slen))
goto err;
if(!(*sig = OPENSSL_malloc(sizeof(unsigned char) * (*slen))))
goto err;
if(1 != EVP_DigestSignFinal(mdctx, sig, slen))
goto err;