asymcipher.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /*
  2. * Copyright 2006-2023 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. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <openssl/objects.h>
  12. #include <openssl/evp.h>
  13. #include "internal/cryptlib.h"
  14. #include "internal/provider.h"
  15. #include "internal/core.h"
  16. #include "crypto/evp.h"
  17. #include "evp_local.h"
  18. static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation,
  19. const OSSL_PARAM params[])
  20. {
  21. int ret = 0;
  22. void *provkey = NULL;
  23. EVP_ASYM_CIPHER *cipher = NULL;
  24. EVP_KEYMGMT *tmp_keymgmt = NULL;
  25. const OSSL_PROVIDER *tmp_prov = NULL;
  26. const char *supported_ciph = NULL;
  27. int iter;
  28. if (ctx == NULL) {
  29. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  30. return -2;
  31. }
  32. evp_pkey_ctx_free_old_ops(ctx);
  33. ctx->operation = operation;
  34. ERR_set_mark();
  35. if (evp_pkey_ctx_is_legacy(ctx))
  36. goto legacy;
  37. if (ctx->pkey == NULL) {
  38. ERR_clear_last_mark();
  39. ERR_raise(ERR_LIB_EVP, EVP_R_NO_KEY_SET);
  40. goto err;
  41. }
  42. /*
  43. * Try to derive the supported asym cipher from |ctx->keymgmt|.
  44. */
  45. if (!ossl_assert(ctx->pkey->keymgmt == NULL
  46. || ctx->pkey->keymgmt == ctx->keymgmt)) {
  47. ERR_clear_last_mark();
  48. ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
  49. goto err;
  50. }
  51. supported_ciph
  52. = evp_keymgmt_util_query_operation_name(ctx->keymgmt,
  53. OSSL_OP_ASYM_CIPHER);
  54. if (supported_ciph == NULL) {
  55. ERR_clear_last_mark();
  56. ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
  57. goto err;
  58. }
  59. /*
  60. * We perform two iterations:
  61. *
  62. * 1. Do the normal asym cipher fetch, using the fetching data given by
  63. * the EVP_PKEY_CTX.
  64. * 2. Do the provider specific asym cipher fetch, from the same provider
  65. * as |ctx->keymgmt|
  66. *
  67. * We then try to fetch the keymgmt from the same provider as the
  68. * asym cipher, and try to export |ctx->pkey| to that keymgmt (when
  69. * this keymgmt happens to be the same as |ctx->keymgmt|, the export
  70. * is a no-op, but we call it anyway to not complicate the code even
  71. * more).
  72. * If the export call succeeds (returns a non-NULL provider key pointer),
  73. * we're done and can perform the operation itself. If not, we perform
  74. * the second iteration, or jump to legacy.
  75. */
  76. for (iter = 1, provkey = NULL; iter < 3 && provkey == NULL; iter++) {
  77. EVP_KEYMGMT *tmp_keymgmt_tofree;
  78. /*
  79. * If we're on the second iteration, free the results from the first.
  80. * They are NULL on the first iteration, so no need to check what
  81. * iteration we're on.
  82. */
  83. EVP_ASYM_CIPHER_free(cipher);
  84. EVP_KEYMGMT_free(tmp_keymgmt);
  85. switch (iter) {
  86. case 1:
  87. cipher = EVP_ASYM_CIPHER_fetch(ctx->libctx, supported_ciph,
  88. ctx->propquery);
  89. if (cipher != NULL)
  90. tmp_prov = EVP_ASYM_CIPHER_get0_provider(cipher);
  91. break;
  92. case 2:
  93. tmp_prov = EVP_KEYMGMT_get0_provider(ctx->keymgmt);
  94. cipher =
  95. evp_asym_cipher_fetch_from_prov((OSSL_PROVIDER *)tmp_prov,
  96. supported_ciph, ctx->propquery);
  97. if (cipher == NULL)
  98. goto legacy;
  99. break;
  100. }
  101. if (cipher == NULL)
  102. continue;
  103. /*
  104. * Ensure that the key is provided, either natively, or as a cached
  105. * export. We start by fetching the keymgmt with the same name as
  106. * |ctx->pkey|, but from the provider of the asym cipher method, using
  107. * the same property query as when fetching the asym cipher method.
  108. * With the keymgmt we found (if we did), we try to export |ctx->pkey|
  109. * to it (evp_pkey_export_to_provider() is smart enough to only actually
  110. * export it if |tmp_keymgmt| is different from |ctx->pkey|'s keymgmt)
  111. */
  112. tmp_keymgmt_tofree = tmp_keymgmt
  113. = evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *)tmp_prov,
  114. EVP_KEYMGMT_get0_name(ctx->keymgmt),
  115. ctx->propquery);
  116. if (tmp_keymgmt != NULL)
  117. provkey = evp_pkey_export_to_provider(ctx->pkey, ctx->libctx,
  118. &tmp_keymgmt, ctx->propquery);
  119. if (tmp_keymgmt == NULL)
  120. EVP_KEYMGMT_free(tmp_keymgmt_tofree);
  121. }
  122. if (provkey == NULL) {
  123. EVP_ASYM_CIPHER_free(cipher);
  124. goto legacy;
  125. }
  126. ERR_pop_to_mark();
  127. /* No more legacy from here down to legacy: */
  128. ctx->op.ciph.cipher = cipher;
  129. ctx->op.ciph.algctx = cipher->newctx(ossl_provider_ctx(cipher->prov));
  130. if (ctx->op.ciph.algctx == NULL) {
  131. /* The provider key can stay in the cache */
  132. ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
  133. goto err;
  134. }
  135. switch (operation) {
  136. case EVP_PKEY_OP_ENCRYPT:
  137. if (cipher->encrypt_init == NULL) {
  138. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  139. ret = -2;
  140. goto err;
  141. }
  142. ret = cipher->encrypt_init(ctx->op.ciph.algctx, provkey, params);
  143. break;
  144. case EVP_PKEY_OP_DECRYPT:
  145. if (cipher->decrypt_init == NULL) {
  146. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  147. ret = -2;
  148. goto err;
  149. }
  150. ret = cipher->decrypt_init(ctx->op.ciph.algctx, provkey, params);
  151. break;
  152. default:
  153. ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
  154. goto err;
  155. }
  156. if (ret <= 0)
  157. goto err;
  158. EVP_KEYMGMT_free(tmp_keymgmt);
  159. return 1;
  160. legacy:
  161. /*
  162. * If we don't have the full support we need with provided methods,
  163. * let's go see if legacy does.
  164. */
  165. ERR_pop_to_mark();
  166. EVP_KEYMGMT_free(tmp_keymgmt);
  167. tmp_keymgmt = NULL;
  168. if (ctx->pmeth == NULL || ctx->pmeth->encrypt == NULL) {
  169. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  170. return -2;
  171. }
  172. switch (ctx->operation) {
  173. case EVP_PKEY_OP_ENCRYPT:
  174. if (ctx->pmeth->encrypt_init == NULL)
  175. return 1;
  176. ret = ctx->pmeth->encrypt_init(ctx);
  177. break;
  178. case EVP_PKEY_OP_DECRYPT:
  179. if (ctx->pmeth->decrypt_init == NULL)
  180. return 1;
  181. ret = ctx->pmeth->decrypt_init(ctx);
  182. break;
  183. default:
  184. ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
  185. ret = -1;
  186. }
  187. err:
  188. if (ret <= 0) {
  189. evp_pkey_ctx_free_old_ops(ctx);
  190. ctx->operation = EVP_PKEY_OP_UNDEFINED;
  191. }
  192. EVP_KEYMGMT_free(tmp_keymgmt);
  193. return ret;
  194. }
  195. int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx)
  196. {
  197. return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_ENCRYPT, NULL);
  198. }
  199. int EVP_PKEY_encrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[])
  200. {
  201. return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_ENCRYPT, params);
  202. }
  203. int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
  204. unsigned char *out, size_t *outlen,
  205. const unsigned char *in, size_t inlen)
  206. {
  207. int ret;
  208. if (ctx == NULL) {
  209. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  210. return -2;
  211. }
  212. if (ctx->operation != EVP_PKEY_OP_ENCRYPT) {
  213. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_INITIALIZED);
  214. return -1;
  215. }
  216. if (ctx->op.ciph.algctx == NULL)
  217. goto legacy;
  218. ret = ctx->op.ciph.cipher->encrypt(ctx->op.ciph.algctx, out, outlen,
  219. (out == NULL ? 0 : *outlen), in, inlen);
  220. return ret;
  221. legacy:
  222. if (ctx->pmeth == NULL || ctx->pmeth->encrypt == NULL) {
  223. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  224. return -2;
  225. }
  226. M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_ENCRYPT)
  227. return ctx->pmeth->encrypt(ctx, out, outlen, in, inlen);
  228. }
  229. int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx)
  230. {
  231. return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_DECRYPT, NULL);
  232. }
  233. int EVP_PKEY_decrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[])
  234. {
  235. return evp_pkey_asym_cipher_init(ctx, EVP_PKEY_OP_DECRYPT, params);
  236. }
  237. int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
  238. unsigned char *out, size_t *outlen,
  239. const unsigned char *in, size_t inlen)
  240. {
  241. int ret;
  242. if (ctx == NULL) {
  243. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  244. return -2;
  245. }
  246. if (ctx->operation != EVP_PKEY_OP_DECRYPT) {
  247. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_INITIALIZED);
  248. return -1;
  249. }
  250. if (ctx->op.ciph.algctx == NULL)
  251. goto legacy;
  252. ret = ctx->op.ciph.cipher->decrypt(ctx->op.ciph.algctx, out, outlen,
  253. (out == NULL ? 0 : *outlen), in, inlen);
  254. return ret;
  255. legacy:
  256. if (ctx->pmeth == NULL || ctx->pmeth->decrypt == NULL) {
  257. ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  258. return -2;
  259. }
  260. M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_DECRYPT)
  261. return ctx->pmeth->decrypt(ctx, out, outlen, in, inlen);
  262. }
  263. /* decrypt to new buffer of dynamic size, checking any pre-determined size */
  264. int evp_pkey_decrypt_alloc(EVP_PKEY_CTX *ctx, unsigned char **outp,
  265. size_t *outlenp, size_t expected_outlen,
  266. const unsigned char *in, size_t inlen)
  267. {
  268. if (EVP_PKEY_decrypt(ctx, NULL, outlenp, in, inlen) <= 0
  269. || (*outp = OPENSSL_malloc(*outlenp)) == NULL)
  270. return -1;
  271. if (EVP_PKEY_decrypt(ctx, *outp, outlenp, in, inlen) <= 0
  272. || *outlenp == 0
  273. || (expected_outlen != 0 && *outlenp != expected_outlen)) {
  274. ERR_raise(ERR_LIB_EVP, ERR_R_EVP_LIB);
  275. OPENSSL_clear_free(*outp, *outlenp);
  276. *outp = NULL;
  277. return 0;
  278. }
  279. return 1;
  280. }
  281. static EVP_ASYM_CIPHER *evp_asym_cipher_new(OSSL_PROVIDER *prov)
  282. {
  283. EVP_ASYM_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_ASYM_CIPHER));
  284. if (cipher == NULL)
  285. return NULL;
  286. if (!CRYPTO_NEW_REF(&cipher->refcnt, 1)) {
  287. OPENSSL_free(cipher);
  288. return NULL;
  289. }
  290. cipher->prov = prov;
  291. ossl_provider_up_ref(prov);
  292. return cipher;
  293. }
  294. static void *evp_asym_cipher_from_algorithm(int name_id,
  295. const OSSL_ALGORITHM *algodef,
  296. OSSL_PROVIDER *prov)
  297. {
  298. const OSSL_DISPATCH *fns = algodef->implementation;
  299. EVP_ASYM_CIPHER *cipher = NULL;
  300. int ctxfncnt = 0, encfncnt = 0, decfncnt = 0;
  301. int gparamfncnt = 0, sparamfncnt = 0;
  302. if ((cipher = evp_asym_cipher_new(prov)) == NULL) {
  303. ERR_raise(ERR_LIB_EVP, ERR_R_EVP_LIB);
  304. goto err;
  305. }
  306. cipher->name_id = name_id;
  307. if ((cipher->type_name = ossl_algorithm_get1_first_name(algodef)) == NULL)
  308. goto err;
  309. cipher->description = algodef->algorithm_description;
  310. for (; fns->function_id != 0; fns++) {
  311. switch (fns->function_id) {
  312. case OSSL_FUNC_ASYM_CIPHER_NEWCTX:
  313. if (cipher->newctx != NULL)
  314. break;
  315. cipher->newctx = OSSL_FUNC_asym_cipher_newctx(fns);
  316. ctxfncnt++;
  317. break;
  318. case OSSL_FUNC_ASYM_CIPHER_ENCRYPT_INIT:
  319. if (cipher->encrypt_init != NULL)
  320. break;
  321. cipher->encrypt_init = OSSL_FUNC_asym_cipher_encrypt_init(fns);
  322. encfncnt++;
  323. break;
  324. case OSSL_FUNC_ASYM_CIPHER_ENCRYPT:
  325. if (cipher->encrypt != NULL)
  326. break;
  327. cipher->encrypt = OSSL_FUNC_asym_cipher_encrypt(fns);
  328. encfncnt++;
  329. break;
  330. case OSSL_FUNC_ASYM_CIPHER_DECRYPT_INIT:
  331. if (cipher->decrypt_init != NULL)
  332. break;
  333. cipher->decrypt_init = OSSL_FUNC_asym_cipher_decrypt_init(fns);
  334. decfncnt++;
  335. break;
  336. case OSSL_FUNC_ASYM_CIPHER_DECRYPT:
  337. if (cipher->decrypt != NULL)
  338. break;
  339. cipher->decrypt = OSSL_FUNC_asym_cipher_decrypt(fns);
  340. decfncnt++;
  341. break;
  342. case OSSL_FUNC_ASYM_CIPHER_FREECTX:
  343. if (cipher->freectx != NULL)
  344. break;
  345. cipher->freectx = OSSL_FUNC_asym_cipher_freectx(fns);
  346. ctxfncnt++;
  347. break;
  348. case OSSL_FUNC_ASYM_CIPHER_DUPCTX:
  349. if (cipher->dupctx != NULL)
  350. break;
  351. cipher->dupctx = OSSL_FUNC_asym_cipher_dupctx(fns);
  352. break;
  353. case OSSL_FUNC_ASYM_CIPHER_GET_CTX_PARAMS:
  354. if (cipher->get_ctx_params != NULL)
  355. break;
  356. cipher->get_ctx_params
  357. = OSSL_FUNC_asym_cipher_get_ctx_params(fns);
  358. gparamfncnt++;
  359. break;
  360. case OSSL_FUNC_ASYM_CIPHER_GETTABLE_CTX_PARAMS:
  361. if (cipher->gettable_ctx_params != NULL)
  362. break;
  363. cipher->gettable_ctx_params
  364. = OSSL_FUNC_asym_cipher_gettable_ctx_params(fns);
  365. gparamfncnt++;
  366. break;
  367. case OSSL_FUNC_ASYM_CIPHER_SET_CTX_PARAMS:
  368. if (cipher->set_ctx_params != NULL)
  369. break;
  370. cipher->set_ctx_params
  371. = OSSL_FUNC_asym_cipher_set_ctx_params(fns);
  372. sparamfncnt++;
  373. break;
  374. case OSSL_FUNC_ASYM_CIPHER_SETTABLE_CTX_PARAMS:
  375. if (cipher->settable_ctx_params != NULL)
  376. break;
  377. cipher->settable_ctx_params
  378. = OSSL_FUNC_asym_cipher_settable_ctx_params(fns);
  379. sparamfncnt++;
  380. break;
  381. }
  382. }
  383. if (ctxfncnt != 2
  384. || (encfncnt != 0 && encfncnt != 2)
  385. || (decfncnt != 0 && decfncnt != 2)
  386. || (encfncnt != 2 && decfncnt != 2)
  387. || (gparamfncnt != 0 && gparamfncnt != 2)
  388. || (sparamfncnt != 0 && sparamfncnt != 2)) {
  389. /*
  390. * In order to be a consistent set of functions we must have at least
  391. * a set of context functions (newctx and freectx) as well as a pair of
  392. * "cipher" functions: (encrypt_init, encrypt) or
  393. * (decrypt_init decrypt). set_ctx_params and settable_ctx_params are
  394. * optional, but if one of them is present then the other one must also
  395. * be present. The same applies to get_ctx_params and
  396. * gettable_ctx_params. The dupctx function is optional.
  397. */
  398. ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS);
  399. goto err;
  400. }
  401. return cipher;
  402. err:
  403. EVP_ASYM_CIPHER_free(cipher);
  404. return NULL;
  405. }
  406. void EVP_ASYM_CIPHER_free(EVP_ASYM_CIPHER *cipher)
  407. {
  408. int i;
  409. if (cipher == NULL)
  410. return;
  411. CRYPTO_DOWN_REF(&cipher->refcnt, &i);
  412. if (i > 0)
  413. return;
  414. OPENSSL_free(cipher->type_name);
  415. ossl_provider_free(cipher->prov);
  416. CRYPTO_FREE_REF(&cipher->refcnt);
  417. OPENSSL_free(cipher);
  418. }
  419. int EVP_ASYM_CIPHER_up_ref(EVP_ASYM_CIPHER *cipher)
  420. {
  421. int ref = 0;
  422. CRYPTO_UP_REF(&cipher->refcnt, &ref);
  423. return 1;
  424. }
  425. OSSL_PROVIDER *EVP_ASYM_CIPHER_get0_provider(const EVP_ASYM_CIPHER *cipher)
  426. {
  427. return cipher->prov;
  428. }
  429. EVP_ASYM_CIPHER *EVP_ASYM_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
  430. const char *properties)
  431. {
  432. return evp_generic_fetch(ctx, OSSL_OP_ASYM_CIPHER, algorithm, properties,
  433. evp_asym_cipher_from_algorithm,
  434. (int (*)(void *))EVP_ASYM_CIPHER_up_ref,
  435. (void (*)(void *))EVP_ASYM_CIPHER_free);
  436. }
  437. EVP_ASYM_CIPHER *evp_asym_cipher_fetch_from_prov(OSSL_PROVIDER *prov,
  438. const char *algorithm,
  439. const char *properties)
  440. {
  441. return evp_generic_fetch_from_prov(prov, OSSL_OP_ASYM_CIPHER,
  442. algorithm, properties,
  443. evp_asym_cipher_from_algorithm,
  444. (int (*)(void *))EVP_ASYM_CIPHER_up_ref,
  445. (void (*)(void *))EVP_ASYM_CIPHER_free);
  446. }
  447. int EVP_ASYM_CIPHER_is_a(const EVP_ASYM_CIPHER *cipher, const char *name)
  448. {
  449. return evp_is_a(cipher->prov, cipher->name_id, NULL, name);
  450. }
  451. int evp_asym_cipher_get_number(const EVP_ASYM_CIPHER *cipher)
  452. {
  453. return cipher->name_id;
  454. }
  455. const char *EVP_ASYM_CIPHER_get0_name(const EVP_ASYM_CIPHER *cipher)
  456. {
  457. return cipher->type_name;
  458. }
  459. const char *EVP_ASYM_CIPHER_get0_description(const EVP_ASYM_CIPHER *cipher)
  460. {
  461. return cipher->description;
  462. }
  463. void EVP_ASYM_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx,
  464. void (*fn)(EVP_ASYM_CIPHER *cipher,
  465. void *arg),
  466. void *arg)
  467. {
  468. evp_generic_do_all(libctx, OSSL_OP_ASYM_CIPHER,
  469. (void (*)(void *, void *))fn, arg,
  470. evp_asym_cipher_from_algorithm,
  471. (int (*)(void *))EVP_ASYM_CIPHER_up_ref,
  472. (void (*)(void *))EVP_ASYM_CIPHER_free);
  473. }
  474. int EVP_ASYM_CIPHER_names_do_all(const EVP_ASYM_CIPHER *cipher,
  475. void (*fn)(const char *name, void *data),
  476. void *data)
  477. {
  478. if (cipher->prov != NULL)
  479. return evp_names_do_all(cipher->prov, cipher->name_id, fn, data);
  480. return 1;
  481. }
  482. const OSSL_PARAM *EVP_ASYM_CIPHER_gettable_ctx_params(const EVP_ASYM_CIPHER *cip)
  483. {
  484. void *provctx;
  485. if (cip == NULL || cip->gettable_ctx_params == NULL)
  486. return NULL;
  487. provctx = ossl_provider_ctx(EVP_ASYM_CIPHER_get0_provider(cip));
  488. return cip->gettable_ctx_params(NULL, provctx);
  489. }
  490. const OSSL_PARAM *EVP_ASYM_CIPHER_settable_ctx_params(const EVP_ASYM_CIPHER *cip)
  491. {
  492. void *provctx;
  493. if (cip == NULL || cip->settable_ctx_params == NULL)
  494. return NULL;
  495. provctx = ossl_provider_ctx(EVP_ASYM_CIPHER_get0_provider(cip));
  496. return cip->settable_ctx_params(NULL, provctx);
  497. }