dsa_sig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * Copyright 2019-2021 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. * DSA low level APIs are deprecated for public use, but still ok for
  11. * internal use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <string.h>
  15. #include <openssl/crypto.h>
  16. #include <openssl/core_dispatch.h>
  17. #include <openssl/core_names.h>
  18. #include <openssl/err.h>
  19. #include <openssl/dsa.h>
  20. #include <openssl/params.h>
  21. #include <openssl/evp.h>
  22. #include <openssl/proverr.h>
  23. #include "internal/nelem.h"
  24. #include "internal/sizes.h"
  25. #include "internal/cryptlib.h"
  26. #include "prov/providercommon.h"
  27. #include "prov/implementations.h"
  28. #include "prov/provider_ctx.h"
  29. #include "prov/securitycheck.h"
  30. #include "crypto/dsa.h"
  31. #include "prov/der_dsa.h"
  32. static OSSL_FUNC_signature_newctx_fn dsa_newctx;
  33. static OSSL_FUNC_signature_sign_init_fn dsa_sign_init;
  34. static OSSL_FUNC_signature_verify_init_fn dsa_verify_init;
  35. static OSSL_FUNC_signature_sign_fn dsa_sign;
  36. static OSSL_FUNC_signature_verify_fn dsa_verify;
  37. static OSSL_FUNC_signature_digest_sign_init_fn dsa_digest_sign_init;
  38. static OSSL_FUNC_signature_digest_sign_update_fn dsa_digest_signverify_update;
  39. static OSSL_FUNC_signature_digest_sign_final_fn dsa_digest_sign_final;
  40. static OSSL_FUNC_signature_digest_verify_init_fn dsa_digest_verify_init;
  41. static OSSL_FUNC_signature_digest_verify_update_fn dsa_digest_signverify_update;
  42. static OSSL_FUNC_signature_digest_verify_final_fn dsa_digest_verify_final;
  43. static OSSL_FUNC_signature_freectx_fn dsa_freectx;
  44. static OSSL_FUNC_signature_dupctx_fn dsa_dupctx;
  45. static OSSL_FUNC_signature_get_ctx_params_fn dsa_get_ctx_params;
  46. static OSSL_FUNC_signature_gettable_ctx_params_fn dsa_gettable_ctx_params;
  47. static OSSL_FUNC_signature_set_ctx_params_fn dsa_set_ctx_params;
  48. static OSSL_FUNC_signature_settable_ctx_params_fn dsa_settable_ctx_params;
  49. static OSSL_FUNC_signature_get_ctx_md_params_fn dsa_get_ctx_md_params;
  50. static OSSL_FUNC_signature_gettable_ctx_md_params_fn dsa_gettable_ctx_md_params;
  51. static OSSL_FUNC_signature_set_ctx_md_params_fn dsa_set_ctx_md_params;
  52. static OSSL_FUNC_signature_settable_ctx_md_params_fn dsa_settable_ctx_md_params;
  53. /*
  54. * What's passed as an actual key is defined by the KEYMGMT interface.
  55. * We happen to know that our KEYMGMT simply passes DSA structures, so
  56. * we use that here too.
  57. */
  58. typedef struct {
  59. OSSL_LIB_CTX *libctx;
  60. char *propq;
  61. DSA *dsa;
  62. /*
  63. * Flag to determine if the hash function can be changed (1) or not (0)
  64. * Because it's dangerous to change during a DigestSign or DigestVerify
  65. * operation, this flag is cleared by their Init function, and set again
  66. * by their Final function.
  67. */
  68. unsigned int flag_allow_md : 1;
  69. /* If this is set to 1 then the generated k is not random */
  70. unsigned int nonce_type;
  71. char mdname[OSSL_MAX_NAME_SIZE];
  72. /* The Algorithm Identifier of the combined signature algorithm */
  73. unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
  74. unsigned char *aid;
  75. size_t aid_len;
  76. /* main digest */
  77. EVP_MD *md;
  78. EVP_MD_CTX *mdctx;
  79. int operation;
  80. } PROV_DSA_CTX;
  81. static size_t dsa_get_md_size(const PROV_DSA_CTX *pdsactx)
  82. {
  83. if (pdsactx->md != NULL)
  84. return EVP_MD_get_size(pdsactx->md);
  85. return 0;
  86. }
  87. static void *dsa_newctx(void *provctx, const char *propq)
  88. {
  89. PROV_DSA_CTX *pdsactx;
  90. if (!ossl_prov_is_running())
  91. return NULL;
  92. pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX));
  93. if (pdsactx == NULL)
  94. return NULL;
  95. pdsactx->libctx = PROV_LIBCTX_OF(provctx);
  96. pdsactx->flag_allow_md = 1;
  97. if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) {
  98. OPENSSL_free(pdsactx);
  99. pdsactx = NULL;
  100. }
  101. return pdsactx;
  102. }
  103. static int dsa_setup_md(PROV_DSA_CTX *ctx,
  104. const char *mdname, const char *mdprops)
  105. {
  106. if (mdprops == NULL)
  107. mdprops = ctx->propq;
  108. if (mdname != NULL) {
  109. int sha1_allowed = (ctx->operation != EVP_PKEY_OP_SIGN);
  110. WPACKET pkt;
  111. EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
  112. int md_nid = ossl_digest_get_approved_nid_with_sha1(ctx->libctx, md,
  113. sha1_allowed);
  114. size_t mdname_len = strlen(mdname);
  115. if (md == NULL || md_nid < 0) {
  116. if (md == NULL)
  117. ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
  118. "%s could not be fetched", mdname);
  119. if (md_nid < 0)
  120. ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED,
  121. "digest=%s", mdname);
  122. if (mdname_len >= sizeof(ctx->mdname))
  123. ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
  124. "%s exceeds name buffer length", mdname);
  125. EVP_MD_free(md);
  126. return 0;
  127. }
  128. if (!ctx->flag_allow_md) {
  129. if (ctx->mdname[0] != '\0' && !EVP_MD_is_a(md, ctx->mdname)) {
  130. ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED,
  131. "digest %s != %s", mdname, ctx->mdname);
  132. EVP_MD_free(md);
  133. return 0;
  134. }
  135. EVP_MD_free(md);
  136. return 1;
  137. }
  138. EVP_MD_CTX_free(ctx->mdctx);
  139. EVP_MD_free(ctx->md);
  140. /*
  141. * We do not care about DER writing errors.
  142. * All it really means is that for some reason, there's no
  143. * AlgorithmIdentifier to be had, but the operation itself is
  144. * still valid, just as long as it's not used to construct
  145. * anything that needs an AlgorithmIdentifier.
  146. */
  147. ctx->aid_len = 0;
  148. if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
  149. && ossl_DER_w_algorithmIdentifier_DSA_with_MD(&pkt, -1, ctx->dsa,
  150. md_nid)
  151. && WPACKET_finish(&pkt)) {
  152. WPACKET_get_total_written(&pkt, &ctx->aid_len);
  153. ctx->aid = WPACKET_get_curr(&pkt);
  154. }
  155. WPACKET_cleanup(&pkt);
  156. ctx->mdctx = NULL;
  157. ctx->md = md;
  158. OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname));
  159. }
  160. return 1;
  161. }
  162. static int dsa_signverify_init(void *vpdsactx, void *vdsa,
  163. const OSSL_PARAM params[], int operation)
  164. {
  165. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  166. if (!ossl_prov_is_running()
  167. || pdsactx == NULL)
  168. return 0;
  169. if (vdsa == NULL && pdsactx->dsa == NULL) {
  170. ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
  171. return 0;
  172. }
  173. if (vdsa != NULL) {
  174. if (!ossl_dsa_check_key(pdsactx->libctx, vdsa,
  175. operation == EVP_PKEY_OP_SIGN)) {
  176. ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
  177. return 0;
  178. }
  179. if (!DSA_up_ref(vdsa))
  180. return 0;
  181. DSA_free(pdsactx->dsa);
  182. pdsactx->dsa = vdsa;
  183. }
  184. pdsactx->operation = operation;
  185. if (!dsa_set_ctx_params(pdsactx, params))
  186. return 0;
  187. return 1;
  188. }
  189. static int dsa_sign_init(void *vpdsactx, void *vdsa, const OSSL_PARAM params[])
  190. {
  191. return dsa_signverify_init(vpdsactx, vdsa, params, EVP_PKEY_OP_SIGN);
  192. }
  193. static int dsa_verify_init(void *vpdsactx, void *vdsa,
  194. const OSSL_PARAM params[])
  195. {
  196. return dsa_signverify_init(vpdsactx, vdsa, params, EVP_PKEY_OP_VERIFY);
  197. }
  198. static int dsa_sign(void *vpdsactx, unsigned char *sig, size_t *siglen,
  199. size_t sigsize, const unsigned char *tbs, size_t tbslen)
  200. {
  201. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  202. int ret;
  203. unsigned int sltmp;
  204. size_t dsasize = DSA_size(pdsactx->dsa);
  205. size_t mdsize = dsa_get_md_size(pdsactx);
  206. if (!ossl_prov_is_running())
  207. return 0;
  208. if (sig == NULL) {
  209. *siglen = dsasize;
  210. return 1;
  211. }
  212. if (sigsize < (size_t)dsasize)
  213. return 0;
  214. if (mdsize != 0 && tbslen != mdsize)
  215. return 0;
  216. ret = ossl_dsa_sign_int(0, tbs, tbslen, sig, &sltmp, pdsactx->dsa,
  217. pdsactx->nonce_type, pdsactx->mdname,
  218. pdsactx->libctx, pdsactx->propq);
  219. if (ret <= 0)
  220. return 0;
  221. *siglen = sltmp;
  222. return 1;
  223. }
  224. static int dsa_verify(void *vpdsactx, const unsigned char *sig, size_t siglen,
  225. const unsigned char *tbs, size_t tbslen)
  226. {
  227. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  228. size_t mdsize = dsa_get_md_size(pdsactx);
  229. if (!ossl_prov_is_running() || (mdsize != 0 && tbslen != mdsize))
  230. return 0;
  231. return DSA_verify(0, tbs, tbslen, sig, siglen, pdsactx->dsa);
  232. }
  233. static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname,
  234. void *vdsa, const OSSL_PARAM params[],
  235. int operation)
  236. {
  237. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  238. if (!ossl_prov_is_running())
  239. return 0;
  240. if (!dsa_signverify_init(vpdsactx, vdsa, params, operation))
  241. return 0;
  242. if (!dsa_setup_md(pdsactx, mdname, NULL))
  243. return 0;
  244. pdsactx->flag_allow_md = 0;
  245. if (pdsactx->mdctx == NULL) {
  246. pdsactx->mdctx = EVP_MD_CTX_new();
  247. if (pdsactx->mdctx == NULL)
  248. goto error;
  249. }
  250. if (!EVP_DigestInit_ex2(pdsactx->mdctx, pdsactx->md, params))
  251. goto error;
  252. return 1;
  253. error:
  254. EVP_MD_CTX_free(pdsactx->mdctx);
  255. pdsactx->mdctx = NULL;
  256. return 0;
  257. }
  258. static int dsa_digest_sign_init(void *vpdsactx, const char *mdname,
  259. void *vdsa, const OSSL_PARAM params[])
  260. {
  261. return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params,
  262. EVP_PKEY_OP_SIGN);
  263. }
  264. static int dsa_digest_verify_init(void *vpdsactx, const char *mdname,
  265. void *vdsa, const OSSL_PARAM params[])
  266. {
  267. return dsa_digest_signverify_init(vpdsactx, mdname, vdsa, params,
  268. EVP_PKEY_OP_VERIFY);
  269. }
  270. int dsa_digest_signverify_update(void *vpdsactx, const unsigned char *data,
  271. size_t datalen)
  272. {
  273. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  274. if (pdsactx == NULL || pdsactx->mdctx == NULL)
  275. return 0;
  276. return EVP_DigestUpdate(pdsactx->mdctx, data, datalen);
  277. }
  278. int dsa_digest_sign_final(void *vpdsactx, unsigned char *sig, size_t *siglen,
  279. size_t sigsize)
  280. {
  281. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  282. unsigned char digest[EVP_MAX_MD_SIZE];
  283. unsigned int dlen = 0;
  284. if (!ossl_prov_is_running() || pdsactx == NULL || pdsactx->mdctx == NULL)
  285. return 0;
  286. /*
  287. * If sig is NULL then we're just finding out the sig size. Other fields
  288. * are ignored. Defer to dsa_sign.
  289. */
  290. if (sig != NULL) {
  291. /*
  292. * There is the possibility that some externally provided
  293. * digests exceed EVP_MAX_MD_SIZE. We should probably handle that somehow -
  294. * but that problem is much larger than just in DSA.
  295. */
  296. if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen))
  297. return 0;
  298. }
  299. pdsactx->flag_allow_md = 1;
  300. return dsa_sign(vpdsactx, sig, siglen, sigsize, digest, (size_t)dlen);
  301. }
  302. int dsa_digest_verify_final(void *vpdsactx, const unsigned char *sig,
  303. size_t siglen)
  304. {
  305. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  306. unsigned char digest[EVP_MAX_MD_SIZE];
  307. unsigned int dlen = 0;
  308. if (!ossl_prov_is_running() || pdsactx == NULL || pdsactx->mdctx == NULL)
  309. return 0;
  310. /*
  311. * There is the possibility that some externally provided
  312. * digests exceed EVP_MAX_MD_SIZE. We should probably handle that somehow -
  313. * but that problem is much larger than just in DSA.
  314. */
  315. if (!EVP_DigestFinal_ex(pdsactx->mdctx, digest, &dlen))
  316. return 0;
  317. pdsactx->flag_allow_md = 1;
  318. return dsa_verify(vpdsactx, sig, siglen, digest, (size_t)dlen);
  319. }
  320. static void dsa_freectx(void *vpdsactx)
  321. {
  322. PROV_DSA_CTX *ctx = (PROV_DSA_CTX *)vpdsactx;
  323. OPENSSL_free(ctx->propq);
  324. EVP_MD_CTX_free(ctx->mdctx);
  325. EVP_MD_free(ctx->md);
  326. ctx->propq = NULL;
  327. ctx->mdctx = NULL;
  328. ctx->md = NULL;
  329. DSA_free(ctx->dsa);
  330. OPENSSL_free(ctx);
  331. }
  332. static void *dsa_dupctx(void *vpdsactx)
  333. {
  334. PROV_DSA_CTX *srcctx = (PROV_DSA_CTX *)vpdsactx;
  335. PROV_DSA_CTX *dstctx;
  336. if (!ossl_prov_is_running())
  337. return NULL;
  338. dstctx = OPENSSL_zalloc(sizeof(*srcctx));
  339. if (dstctx == NULL)
  340. return NULL;
  341. *dstctx = *srcctx;
  342. dstctx->dsa = NULL;
  343. dstctx->md = NULL;
  344. dstctx->mdctx = NULL;
  345. dstctx->propq = NULL;
  346. if (srcctx->dsa != NULL && !DSA_up_ref(srcctx->dsa))
  347. goto err;
  348. dstctx->dsa = srcctx->dsa;
  349. if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
  350. goto err;
  351. dstctx->md = srcctx->md;
  352. if (srcctx->mdctx != NULL) {
  353. dstctx->mdctx = EVP_MD_CTX_new();
  354. if (dstctx->mdctx == NULL
  355. || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
  356. goto err;
  357. }
  358. if (srcctx->propq != NULL) {
  359. dstctx->propq = OPENSSL_strdup(srcctx->propq);
  360. if (dstctx->propq == NULL)
  361. goto err;
  362. }
  363. return dstctx;
  364. err:
  365. dsa_freectx(dstctx);
  366. return NULL;
  367. }
  368. static int dsa_get_ctx_params(void *vpdsactx, OSSL_PARAM *params)
  369. {
  370. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  371. OSSL_PARAM *p;
  372. if (pdsactx == NULL)
  373. return 0;
  374. p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
  375. if (p != NULL
  376. && !OSSL_PARAM_set_octet_string(p, pdsactx->aid, pdsactx->aid_len))
  377. return 0;
  378. p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
  379. if (p != NULL && !OSSL_PARAM_set_utf8_string(p, pdsactx->mdname))
  380. return 0;
  381. p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE);
  382. if (p != NULL && !OSSL_PARAM_set_uint(p, pdsactx->nonce_type))
  383. return 0;
  384. return 1;
  385. }
  386. static const OSSL_PARAM known_gettable_ctx_params[] = {
  387. OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0),
  388. OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
  389. OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE, NULL),
  390. OSSL_PARAM_END
  391. };
  392. static const OSSL_PARAM *dsa_gettable_ctx_params(ossl_unused void *ctx,
  393. ossl_unused void *provctx)
  394. {
  395. return known_gettable_ctx_params;
  396. }
  397. static int dsa_set_ctx_params(void *vpdsactx, const OSSL_PARAM params[])
  398. {
  399. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  400. const OSSL_PARAM *p;
  401. if (pdsactx == NULL)
  402. return 0;
  403. if (params == NULL)
  404. return 1;
  405. p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
  406. if (p != NULL) {
  407. char mdname[OSSL_MAX_NAME_SIZE] = "", *pmdname = mdname;
  408. char mdprops[OSSL_MAX_PROPQUERY_SIZE] = "", *pmdprops = mdprops;
  409. const OSSL_PARAM *propsp =
  410. OSSL_PARAM_locate_const(params,
  411. OSSL_SIGNATURE_PARAM_PROPERTIES);
  412. if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname)))
  413. return 0;
  414. if (propsp != NULL
  415. && !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops)))
  416. return 0;
  417. if (!dsa_setup_md(pdsactx, mdname, mdprops))
  418. return 0;
  419. }
  420. p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_NONCE_TYPE);
  421. if (p != NULL
  422. && !OSSL_PARAM_get_uint(p, &pdsactx->nonce_type))
  423. return 0;
  424. return 1;
  425. }
  426. static const OSSL_PARAM settable_ctx_params[] = {
  427. OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
  428. OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PROPERTIES, NULL, 0),
  429. OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_NONCE_TYPE, NULL),
  430. OSSL_PARAM_END
  431. };
  432. static const OSSL_PARAM settable_ctx_params_no_digest[] = {
  433. OSSL_PARAM_END
  434. };
  435. static const OSSL_PARAM *dsa_settable_ctx_params(void *vpdsactx,
  436. ossl_unused void *provctx)
  437. {
  438. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  439. if (pdsactx != NULL && !pdsactx->flag_allow_md)
  440. return settable_ctx_params_no_digest;
  441. return settable_ctx_params;
  442. }
  443. static int dsa_get_ctx_md_params(void *vpdsactx, OSSL_PARAM *params)
  444. {
  445. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  446. if (pdsactx->mdctx == NULL)
  447. return 0;
  448. return EVP_MD_CTX_get_params(pdsactx->mdctx, params);
  449. }
  450. static const OSSL_PARAM *dsa_gettable_ctx_md_params(void *vpdsactx)
  451. {
  452. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  453. if (pdsactx->md == NULL)
  454. return 0;
  455. return EVP_MD_gettable_ctx_params(pdsactx->md);
  456. }
  457. static int dsa_set_ctx_md_params(void *vpdsactx, const OSSL_PARAM params[])
  458. {
  459. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  460. if (pdsactx->mdctx == NULL)
  461. return 0;
  462. return EVP_MD_CTX_set_params(pdsactx->mdctx, params);
  463. }
  464. static const OSSL_PARAM *dsa_settable_ctx_md_params(void *vpdsactx)
  465. {
  466. PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx;
  467. if (pdsactx->md == NULL)
  468. return 0;
  469. return EVP_MD_settable_ctx_params(pdsactx->md);
  470. }
  471. const OSSL_DISPATCH ossl_dsa_signature_functions[] = {
  472. { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))dsa_newctx },
  473. { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))dsa_sign_init },
  474. { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))dsa_sign },
  475. { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))dsa_verify_init },
  476. { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))dsa_verify },
  477. { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
  478. (void (*)(void))dsa_digest_sign_init },
  479. { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
  480. (void (*)(void))dsa_digest_signverify_update },
  481. { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
  482. (void (*)(void))dsa_digest_sign_final },
  483. { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
  484. (void (*)(void))dsa_digest_verify_init },
  485. { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
  486. (void (*)(void))dsa_digest_signverify_update },
  487. { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
  488. (void (*)(void))dsa_digest_verify_final },
  489. { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))dsa_freectx },
  490. { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))dsa_dupctx },
  491. { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))dsa_get_ctx_params },
  492. { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
  493. (void (*)(void))dsa_gettable_ctx_params },
  494. { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))dsa_set_ctx_params },
  495. { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
  496. (void (*)(void))dsa_settable_ctx_params },
  497. { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS,
  498. (void (*)(void))dsa_get_ctx_md_params },
  499. { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS,
  500. (void (*)(void))dsa_gettable_ctx_md_params },
  501. { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS,
  502. (void (*)(void))dsa_set_ctx_md_params },
  503. { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS,
  504. (void (*)(void))dsa_settable_ctx_md_params },
  505. OSSL_DISPATCH_END
  506. };