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