/src/openssl/include/crypto/evp.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2015-2025 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #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" |
18 | | |
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 | 0 | #define PKCS5_DEFAULT_PBE1_SALT_LEN PKCS5_SALT_LEN |
27 | 0 | #define PKCS5_DEFAULT_PBE2_SALT_LEN 16 |
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 | 9.60k | #define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX 0x0400 |
33 | 28.8k | #define EVP_MD_CTX_FLAG_FINALISED 0x0800 |
34 | | |
35 | | #define evp_pkey_ctx_is_legacy(ctx) \ |
36 | 0 | ((ctx)->keymgmt == NULL) |
37 | | #define evp_pkey_ctx_is_provided(ctx) \ |
38 | 0 | (!evp_pkey_ctx_is_legacy(ctx)) |
39 | | |
40 | | struct evp_pkey_ctx_st { |
41 | | /* Actual operation */ |
42 | | int operation; |
43 | | |
44 | | /* |
45 | | * Library context, property query, keytype and keymgmt associated with |
46 | | * this context |
47 | | */ |
48 | | OSSL_LIB_CTX *libctx; |
49 | | char *propquery; |
50 | | const char *keytype; |
51 | | /* If |pkey| below is set, this field is always a reference to its keymgmt */ |
52 | | EVP_KEYMGMT *keymgmt; |
53 | | |
54 | | union { |
55 | | struct { |
56 | | void *genctx; |
57 | | } keymgmt; |
58 | | |
59 | | struct { |
60 | | EVP_KEYEXCH *exchange; |
61 | | /* |
62 | | * Opaque ctx returned from a providers exchange algorithm |
63 | | * implementation OSSL_FUNC_keyexch_newctx() |
64 | | */ |
65 | | void *algctx; |
66 | | } kex; |
67 | | |
68 | | struct { |
69 | | EVP_SIGNATURE *signature; |
70 | | /* |
71 | | * Opaque ctx returned from a providers signature algorithm |
72 | | * implementation OSSL_FUNC_signature_newctx() |
73 | | */ |
74 | | void *algctx; |
75 | | } sig; |
76 | | |
77 | | struct { |
78 | | EVP_ASYM_CIPHER *cipher; |
79 | | /* |
80 | | * Opaque ctx returned from a providers asymmetric cipher algorithm |
81 | | * implementation OSSL_FUNC_asym_cipher_newctx() |
82 | | */ |
83 | | void *algctx; |
84 | | } ciph; |
85 | | struct { |
86 | | EVP_KEM *kem; |
87 | | /* |
88 | | * Opaque ctx returned from a providers KEM algorithm |
89 | | * implementation OSSL_FUNC_kem_newctx() |
90 | | */ |
91 | | void *algctx; |
92 | | } encap; |
93 | | } op; |
94 | | |
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 | | |
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 | | |
118 | | /* Legacy fields below */ |
119 | | |
120 | | /* EVP_PKEY identity */ |
121 | | int legacy_keytype; |
122 | | /* Key: may be NULL */ |
123 | | EVP_PKEY *pkey; |
124 | | /* Peer key for key agreement, may be NULL */ |
125 | | EVP_PKEY *peerkey; |
126 | | /* Algorithm specific data */ |
127 | | void *data; |
128 | | /* |
129 | | * Used to support taking custody of memory in the case of a provider being |
130 | | * used with the deprecated EVP_PKEY_CTX_set_rsa_keygen_pubexp() API. This |
131 | | * member should NOT be used for any other purpose and should be removed |
132 | | * when said deprecated API is excised completely. |
133 | | */ |
134 | | BIGNUM *rsa_pubexp; |
135 | | } /* EVP_PKEY_CTX */; |
136 | | |
137 | | #define EVP_PKEY_FLAG_DYNAMIC 1 |
138 | | |
139 | | void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx); |
140 | | |
141 | | struct evp_mac_st { |
142 | | OSSL_PROVIDER *prov; |
143 | | int name_id; |
144 | | char *type_name; |
145 | | const char *description; |
146 | | |
147 | | CRYPTO_REF_COUNT refcnt; |
148 | | |
149 | | OSSL_FUNC_mac_newctx_fn *newctx; |
150 | | OSSL_FUNC_mac_dupctx_fn *dupctx; |
151 | | OSSL_FUNC_mac_freectx_fn *freectx; |
152 | | OSSL_FUNC_mac_init_fn *init; |
153 | | OSSL_FUNC_mac_update_fn *update; |
154 | | OSSL_FUNC_mac_final_fn *final; |
155 | | OSSL_FUNC_mac_gettable_params_fn *gettable_params; |
156 | | OSSL_FUNC_mac_gettable_ctx_params_fn *gettable_ctx_params; |
157 | | OSSL_FUNC_mac_settable_ctx_params_fn *settable_ctx_params; |
158 | | OSSL_FUNC_mac_get_params_fn *get_params; |
159 | | OSSL_FUNC_mac_get_ctx_params_fn *get_ctx_params; |
160 | | OSSL_FUNC_mac_set_ctx_params_fn *set_ctx_params; |
161 | | OSSL_FUNC_mac_init_skey_fn *init_skey; |
162 | | }; |
163 | | |
164 | | struct evp_kdf_st { |
165 | | OSSL_PROVIDER *prov; |
166 | | int name_id; |
167 | | char *type_name; |
168 | | const char *description; |
169 | | CRYPTO_REF_COUNT refcnt; |
170 | | |
171 | | OSSL_FUNC_kdf_newctx_fn *newctx; |
172 | | OSSL_FUNC_kdf_dupctx_fn *dupctx; |
173 | | OSSL_FUNC_kdf_freectx_fn *freectx; |
174 | | OSSL_FUNC_kdf_reset_fn *reset; |
175 | | OSSL_FUNC_kdf_derive_fn *derive; |
176 | | OSSL_FUNC_kdf_gettable_params_fn *gettable_params; |
177 | | OSSL_FUNC_kdf_gettable_ctx_params_fn *gettable_ctx_params; |
178 | | OSSL_FUNC_kdf_settable_ctx_params_fn *settable_ctx_params; |
179 | | OSSL_FUNC_kdf_get_params_fn *get_params; |
180 | | OSSL_FUNC_kdf_get_ctx_params_fn *get_ctx_params; |
181 | | OSSL_FUNC_kdf_set_ctx_params_fn *set_ctx_params; |
182 | | OSSL_FUNC_kdf_set_skey_fn *set_skey; |
183 | | OSSL_FUNC_kdf_derive_skey_fn *derive_skey; |
184 | | }; |
185 | | |
186 | 1.59M | #define EVP_ORIG_DYNAMIC 0 |
187 | 6 | #define EVP_ORIG_GLOBAL 1 |
188 | | |
189 | | struct evp_md_st { |
190 | | /* nid */ |
191 | | int type; |
192 | | |
193 | | /* Legacy structure members */ |
194 | | int pkey_type; |
195 | | int md_size; |
196 | | unsigned long flags; |
197 | | int origin; |
198 | | int (*init)(EVP_MD_CTX *ctx); |
199 | | int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count); |
200 | | int (*final)(EVP_MD_CTX *ctx, unsigned char *md); |
201 | | int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from); |
202 | | int (*cleanup)(EVP_MD_CTX *ctx); |
203 | | int block_size; |
204 | | int ctx_size; /* how big does the ctx->md_data need to be */ |
205 | | /* control function */ |
206 | | int (*md_ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2); |
207 | | |
208 | | /* New structure members */ |
209 | | /* Above comment to be removed when legacy has gone */ |
210 | | int name_id; |
211 | | char *type_name; |
212 | | const char *description; |
213 | | OSSL_PROVIDER *prov; |
214 | | CRYPTO_REF_COUNT refcnt; |
215 | | OSSL_FUNC_digest_newctx_fn *newctx; |
216 | | OSSL_FUNC_digest_init_fn *dinit; |
217 | | OSSL_FUNC_digest_update_fn *dupdate; |
218 | | OSSL_FUNC_digest_final_fn *dfinal; |
219 | | OSSL_FUNC_digest_squeeze_fn *dsqueeze; |
220 | | OSSL_FUNC_digest_digest_fn *digest; |
221 | | OSSL_FUNC_digest_freectx_fn *freectx; |
222 | | OSSL_FUNC_digest_copyctx_fn *copyctx; |
223 | | OSSL_FUNC_digest_dupctx_fn *dupctx; |
224 | | OSSL_FUNC_digest_get_params_fn *get_params; |
225 | | OSSL_FUNC_digest_set_ctx_params_fn *set_ctx_params; |
226 | | OSSL_FUNC_digest_get_ctx_params_fn *get_ctx_params; |
227 | | OSSL_FUNC_digest_gettable_params_fn *gettable_params; |
228 | | OSSL_FUNC_digest_settable_ctx_params_fn *settable_ctx_params; |
229 | | OSSL_FUNC_digest_gettable_ctx_params_fn *gettable_ctx_params; |
230 | | OSSL_FUNC_digest_serialize_fn *serialize; |
231 | | OSSL_FUNC_digest_deserialize_fn *deserialize; |
232 | | |
233 | | } /* EVP_MD */; |
234 | | |
235 | | struct evp_cipher_st { |
236 | | int nid; |
237 | | |
238 | | int block_size; |
239 | | /* Default value for variable length ciphers */ |
240 | | int key_len; |
241 | | int iv_len; |
242 | | |
243 | | /* Legacy structure members */ |
244 | | /* Various flags */ |
245 | | unsigned long flags; |
246 | | /* How the EVP_CIPHER was created. */ |
247 | | int origin; |
248 | | /* init key */ |
249 | | int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
250 | | const unsigned char *iv, int enc); |
251 | | /* encrypt/decrypt data */ |
252 | | int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out, |
253 | | const unsigned char *in, size_t inl); |
254 | | /* cleanup ctx */ |
255 | | int (*cleanup)(EVP_CIPHER_CTX *); |
256 | | /* how big ctx->cipher_data needs to be */ |
257 | | int ctx_size; |
258 | | /* Populate a ASN1_TYPE with parameters */ |
259 | | int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); |
260 | | /* Get parameters from a ASN1_TYPE */ |
261 | | int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); |
262 | | /* Miscellaneous operations */ |
263 | | int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); |
264 | | /* Application data */ |
265 | | void *app_data; |
266 | | |
267 | | /* New structure members */ |
268 | | /* Above comment to be removed when legacy has gone */ |
269 | | int name_id; |
270 | | char *type_name; |
271 | | const char *description; |
272 | | OSSL_PROVIDER *prov; |
273 | | CRYPTO_REF_COUNT refcnt; |
274 | | OSSL_FUNC_cipher_newctx_fn *newctx; |
275 | | OSSL_FUNC_cipher_encrypt_init_fn *einit; |
276 | | OSSL_FUNC_cipher_decrypt_init_fn *dinit; |
277 | | OSSL_FUNC_cipher_update_fn *cupdate; |
278 | | OSSL_FUNC_cipher_final_fn *cfinal; |
279 | | OSSL_FUNC_cipher_cipher_fn *ccipher; |
280 | | OSSL_FUNC_cipher_pipeline_encrypt_init_fn *p_einit; |
281 | | OSSL_FUNC_cipher_pipeline_decrypt_init_fn *p_dinit; |
282 | | OSSL_FUNC_cipher_pipeline_update_fn *p_cupdate; |
283 | | OSSL_FUNC_cipher_pipeline_final_fn *p_cfinal; |
284 | | OSSL_FUNC_cipher_freectx_fn *freectx; |
285 | | OSSL_FUNC_cipher_dupctx_fn *dupctx; |
286 | | OSSL_FUNC_cipher_get_params_fn *get_params; |
287 | | OSSL_FUNC_cipher_get_ctx_params_fn *get_ctx_params; |
288 | | OSSL_FUNC_cipher_set_ctx_params_fn *set_ctx_params; |
289 | | OSSL_FUNC_cipher_gettable_params_fn *gettable_params; |
290 | | OSSL_FUNC_cipher_gettable_ctx_params_fn *gettable_ctx_params; |
291 | | OSSL_FUNC_cipher_settable_ctx_params_fn *settable_ctx_params; |
292 | | OSSL_FUNC_cipher_encrypt_skey_init_fn *einit_skey; |
293 | | OSSL_FUNC_cipher_decrypt_skey_init_fn *dinit_skey; |
294 | | } /* EVP_CIPHER */; |
295 | | |
296 | | /* Macros to code block cipher wrappers */ |
297 | | |
298 | | /* Wrapper functions for each cipher mode */ |
299 | | |
300 | | #define EVP_C_DATA(kstruct, ctx) \ |
301 | 0 | ((kstruct *)EVP_CIPHER_CTX_get_cipher_data(ctx)) |
302 | | |
303 | | #define BLOCK_CIPHER_ecb_loop() \ |
304 | 0 | size_t i, bl; \ |
305 | 0 | bl = EVP_CIPHER_CTX_get0_cipher(ctx)->block_size; \ |
306 | 0 | if (inl < bl) \ |
307 | 0 | return 1; \ |
308 | 0 | inl -= bl; \ |
309 | 0 | for (i = 0; i <= inl; i += bl) |
310 | | |
311 | | #define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \ |
312 | | static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \ |
313 | 0 | { \ |
314 | 0 | BLOCK_CIPHER_ecb_loop() \ |
315 | 0 | cprefix##_ecb_encrypt(in + i, out + i, &EVP_C_DATA(kstruct, ctx)->ksched, EVP_CIPHER_CTX_is_encrypting(ctx)); \ |
316 | 0 | return 1; \ |
317 | 0 | } Unexecuted instantiation: e_aria.c:aria_128_ecb_cipher Unexecuted instantiation: e_aria.c:aria_192_ecb_cipher Unexecuted instantiation: e_aria.c:aria_256_ecb_cipher Unexecuted instantiation: e_bf.c:bf_ecb_cipher Unexecuted instantiation: e_cast.c:cast5_ecb_cipher Unexecuted instantiation: e_rc2.c:rc2_ecb_cipher Unexecuted instantiation: e_seed.c:seed_ecb_cipher |
318 | | |
319 | 0 | #define EVP_MAXCHUNK ((size_t)1 << 30) |
320 | | |
321 | | #define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \ |
322 | | static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \ |
323 | 0 | { \ |
324 | 0 | while (inl >= EVP_MAXCHUNK) { \ |
325 | 0 | int num = EVP_CIPHER_CTX_get_num(ctx); \ |
326 | 0 | cprefix##_ofb##cbits##_encrypt(in, out, (long)EVP_MAXCHUNK, &EVP_C_DATA(kstruct, ctx)->ksched, ctx->iv, &num); \ |
327 | 0 | EVP_CIPHER_CTX_set_num(ctx, num); \ |
328 | 0 | inl -= EVP_MAXCHUNK; \ |
329 | 0 | in += EVP_MAXCHUNK; \ |
330 | 0 | out += EVP_MAXCHUNK; \ |
331 | 0 | } \ |
332 | 0 | if (inl) { \ |
333 | 0 | int num = EVP_CIPHER_CTX_get_num(ctx); \ |
334 | 0 | cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct, ctx)->ksched, ctx->iv, &num); \ |
335 | 0 | EVP_CIPHER_CTX_set_num(ctx, num); \ |
336 | 0 | } \ |
337 | 0 | return 1; \ |
338 | 0 | } Unexecuted instantiation: e_aria.c:aria_128_ofb_cipher Unexecuted instantiation: e_aria.c:aria_192_ofb_cipher Unexecuted instantiation: e_aria.c:aria_256_ofb_cipher Unexecuted instantiation: e_bf.c:bf_ofb_cipher Unexecuted instantiation: e_cast.c:cast5_ofb_cipher Unexecuted instantiation: e_idea.c:idea_ofb_cipher Unexecuted instantiation: e_rc2.c:rc2_ofb_cipher Unexecuted instantiation: e_seed.c:seed_ofb_cipher |
339 | | |
340 | | #define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \ |
341 | | static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \ |
342 | 0 | { \ |
343 | 0 | while (inl >= EVP_MAXCHUNK) { \ |
344 | 0 | cprefix##_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &EVP_C_DATA(kstruct, ctx)->ksched, ctx->iv, EVP_CIPHER_CTX_is_encrypting(ctx)); \ |
345 | 0 | inl -= EVP_MAXCHUNK; \ |
346 | 0 | in += EVP_MAXCHUNK; \ |
347 | 0 | out += EVP_MAXCHUNK; \ |
348 | 0 | } \ |
349 | 0 | if (inl) \ |
350 | 0 | cprefix##_cbc_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct, ctx)->ksched, ctx->iv, EVP_CIPHER_CTX_is_encrypting(ctx)); \ |
351 | 0 | return 1; \ |
352 | 0 | } Unexecuted instantiation: e_aria.c:aria_128_cbc_cipher Unexecuted instantiation: e_aria.c:aria_192_cbc_cipher Unexecuted instantiation: e_aria.c:aria_256_cbc_cipher Unexecuted instantiation: e_bf.c:bf_cbc_cipher Unexecuted instantiation: e_cast.c:cast5_cbc_cipher Unexecuted instantiation: e_idea.c:idea_cbc_cipher Unexecuted instantiation: e_rc2.c:rc2_cbc_cipher Unexecuted instantiation: e_seed.c:seed_cbc_cipher |
353 | | |
354 | | #define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \ |
355 | | static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \ |
356 | 0 | { \ |
357 | 0 | size_t chunk = EVP_MAXCHUNK; \ |
358 | 0 | if (cbits == 1) \ |
359 | 0 | chunk >>= 3; \ |
360 | 0 | if (inl < chunk) \ |
361 | 0 | chunk = inl; \ |
362 | 0 | while (inl && inl >= chunk) { \ |
363 | 0 | int num = EVP_CIPHER_CTX_get_num(ctx); \ |
364 | 0 | cprefix##_cfb##cbits##_encrypt(in, out, (long)((cbits == 1) && !EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS) ? chunk * 8 : chunk), \ |
365 | 0 | &EVP_C_DATA(kstruct, ctx)->ksched, ctx->iv, \ |
366 | 0 | &num, EVP_CIPHER_CTX_is_encrypting(ctx)); \ |
367 | 0 | EVP_CIPHER_CTX_set_num(ctx, num); \ |
368 | 0 | inl -= chunk; \ |
369 | 0 | in += chunk; \ |
370 | 0 | out += chunk; \ |
371 | 0 | if (inl < chunk) \ |
372 | 0 | chunk = inl; \ |
373 | 0 | } \ |
374 | 0 | return 1; \ |
375 | 0 | } Unexecuted instantiation: e_aria.c:aria_128_cfb128_cipher Unexecuted instantiation: e_aria.c:aria_192_cfb128_cipher Unexecuted instantiation: e_aria.c:aria_256_cfb128_cipher Unexecuted instantiation: e_aria.c:aria_128_cfb1_cipher Unexecuted instantiation: e_aria.c:aria_192_cfb1_cipher Unexecuted instantiation: e_aria.c:aria_256_cfb1_cipher Unexecuted instantiation: e_aria.c:aria_128_cfb8_cipher Unexecuted instantiation: e_aria.c:aria_192_cfb8_cipher Unexecuted instantiation: e_aria.c:aria_256_cfb8_cipher Unexecuted instantiation: e_bf.c:bf_cfb64_cipher Unexecuted instantiation: e_cast.c:cast5_cfb64_cipher Unexecuted instantiation: e_idea.c:idea_cfb64_cipher Unexecuted instantiation: e_rc2.c:rc2_cfb64_cipher Unexecuted instantiation: e_seed.c:seed_cfb128_cipher |
376 | | |
377 | | #define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \ |
378 | | BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \ |
379 | | BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \ |
380 | | BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \ |
381 | | BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) |
382 | | |
383 | | #define BLOCK_CIPHER_def1(cname, nmode, mode, MODE, kstruct, nid, block_size, \ |
384 | | key_len, iv_len, flags, init_key, cleanup, \ |
385 | | set_asn1, get_asn1, ctrl) \ |
386 | | static const EVP_CIPHER cname##_##mode = { \ |
387 | | nid##_##nmode, block_size, key_len, iv_len, \ |
388 | | flags | EVP_CIPH_##MODE##_MODE, \ |
389 | | EVP_ORIG_GLOBAL, \ |
390 | | init_key, \ |
391 | | cname##_##mode##_cipher, \ |
392 | | cleanup, \ |
393 | | sizeof(kstruct), \ |
394 | | set_asn1, get_asn1, \ |
395 | | ctrl, \ |
396 | | NULL \ |
397 | | }; \ |
398 | 52 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; }Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Unexecuted instantiation: EVP_des_ede_ecb Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Unexecuted instantiation: EVP_des_ede3_ecb Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
Line | Count | Source | 398 | 1 | const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } |
|
399 | | |
400 | | #define BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, \ |
401 | | iv_len, flags, init_key, cleanup, set_asn1, \ |
402 | | get_asn1, ctrl) \ |
403 | | BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \ |
404 | | iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl) |
405 | | |
406 | | #define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, \ |
407 | | iv_len, cbits, flags, init_key, cleanup, \ |
408 | | set_asn1, get_asn1, ctrl) \ |
409 | | BLOCK_CIPHER_def1(cname, cfb##cbits, cfb##cbits, CFB, kstruct, nid, 1, \ |
410 | | key_len, iv_len, flags, init_key, cleanup, set_asn1, \ |
411 | | get_asn1, ctrl) |
412 | | |
413 | | #define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, \ |
414 | | iv_len, cbits, flags, init_key, cleanup, \ |
415 | | set_asn1, get_asn1, ctrl) \ |
416 | | BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, 1, \ |
417 | | key_len, iv_len, flags, init_key, cleanup, set_asn1, \ |
418 | | get_asn1, ctrl) |
419 | | |
420 | | #define BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, \ |
421 | | flags, init_key, cleanup, set_asn1, \ |
422 | | get_asn1, ctrl) \ |
423 | | BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \ |
424 | | 0, flags, init_key, cleanup, set_asn1, get_asn1, ctrl) |
425 | | |
426 | | #define BLOCK_CIPHER_defs(cname, kstruct, \ |
427 | | nid, block_size, key_len, iv_len, cbits, flags, \ |
428 | | init_key, cleanup, set_asn1, get_asn1, ctrl) \ |
429 | | BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \ |
430 | | init_key, cleanup, set_asn1, get_asn1, ctrl) \ |
431 | | BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, iv_len, cbits, \ |
432 | | flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \ |
433 | | BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, iv_len, cbits, \ |
434 | | flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \ |
435 | | BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, flags, \ |
436 | | init_key, cleanup, set_asn1, get_asn1, ctrl) |
437 | | |
438 | | /*- |
439 | | #define BLOCK_CIPHER_defs(cname, kstruct, \ |
440 | | nid, block_size, key_len, iv_len, flags,\ |
441 | | init_key, cleanup, set_asn1, get_asn1, ctrl)\ |
442 | | static const EVP_CIPHER cname##_cbc = {\ |
443 | | nid##_cbc, block_size, key_len, iv_len, \ |
444 | | flags | EVP_CIPH_CBC_MODE,\ |
445 | | EVP_ORIG_GLOBAL,\ |
446 | | init_key,\ |
447 | | cname##_cbc_cipher,\ |
448 | | cleanup,\ |
449 | | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\ |
450 | | sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\ |
451 | | set_asn1, get_asn1,\ |
452 | | ctrl, \ |
453 | | NULL \ |
454 | | };\ |
455 | | const EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\ |
456 | | static const EVP_CIPHER cname##_cfb = {\ |
457 | | nid##_cfb64, 1, key_len, iv_len, \ |
458 | | flags | EVP_CIPH_CFB_MODE,\ |
459 | | EVP_ORIG_GLOBAL,\ |
460 | | init_key,\ |
461 | | cname##_cfb_cipher,\ |
462 | | cleanup,\ |
463 | | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\ |
464 | | sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\ |
465 | | set_asn1, get_asn1,\ |
466 | | ctrl,\ |
467 | | NULL \ |
468 | | };\ |
469 | | const EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\ |
470 | | static const EVP_CIPHER cname##_ofb = {\ |
471 | | nid##_ofb64, 1, key_len, iv_len, \ |
472 | | flags | EVP_CIPH_OFB_MODE,\ |
473 | | EVP_ORIG_GLOBAL,\ |
474 | | init_key,\ |
475 | | cname##_ofb_cipher,\ |
476 | | cleanup,\ |
477 | | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\ |
478 | | sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\ |
479 | | set_asn1, get_asn1,\ |
480 | | ctrl,\ |
481 | | NULL \ |
482 | | };\ |
483 | | const EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\ |
484 | | static const EVP_CIPHER cname##_ecb = {\ |
485 | | nid##_ecb, block_size, key_len, iv_len, \ |
486 | | flags | EVP_CIPH_ECB_MODE,\ |
487 | | EVP_ORIG_GLOBAL,\ |
488 | | init_key,\ |
489 | | cname##_ecb_cipher,\ |
490 | | cleanup,\ |
491 | | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\ |
492 | | sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\ |
493 | | set_asn1, get_asn1,\ |
494 | | ctrl,\ |
495 | | NULL \ |
496 | | };\ |
497 | | const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; } |
498 | | */ |
499 | | |
500 | | #define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid, \ |
501 | | block_size, key_len, iv_len, cbits, \ |
502 | | flags, init_key, \ |
503 | | cleanup, set_asn1, get_asn1, ctrl) \ |
504 | | BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \ |
505 | | BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, \ |
506 | | cbits, flags, init_key, cleanup, set_asn1, \ |
507 | | get_asn1, ctrl) |
508 | | |
509 | | #define IMPLEMENT_CFBR(cipher, cprefix, kstruct, ksched, keysize, cbits, iv_len, fl) \ |
510 | | BLOCK_CIPHER_func_cfb(cipher##_##keysize, cprefix, cbits, kstruct, ksched) \ |
511 | | BLOCK_CIPHER_def_cfb(cipher##_##keysize, kstruct, \ |
512 | | NID_##cipher##_##keysize, keysize / 8, iv_len, cbits, \ |
513 | | (fl) | EVP_CIPH_FLAG_DEFAULT_ASN1, \ |
514 | | cipher##_init_key, NULL, NULL, NULL, NULL) |
515 | | |
516 | | typedef struct { |
517 | | unsigned char iv[EVP_MAX_IV_LENGTH]; |
518 | | unsigned int iv_len; |
519 | | unsigned int tag_len; |
520 | | } evp_cipher_aead_asn1_params; |
521 | | |
522 | | int evp_cipher_param_to_asn1_ex(EVP_CIPHER_CTX *c, ASN1_TYPE *type, |
523 | | evp_cipher_aead_asn1_params *params); |
524 | | |
525 | | int evp_cipher_asn1_to_param_ex(EVP_CIPHER_CTX *c, ASN1_TYPE *type, |
526 | | evp_cipher_aead_asn1_params *params); |
527 | | |
528 | | /* |
529 | | * To support transparent execution of operation in backends other |
530 | | * than the "origin" key, we support transparent export/import to |
531 | | * those providers, and maintain a cache of the imported keydata, |
532 | | * so we don't need to redo the export/import every time we perform |
533 | | * the same operation in that same provider. |
534 | | * This requires that the "origin" backend (whether it's a legacy or a |
535 | | * provider "origin") implements exports, and that the target provider |
536 | | * has an EVP_KEYMGMT that implements import. |
537 | | */ |
538 | | typedef struct { |
539 | | EVP_KEYMGMT *keymgmt; |
540 | | void *keydata; |
541 | | int selection; |
542 | | } OP_CACHE_ELEM; |
543 | | |
544 | | DEFINE_STACK_OF(OP_CACHE_ELEM) |
545 | | |
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 | 0 | ((pk)->type == EVP_PKEY_NONE && (pk)->keymgmt == NULL) |
573 | | #define evp_pkey_is_typed(pk) \ |
574 | 0 | ((pk)->type != EVP_PKEY_NONE || (pk)->keymgmt != NULL) |
575 | | #ifndef FIPS_MODULE |
576 | | #define evp_pkey_is_assigned(pk) \ |
577 | 0 | ((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 | 0 | ((pk)->type != EVP_PKEY_NONE && (pk)->keymgmt == NULL) |
584 | | #define evp_pkey_is_provided(pk) \ |
585 | 0 | ((pk)->keymgmt != NULL) |
586 | | |
587 | | union legacy_pkey_st { |
588 | | void *ptr; |
589 | | struct rsa_st *rsa; /* RSA */ |
590 | | #ifndef OPENSSL_NO_DSA |
591 | | struct dsa_st *dsa; /* DSA */ |
592 | | #endif |
593 | | #ifndef OPENSSL_NO_DH |
594 | | struct dh_st *dh; /* DH */ |
595 | | #endif |
596 | | #ifndef OPENSSL_NO_EC |
597 | | struct ec_key_st *ec; /* ECC */ |
598 | | #ifndef OPENSSL_NO_ECX |
599 | | ECX_KEY *ecx; /* X25519, X448, Ed25519, Ed448 */ |
600 | | #endif |
601 | | #endif |
602 | | }; |
603 | | |
604 | | struct evp_pkey_st { |
605 | | /* == Legacy attributes == */ |
606 | | int type; |
607 | | int save_type; |
608 | | |
609 | | #ifndef FIPS_MODULE |
610 | | /* |
611 | | * Legacy key "origin" is composed of a pointer to an EVP_PKEY_ASN1_METHOD, |
612 | | * a pointer to a low level key and possibly a pointer to an engine. |
613 | | */ |
614 | | const EVP_PKEY_ASN1_METHOD *ameth; |
615 | | |
616 | | /* Union to store the reference to an origin legacy key */ |
617 | | union legacy_pkey_st pkey; |
618 | | |
619 | | /* Union to store the reference to a non-origin legacy key */ |
620 | | union legacy_pkey_st legacy_cache_pkey; |
621 | | #endif |
622 | | |
623 | | /* == Common attributes == */ |
624 | | CRYPTO_REF_COUNT references; |
625 | | CRYPTO_RWLOCK *lock; |
626 | | #ifndef FIPS_MODULE |
627 | | STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ |
628 | | int save_parameters; |
629 | | unsigned int foreign : 1; /* the low-level key is using an engine or an app-method */ |
630 | | CRYPTO_EX_DATA ex_data; |
631 | | #endif |
632 | | |
633 | | /* == Provider attributes == */ |
634 | | |
635 | | /* |
636 | | * Provider keydata "origin" is composed of a pointer to an EVP_KEYMGMT |
637 | | * and a pointer to the provider side key data. This is never used at |
638 | | * the same time as the legacy key data above. |
639 | | */ |
640 | | EVP_KEYMGMT *keymgmt; |
641 | | void *keydata; |
642 | | /* |
643 | | * If any libcrypto code does anything that may modify the keydata |
644 | | * contents, this dirty counter must be incremented. |
645 | | */ |
646 | | size_t dirty_cnt; |
647 | | |
648 | | /* |
649 | | * To support transparent execution of operation in backends other |
650 | | * than the "origin" key, we support transparent export/import to |
651 | | * those providers, and maintain a cache of the imported keydata, |
652 | | * so we don't need to redo the export/import every time we perform |
653 | | * the same operation in that same provider. |
654 | | */ |
655 | | STACK_OF(OP_CACHE_ELEM) *operation_cache; |
656 | | |
657 | | /* |
658 | | * We keep a copy of that "origin"'s dirty count, so we know if the |
659 | | * operation cache needs flushing. |
660 | | */ |
661 | | size_t dirty_cnt_copy; |
662 | | |
663 | | /* Cache of key object information */ |
664 | | struct { |
665 | | int bits; |
666 | | int security_bits; |
667 | | int security_category; |
668 | | int size; |
669 | | } cache; |
670 | | }; /* EVP_PKEY */ |
671 | | |
672 | | /* The EVP_PKEY_OP_TYPE_ macros are found in include/openssl/evp.h */ |
673 | | |
674 | | #define EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) \ |
675 | 38.4k | (((ctx)->operation & EVP_PKEY_OP_TYPE_SIG) != 0) |
676 | | |
677 | | #define EVP_PKEY_CTX_IS_DERIVE_OP(ctx) \ |
678 | 0 | (((ctx)->operation & EVP_PKEY_OP_TYPE_DERIVE) != 0) |
679 | | |
680 | | #define EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) \ |
681 | 0 | (((ctx)->operation & EVP_PKEY_OP_TYPE_CRYPT) != 0) |
682 | | |
683 | | #define EVP_PKEY_CTX_IS_GEN_OP(ctx) \ |
684 | 0 | (((ctx)->operation & EVP_PKEY_OP_TYPE_GEN) != 0) |
685 | | |
686 | | #define EVP_PKEY_CTX_IS_FROMDATA_OP(ctx) \ |
687 | 0 | (((ctx)->operation & EVP_PKEY_OP_TYPE_DATA) != 0) |
688 | | |
689 | | #define EVP_PKEY_CTX_IS_KEM_OP(ctx) \ |
690 | 0 | (((ctx)->operation & EVP_PKEY_OP_TYPE_KEM) != 0) |
691 | | |
692 | | struct evp_skey_st { |
693 | | /* == Common attributes == */ |
694 | | CRYPTO_REF_COUNT references; |
695 | | CRYPTO_RWLOCK *lock; |
696 | | |
697 | | void *keydata; /* Alg-specific key data */ |
698 | | EVP_SKEYMGMT *skeymgmt; /* Import, export, manage */ |
699 | | }; /* EVP_SKEY */ |
700 | | |
701 | | void openssl_add_all_ciphers_int(void); |
702 | | void openssl_add_all_digests_int(void); |
703 | | void evp_cleanup_int(void); |
704 | | void *evp_pkey_export_to_provider(EVP_PKEY *pk, OSSL_LIB_CTX *libctx, |
705 | | EVP_KEYMGMT **keymgmt, |
706 | | const char *propquery); |
707 | | #ifndef FIPS_MODULE |
708 | | int evp_pkey_copy_downgraded(EVP_PKEY **dest, const EVP_PKEY *src); |
709 | | void *evp_pkey_get_legacy(EVP_PKEY *pk); |
710 | | void evp_pkey_free_legacy(EVP_PKEY *x); |
711 | | EVP_PKEY *evp_pkcs82pkey_legacy(const PKCS8_PRIV_KEY_INFO *p8inf, |
712 | | OSSL_LIB_CTX *libctx, const char *propq); |
713 | | #endif |
714 | | |
715 | | /* |
716 | | * KEYMGMT utility functions |
717 | | */ |
718 | | |
719 | | /* |
720 | | * Key import structure and helper function, to be used as an export callback |
721 | | */ |
722 | | struct evp_keymgmt_util_try_import_data_st { |
723 | | EVP_KEYMGMT *keymgmt; |
724 | | void *keydata; |
725 | | |
726 | | int selection; |
727 | | }; |
728 | | int evp_keymgmt_util_try_import(const OSSL_PARAM params[], void *arg); |
729 | | int evp_keymgmt_util_assign_pkey(EVP_PKEY *pkey, EVP_KEYMGMT *keymgmt, |
730 | | void *keydata); |
731 | | EVP_PKEY *evp_keymgmt_util_make_pkey(EVP_KEYMGMT *keymgmt, void *keydata); |
732 | | |
733 | | int evp_keymgmt_util_export(const EVP_PKEY *pk, int selection, |
734 | | OSSL_CALLBACK *export_cb, void *export_cbarg); |
735 | | void *evp_keymgmt_util_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt, |
736 | | int selection); |
737 | | OP_CACHE_ELEM *evp_keymgmt_util_find_operation_cache(EVP_PKEY *pk, |
738 | | EVP_KEYMGMT *keymgmt, |
739 | | int selection); |
740 | | int evp_keymgmt_util_clear_operation_cache(EVP_PKEY *pk); |
741 | | int evp_keymgmt_util_cache_keydata(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt, |
742 | | void *keydata, int selection); |
743 | | void evp_keymgmt_util_cache_keyinfo(EVP_PKEY *pk); |
744 | | void *evp_keymgmt_util_fromdata(EVP_PKEY *target, EVP_KEYMGMT *keymgmt, |
745 | | int selection, const OSSL_PARAM params[]); |
746 | | int evp_keymgmt_util_has(EVP_PKEY *pk, int selection); |
747 | | int evp_keymgmt_util_match(EVP_PKEY *pk1, EVP_PKEY *pk2, int selection); |
748 | | int evp_keymgmt_util_copy(EVP_PKEY *to, EVP_PKEY *from, int selection); |
749 | | void *evp_keymgmt_util_gen(EVP_PKEY *target, EVP_KEYMGMT *keymgmt, |
750 | | void *genctx, OSSL_CALLBACK *cb, void *cbarg); |
751 | | int evp_keymgmt_util_get_deflt_digest_name(EVP_KEYMGMT *keymgmt, |
752 | | void *keydata, |
753 | | char *mdname, size_t mdname_sz); |
754 | | const char *evp_keymgmt_util_query_operation_name(EVP_KEYMGMT *keymgmt, |
755 | | int op_id); |
756 | | |
757 | | /* |
758 | | * KEYMGMT provider interface functions |
759 | | */ |
760 | | void *evp_keymgmt_newdata(const EVP_KEYMGMT *keymgmt); |
761 | | void evp_keymgmt_freedata(const EVP_KEYMGMT *keymgmt, void *keyddata); |
762 | | int evp_keymgmt_get_params(const EVP_KEYMGMT *keymgmt, |
763 | | void *keydata, OSSL_PARAM params[]); |
764 | | int evp_keymgmt_set_params(const EVP_KEYMGMT *keymgmt, |
765 | | void *keydata, const OSSL_PARAM params[]); |
766 | | void *evp_keymgmt_gen_init(const EVP_KEYMGMT *keymgmt, int selection, |
767 | | const OSSL_PARAM params[]); |
768 | | int evp_keymgmt_gen_set_template(const EVP_KEYMGMT *keymgmt, void *genctx, |
769 | | void *templ); |
770 | | int evp_keymgmt_gen_set_params(const EVP_KEYMGMT *keymgmt, void *genctx, |
771 | | const OSSL_PARAM params[]); |
772 | | int evp_keymgmt_gen_get_params(const EVP_KEYMGMT *keymgmt, |
773 | | void *genctx, OSSL_PARAM params[]); |
774 | | void *evp_keymgmt_gen(const EVP_KEYMGMT *keymgmt, void *genctx, |
775 | | OSSL_CALLBACK *cb, void *cbarg); |
776 | | void evp_keymgmt_gen_cleanup(const EVP_KEYMGMT *keymgmt, void *genctx); |
777 | | |
778 | | int evp_keymgmt_has_load(const EVP_KEYMGMT *keymgmt); |
779 | | void *evp_keymgmt_load(const EVP_KEYMGMT *keymgmt, |
780 | | const void *objref, size_t objref_sz); |
781 | | |
782 | | int evp_keymgmt_has(const EVP_KEYMGMT *keymgmt, void *keyddata, int selection); |
783 | | int evp_keymgmt_validate(const EVP_KEYMGMT *keymgmt, void *keydata, |
784 | | int selection, int checktype); |
785 | | int evp_keymgmt_match(const EVP_KEYMGMT *keymgmt, |
786 | | const void *keydata1, const void *keydata2, |
787 | | int selection); |
788 | | |
789 | | int evp_keymgmt_import(const EVP_KEYMGMT *keymgmt, void *keydata, |
790 | | int selection, const OSSL_PARAM params[]); |
791 | | const OSSL_PARAM *evp_keymgmt_import_types(const EVP_KEYMGMT *keymgmt, |
792 | | int selection); |
793 | | int evp_keymgmt_export(const EVP_KEYMGMT *keymgmt, void *keydata, |
794 | | int selection, OSSL_CALLBACK *param_cb, void *cbarg); |
795 | | const OSSL_PARAM *evp_keymgmt_export_types(const EVP_KEYMGMT *keymgmt, |
796 | | int selection); |
797 | | void *evp_keymgmt_dup(const EVP_KEYMGMT *keymgmt, |
798 | | const void *keydata_from, int selection); |
799 | | EVP_KEYMGMT *evp_keymgmt_fetch_from_prov(OSSL_PROVIDER *prov, |
800 | | const char *name, |
801 | | const char *properties); |
802 | | |
803 | | /* |
804 | | * SKEYMGMT provider interface functions |
805 | | */ |
806 | | EVP_SKEY *evp_skey_alloc(EVP_SKEYMGMT *skeymgmt); |
807 | | void evp_skeymgmt_freedata(const EVP_SKEYMGMT *keymgmt, void *keyddata); |
808 | | void *evp_skeymgmt_import(const EVP_SKEYMGMT *skeymgmt, int selection, const OSSL_PARAM params[]); |
809 | | int evp_skeymgmt_export(const EVP_SKEYMGMT *skeymgmt, void *keydata, |
810 | | int selection, OSSL_CALLBACK *param_cb, void *cbarg); |
811 | | void *evp_skeymgmt_generate(const EVP_SKEYMGMT *skeymgmt, const OSSL_PARAM params[]); |
812 | | EVP_SKEYMGMT *evp_skeymgmt_fetch_from_prov(OSSL_PROVIDER *prov, |
813 | | const char *name, |
814 | | const char *properties); |
815 | | |
816 | | /* Pulling defines out of C source files */ |
817 | | |
818 | | #define EVP_RC4_KEY_SIZE 16 |
819 | | #ifndef TLS1_1_VERSION |
820 | | #define TLS1_1_VERSION 0x0302 |
821 | | #endif |
822 | | |
823 | | void evp_encode_ctx_set_flags(EVP_ENCODE_CTX *ctx, unsigned int flags); |
824 | | |
825 | | /* EVP_ENCODE_CTX flags */ |
826 | | /* Don't generate new lines when encoding */ |
827 | 0 | #define EVP_ENCODE_CTX_NO_NEWLINES 1 |
828 | | /* Use the SRP base64 alphabet instead of the standard one */ |
829 | 0 | #define EVP_ENCODE_CTX_USE_SRP_ALPHABET 2 |
830 | | |
831 | | const EVP_CIPHER *evp_get_cipherbyname_ex(OSSL_LIB_CTX *libctx, |
832 | | const char *name); |
833 | | const EVP_MD *evp_get_digestbyname_ex(OSSL_LIB_CTX *libctx, |
834 | | const char *name); |
835 | | |
836 | | int ossl_pkcs5_pbkdf2_hmac_ex(const char *pass, int passlen, |
837 | | const unsigned char *salt, int saltlen, int iter, |
838 | | const EVP_MD *digest, int keylen, |
839 | | unsigned char *out, |
840 | | OSSL_LIB_CTX *libctx, const char *propq); |
841 | | |
842 | | #ifndef FIPS_MODULE |
843 | | /* |
844 | | * Internal helpers for stricter EVP_PKEY_CTX_{set,get}_params(). |
845 | | * |
846 | | * Return 1 on success, 0 or negative for errors. |
847 | | * |
848 | | * In particular they return -2 if any of the params is not supported. |
849 | | * |
850 | | * They are not available in FIPS_MODULE as they depend on |
851 | | * - EVP_PKEY_CTX_{get,set}_params() |
852 | | * - EVP_PKEY_CTX_{gettable,settable}_params() |
853 | | * |
854 | | */ |
855 | | int evp_pkey_ctx_set_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params); |
856 | | int evp_pkey_ctx_get_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params); |
857 | | |
858 | | EVP_MD_CTX *evp_md_ctx_new_ex(EVP_PKEY *pkey, const ASN1_OCTET_STRING *id, |
859 | | OSSL_LIB_CTX *libctx, const char *propq); |
860 | | int evp_pkey_name2type(const char *name); |
861 | | const char *evp_pkey_type2name(int type); |
862 | | |
863 | | int evp_pkey_ctx_use_cached_data(EVP_PKEY_CTX *ctx); |
864 | | #endif /* !defined(FIPS_MODULE) */ |
865 | | |
866 | | int evp_method_store_cache_flush(OSSL_LIB_CTX *libctx); |
867 | | int evp_method_store_remove_all_provided(const OSSL_PROVIDER *prov); |
868 | | |
869 | | int evp_default_properties_enable_fips_int(OSSL_LIB_CTX *libctx, int enable, |
870 | | int loadconfig); |
871 | | int evp_set_default_properties_int(OSSL_LIB_CTX *libctx, const char *propq, |
872 | | int loadconfig, int mirrored); |
873 | | char *evp_get_global_properties_str(OSSL_LIB_CTX *libctx, int loadconfig); |
874 | | |
875 | | void evp_md_ctx_clear_digest(EVP_MD_CTX *ctx, int force, int keep_digest); |
876 | | /* just free the algctx if set, returns 0 on inconsistent state of ctx */ |
877 | | int evp_md_ctx_free_algctx(EVP_MD_CTX *ctx); |
878 | | |
879 | | /* Three possible states: */ |
880 | 0 | #define EVP_PKEY_STATE_UNKNOWN 0 |
881 | 0 | #define EVP_PKEY_STATE_LEGACY 1 |
882 | 0 | #define EVP_PKEY_STATE_PROVIDER 2 |
883 | | int evp_pkey_ctx_state(const EVP_PKEY_CTX *ctx); |
884 | | |
885 | | /* These two must ONLY be called for provider side operations */ |
886 | | int evp_pkey_ctx_ctrl_to_param(EVP_PKEY_CTX *ctx, |
887 | | int keytype, int optype, |
888 | | int cmd, int p1, void *p2); |
889 | | int evp_pkey_ctx_ctrl_str_to_param(EVP_PKEY_CTX *ctx, |
890 | | const char *name, const char *value); |
891 | | |
892 | | /* These two must ONLY be called for legacy operations */ |
893 | | int evp_pkey_ctx_set_params_to_ctrl(EVP_PKEY_CTX *ctx, const OSSL_PARAM *params); |
894 | | int evp_pkey_ctx_get_params_to_ctrl(EVP_PKEY_CTX *ctx, OSSL_PARAM *params); |
895 | | |
896 | | /* This must ONLY be called for legacy EVP_PKEYs */ |
897 | | int evp_pkey_get_params_to_ctrl(const EVP_PKEY *pkey, OSSL_PARAM *params); |
898 | | |
899 | | /* Same as the public get0 functions but are not const */ |
900 | | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
901 | | DH *evp_pkey_get0_DH_int(const EVP_PKEY *pkey); |
902 | | EC_KEY *evp_pkey_get0_EC_KEY_int(const EVP_PKEY *pkey); |
903 | | RSA *evp_pkey_get0_RSA_int(const EVP_PKEY *pkey); |
904 | | #endif |
905 | | |
906 | | /* Get internal identification number routines */ |
907 | | int evp_asym_cipher_get_number(const EVP_ASYM_CIPHER *cipher); |
908 | | int evp_cipher_get_number(const EVP_CIPHER *cipher); |
909 | | int evp_kdf_get_number(const EVP_KDF *kdf); |
910 | | int evp_kem_get_number(const EVP_KEM *wrap); |
911 | | int evp_keyexch_get_number(const EVP_KEYEXCH *keyexch); |
912 | | int evp_keymgmt_get_number(const EVP_KEYMGMT *keymgmt); |
913 | | int evp_keymgmt_get_legacy_alg(const EVP_KEYMGMT *keymgmt); |
914 | | int evp_mac_get_number(const EVP_MAC *mac); |
915 | | int evp_md_get_number(const EVP_MD *md); |
916 | | int evp_rand_get_number(const EVP_RAND *rand); |
917 | | int evp_rand_can_seed(EVP_RAND_CTX *ctx); |
918 | | size_t evp_rand_get_seed(EVP_RAND_CTX *ctx, |
919 | | unsigned char **buffer, |
920 | | int entropy, size_t min_len, size_t max_len, |
921 | | int prediction_resistance, |
922 | | const unsigned char *adin, size_t adin_len); |
923 | | void evp_rand_clear_seed(EVP_RAND_CTX *ctx, |
924 | | unsigned char *buffer, size_t b_len); |
925 | | int evp_signature_get_number(const EVP_SIGNATURE *signature); |
926 | | |
927 | | int evp_pkey_decrypt_alloc(EVP_PKEY_CTX *ctx, unsigned char **outp, |
928 | | size_t *outlenp, size_t expected_outlen, |
929 | | const unsigned char *in, size_t inlen); |
930 | | |
931 | | int ossl_md2hmacnid(int mdnid); |
932 | | int ossl_hmac2mdnid(int hmac_nid); |
933 | | |
934 | | #endif /* OSSL_CRYPTO_EVP_H */ |