Tongsuo icon indicating copy to clipboard operation
Tongsuo copied to clipboard

按照文档构建SM2签名算法失败

Open RideDi opened this issue 2 years ago • 6 comments

按照 SM2文档中的例子来实现一个demo的时候总是会出现段错误,请问是密钥生成部分不足还是?有没有修改方式呢? `

char          msg[] = "Performance Test!\n";
char          *priKey, *pubKey;
EVP_MD_CTX    *mctx = NULL;
EVP_PKEY      *pkey = NULL;
EVP_PKEY_CTX  *pctx = NULL;
unsigned char sig[1024];
EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
mctx = EVP_MD_CTX_new();
pctx = EVP_PKEY_CTX_new(pkey, NULL);
EVP_PKEY_CTX_set1_id(pctx, SM2_ID, SM2_ID_LEN);
EVP_MD_CTX_set_pkey_ctx(mctx, pctx);
EVP_DigestSignInit(mctx, NULL, EVP_sm3(), NULL, pkey);
EVP_DigestSignUpdate(mctx, msg, strlen(msg));
EVP_DigestSignFinal(mctx, sig, &sig_len);`

RideDi avatar Oct 20 '22 09:10 RideDi