sm2_sig.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*
  2. * Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /*
  10. * ECDSA low level APIs are deprecated for public use, but still ok for
  11. * internal use - SM2 implementation uses ECDSA_size() function.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <string.h> /* memcpy */
  15. #include <openssl/crypto.h>
  16. #include <openssl/core_dispatch.h>
  17. #include <openssl/core_names.h>
  18. #include <openssl/dsa.h>
  19. #include <openssl/params.h>
  20. #include <openssl/evp.h>
  21. #include <openssl/err.h>
  22. #include <openssl/proverr.h>
  23. #include "internal/nelem.h"
  24. #include "internal/sizes.h"
  25. #include "internal/cryptlib.h"
  26. #include "internal/sm3.h"
  27. #include "prov/implementations.h"
  28. #include "prov/providercommon.h"
  29. #include "prov/provider_ctx.h"
  30. #include "crypto/ec.h"
  31. #include "crypto/sm2.h"
  32. #include "prov/der_sm2.h"
  33. static OSSL_FUNC_signature_newctx_fn sm2sig_newctx;
  34. static OSSL_FUNC_signature_sign_init_fn sm2sig_signature_init;
  35. static OSSL_FUNC_signature_verify_init_fn sm2sig_signature_init;
  36. static OSSL_FUNC_signature_sign_fn sm2sig_sign;
  37. static OSSL_FUNC_signature_verify_fn sm2sig_verify;
  38. static OSSL_FUNC_signature_digest_sign_init_fn sm2sig_digest_signverify_init;
  39. static OSSL_FUNC_signature_digest_sign_update_fn sm2sig_digest_signverify_update;
  40. static OSSL_FUNC_signature_digest_sign_final_fn sm2sig_digest_sign_final;
  41. static OSSL_FUNC_signature_digest_verify_init_fn sm2sig_digest_signverify_init;
  42. static OSSL_FUNC_signature_digest_verify_update_fn sm2sig_digest_signverify_update;
  43. static OSSL_FUNC_signature_digest_verify_final_fn sm2sig_digest_verify_final;
  44. static OSSL_FUNC_signature_freectx_fn sm2sig_freectx;
  45. static OSSL_FUNC_signature_dupctx_fn sm2sig_dupctx;
  46. static OSSL_FUNC_signature_get_ctx_params_fn sm2sig_get_ctx_params;
  47. static OSSL_FUNC_signature_gettable_ctx_params_fn sm2sig_gettable_ctx_params;
  48. static OSSL_FUNC_signature_set_ctx_params_fn sm2sig_set_ctx_params;
  49. static OSSL_FUNC_signature_settable_ctx_params_fn sm2sig_settable_ctx_params;
  50. static OSSL_FUNC_signature_get_ctx_md_params_fn sm2sig_get_ctx_md_params;
  51. static OSSL_FUNC_signature_gettable_ctx_md_params_fn sm2sig_gettable_ctx_md_params;
  52. static OSSL_FUNC_signature_set_ctx_md_params_fn sm2sig_set_ctx_md_params;
  53. static OSSL_FUNC_signature_settable_ctx_md_params_fn sm2sig_settable_ctx_md_params;
  54. /*
  55. * What's passed as an actual key is defined by the KEYMGMT interface.
  56. * We happen to know that our KEYMGMT simply passes EC structures, so
  57. * we use that here too.
  58. */
  59. typedef struct {
  60. OSSL_LIB_CTX *libctx;
  61. char *propq;
  62. EC_KEY *ec;
  63. /*
  64. * Flag to determine if the 'z' digest needs to be computed and fed to the
  65. * hash function.
  66. * This flag should be set on initialization and the computation should
  67. * be performed only once, on first update.
  68. */
  69. unsigned int flag_compute_z_digest : 1;
  70. char mdname[OSSL_MAX_NAME_SIZE];
  71. /* The Algorithm Identifier of the combined signature algorithm */
  72. unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
  73. size_t aid_len;
  74. /* main digest */
  75. EVP_MD *md;
  76. EVP_MD_CTX *mdctx;
  77. size_t mdsize;
  78. /* SM2 ID used for calculating the Z value */
  79. unsigned char *id;
  80. size_t id_len;
  81. } PROV_SM2_CTX;
  82. static int sm2sig_set_mdname(PROV_SM2_CTX *psm2ctx, const char *mdname)
  83. {
  84. if (psm2ctx->md == NULL) /* We need an SM3 md to compare with */
  85. psm2ctx->md = EVP_MD_fetch(psm2ctx->libctx, psm2ctx->mdname,
  86. psm2ctx->propq);
  87. if (psm2ctx->md == NULL)
  88. return 0;
  89. /* XOF digests don't work */
  90. if (EVP_MD_xof(psm2ctx->md)) {
  91. ERR_raise(ERR_LIB_PROV, PROV_R_XOF_DIGESTS_NOT_ALLOWED);
  92. return 0;
  93. }
  94. if (mdname == NULL)
  95. return 1;
  96. if (strlen(mdname) >= sizeof(psm2ctx->mdname)
  97. || !EVP_MD_is_a(psm2ctx->md, mdname)) {
  98. ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, "digest=%s",
  99. mdname);
  100. return 0;
  101. }
  102. OPENSSL_strlcpy(psm2ctx->mdname, mdname, sizeof(psm2ctx->mdname));
  103. return 1;
  104. }
  105. static void *sm2sig_newctx(void *provctx, const char *propq)
  106. {
  107. PROV_SM2_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_SM2_CTX));
  108. if (ctx == NULL)
  109. return NULL;
  110. ctx->libctx = PROV_LIBCTX_OF(provctx);
  111. if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL) {
  112. OPENSSL_free(ctx);
  113. return NULL;
  114. }
  115. ctx->mdsize = SM3_DIGEST_LENGTH;
  116. strcpy(ctx->mdname, OSSL_DIGEST_NAME_SM3);
  117. return ctx;
  118. }
  119. static int sm2sig_signature_init(void *vpsm2ctx, void *ec,
  120. const OSSL_PARAM params[])
  121. {
  122. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  123. if (!ossl_prov_is_running()
  124. || psm2ctx == NULL)
  125. return 0;
  126. if (ec == NULL && psm2ctx->ec == NULL) {
  127. ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
  128. return 0;
  129. }
  130. if (ec != NULL) {
  131. if (!EC_KEY_up_ref(ec))
  132. return 0;
  133. EC_KEY_free(psm2ctx->ec);
  134. psm2ctx->ec = ec;
  135. }
  136. return sm2sig_set_ctx_params(psm2ctx, params);
  137. }
  138. static int sm2sig_sign(void *vpsm2ctx, unsigned char *sig, size_t *siglen,
  139. size_t sigsize, const unsigned char *tbs, size_t tbslen)
  140. {
  141. PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
  142. int ret;
  143. unsigned int sltmp;
  144. /* SM2 uses ECDSA_size as well */
  145. size_t ecsize = ECDSA_size(ctx->ec);
  146. if (sig == NULL) {
  147. *siglen = ecsize;
  148. return 1;
  149. }
  150. if (sigsize < (size_t)ecsize)
  151. return 0;
  152. if (ctx->mdsize != 0 && tbslen != ctx->mdsize)
  153. return 0;
  154. ret = ossl_sm2_internal_sign(tbs, tbslen, sig, &sltmp, ctx->ec);
  155. if (ret <= 0)
  156. return 0;
  157. *siglen = sltmp;
  158. return 1;
  159. }
  160. static int sm2sig_verify(void *vpsm2ctx, const unsigned char *sig, size_t siglen,
  161. const unsigned char *tbs, size_t tbslen)
  162. {
  163. PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
  164. if (ctx->mdsize != 0 && tbslen != ctx->mdsize)
  165. return 0;
  166. return ossl_sm2_internal_verify(tbs, tbslen, sig, siglen, ctx->ec);
  167. }
  168. static void free_md(PROV_SM2_CTX *ctx)
  169. {
  170. EVP_MD_CTX_free(ctx->mdctx);
  171. EVP_MD_free(ctx->md);
  172. ctx->mdctx = NULL;
  173. ctx->md = NULL;
  174. }
  175. static int sm2sig_digest_signverify_init(void *vpsm2ctx, const char *mdname,
  176. void *ec, const OSSL_PARAM params[])
  177. {
  178. PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
  179. int md_nid;
  180. WPACKET pkt;
  181. int ret = 0;
  182. unsigned char *aid = NULL;
  183. if (!sm2sig_signature_init(vpsm2ctx, ec, params)
  184. || !sm2sig_set_mdname(ctx, mdname))
  185. return ret;
  186. if (ctx->mdctx == NULL) {
  187. ctx->mdctx = EVP_MD_CTX_new();
  188. if (ctx->mdctx == NULL)
  189. goto error;
  190. }
  191. md_nid = EVP_MD_get_type(ctx->md);
  192. /*
  193. * We do not care about DER writing errors.
  194. * All it really means is that for some reason, there's no
  195. * AlgorithmIdentifier to be had, but the operation itself is
  196. * still valid, just as long as it's not used to construct
  197. * anything that needs an AlgorithmIdentifier.
  198. */
  199. ctx->aid_len = 0;
  200. if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
  201. && ossl_DER_w_algorithmIdentifier_SM2_with_MD(&pkt, -1, ctx->ec, md_nid)
  202. && WPACKET_finish(&pkt)) {
  203. WPACKET_get_total_written(&pkt, &ctx->aid_len);
  204. aid = WPACKET_get_curr(&pkt);
  205. }
  206. WPACKET_cleanup(&pkt);
  207. if (aid != NULL && ctx->aid_len != 0)
  208. memmove(ctx->aid_buf, aid, ctx->aid_len);
  209. if (!EVP_DigestInit_ex2(ctx->mdctx, ctx->md, params))
  210. goto error;
  211. ctx->flag_compute_z_digest = 1;
  212. ret = 1;
  213. error:
  214. return ret;
  215. }
  216. static int sm2sig_compute_z_digest(PROV_SM2_CTX *ctx)
  217. {
  218. uint8_t *z = NULL;
  219. int ret = 1;
  220. if (ctx->flag_compute_z_digest) {
  221. /* Only do this once */
  222. ctx->flag_compute_z_digest = 0;
  223. if ((z = OPENSSL_zalloc(ctx->mdsize)) == NULL
  224. /* get hashed prefix 'z' of tbs message */
  225. || !ossl_sm2_compute_z_digest(z, ctx->md, ctx->id, ctx->id_len,
  226. ctx->ec)
  227. || !EVP_DigestUpdate(ctx->mdctx, z, ctx->mdsize))
  228. ret = 0;
  229. OPENSSL_free(z);
  230. }
  231. return ret;
  232. }
  233. int sm2sig_digest_signverify_update(void *vpsm2ctx, const unsigned char *data,
  234. size_t datalen)
  235. {
  236. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  237. if (psm2ctx == NULL || psm2ctx->mdctx == NULL)
  238. return 0;
  239. return sm2sig_compute_z_digest(psm2ctx)
  240. && EVP_DigestUpdate(psm2ctx->mdctx, data, datalen);
  241. }
  242. int sm2sig_digest_sign_final(void *vpsm2ctx, unsigned char *sig, size_t *siglen,
  243. size_t sigsize)
  244. {
  245. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  246. unsigned char digest[EVP_MAX_MD_SIZE];
  247. unsigned int dlen = 0;
  248. if (psm2ctx == NULL || psm2ctx->mdctx == NULL)
  249. return 0;
  250. /*
  251. * If sig is NULL then we're just finding out the sig size. Other fields
  252. * are ignored. Defer to sm2sig_sign.
  253. */
  254. if (sig != NULL) {
  255. if (!(sm2sig_compute_z_digest(psm2ctx)
  256. && EVP_DigestFinal_ex(psm2ctx->mdctx, digest, &dlen)))
  257. return 0;
  258. }
  259. return sm2sig_sign(vpsm2ctx, sig, siglen, sigsize, digest, (size_t)dlen);
  260. }
  261. int sm2sig_digest_verify_final(void *vpsm2ctx, const unsigned char *sig,
  262. size_t siglen)
  263. {
  264. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  265. unsigned char digest[EVP_MAX_MD_SIZE];
  266. unsigned int dlen = 0;
  267. int md_size;
  268. if (psm2ctx == NULL || psm2ctx->mdctx == NULL)
  269. return 0;
  270. md_size = EVP_MD_get_size(psm2ctx->md);
  271. if (md_size <= 0 || md_size > (int)sizeof(digest))
  272. return 0;
  273. if (!(sm2sig_compute_z_digest(psm2ctx)
  274. && EVP_DigestFinal_ex(psm2ctx->mdctx, digest, &dlen)))
  275. return 0;
  276. return sm2sig_verify(vpsm2ctx, sig, siglen, digest, (size_t)dlen);
  277. }
  278. static void sm2sig_freectx(void *vpsm2ctx)
  279. {
  280. PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
  281. free_md(ctx);
  282. EC_KEY_free(ctx->ec);
  283. OPENSSL_free(ctx->propq);
  284. OPENSSL_free(ctx->id);
  285. OPENSSL_free(ctx);
  286. }
  287. static void *sm2sig_dupctx(void *vpsm2ctx)
  288. {
  289. PROV_SM2_CTX *srcctx = (PROV_SM2_CTX *)vpsm2ctx;
  290. PROV_SM2_CTX *dstctx;
  291. dstctx = OPENSSL_zalloc(sizeof(*srcctx));
  292. if (dstctx == NULL)
  293. return NULL;
  294. *dstctx = *srcctx;
  295. dstctx->ec = NULL;
  296. dstctx->propq = NULL;
  297. dstctx->md = NULL;
  298. dstctx->mdctx = NULL;
  299. dstctx->id = NULL;
  300. if (srcctx->ec != NULL && !EC_KEY_up_ref(srcctx->ec))
  301. goto err;
  302. dstctx->ec = srcctx->ec;
  303. if (srcctx->propq != NULL) {
  304. dstctx->propq = OPENSSL_strdup(srcctx->propq);
  305. if (dstctx->propq == NULL)
  306. goto err;
  307. }
  308. if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
  309. goto err;
  310. dstctx->md = srcctx->md;
  311. if (srcctx->mdctx != NULL) {
  312. dstctx->mdctx = EVP_MD_CTX_new();
  313. if (dstctx->mdctx == NULL
  314. || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
  315. goto err;
  316. }
  317. if (srcctx->id != NULL) {
  318. dstctx->id = OPENSSL_malloc(srcctx->id_len);
  319. if (dstctx->id == NULL)
  320. goto err;
  321. dstctx->id_len = srcctx->id_len;
  322. memcpy(dstctx->id, srcctx->id, srcctx->id_len);
  323. }
  324. return dstctx;
  325. err:
  326. sm2sig_freectx(dstctx);
  327. return NULL;
  328. }
  329. static int sm2sig_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
  330. {
  331. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  332. OSSL_PARAM *p;
  333. if (psm2ctx == NULL)
  334. return 0;
  335. p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
  336. if (p != NULL
  337. && !OSSL_PARAM_set_octet_string(p,
  338. psm2ctx->aid_len == 0 ? NULL : psm2ctx->aid_buf,
  339. psm2ctx->aid_len))
  340. return 0;
  341. p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
  342. if (p != NULL && !OSSL_PARAM_set_size_t(p, psm2ctx->mdsize))
  343. return 0;
  344. p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
  345. if (p != NULL && !OSSL_PARAM_set_utf8_string(p, psm2ctx->md == NULL
  346. ? psm2ctx->mdname
  347. : EVP_MD_get0_name(psm2ctx->md)))
  348. return 0;
  349. return 1;
  350. }
  351. static const OSSL_PARAM known_gettable_ctx_params[] = {
  352. OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0),
  353. OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
  354. OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
  355. OSSL_PARAM_END
  356. };
  357. static const OSSL_PARAM *sm2sig_gettable_ctx_params(ossl_unused void *vpsm2ctx,
  358. ossl_unused void *provctx)
  359. {
  360. return known_gettable_ctx_params;
  361. }
  362. static int sm2sig_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[])
  363. {
  364. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  365. const OSSL_PARAM *p;
  366. size_t mdsize;
  367. if (psm2ctx == NULL)
  368. return 0;
  369. if (ossl_param_is_empty(params))
  370. return 1;
  371. p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DIST_ID);
  372. if (p != NULL) {
  373. void *tmp_id = NULL;
  374. size_t tmp_idlen = 0;
  375. /*
  376. * If the 'z' digest has already been computed, the ID is set too late
  377. */
  378. if (!psm2ctx->flag_compute_z_digest)
  379. return 0;
  380. if (p->data_size != 0
  381. && !OSSL_PARAM_get_octet_string(p, &tmp_id, 0, &tmp_idlen))
  382. return 0;
  383. OPENSSL_free(psm2ctx->id);
  384. psm2ctx->id = tmp_id;
  385. psm2ctx->id_len = tmp_idlen;
  386. }
  387. /*
  388. * The following code checks that the size is the same as the SM3 digest
  389. * size returning an error otherwise.
  390. * If there is ever any different digest algorithm allowed with SM2
  391. * this needs to be adjusted accordingly.
  392. */
  393. p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
  394. if (p != NULL && (!OSSL_PARAM_get_size_t(p, &mdsize)
  395. || mdsize != psm2ctx->mdsize))
  396. return 0;
  397. p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
  398. if (p != NULL) {
  399. char *mdname = NULL;
  400. if (!OSSL_PARAM_get_utf8_string(p, &mdname, 0))
  401. return 0;
  402. if (!sm2sig_set_mdname(psm2ctx, mdname)) {
  403. OPENSSL_free(mdname);
  404. return 0;
  405. }
  406. OPENSSL_free(mdname);
  407. }
  408. return 1;
  409. }
  410. static const OSSL_PARAM known_settable_ctx_params[] = {
  411. OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
  412. OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
  413. OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_DIST_ID, NULL, 0),
  414. OSSL_PARAM_END
  415. };
  416. static const OSSL_PARAM *sm2sig_settable_ctx_params(ossl_unused void *vpsm2ctx,
  417. ossl_unused void *provctx)
  418. {
  419. return known_settable_ctx_params;
  420. }
  421. static int sm2sig_get_ctx_md_params(void *vpsm2ctx, OSSL_PARAM *params)
  422. {
  423. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  424. if (psm2ctx->mdctx == NULL)
  425. return 0;
  426. return EVP_MD_CTX_get_params(psm2ctx->mdctx, params);
  427. }
  428. static const OSSL_PARAM *sm2sig_gettable_ctx_md_params(void *vpsm2ctx)
  429. {
  430. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  431. if (psm2ctx->md == NULL)
  432. return 0;
  433. return EVP_MD_gettable_ctx_params(psm2ctx->md);
  434. }
  435. static int sm2sig_set_ctx_md_params(void *vpsm2ctx, const OSSL_PARAM params[])
  436. {
  437. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  438. if (psm2ctx->mdctx == NULL)
  439. return 0;
  440. return EVP_MD_CTX_set_params(psm2ctx->mdctx, params);
  441. }
  442. static const OSSL_PARAM *sm2sig_settable_ctx_md_params(void *vpsm2ctx)
  443. {
  444. PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
  445. if (psm2ctx->md == NULL)
  446. return 0;
  447. return EVP_MD_settable_ctx_params(psm2ctx->md);
  448. }
  449. const OSSL_DISPATCH ossl_sm2_signature_functions[] = {
  450. { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))sm2sig_newctx },
  451. { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))sm2sig_signature_init },
  452. { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))sm2sig_sign },
  453. { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))sm2sig_signature_init },
  454. { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))sm2sig_verify },
  455. { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
  456. (void (*)(void))sm2sig_digest_signverify_init },
  457. { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
  458. (void (*)(void))sm2sig_digest_signverify_update },
  459. { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
  460. (void (*)(void))sm2sig_digest_sign_final },
  461. { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
  462. (void (*)(void))sm2sig_digest_signverify_init },
  463. { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
  464. (void (*)(void))sm2sig_digest_signverify_update },
  465. { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
  466. (void (*)(void))sm2sig_digest_verify_final },
  467. { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))sm2sig_freectx },
  468. { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))sm2sig_dupctx },
  469. { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))sm2sig_get_ctx_params },
  470. { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
  471. (void (*)(void))sm2sig_gettable_ctx_params },
  472. { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))sm2sig_set_ctx_params },
  473. { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
  474. (void (*)(void))sm2sig_settable_ctx_params },
  475. { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS,
  476. (void (*)(void))sm2sig_get_ctx_md_params },
  477. { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS,
  478. (void (*)(void))sm2sig_gettable_ctx_md_params },
  479. { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS,
  480. (void (*)(void))sm2sig_set_ctx_md_params },
  481. { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS,
  482. (void (*)(void))sm2sig_settable_ctx_md_params },
  483. OSSL_DISPATCH_END
  484. };