ecdsa_sig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * Copyright 2020-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. * ECDSA 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> /* 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 "prov/providercommon.h"
  27. #include "prov/implementations.h"
  28. #include "prov/provider_ctx.h"
  29. #include "prov/securitycheck.h"
  30. #include "crypto/ec.h"
  31. #include "prov/der_ec.h"
  32. static OSSL_FUNC_signature_newctx_fn ecdsa_newctx;
  33. static OSSL_FUNC_signature_sign_init_fn ecdsa_sign_init;
  34. static OSSL_FUNC_signature_verify_init_fn ecdsa_verify_init;
  35. static OSSL_FUNC_signature_sign_fn ecdsa_sign;
  36. static OSSL_FUNC_signature_verify_fn ecdsa_verify;
  37. static OSSL_FUNC_signature_digest_sign_init_fn ecdsa_digest_sign_init;
  38. static OSSL_FUNC_signature_digest_sign_update_fn ecdsa_digest_signverify_update;
  39. static OSSL_FUNC_signature_digest_sign_final_fn ecdsa_digest_sign_final;
  40. static OSSL_FUNC_signature_digest_verify_init_fn ecdsa_digest_verify_init;
  41. static OSSL_FUNC_signature_digest_verify_update_fn ecdsa_digest_signverify_update;
  42. static OSSL_FUNC_signature_digest_verify_final_fn ecdsa_digest_verify_final;
  43. static OSSL_FUNC_signature_freectx_fn ecdsa_freectx;
  44. static OSSL_FUNC_signature_dupctx_fn ecdsa_dupctx;
  45. static OSSL_FUNC_signature_get_ctx_params_fn ecdsa_get_ctx_params;
  46. static OSSL_FUNC_signature_gettable_ctx_params_fn ecdsa_gettable_ctx_params;
  47. static OSSL_FUNC_signature_set_ctx_params_fn ecdsa_set_ctx_params;
  48. static OSSL_FUNC_signature_settable_ctx_params_fn ecdsa_settable_ctx_params;
  49. static OSSL_FUNC_signature_get_ctx_md_params_fn ecdsa_get_ctx_md_params;
  50. static OSSL_FUNC_signature_gettable_ctx_md_params_fn ecdsa_gettable_ctx_md_params;
  51. static OSSL_FUNC_signature_set_ctx_md_params_fn ecdsa_set_ctx_md_params;
  52. static OSSL_FUNC_signature_settable_ctx_md_params_fn ecdsa_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. EC_KEY *ec;
  62. char mdname[OSSL_MAX_NAME_SIZE];
  63. /*
  64. * Flag to determine if the hash function can be changed (1) or not (0)
  65. * Because it's dangerous to change during a DigestSign or DigestVerify
  66. * operation, this flag is cleared by their Init function, and set again
  67. * by their Final function.
  68. */
  69. unsigned int flag_allow_md : 1;
  70. /* The Algorithm Identifier of the combined signature algorithm */
  71. unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
  72. unsigned char *aid;
  73. size_t aid_len;
  74. size_t mdsize;
  75. int operation;
  76. EVP_MD *md;
  77. EVP_MD_CTX *mdctx;
  78. /*
  79. * Internally used to cache the results of calling the EC group
  80. * sign_setup() methods which are then passed to the sign operation.
  81. * This is used by CAVS failure tests to terminate a loop if the signature
  82. * is not valid.
  83. * This could of also been done with a simple flag.
  84. */
  85. BIGNUM *kinv;
  86. BIGNUM *r;
  87. #if !defined(OPENSSL_NO_ACVP_TESTS)
  88. /*
  89. * This indicates that KAT (CAVS) test is running. Externally an app will
  90. * override the random callback such that the generated private key and k
  91. * are known.
  92. * Normal operation will loop to choose a new k if the signature is not
  93. * valid - but for this mode of operation it forces a failure instead.
  94. */
  95. unsigned int kattest;
  96. #endif
  97. } PROV_ECDSA_CTX;
  98. static void *ecdsa_newctx(void *provctx, const char *propq)
  99. {
  100. PROV_ECDSA_CTX *ctx;
  101. if (!ossl_prov_is_running())
  102. return NULL;
  103. ctx = OPENSSL_zalloc(sizeof(PROV_ECDSA_CTX));
  104. if (ctx == NULL)
  105. return NULL;
  106. ctx->flag_allow_md = 1;
  107. ctx->libctx = PROV_LIBCTX_OF(provctx);
  108. if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL) {
  109. OPENSSL_free(ctx);
  110. ctx = NULL;
  111. ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
  112. }
  113. return ctx;
  114. }
  115. static int ecdsa_signverify_init(void *vctx, void *ec,
  116. const OSSL_PARAM params[], int operation)
  117. {
  118. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  119. if (!ossl_prov_is_running()
  120. || ctx == NULL)
  121. return 0;
  122. if (ec == NULL && ctx->ec == NULL) {
  123. ERR_raise(ERR_LIB_PROV, PROV_R_NO_KEY_SET);
  124. return 0;
  125. }
  126. if (ec != NULL) {
  127. if (!ossl_ec_check_key(ctx->libctx, ec, operation == EVP_PKEY_OP_SIGN))
  128. return 0;
  129. if (!EC_KEY_up_ref(ec))
  130. return 0;
  131. EC_KEY_free(ctx->ec);
  132. ctx->ec = ec;
  133. }
  134. ctx->operation = operation;
  135. if (!ecdsa_set_ctx_params(ctx, params))
  136. return 0;
  137. return 1;
  138. }
  139. static int ecdsa_sign_init(void *vctx, void *ec, const OSSL_PARAM params[])
  140. {
  141. return ecdsa_signverify_init(vctx, ec, params, EVP_PKEY_OP_SIGN);
  142. }
  143. static int ecdsa_verify_init(void *vctx, void *ec, const OSSL_PARAM params[])
  144. {
  145. return ecdsa_signverify_init(vctx, ec, params, EVP_PKEY_OP_VERIFY);
  146. }
  147. static int ecdsa_sign(void *vctx, unsigned char *sig, size_t *siglen,
  148. size_t sigsize, const unsigned char *tbs, size_t tbslen)
  149. {
  150. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  151. int ret;
  152. unsigned int sltmp;
  153. size_t ecsize = ECDSA_size(ctx->ec);
  154. if (!ossl_prov_is_running())
  155. return 0;
  156. if (sig == NULL) {
  157. *siglen = ecsize;
  158. return 1;
  159. }
  160. #if !defined(OPENSSL_NO_ACVP_TESTS)
  161. if (ctx->kattest && !ECDSA_sign_setup(ctx->ec, NULL, &ctx->kinv, &ctx->r))
  162. return 0;
  163. #endif
  164. if (sigsize < (size_t)ecsize)
  165. return 0;
  166. if (ctx->mdsize != 0 && tbslen != ctx->mdsize)
  167. return 0;
  168. ret = ECDSA_sign_ex(0, tbs, tbslen, sig, &sltmp, ctx->kinv, ctx->r, ctx->ec);
  169. if (ret <= 0)
  170. return 0;
  171. *siglen = sltmp;
  172. return 1;
  173. }
  174. static int ecdsa_verify(void *vctx, const unsigned char *sig, size_t siglen,
  175. const unsigned char *tbs, size_t tbslen)
  176. {
  177. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  178. if (!ossl_prov_is_running() || (ctx->mdsize != 0 && tbslen != ctx->mdsize))
  179. return 0;
  180. return ECDSA_verify(0, tbs, tbslen, sig, siglen, ctx->ec);
  181. }
  182. static int ecdsa_setup_md(PROV_ECDSA_CTX *ctx, const char *mdname,
  183. const char *mdprops)
  184. {
  185. EVP_MD *md = NULL;
  186. size_t mdname_len;
  187. int md_nid, sha1_allowed;
  188. WPACKET pkt;
  189. if (mdname == NULL)
  190. return 1;
  191. mdname_len = strlen(mdname);
  192. if (mdname_len >= sizeof(ctx->mdname)) {
  193. ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
  194. "%s exceeds name buffer length", mdname);
  195. return 0;
  196. }
  197. if (mdprops == NULL)
  198. mdprops = ctx->propq;
  199. md = EVP_MD_fetch(ctx->libctx, mdname, mdprops);
  200. if (md == NULL) {
  201. ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST,
  202. "%s could not be fetched", mdname);
  203. return 0;
  204. }
  205. sha1_allowed = (ctx->operation != EVP_PKEY_OP_SIGN);
  206. md_nid = ossl_digest_get_approved_nid_with_sha1(ctx->libctx, md,
  207. sha1_allowed);
  208. if (md_nid < 0) {
  209. ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED,
  210. "digest=%s", mdname);
  211. EVP_MD_free(md);
  212. return 0;
  213. }
  214. if (!ctx->flag_allow_md) {
  215. if (ctx->mdname[0] != '\0' && !EVP_MD_is_a(md, ctx->mdname)) {
  216. ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED,
  217. "digest %s != %s", mdname, ctx->mdname);
  218. EVP_MD_free(md);
  219. return 0;
  220. }
  221. EVP_MD_free(md);
  222. return 1;
  223. }
  224. EVP_MD_CTX_free(ctx->mdctx);
  225. EVP_MD_free(ctx->md);
  226. ctx->aid_len = 0;
  227. if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
  228. && ossl_DER_w_algorithmIdentifier_ECDSA_with_MD(&pkt, -1, ctx->ec,
  229. md_nid)
  230. && WPACKET_finish(&pkt)) {
  231. WPACKET_get_total_written(&pkt, &ctx->aid_len);
  232. ctx->aid = WPACKET_get_curr(&pkt);
  233. }
  234. WPACKET_cleanup(&pkt);
  235. ctx->mdctx = NULL;
  236. ctx->md = md;
  237. ctx->mdsize = EVP_MD_get_size(ctx->md);
  238. OPENSSL_strlcpy(ctx->mdname, mdname, sizeof(ctx->mdname));
  239. return 1;
  240. }
  241. static int ecdsa_digest_signverify_init(void *vctx, const char *mdname,
  242. void *ec, const OSSL_PARAM params[],
  243. int operation)
  244. {
  245. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  246. if (!ossl_prov_is_running())
  247. return 0;
  248. if (!ecdsa_signverify_init(vctx, ec, params, operation)
  249. || !ecdsa_setup_md(ctx, mdname, NULL))
  250. return 0;
  251. ctx->flag_allow_md = 0;
  252. if (ctx->mdctx == NULL) {
  253. ctx->mdctx = EVP_MD_CTX_new();
  254. if (ctx->mdctx == NULL)
  255. goto error;
  256. }
  257. if (!EVP_DigestInit_ex2(ctx->mdctx, ctx->md, params))
  258. goto error;
  259. return 1;
  260. error:
  261. EVP_MD_CTX_free(ctx->mdctx);
  262. ctx->mdctx = NULL;
  263. return 0;
  264. }
  265. static int ecdsa_digest_sign_init(void *vctx, const char *mdname, void *ec,
  266. const OSSL_PARAM params[])
  267. {
  268. return ecdsa_digest_signverify_init(vctx, mdname, ec, params,
  269. EVP_PKEY_OP_SIGN);
  270. }
  271. static int ecdsa_digest_verify_init(void *vctx, const char *mdname, void *ec,
  272. const OSSL_PARAM params[])
  273. {
  274. return ecdsa_digest_signverify_init(vctx, mdname, ec, params,
  275. EVP_PKEY_OP_VERIFY);
  276. }
  277. int ecdsa_digest_signverify_update(void *vctx, const unsigned char *data,
  278. size_t datalen)
  279. {
  280. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  281. if (ctx == NULL || ctx->mdctx == NULL)
  282. return 0;
  283. return EVP_DigestUpdate(ctx->mdctx, data, datalen);
  284. }
  285. int ecdsa_digest_sign_final(void *vctx, unsigned char *sig, size_t *siglen,
  286. size_t sigsize)
  287. {
  288. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  289. unsigned char digest[EVP_MAX_MD_SIZE];
  290. unsigned int dlen = 0;
  291. if (!ossl_prov_is_running() || ctx == NULL || ctx->mdctx == NULL)
  292. return 0;
  293. /*
  294. * If sig is NULL then we're just finding out the sig size. Other fields
  295. * are ignored. Defer to ecdsa_sign.
  296. */
  297. if (sig != NULL
  298. && !EVP_DigestFinal_ex(ctx->mdctx, digest, &dlen))
  299. return 0;
  300. ctx->flag_allow_md = 1;
  301. return ecdsa_sign(vctx, sig, siglen, sigsize, digest, (size_t)dlen);
  302. }
  303. int ecdsa_digest_verify_final(void *vctx, const unsigned char *sig,
  304. size_t siglen)
  305. {
  306. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  307. unsigned char digest[EVP_MAX_MD_SIZE];
  308. unsigned int dlen = 0;
  309. if (!ossl_prov_is_running() || ctx == NULL || ctx->mdctx == NULL)
  310. return 0;
  311. if (!EVP_DigestFinal_ex(ctx->mdctx, digest, &dlen))
  312. return 0;
  313. ctx->flag_allow_md = 1;
  314. return ecdsa_verify(ctx, sig, siglen, digest, (size_t)dlen);
  315. }
  316. static void ecdsa_freectx(void *vctx)
  317. {
  318. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  319. OPENSSL_free(ctx->propq);
  320. EVP_MD_CTX_free(ctx->mdctx);
  321. EVP_MD_free(ctx->md);
  322. ctx->propq = NULL;
  323. ctx->mdctx = NULL;
  324. ctx->md = NULL;
  325. ctx->mdsize = 0;
  326. EC_KEY_free(ctx->ec);
  327. BN_clear_free(ctx->kinv);
  328. BN_clear_free(ctx->r);
  329. OPENSSL_free(ctx);
  330. }
  331. static void *ecdsa_dupctx(void *vctx)
  332. {
  333. PROV_ECDSA_CTX *srcctx = (PROV_ECDSA_CTX *)vctx;
  334. PROV_ECDSA_CTX *dstctx;
  335. if (!ossl_prov_is_running())
  336. return NULL;
  337. dstctx = OPENSSL_zalloc(sizeof(*srcctx));
  338. if (dstctx == NULL)
  339. return NULL;
  340. *dstctx = *srcctx;
  341. dstctx->ec = NULL;
  342. dstctx->md = NULL;
  343. dstctx->mdctx = NULL;
  344. dstctx->propq = NULL;
  345. if (srcctx->ec != NULL && !EC_KEY_up_ref(srcctx->ec))
  346. goto err;
  347. /* Test KATS should not need to be supported */
  348. if (srcctx->kinv != NULL || srcctx->r != NULL)
  349. goto err;
  350. dstctx->ec = srcctx->ec;
  351. if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
  352. goto err;
  353. dstctx->md = srcctx->md;
  354. if (srcctx->mdctx != NULL) {
  355. dstctx->mdctx = EVP_MD_CTX_new();
  356. if (dstctx->mdctx == NULL
  357. || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
  358. goto err;
  359. }
  360. if (srcctx->propq != NULL) {
  361. dstctx->propq = OPENSSL_strdup(srcctx->propq);
  362. if (dstctx->propq == NULL)
  363. goto err;
  364. }
  365. return dstctx;
  366. err:
  367. ecdsa_freectx(dstctx);
  368. return NULL;
  369. }
  370. static int ecdsa_get_ctx_params(void *vctx, OSSL_PARAM *params)
  371. {
  372. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  373. OSSL_PARAM *p;
  374. if (ctx == NULL)
  375. return 0;
  376. p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
  377. if (p != NULL && !OSSL_PARAM_set_octet_string(p, ctx->aid, ctx->aid_len))
  378. return 0;
  379. p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
  380. if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->mdsize))
  381. return 0;
  382. p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
  383. if (p != NULL && !OSSL_PARAM_set_utf8_string(p, ctx->md == NULL
  384. ? ctx->mdname
  385. : EVP_MD_get0_name(ctx->md)))
  386. return 0;
  387. return 1;
  388. }
  389. static const OSSL_PARAM known_gettable_ctx_params[] = {
  390. OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0),
  391. OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
  392. OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
  393. OSSL_PARAM_END
  394. };
  395. static const OSSL_PARAM *ecdsa_gettable_ctx_params(ossl_unused void *vctx,
  396. ossl_unused void *provctx)
  397. {
  398. return known_gettable_ctx_params;
  399. }
  400. static int ecdsa_set_ctx_params(void *vctx, const OSSL_PARAM params[])
  401. {
  402. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  403. const OSSL_PARAM *p;
  404. size_t mdsize = 0;
  405. if (ctx == NULL)
  406. return 0;
  407. if (params == NULL)
  408. return 1;
  409. #if !defined(OPENSSL_NO_ACVP_TESTS)
  410. p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_KAT);
  411. if (p != NULL && !OSSL_PARAM_get_uint(p, &ctx->kattest))
  412. return 0;
  413. #endif
  414. p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
  415. if (p != NULL) {
  416. char mdname[OSSL_MAX_NAME_SIZE] = "", *pmdname = mdname;
  417. char mdprops[OSSL_MAX_PROPQUERY_SIZE] = "", *pmdprops = mdprops;
  418. const OSSL_PARAM *propsp =
  419. OSSL_PARAM_locate_const(params,
  420. OSSL_SIGNATURE_PARAM_PROPERTIES);
  421. if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname)))
  422. return 0;
  423. if (propsp != NULL
  424. && !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops)))
  425. return 0;
  426. if (!ecdsa_setup_md(ctx, mdname, mdprops))
  427. return 0;
  428. }
  429. p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
  430. if (p != NULL) {
  431. if (!OSSL_PARAM_get_size_t(p, &mdsize)
  432. || (!ctx->flag_allow_md && mdsize != ctx->mdsize))
  433. return 0;
  434. ctx->mdsize = mdsize;
  435. }
  436. return 1;
  437. }
  438. static const OSSL_PARAM settable_ctx_params[] = {
  439. OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
  440. OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
  441. OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PROPERTIES, NULL, 0),
  442. OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_KAT, NULL),
  443. OSSL_PARAM_END
  444. };
  445. static const OSSL_PARAM settable_ctx_params_no_digest[] = {
  446. OSSL_PARAM_uint(OSSL_SIGNATURE_PARAM_KAT, NULL),
  447. OSSL_PARAM_END
  448. };
  449. static const OSSL_PARAM *ecdsa_settable_ctx_params(void *vctx,
  450. ossl_unused void *provctx)
  451. {
  452. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  453. if (ctx != NULL && !ctx->flag_allow_md)
  454. return settable_ctx_params_no_digest;
  455. return settable_ctx_params;
  456. }
  457. static int ecdsa_get_ctx_md_params(void *vctx, OSSL_PARAM *params)
  458. {
  459. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  460. if (ctx->mdctx == NULL)
  461. return 0;
  462. return EVP_MD_CTX_get_params(ctx->mdctx, params);
  463. }
  464. static const OSSL_PARAM *ecdsa_gettable_ctx_md_params(void *vctx)
  465. {
  466. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  467. if (ctx->md == NULL)
  468. return 0;
  469. return EVP_MD_gettable_ctx_params(ctx->md);
  470. }
  471. static int ecdsa_set_ctx_md_params(void *vctx, const OSSL_PARAM params[])
  472. {
  473. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  474. if (ctx->mdctx == NULL)
  475. return 0;
  476. return EVP_MD_CTX_set_params(ctx->mdctx, params);
  477. }
  478. static const OSSL_PARAM *ecdsa_settable_ctx_md_params(void *vctx)
  479. {
  480. PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx;
  481. if (ctx->md == NULL)
  482. return 0;
  483. return EVP_MD_settable_ctx_params(ctx->md);
  484. }
  485. const OSSL_DISPATCH ossl_ecdsa_signature_functions[] = {
  486. { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))ecdsa_newctx },
  487. { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))ecdsa_sign_init },
  488. { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))ecdsa_sign },
  489. { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))ecdsa_verify_init },
  490. { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))ecdsa_verify },
  491. { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
  492. (void (*)(void))ecdsa_digest_sign_init },
  493. { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
  494. (void (*)(void))ecdsa_digest_signverify_update },
  495. { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
  496. (void (*)(void))ecdsa_digest_sign_final },
  497. { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
  498. (void (*)(void))ecdsa_digest_verify_init },
  499. { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
  500. (void (*)(void))ecdsa_digest_signverify_update },
  501. { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
  502. (void (*)(void))ecdsa_digest_verify_final },
  503. { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))ecdsa_freectx },
  504. { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))ecdsa_dupctx },
  505. { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))ecdsa_get_ctx_params },
  506. { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
  507. (void (*)(void))ecdsa_gettable_ctx_params },
  508. { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))ecdsa_set_ctx_params },
  509. { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
  510. (void (*)(void))ecdsa_settable_ctx_params },
  511. { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS,
  512. (void (*)(void))ecdsa_get_ctx_md_params },
  513. { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS,
  514. (void (*)(void))ecdsa_gettable_ctx_md_params },
  515. { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS,
  516. (void (*)(void))ecdsa_set_ctx_md_params },
  517. { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS,
  518. (void (*)(void))ecdsa_settable_ctx_md_params },
  519. { 0, NULL }
  520. };