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