evp.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. /*
  2. * Copyright 2015-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. #ifndef OSSL_CRYPTO_EVP_H
  10. # define OSSL_CRYPTO_EVP_H
  11. # pragma once
  12. # include <openssl/evp.h>
  13. # include <openssl/core_dispatch.h>
  14. # include "internal/refcount.h"
  15. # include "crypto/ecx.h"
  16. /*
  17. * Don't free up md_ctx->pctx in EVP_MD_CTX_reset, use the reserved flag
  18. * values in evp.h
  19. */
  20. #define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX 0x0400
  21. /*
  22. * An EVP_PKEY_CTX can have the following support states:
  23. *
  24. * Supports legacy implementations only:
  25. *
  26. * engine != NULL || keytype == NULL
  27. *
  28. * Supports provided implementations:
  29. *
  30. * engine == NULL && keytype != NULL
  31. */
  32. #define evp_pkey_ctx_is_legacy(ctx) \
  33. ((ctx)->engine != NULL || (ctx)->keytype == NULL)
  34. #define evp_pkey_ctx_is_provided(ctx) \
  35. (!evp_pkey_ctx_is_legacy(ctx))
  36. struct evp_pkey_ctx_st {
  37. /* Actual operation */
  38. int operation;
  39. /*
  40. * Library context, property query, keytype and keymgmt associated with
  41. * this context
  42. */
  43. OSSL_LIB_CTX *libctx;
  44. char *propquery;
  45. const char *keytype;
  46. EVP_KEYMGMT *keymgmt;
  47. union {
  48. struct {
  49. void *genctx;
  50. } keymgmt;
  51. struct {
  52. EVP_KEYEXCH *exchange;
  53. /*
  54. * Opaque ctx returned from a providers exchange algorithm
  55. * implementation OSSL_FUNC_keyexch_newctx()
  56. */
  57. void *algctx;
  58. } kex;
  59. struct {
  60. EVP_SIGNATURE *signature;
  61. /*
  62. * Opaque ctx returned from a providers signature algorithm
  63. * implementation OSSL_FUNC_signature_newctx()
  64. */
  65. void *algctx;
  66. } sig;
  67. struct {
  68. EVP_ASYM_CIPHER *cipher;
  69. /*
  70. * Opaque ctx returned from a providers asymmetric cipher algorithm
  71. * implementation OSSL_FUNC_asym_cipher_newctx()
  72. */
  73. void *algctx;
  74. } ciph;
  75. struct {
  76. EVP_KEM *kem;
  77. /*
  78. * Opaque ctx returned from a providers KEM algorithm
  79. * implementation OSSL_FUNC_kem_newctx()
  80. */
  81. void *algctx;
  82. } encap;
  83. } op;
  84. /*
  85. * Cached parameters. Inits of operations that depend on these should
  86. * call evp_pkey_ctx_use_delayed_data() when the operation has been set
  87. * up properly.
  88. */
  89. struct {
  90. /* Distinguishing Identifier, ISO/IEC 15946-3, FIPS 196 */
  91. char *dist_id_name; /* The name used with EVP_PKEY_CTX_ctrl_str() */
  92. void *dist_id; /* The distinguishing ID itself */
  93. size_t dist_id_len; /* The length of the distinguishing ID */
  94. /* Indicators of what has been set. Keep them together! */
  95. unsigned int dist_id_set : 1;
  96. } cached_parameters;
  97. /* Application specific data, usually used by the callback */
  98. void *app_data;
  99. /* Keygen callback */
  100. EVP_PKEY_gen_cb *pkey_gencb;
  101. /* implementation specific keygen data */
  102. int *keygen_info;
  103. int keygen_info_count;
  104. /* Legacy fields below */
  105. /* EVP_PKEY identity */
  106. int legacy_keytype;
  107. /* Method associated with this operation */
  108. const EVP_PKEY_METHOD *pmeth;
  109. /* Engine that implements this method or NULL if builtin */
  110. ENGINE *engine;
  111. /* Key: may be NULL */
  112. EVP_PKEY *pkey;
  113. /* Peer key for key agreement, may be NULL */
  114. EVP_PKEY *peerkey;
  115. /* Algorithm specific data */
  116. void *data;
  117. /* Indicator if digest_custom needs to be called */
  118. unsigned int flag_call_digest_custom:1;
  119. /*
  120. * Used to support taking custody of memory in the case of a provider being
  121. * used with the deprecated EVP_PKEY_CTX_set_rsa_keygen_pubexp() API. This
  122. * member should NOT be used for any other purpose and should be removed
  123. * when said deprecated API is excised completely.
  124. */
  125. BIGNUM *rsa_pubexp;
  126. } /* EVP_PKEY_CTX */ ;
  127. #define EVP_PKEY_FLAG_DYNAMIC 1
  128. struct evp_pkey_method_st {
  129. int pkey_id;
  130. int flags;
  131. int (*init) (EVP_PKEY_CTX *ctx);
  132. int (*copy) (EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src);
  133. void (*cleanup) (EVP_PKEY_CTX *ctx);
  134. int (*paramgen_init) (EVP_PKEY_CTX *ctx);
  135. int (*paramgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
  136. int (*keygen_init) (EVP_PKEY_CTX *ctx);
  137. int (*keygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
  138. int (*sign_init) (EVP_PKEY_CTX *ctx);
  139. int (*sign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
  140. const unsigned char *tbs, size_t tbslen);
  141. int (*verify_init) (EVP_PKEY_CTX *ctx);
  142. int (*verify) (EVP_PKEY_CTX *ctx,
  143. const unsigned char *sig, size_t siglen,
  144. const unsigned char *tbs, size_t tbslen);
  145. int (*verify_recover_init) (EVP_PKEY_CTX *ctx);
  146. int (*verify_recover) (EVP_PKEY_CTX *ctx,
  147. unsigned char *rout, size_t *routlen,
  148. const unsigned char *sig, size_t siglen);
  149. int (*signctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
  150. int (*signctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
  151. EVP_MD_CTX *mctx);
  152. int (*verifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
  153. int (*verifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen,
  154. EVP_MD_CTX *mctx);
  155. int (*encrypt_init) (EVP_PKEY_CTX *ctx);
  156. int (*encrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
  157. const unsigned char *in, size_t inlen);
  158. int (*decrypt_init) (EVP_PKEY_CTX *ctx);
  159. int (*decrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
  160. const unsigned char *in, size_t inlen);
  161. int (*derive_init) (EVP_PKEY_CTX *ctx);
  162. int (*derive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
  163. int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2);
  164. int (*ctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value);
  165. int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
  166. const unsigned char *tbs, size_t tbslen);
  167. int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
  168. size_t siglen, const unsigned char *tbs,
  169. size_t tbslen);
  170. int (*check) (EVP_PKEY *pkey);
  171. int (*public_check) (EVP_PKEY *pkey);
  172. int (*param_check) (EVP_PKEY *pkey);
  173. int (*digest_custom) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
  174. } /* EVP_PKEY_METHOD */ ;
  175. DEFINE_STACK_OF_CONST(EVP_PKEY_METHOD)
  176. void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);
  177. const EVP_PKEY_METHOD *ossl_dh_pkey_method(void);
  178. const EVP_PKEY_METHOD *ossl_dhx_pkey_method(void);
  179. const EVP_PKEY_METHOD *ossl_dsa_pkey_method(void);
  180. const EVP_PKEY_METHOD *ossl_ec_pkey_method(void);
  181. const EVP_PKEY_METHOD *ossl_ecx25519_pkey_method(void);
  182. const EVP_PKEY_METHOD *ossl_ecx448_pkey_method(void);
  183. const EVP_PKEY_METHOD *ossl_ed25519_pkey_method(void);
  184. const EVP_PKEY_METHOD *ossl_ed448_pkey_method(void);
  185. const EVP_PKEY_METHOD *ossl_rsa_pkey_method(void);
  186. const EVP_PKEY_METHOD *ossl_rsa_pss_pkey_method(void);
  187. struct evp_mac_st {
  188. OSSL_PROVIDER *prov;
  189. int name_id;
  190. char *type_name;
  191. const char *description;
  192. CRYPTO_REF_COUNT refcnt;
  193. CRYPTO_RWLOCK *lock;
  194. OSSL_FUNC_mac_newctx_fn *newctx;
  195. OSSL_FUNC_mac_dupctx_fn *dupctx;
  196. OSSL_FUNC_mac_freectx_fn *freectx;
  197. OSSL_FUNC_mac_init_fn *init;
  198. OSSL_FUNC_mac_update_fn *update;
  199. OSSL_FUNC_mac_final_fn *final;
  200. OSSL_FUNC_mac_gettable_params_fn *gettable_params;
  201. OSSL_FUNC_mac_gettable_ctx_params_fn *gettable_ctx_params;
  202. OSSL_FUNC_mac_settable_ctx_params_fn *settable_ctx_params;
  203. OSSL_FUNC_mac_get_params_fn *get_params;
  204. OSSL_FUNC_mac_get_ctx_params_fn *get_ctx_params;
  205. OSSL_FUNC_mac_set_ctx_params_fn *set_ctx_params;
  206. };
  207. struct evp_kdf_st {
  208. OSSL_PROVIDER *prov;
  209. int name_id;
  210. char *type_name;
  211. const char *description;
  212. CRYPTO_REF_COUNT refcnt;
  213. CRYPTO_RWLOCK *lock;
  214. OSSL_FUNC_kdf_newctx_fn *newctx;
  215. OSSL_FUNC_kdf_dupctx_fn *dupctx;
  216. OSSL_FUNC_kdf_freectx_fn *freectx;
  217. OSSL_FUNC_kdf_reset_fn *reset;
  218. OSSL_FUNC_kdf_derive_fn *derive;
  219. OSSL_FUNC_kdf_gettable_params_fn *gettable_params;
  220. OSSL_FUNC_kdf_gettable_ctx_params_fn *gettable_ctx_params;
  221. OSSL_FUNC_kdf_settable_ctx_params_fn *settable_ctx_params;
  222. OSSL_FUNC_kdf_get_params_fn *get_params;
  223. OSSL_FUNC_kdf_get_ctx_params_fn *get_ctx_params;
  224. OSSL_FUNC_kdf_set_ctx_params_fn *set_ctx_params;
  225. };
  226. #define EVP_ORIG_DYNAMIC 0
  227. #define EVP_ORIG_GLOBAL 1
  228. #define EVP_ORIG_METH 2
  229. struct evp_md_st {
  230. /* nid */
  231. int type;
  232. /* Legacy structure members */
  233. int pkey_type;
  234. int md_size;
  235. unsigned long flags;
  236. int origin;
  237. int (*init) (EVP_MD_CTX *ctx);
  238. int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count);
  239. int (*final) (EVP_MD_CTX *ctx, unsigned char *md);
  240. int (*copy) (EVP_MD_CTX *to, const EVP_MD_CTX *from);
  241. int (*cleanup) (EVP_MD_CTX *ctx);
  242. int block_size;
  243. int ctx_size; /* how big does the ctx->md_data need to be */
  244. /* control function */
  245. int (*md_ctrl) (EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
  246. /* New structure members */
  247. /* Above comment to be removed when legacy has gone */
  248. int name_id;
  249. char *type_name;
  250. const char *description;
  251. OSSL_PROVIDER *prov;
  252. CRYPTO_REF_COUNT refcnt;
  253. CRYPTO_RWLOCK *lock;
  254. OSSL_FUNC_digest_newctx_fn *newctx;
  255. OSSL_FUNC_digest_init_fn *dinit;
  256. OSSL_FUNC_digest_update_fn *dupdate;
  257. OSSL_FUNC_digest_final_fn *dfinal;
  258. OSSL_FUNC_digest_digest_fn *digest;
  259. OSSL_FUNC_digest_freectx_fn *freectx;
  260. OSSL_FUNC_digest_dupctx_fn *dupctx;
  261. OSSL_FUNC_digest_get_params_fn *get_params;
  262. OSSL_FUNC_digest_set_ctx_params_fn *set_ctx_params;
  263. OSSL_FUNC_digest_get_ctx_params_fn *get_ctx_params;
  264. OSSL_FUNC_digest_gettable_params_fn *gettable_params;
  265. OSSL_FUNC_digest_settable_ctx_params_fn *settable_ctx_params;
  266. OSSL_FUNC_digest_gettable_ctx_params_fn *gettable_ctx_params;
  267. } /* EVP_MD */ ;
  268. struct evp_cipher_st {
  269. int nid;
  270. int block_size;
  271. /* Default value for variable length ciphers */
  272. int key_len;
  273. int iv_len;
  274. /* Legacy structure members */
  275. /* Various flags */
  276. unsigned long flags;
  277. /* How the EVP_CIPHER was created. */
  278. int origin;
  279. /* init key */
  280. int (*init) (EVP_CIPHER_CTX *ctx, const unsigned char *key,
  281. const unsigned char *iv, int enc);
  282. /* encrypt/decrypt data */
  283. int (*do_cipher) (EVP_CIPHER_CTX *ctx, unsigned char *out,
  284. const unsigned char *in, size_t inl);
  285. /* cleanup ctx */
  286. int (*cleanup) (EVP_CIPHER_CTX *);
  287. /* how big ctx->cipher_data needs to be */
  288. int ctx_size;
  289. /* Populate a ASN1_TYPE with parameters */
  290. int (*set_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *);
  291. /* Get parameters from a ASN1_TYPE */
  292. int (*get_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *);
  293. /* Miscellaneous operations */
  294. int (*ctrl) (EVP_CIPHER_CTX *, int type, int arg, void *ptr);
  295. /* Application data */
  296. void *app_data;
  297. /* New structure members */
  298. /* Above comment to be removed when legacy has gone */
  299. int name_id;
  300. char *type_name;
  301. const char *description;
  302. OSSL_PROVIDER *prov;
  303. CRYPTO_REF_COUNT refcnt;
  304. CRYPTO_RWLOCK *lock;
  305. OSSL_FUNC_cipher_newctx_fn *newctx;
  306. OSSL_FUNC_cipher_encrypt_init_fn *einit;
  307. OSSL_FUNC_cipher_decrypt_init_fn *dinit;
  308. OSSL_FUNC_cipher_update_fn *cupdate;
  309. OSSL_FUNC_cipher_final_fn *cfinal;
  310. OSSL_FUNC_cipher_cipher_fn *ccipher;
  311. OSSL_FUNC_cipher_freectx_fn *freectx;
  312. OSSL_FUNC_cipher_dupctx_fn *dupctx;
  313. OSSL_FUNC_cipher_get_params_fn *get_params;
  314. OSSL_FUNC_cipher_get_ctx_params_fn *get_ctx_params;
  315. OSSL_FUNC_cipher_set_ctx_params_fn *set_ctx_params;
  316. OSSL_FUNC_cipher_gettable_params_fn *gettable_params;
  317. OSSL_FUNC_cipher_gettable_ctx_params_fn *gettable_ctx_params;
  318. OSSL_FUNC_cipher_settable_ctx_params_fn *settable_ctx_params;
  319. } /* EVP_CIPHER */ ;
  320. /* Macros to code block cipher wrappers */
  321. /* Wrapper functions for each cipher mode */
  322. #define EVP_C_DATA(kstruct, ctx) \
  323. ((kstruct *)EVP_CIPHER_CTX_get_cipher_data(ctx))
  324. #define BLOCK_CIPHER_ecb_loop() \
  325. size_t i, bl; \
  326. bl = EVP_CIPHER_CTX_get0_cipher(ctx)->block_size; \
  327. if (inl < bl) return 1;\
  328. inl -= bl; \
  329. for (i=0; i <= inl; i+=bl)
  330. #define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
  331. static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  332. {\
  333. BLOCK_CIPHER_ecb_loop() \
  334. cprefix##_ecb_encrypt(in + i, out + i, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_is_encrypting(ctx)); \
  335. return 1;\
  336. }
  337. #define EVP_MAXCHUNK ((size_t)1<<(sizeof(long)*8-2))
  338. #define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
  339. static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  340. {\
  341. while(inl>=EVP_MAXCHUNK) {\
  342. int num = EVP_CIPHER_CTX_get_num(ctx);\
  343. cprefix##_ofb##cbits##_encrypt(in, out, (long)EVP_MAXCHUNK, &EVP_C_DATA(kstruct,ctx)->ksched, ctx->iv, &num); \
  344. EVP_CIPHER_CTX_set_num(ctx, num);\
  345. inl-=EVP_MAXCHUNK;\
  346. in +=EVP_MAXCHUNK;\
  347. out+=EVP_MAXCHUNK;\
  348. }\
  349. if (inl) {\
  350. int num = EVP_CIPHER_CTX_get_num(ctx);\
  351. cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct,ctx)->ksched, ctx->iv, &num); \
  352. EVP_CIPHER_CTX_set_num(ctx, num);\
  353. }\
  354. return 1;\
  355. }
  356. #define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
  357. static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  358. {\
  359. while(inl>=EVP_MAXCHUNK) \
  360. {\
  361. cprefix##_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &EVP_C_DATA(kstruct,ctx)->ksched, ctx->iv, EVP_CIPHER_CTX_is_encrypting(ctx));\
  362. inl-=EVP_MAXCHUNK;\
  363. in +=EVP_MAXCHUNK;\
  364. out+=EVP_MAXCHUNK;\
  365. }\
  366. if (inl)\
  367. cprefix##_cbc_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct,ctx)->ksched, ctx->iv, EVP_CIPHER_CTX_is_encrypting(ctx));\
  368. return 1;\
  369. }
  370. #define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
  371. static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  372. {\
  373. size_t chunk = EVP_MAXCHUNK;\
  374. if (cbits == 1) chunk >>= 3;\
  375. if (inl < chunk) chunk = inl;\
  376. while (inl && inl >= chunk)\
  377. {\
  378. int num = EVP_CIPHER_CTX_get_num(ctx);\
  379. cprefix##_cfb##cbits##_encrypt(in, out, (long) \
  380. ((cbits == 1) \
  381. && !EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS) \
  382. ? chunk*8 : chunk), \
  383. &EVP_C_DATA(kstruct, ctx)->ksched, ctx->iv,\
  384. &num, EVP_CIPHER_CTX_is_encrypting(ctx));\
  385. EVP_CIPHER_CTX_set_num(ctx, num);\
  386. inl -= chunk;\
  387. in += chunk;\
  388. out += chunk;\
  389. if (inl < chunk) chunk = inl;\
  390. }\
  391. return 1;\
  392. }
  393. #define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
  394. BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
  395. BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
  396. BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
  397. BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched)
  398. #define BLOCK_CIPHER_def1(cname, nmode, mode, MODE, kstruct, nid, block_size, \
  399. key_len, iv_len, flags, init_key, cleanup, \
  400. set_asn1, get_asn1, ctrl) \
  401. static const EVP_CIPHER cname##_##mode = { \
  402. nid##_##nmode, block_size, key_len, iv_len, \
  403. flags | EVP_CIPH_##MODE##_MODE, \
  404. EVP_ORIG_GLOBAL, \
  405. init_key, \
  406. cname##_##mode##_cipher, \
  407. cleanup, \
  408. sizeof(kstruct), \
  409. set_asn1, get_asn1,\
  410. ctrl, \
  411. NULL \
  412. }; \
  413. const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; }
  414. #define BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, \
  415. iv_len, flags, init_key, cleanup, set_asn1, \
  416. get_asn1, ctrl) \
  417. BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \
  418. iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
  419. #define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, \
  420. iv_len, cbits, flags, init_key, cleanup, \
  421. set_asn1, get_asn1, ctrl) \
  422. BLOCK_CIPHER_def1(cname, cfb##cbits, cfb##cbits, CFB, kstruct, nid, 1, \
  423. key_len, iv_len, flags, init_key, cleanup, set_asn1, \
  424. get_asn1, ctrl)
  425. #define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, \
  426. iv_len, cbits, flags, init_key, cleanup, \
  427. set_asn1, get_asn1, ctrl) \
  428. BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, 1, \
  429. key_len, iv_len, flags, init_key, cleanup, set_asn1, \
  430. get_asn1, ctrl)
  431. #define BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, \
  432. flags, init_key, cleanup, set_asn1, \
  433. get_asn1, ctrl) \
  434. BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \
  435. 0, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
  436. #define BLOCK_CIPHER_defs(cname, kstruct, \
  437. nid, block_size, key_len, iv_len, cbits, flags, \
  438. init_key, cleanup, set_asn1, get_asn1, ctrl) \
  439. BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
  440. init_key, cleanup, set_asn1, get_asn1, ctrl) \
  441. BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, iv_len, cbits, \
  442. flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
  443. BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, iv_len, cbits, \
  444. flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
  445. BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, flags, \
  446. init_key, cleanup, set_asn1, get_asn1, ctrl)
  447. /*-
  448. #define BLOCK_CIPHER_defs(cname, kstruct, \
  449. nid, block_size, key_len, iv_len, flags,\
  450. init_key, cleanup, set_asn1, get_asn1, ctrl)\
  451. static const EVP_CIPHER cname##_cbc = {\
  452. nid##_cbc, block_size, key_len, iv_len, \
  453. flags | EVP_CIPH_CBC_MODE,\
  454. EVP_ORIG_GLOBAL,\
  455. init_key,\
  456. cname##_cbc_cipher,\
  457. cleanup,\
  458. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  459. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  460. set_asn1, get_asn1,\
  461. ctrl, \
  462. NULL \
  463. };\
  464. const EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\
  465. static const EVP_CIPHER cname##_cfb = {\
  466. nid##_cfb64, 1, key_len, iv_len, \
  467. flags | EVP_CIPH_CFB_MODE,\
  468. EVP_ORIG_GLOBAL,\
  469. init_key,\
  470. cname##_cfb_cipher,\
  471. cleanup,\
  472. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  473. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  474. set_asn1, get_asn1,\
  475. ctrl,\
  476. NULL \
  477. };\
  478. const EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\
  479. static const EVP_CIPHER cname##_ofb = {\
  480. nid##_ofb64, 1, key_len, iv_len, \
  481. flags | EVP_CIPH_OFB_MODE,\
  482. EVP_ORIG_GLOBAL,\
  483. init_key,\
  484. cname##_ofb_cipher,\
  485. cleanup,\
  486. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  487. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  488. set_asn1, get_asn1,\
  489. ctrl,\
  490. NULL \
  491. };\
  492. const EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\
  493. static const EVP_CIPHER cname##_ecb = {\
  494. nid##_ecb, block_size, key_len, iv_len, \
  495. flags | EVP_CIPH_ECB_MODE,\
  496. EVP_ORIG_GLOBAL,\
  497. init_key,\
  498. cname##_ecb_cipher,\
  499. cleanup,\
  500. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  501. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  502. set_asn1, get_asn1,\
  503. ctrl,\
  504. NULL \
  505. };\
  506. const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
  507. */
  508. #define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid, \
  509. block_size, key_len, iv_len, cbits, \
  510. flags, init_key, \
  511. cleanup, set_asn1, get_asn1, ctrl) \
  512. BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
  513. BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, \
  514. cbits, flags, init_key, cleanup, set_asn1, \
  515. get_asn1, ctrl)
  516. #define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,fl) \
  517. BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
  518. BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
  519. NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
  520. (fl)|EVP_CIPH_FLAG_DEFAULT_ASN1, \
  521. cipher##_init_key, NULL, NULL, NULL, NULL)
  522. typedef struct {
  523. unsigned char iv[EVP_MAX_IV_LENGTH];
  524. unsigned int iv_len;
  525. unsigned int tag_len;
  526. } evp_cipher_aead_asn1_params;
  527. int evp_cipher_param_to_asn1_ex(EVP_CIPHER_CTX *c, ASN1_TYPE *type,
  528. evp_cipher_aead_asn1_params *params);
  529. int evp_cipher_asn1_to_param_ex(EVP_CIPHER_CTX *c, ASN1_TYPE *type,
  530. evp_cipher_aead_asn1_params *params);
  531. /*
  532. * To support transparent execution of operation in backends other
  533. * than the "origin" key, we support transparent export/import to
  534. * those providers, and maintain a cache of the imported keydata,
  535. * so we don't need to redo the export/import every time we perform
  536. * the same operation in that same provider.
  537. * This requires that the "origin" backend (whether it's a legacy or a
  538. * provider "origin") implements exports, and that the target provider
  539. * has an EVP_KEYMGMT that implements import.
  540. */
  541. typedef struct {
  542. EVP_KEYMGMT *keymgmt;
  543. void *keydata;
  544. } OP_CACHE_ELEM;
  545. DEFINE_STACK_OF(OP_CACHE_ELEM)
  546. /*
  547. * An EVP_PKEY can have the following states:
  548. *
  549. * untyped & empty:
  550. *
  551. * type == EVP_PKEY_NONE && keymgmt == NULL
  552. *
  553. * typed & empty:
  554. *
  555. * (type != EVP_PKEY_NONE && pkey.ptr == NULL) ## legacy (libcrypto only)
  556. * || (keymgmt != NULL && keydata == NULL) ## provider side
  557. *
  558. * fully assigned:
  559. *
  560. * (type != EVP_PKEY_NONE && pkey.ptr != NULL) ## legacy (libcrypto only)
  561. * || (keymgmt != NULL && keydata != NULL) ## provider side
  562. *
  563. * The easiest way to detect a legacy key is:
  564. *
  565. * keymgmt == NULL && type != EVP_PKEY_NONE
  566. *
  567. * The easiest way to detect a provider side key is:
  568. *
  569. * keymgmt != NULL
  570. */
  571. #define evp_pkey_is_blank(pk) \
  572. ((pk)->type == EVP_PKEY_NONE && (pk)->keymgmt == NULL)
  573. #define evp_pkey_is_typed(pk) \
  574. ((pk)->type != EVP_PKEY_NONE || (pk)->keymgmt != NULL)
  575. #ifndef FIPS_MODULE
  576. # define evp_pkey_is_assigned(pk) \
  577. ((pk)->pkey.ptr != NULL || (pk)->keydata != NULL)
  578. #else
  579. # define evp_pkey_is_assigned(pk) \
  580. ((pk)->keydata != NULL)
  581. #endif
  582. #define evp_pkey_is_legacy(pk) \
  583. ((pk)->type != EVP_PKEY_NONE && (pk)->keymgmt == NULL)
  584. #define evp_pkey_is_provided(pk) \
  585. ((pk)->keymgmt != NULL)
  586. union legacy_pkey_st {
  587. void *ptr;
  588. struct rsa_st *rsa; /* RSA */
  589. # ifndef OPENSSL_NO_DSA
  590. struct dsa_st *dsa; /* DSA */
  591. # endif
  592. # ifndef OPENSSL_NO_DH
  593. struct dh_st *dh; /* DH */
  594. # endif
  595. # ifndef OPENSSL_NO_EC
  596. struct ec_key_st *ec; /* ECC */
  597. ECX_KEY *ecx; /* X25519, X448, Ed25519, Ed448 */
  598. # endif
  599. };
  600. struct evp_pkey_st {
  601. /* == Legacy attributes == */
  602. int type;
  603. int save_type;
  604. # ifndef FIPS_MODULE
  605. /*
  606. * Legacy key "origin" is composed of a pointer to an EVP_PKEY_ASN1_METHOD,
  607. * a pointer to a low level key and possibly a pointer to an engine.
  608. */
  609. const EVP_PKEY_ASN1_METHOD *ameth;
  610. ENGINE *engine;
  611. ENGINE *pmeth_engine; /* If not NULL public key ENGINE to use */
  612. /* Union to store the reference to an origin legacy key */
  613. union legacy_pkey_st pkey;
  614. /* Union to store the reference to a non-origin legacy key */
  615. union legacy_pkey_st legacy_cache_pkey;
  616. # endif
  617. /* == Common attributes == */
  618. CRYPTO_REF_COUNT references;
  619. CRYPTO_RWLOCK *lock;
  620. #ifndef FIPS_MODULE
  621. STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
  622. int save_parameters;
  623. int foreign:1; /* the low-level key is using an engine or an app-method */
  624. CRYPTO_EX_DATA ex_data;
  625. #endif
  626. /* == Provider attributes == */
  627. /*
  628. * Provider keydata "origin" is composed of a pointer to an EVP_KEYMGMT
  629. * and a pointer to the provider side key data. This is never used at
  630. * the same time as the legacy key data above.
  631. */
  632. EVP_KEYMGMT *keymgmt;
  633. void *keydata;
  634. /*
  635. * If any libcrypto code does anything that may modify the keydata
  636. * contents, this dirty counter must be incremented.
  637. */
  638. size_t dirty_cnt;
  639. /*
  640. * To support transparent execution of operation in backends other
  641. * than the "origin" key, we support transparent export/import to
  642. * those providers, and maintain a cache of the imported keydata,
  643. * so we don't need to redo the export/import every time we perform
  644. * the same operation in that same provider.
  645. */
  646. STACK_OF(OP_CACHE_ELEM) *operation_cache;
  647. /*
  648. * We keep a copy of that "origin"'s dirty count, so we know if the
  649. * operation cache needs flushing.
  650. */
  651. size_t dirty_cnt_copy;
  652. /* Cache of key object information */
  653. struct {
  654. int bits;
  655. int security_bits;
  656. int size;
  657. } cache;
  658. } /* EVP_PKEY */ ;
  659. #define EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) \
  660. ((ctx)->operation == EVP_PKEY_OP_SIGN \
  661. || (ctx)->operation == EVP_PKEY_OP_SIGNCTX \
  662. || (ctx)->operation == EVP_PKEY_OP_VERIFY \
  663. || (ctx)->operation == EVP_PKEY_OP_VERIFYCTX \
  664. || (ctx)->operation == EVP_PKEY_OP_VERIFYRECOVER)
  665. #define EVP_PKEY_CTX_IS_DERIVE_OP(ctx) \
  666. ((ctx)->operation == EVP_PKEY_OP_DERIVE)
  667. #define EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) \
  668. ((ctx)->operation == EVP_PKEY_OP_ENCRYPT \
  669. || (ctx)->operation == EVP_PKEY_OP_DECRYPT)
  670. #define EVP_PKEY_CTX_IS_GEN_OP(ctx) \
  671. ((ctx)->operation == EVP_PKEY_OP_PARAMGEN \
  672. || (ctx)->operation == EVP_PKEY_OP_KEYGEN)
  673. #define EVP_PKEY_CTX_IS_FROMDATA_OP(ctx) \
  674. ((ctx)->operation == EVP_PKEY_OP_FROMDATA)
  675. #define EVP_PKEY_CTX_IS_KEM_OP(ctx) \
  676. ((ctx)->operation == EVP_PKEY_OP_ENCAPSULATE \
  677. || (ctx)->operation == EVP_PKEY_OP_DECAPSULATE)
  678. void openssl_add_all_ciphers_int(void);
  679. void openssl_add_all_digests_int(void);
  680. void evp_cleanup_int(void);
  681. void evp_app_cleanup_int(void);
  682. void *evp_pkey_export_to_provider(EVP_PKEY *pk, OSSL_LIB_CTX *libctx,
  683. EVP_KEYMGMT **keymgmt,
  684. const char *propquery);
  685. #ifndef FIPS_MODULE
  686. int evp_pkey_copy_downgraded(EVP_PKEY **dest, const EVP_PKEY *src);
  687. void *evp_pkey_get_legacy(EVP_PKEY *pk);
  688. void evp_pkey_free_legacy(EVP_PKEY *x);
  689. EVP_PKEY *evp_pkcs82pkey_legacy(const PKCS8_PRIV_KEY_INFO *p8inf,
  690. OSSL_LIB_CTX *libctx, const char *propq);
  691. #endif
  692. /*
  693. * KEYMGMT utility functions
  694. */
  695. /*
  696. * Key import structure and helper function, to be used as an export callback
  697. */
  698. struct evp_keymgmt_util_try_import_data_st {
  699. EVP_KEYMGMT *keymgmt;
  700. void *keydata;
  701. int selection;
  702. };
  703. int evp_keymgmt_util_try_import(const OSSL_PARAM params[], void *arg);
  704. int evp_keymgmt_util_assign_pkey(EVP_PKEY *pkey, EVP_KEYMGMT *keymgmt,
  705. void *keydata);
  706. EVP_PKEY *evp_keymgmt_util_make_pkey(EVP_KEYMGMT *keymgmt, void *keydata);
  707. int evp_keymgmt_util_export(const EVP_PKEY *pk, int selection,
  708. OSSL_CALLBACK *export_cb, void *export_cbarg);
  709. void *evp_keymgmt_util_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt);
  710. OP_CACHE_ELEM *evp_keymgmt_util_find_operation_cache(EVP_PKEY *pk,
  711. EVP_KEYMGMT *keymgmt);
  712. int evp_keymgmt_util_clear_operation_cache(EVP_PKEY *pk, int locking);
  713. int evp_keymgmt_util_cache_keydata(EVP_PKEY *pk,
  714. EVP_KEYMGMT *keymgmt, void *keydata);
  715. void evp_keymgmt_util_cache_keyinfo(EVP_PKEY *pk);
  716. void *evp_keymgmt_util_fromdata(EVP_PKEY *target, EVP_KEYMGMT *keymgmt,
  717. int selection, const OSSL_PARAM params[]);
  718. int evp_keymgmt_util_has(EVP_PKEY *pk, int selection);
  719. int evp_keymgmt_util_match(EVP_PKEY *pk1, EVP_PKEY *pk2, int selection);
  720. int evp_keymgmt_util_copy(EVP_PKEY *to, EVP_PKEY *from, int selection);
  721. void *evp_keymgmt_util_gen(EVP_PKEY *target, EVP_KEYMGMT *keymgmt,
  722. void *genctx, OSSL_CALLBACK *cb, void *cbarg);
  723. int evp_keymgmt_util_get_deflt_digest_name(EVP_KEYMGMT *keymgmt,
  724. void *keydata,
  725. char *mdname, size_t mdname_sz);
  726. /*
  727. * KEYMGMT provider interface functions
  728. */
  729. void *evp_keymgmt_newdata(const EVP_KEYMGMT *keymgmt);
  730. void evp_keymgmt_freedata(const EVP_KEYMGMT *keymgmt, void *keyddata);
  731. int evp_keymgmt_get_params(const EVP_KEYMGMT *keymgmt,
  732. void *keydata, OSSL_PARAM params[]);
  733. int evp_keymgmt_set_params(const EVP_KEYMGMT *keymgmt,
  734. void *keydata, const OSSL_PARAM params[]);
  735. void *evp_keymgmt_gen_init(const EVP_KEYMGMT *keymgmt, int selection,
  736. const OSSL_PARAM params[]);
  737. int evp_keymgmt_gen_set_template(const EVP_KEYMGMT *keymgmt, void *genctx,
  738. void *template);
  739. int evp_keymgmt_gen_set_params(const EVP_KEYMGMT *keymgmt, void *genctx,
  740. const OSSL_PARAM params[]);
  741. void *evp_keymgmt_gen(const EVP_KEYMGMT *keymgmt, void *genctx,
  742. OSSL_CALLBACK *cb, void *cbarg);
  743. void evp_keymgmt_gen_cleanup(const EVP_KEYMGMT *keymgmt, void *genctx);
  744. void *evp_keymgmt_load(const EVP_KEYMGMT *keymgmt,
  745. const void *objref, size_t objref_sz);
  746. int evp_keymgmt_has(const EVP_KEYMGMT *keymgmt, void *keyddata, int selection);
  747. int evp_keymgmt_validate(const EVP_KEYMGMT *keymgmt, void *keydata,
  748. int selection, int checktype);
  749. int evp_keymgmt_match(const EVP_KEYMGMT *keymgmt,
  750. const void *keydata1, const void *keydata2,
  751. int selection);
  752. int evp_keymgmt_import(const EVP_KEYMGMT *keymgmt, void *keydata,
  753. int selection, const OSSL_PARAM params[]);
  754. const OSSL_PARAM *evp_keymgmt_import_types(const EVP_KEYMGMT *keymgmt,
  755. int selection);
  756. int evp_keymgmt_export(const EVP_KEYMGMT *keymgmt, void *keydata,
  757. int selection, OSSL_CALLBACK *param_cb, void *cbarg);
  758. const OSSL_PARAM *evp_keymgmt_export_types(const EVP_KEYMGMT *keymgmt,
  759. int selection);
  760. void *evp_keymgmt_dup(const EVP_KEYMGMT *keymgmt,
  761. const void *keydata_from, int selection);
  762. /* Pulling defines out of C source files */
  763. # define EVP_RC4_KEY_SIZE 16
  764. # ifndef TLS1_1_VERSION
  765. # define TLS1_1_VERSION 0x0302
  766. # endif
  767. void evp_encode_ctx_set_flags(EVP_ENCODE_CTX *ctx, unsigned int flags);
  768. /* EVP_ENCODE_CTX flags */
  769. /* Don't generate new lines when encoding */
  770. #define EVP_ENCODE_CTX_NO_NEWLINES 1
  771. /* Use the SRP base64 alphabet instead of the standard one */
  772. #define EVP_ENCODE_CTX_USE_SRP_ALPHABET 2
  773. const EVP_CIPHER *evp_get_cipherbyname_ex(OSSL_LIB_CTX *libctx,
  774. const char *name);
  775. const EVP_MD *evp_get_digestbyname_ex(OSSL_LIB_CTX *libctx,
  776. const char *name);
  777. int ossl_pkcs5_pbkdf2_hmac_ex(const char *pass, int passlen,
  778. const unsigned char *salt, int saltlen, int iter,
  779. const EVP_MD *digest, int keylen,
  780. unsigned char *out,
  781. OSSL_LIB_CTX *libctx, const char *propq);
  782. # ifndef FIPS_MODULE
  783. /*
  784. * Internal helpers for stricter EVP_PKEY_CTX_{set,get}_params().
  785. *
  786. * Return 1 on success, 0 or negative for errors.
  787. *
  788. * In particular they return -2 if any of the params is not supported.
  789. *
  790. * They are not available in FIPS_MODULE as they depend on
  791. * - EVP_PKEY_CTX_{get,set}_params()
  792. * - EVP_PKEY_CTX_{gettable,settable}_params()
  793. *
  794. */
  795. int evp_pkey_ctx_set_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params);
  796. int evp_pkey_ctx_get_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params);
  797. EVP_MD_CTX *evp_md_ctx_new_ex(EVP_PKEY *pkey, const ASN1_OCTET_STRING *id,
  798. OSSL_LIB_CTX *libctx, const char *propq);
  799. int evp_pkey_name2type(const char *name);
  800. const char *evp_pkey_type2name(int type);
  801. int evp_pkey_ctx_set1_id_prov(EVP_PKEY_CTX *ctx, const void *id, int len);
  802. int evp_pkey_ctx_get1_id_prov(EVP_PKEY_CTX *ctx, void *id);
  803. int evp_pkey_ctx_get1_id_len_prov(EVP_PKEY_CTX *ctx, size_t *id_len);
  804. int evp_pkey_ctx_use_cached_data(EVP_PKEY_CTX *ctx);
  805. # endif /* !defined(FIPS_MODULE) */
  806. int evp_method_store_flush(OSSL_LIB_CTX *libctx);
  807. int evp_set_default_properties_int(OSSL_LIB_CTX *libctx, const char *propq,
  808. int loadconfig, int mirrored);
  809. char *evp_get_global_properties_str(OSSL_LIB_CTX *libctx, int loadconfig);
  810. void evp_md_ctx_clear_digest(EVP_MD_CTX *ctx, int force);
  811. /* Three possible states: */
  812. # define EVP_PKEY_STATE_UNKNOWN 0
  813. # define EVP_PKEY_STATE_LEGACY 1
  814. # define EVP_PKEY_STATE_PROVIDER 2
  815. int evp_pkey_ctx_state(const EVP_PKEY_CTX *ctx);
  816. /* These two must ONLY be called for provider side operations */
  817. int evp_pkey_ctx_ctrl_to_param(EVP_PKEY_CTX *ctx,
  818. int keytype, int optype,
  819. int cmd, int p1, void *p2);
  820. int evp_pkey_ctx_ctrl_str_to_param(EVP_PKEY_CTX *ctx,
  821. const char *name, const char *value);
  822. /* These two must ONLY be called for legacy operations */
  823. int evp_pkey_ctx_set_params_to_ctrl(EVP_PKEY_CTX *ctx, const OSSL_PARAM *params);
  824. int evp_pkey_ctx_get_params_to_ctrl(EVP_PKEY_CTX *ctx, OSSL_PARAM *params);
  825. /* This must ONLY be called for legacy EVP_PKEYs */
  826. int evp_pkey_get_params_to_ctrl(const EVP_PKEY *pkey, OSSL_PARAM *params);
  827. /* Same as the public get0 functions but are not const */
  828. # ifndef OPENSSL_NO_DEPRECATED_3_0
  829. DH *evp_pkey_get0_DH_int(const EVP_PKEY *pkey);
  830. EC_KEY *evp_pkey_get0_EC_KEY_int(const EVP_PKEY *pkey);
  831. RSA *evp_pkey_get0_RSA_int(const EVP_PKEY *pkey);
  832. # endif
  833. /* Get internal identification number routines */
  834. int evp_asym_cipher_get_number(const EVP_ASYM_CIPHER *cipher);
  835. int evp_cipher_get_number(const EVP_CIPHER *cipher);
  836. int evp_kdf_get_number(const EVP_KDF *kdf);
  837. int evp_kem_get_number(const EVP_KEM *wrap);
  838. int evp_keyexch_get_number(const EVP_KEYEXCH *keyexch);
  839. int evp_keymgmt_get_number(const EVP_KEYMGMT *keymgmt);
  840. int evp_mac_get_number(const EVP_MAC *mac);
  841. int evp_md_get_number(const EVP_MD *md);
  842. int evp_rand_get_number(const EVP_RAND *rand);
  843. int evp_signature_get_number(const EVP_SIGNATURE *signature);
  844. #endif /* OSSL_CRYPTO_EVP_H */