1/*
2 * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#ifndef OPENSSL_EVP_H
11# define OPENSSL_EVP_H
12# pragma once
13
14# include <openssl/macros.h>
15# ifndef OPENSSL_NO_DEPRECATED_3_0
16# define HEADER_ENVELOPE_H
17# endif
18
19# include <stdarg.h>
20
21# ifndef OPENSSL_NO_STDIO
22# include <stdio.h>
23# endif
24
25# include <openssl/opensslconf.h>
26# include <openssl/types.h>
27# include <openssl/core.h>
28# include <openssl/core_dispatch.h>
29# include <openssl/symhacks.h>
30# include <openssl/bio.h>
31# include <openssl/evperr.h>
32# include <openssl/params.h>
33
34# define EVP_MAX_MD_SIZE 64/* longest known is SHA512 */
35# define EVP_MAX_KEY_LENGTH 64
36# define EVP_MAX_IV_LENGTH 16
37# define EVP_MAX_BLOCK_LENGTH 32
38# define EVP_MAX_AEAD_TAG_LENGTH 16
39
40# define PKCS5_SALT_LEN 8
41/* Default PKCS#5 iteration count */
42# define PKCS5_DEFAULT_ITER 2048
43
44# include <openssl/objects.h>
45
46# ifndef OPENSSL_NO_DEPRECATED_3_0
47# define EVP_PK_RSA 0x0001
48# define EVP_PK_DSA 0x0002
49# define EVP_PK_DH 0x0004
50# define EVP_PK_EC 0x0008
51# define EVP_PKT_SIGN 0x0010
52# define EVP_PKT_ENC 0x0020
53# define EVP_PKT_EXCH 0x0040
54# define EVP_PKS_RSA 0x0100
55# define EVP_PKS_DSA 0x0200
56# define EVP_PKS_EC 0x0400
57# endif
58
59# define EVP_PKEY_NONE NID_undef
60# define EVP_PKEY_RSA NID_rsaEncryption
61# define EVP_PKEY_RSA2 NID_rsa
62# define EVP_PKEY_RSA_PSS NID_rsassaPss
63# define EVP_PKEY_DSA NID_dsa
64# define EVP_PKEY_DSA1 NID_dsa_2
65# define EVP_PKEY_DSA2 NID_dsaWithSHA
66# define EVP_PKEY_DSA3 NID_dsaWithSHA1
67# define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
68# define EVP_PKEY_DH NID_dhKeyAgreement
69# define EVP_PKEY_DHX NID_dhpublicnumber
70# define EVP_PKEY_EC NID_X9_62_id_ecPublicKey
71# define EVP_PKEY_SM2 NID_sm2
72# define EVP_PKEY_HMAC NID_hmac
73# define EVP_PKEY_CMAC NID_cmac
74# define EVP_PKEY_SCRYPT NID_id_scrypt
75# define EVP_PKEY_TLS1_PRF NID_tls1_prf
76# define EVP_PKEY_HKDF NID_hkdf
77# define EVP_PKEY_POLY1305 NID_poly1305
78# define EVP_PKEY_SIPHASH NID_siphash
79# define EVP_PKEY_X25519 NID_X25519
80# define EVP_PKEY_ED25519 NID_ED25519
81# define EVP_PKEY_X448 NID_X448
82# define EVP_PKEY_ED448 NID_ED448
83/* Special indicator that the object is uniquely provider side */
84# define EVP_PKEY_KEYMGMT -1
85
86/* Easy to use macros for EVP_PKEY related selections */
87# define EVP_PKEY_KEY_PARAMETERS \
88 ( OSSL_KEYMGMT_SELECT_ALL_PARAMETERS )
89# define EVP_PKEY_PRIVATE_KEY \
90 ( EVP_PKEY_KEY_PARAMETERS | OSSL_KEYMGMT_SELECT_PRIVATE_KEY )
91# define EVP_PKEY_PUBLIC_KEY \
92 ( EVP_PKEY_KEY_PARAMETERS | OSSL_KEYMGMT_SELECT_PUBLIC_KEY )
93# define EVP_PKEY_KEYPAIR \
94 ( EVP_PKEY_PUBLIC_KEY | OSSL_KEYMGMT_SELECT_PRIVATE_KEY )
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99
100int EVP_set_default_properties(OSSL_LIB_CTX *libctx, const char *propq);
101int EVP_default_properties_is_fips_enabled(OSSL_LIB_CTX *libctx);
102int EVP_default_properties_enable_fips(OSSL_LIB_CTX *libctx, int enable);
103
104# define EVP_PKEY_MO_SIGN 0x0001
105# define EVP_PKEY_MO_VERIFY 0x0002
106# define EVP_PKEY_MO_ENCRYPT 0x0004
107# define EVP_PKEY_MO_DECRYPT 0x0008
108
109# ifndef EVP_MD
110# ifndef OPENSSL_NO_DEPRECATED_3_0
111OSSL_DEPRECATEDIN_3_0 EVP_MD *EVP_MD_meth_new(int md_type, int pkey_type);
112OSSL_DEPRECATEDIN_3_0 EVP_MD *EVP_MD_meth_dup(const EVP_MD *md);
113OSSL_DEPRECATEDIN_3_0 void EVP_MD_meth_free(EVP_MD *md);
114OSSL_DEPRECATEDIN_3_0
115int EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize);
116OSSL_DEPRECATEDIN_3_0
117int EVP_MD_meth_set_result_size(EVP_MD *md, int resultsize);
118OSSL_DEPRECATEDIN_3_0
119int EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize);
120OSSL_DEPRECATEDIN_3_0
121int EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags);
122OSSL_DEPRECATEDIN_3_0
123int EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx));
124OSSL_DEPRECATEDIN_3_0
125int EVP_MD_meth_set_update(EVP_MD *md, int (*update)(EVP_MD_CTX *ctx,
126 const void *data,
127 size_t count));
128OSSL_DEPRECATEDIN_3_0
129int EVP_MD_meth_set_final(EVP_MD *md, int (*final)(EVP_MD_CTX *ctx,
130 unsigned char *md));
131OSSL_DEPRECATEDIN_3_0
132int EVP_MD_meth_set_copy(EVP_MD *md, int (*copy)(EVP_MD_CTX *to,
133 const EVP_MD_CTX *from));
134OSSL_DEPRECATEDIN_3_0
135int EVP_MD_meth_set_cleanup(EVP_MD *md, int (*cleanup)(EVP_MD_CTX *ctx));
136OSSL_DEPRECATEDIN_3_0
137int EVP_MD_meth_set_ctrl(EVP_MD *md, int (*ctrl)(EVP_MD_CTX *ctx, int cmd,
138 int p1, void *p2));
139OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_get_input_blocksize(const EVP_MD *md);
140OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_get_result_size(const EVP_MD *md);
141OSSL_DEPRECATEDIN_3_0 int EVP_MD_meth_get_app_datasize(const EVP_MD *md);
142OSSL_DEPRECATEDIN_3_0 unsigned long EVP_MD_meth_get_flags(const EVP_MD *md);
143OSSL_DEPRECATEDIN_3_0
144int (*EVP_MD_meth_get_init(const EVP_MD *md))(EVP_MD_CTX *ctx);
145OSSL_DEPRECATEDIN_3_0
146int (*EVP_MD_meth_get_update(const EVP_MD *md))(EVP_MD_CTX *ctx,
147 const void *data, size_t count);
148OSSL_DEPRECATEDIN_3_0
149int (*EVP_MD_meth_get_final(const EVP_MD *md))(EVP_MD_CTX *ctx,
150 unsigned char *md);
151OSSL_DEPRECATEDIN_3_0
152int (*EVP_MD_meth_get_copy(const EVP_MD *md))(EVP_MD_CTX *to,
153 const EVP_MD_CTX *from);
154OSSL_DEPRECATEDIN_3_0
155int (*EVP_MD_meth_get_cleanup(const EVP_MD *md))(EVP_MD_CTX *ctx);
156OSSL_DEPRECATEDIN_3_0
157int (*EVP_MD_meth_get_ctrl(const EVP_MD *md))(EVP_MD_CTX *ctx, int cmd,
158 int p1, void *p2);
159# endif
160/* digest can only handle a single block */
161# define EVP_MD_FLAG_ONESHOT 0x0001
162
163/* digest is extensible-output function, XOF */
164# define EVP_MD_FLAG_XOF 0x0002
165
166/* DigestAlgorithmIdentifier flags... */
167
168# define EVP_MD_FLAG_DIGALGID_MASK 0x0018
169
170/* NULL or absent parameter accepted. Use NULL */
171
172# define EVP_MD_FLAG_DIGALGID_NULL 0x0000
173
174/* NULL or absent parameter accepted. Use NULL for PKCS#1 otherwise absent */
175
176# define EVP_MD_FLAG_DIGALGID_ABSENT 0x0008
177
178/* Custom handling via ctrl */
179
180# define EVP_MD_FLAG_DIGALGID_CUSTOM 0x0018
181
182/* Note if suitable for use in FIPS mode */
183# define EVP_MD_FLAG_FIPS 0x0400
184
185/* Digest ctrls */
186
187# define EVP_MD_CTRL_DIGALGID 0x1
188# define EVP_MD_CTRL_MICALG 0x2
189# define EVP_MD_CTRL_XOF_LEN 0x3
190# define EVP_MD_CTRL_TLSTREE 0x4
191
192/* Minimum Algorithm specific ctrl value */
193
194# define EVP_MD_CTRL_ALG_CTRL 0x1000
195
196# endif /* !EVP_MD */
197
198/* values for EVP_MD_CTX flags */
199
200# define EVP_MD_CTX_FLAG_ONESHOT 0x0001/* digest update will be
201 * called once only */
202# define EVP_MD_CTX_FLAG_CLEANED 0x0002/* context has already been
203 * cleaned */
204# define EVP_MD_CTX_FLAG_REUSE 0x0004/* Don't free up ctx->md_data
205 * in EVP_MD_CTX_reset */
206/*
207 * FIPS and pad options are ignored in 1.0.0, definitions are here so we
208 * don't accidentally reuse the values for other purposes.
209 */
210
211/* This flag has no effect from openssl-3.0 onwards */
212# define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008
213
214/*
215 * The following PAD options are also currently ignored in 1.0.0, digest
216 * parameters are handled through EVP_DigestSign*() and EVP_DigestVerify*()
217 * instead.
218 */
219# define EVP_MD_CTX_FLAG_PAD_MASK 0xF0/* RSA mode to use */
220# define EVP_MD_CTX_FLAG_PAD_PKCS1 0x00/* PKCS#1 v1.5 mode */
221# define EVP_MD_CTX_FLAG_PAD_X931 0x10/* X9.31 mode */
222# define EVP_MD_CTX_FLAG_PAD_PSS 0x20/* PSS mode */
223
224# define EVP_MD_CTX_FLAG_NO_INIT 0x0100/* Don't initialize md_data */
225/*
226 * Some functions such as EVP_DigestSign only finalise copies of internal
227 * contexts so additional data can be included after the finalisation call.
228 * This is inefficient if this functionality is not required: it is disabled
229 * if the following flag is set.
230 */
231# define EVP_MD_CTX_FLAG_FINALISE 0x0200
232/* NOTE: 0x0400 and 0x0800 are reserved for internal usage */
233
234# ifndef OPENSSL_NO_DEPRECATED_3_0
235OSSL_DEPRECATEDIN_3_0
236EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len);
237OSSL_DEPRECATEDIN_3_0
238EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher);
239OSSL_DEPRECATEDIN_3_0
240void EVP_CIPHER_meth_free(EVP_CIPHER *cipher);
241OSSL_DEPRECATEDIN_3_0
242int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len);
243OSSL_DEPRECATEDIN_3_0
244int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags);
245OSSL_DEPRECATEDIN_3_0
246int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size);
247OSSL_DEPRECATEDIN_3_0
248int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
249 int (*init) (EVP_CIPHER_CTX *ctx,
250 const unsigned char *key,
251 const unsigned char *iv,
252 int enc));
253OSSL_DEPRECATEDIN_3_0
254int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
255 int (*do_cipher) (EVP_CIPHER_CTX *ctx,
256 unsigned char *out,
257 const unsigned char *in,
258 size_t inl));
259OSSL_DEPRECATEDIN_3_0
260int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
261 int (*cleanup) (EVP_CIPHER_CTX *));
262OSSL_DEPRECATEDIN_3_0
263int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
264 int (*set_asn1_parameters) (EVP_CIPHER_CTX *,
265 ASN1_TYPE *));
266OSSL_DEPRECATEDIN_3_0
267int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
268 int (*get_asn1_parameters) (EVP_CIPHER_CTX *,
269 ASN1_TYPE *));
270OSSL_DEPRECATEDIN_3_0
271int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
272 int (*ctrl) (EVP_CIPHER_CTX *, int type,
273 int arg, void *ptr));
274OSSL_DEPRECATEDIN_3_0 int
275(*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
276 const unsigned char *key,
277 const unsigned char *iv,
278 int enc);
279OSSL_DEPRECATEDIN_3_0 int
280(*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
281 unsigned char *out,
282 const unsigned char *in,
283 size_t inl);
284OSSL_DEPRECATEDIN_3_0 int
285(*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *);
286OSSL_DEPRECATEDIN_3_0 int
287(*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
288 ASN1_TYPE *);
289OSSL_DEPRECATEDIN_3_0 int
290(*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
291 ASN1_TYPE *);
292OSSL_DEPRECATEDIN_3_0 int
293(*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, int type,
294 int arg, void *ptr);
295# endif
296
297/* Values for cipher flags */
298
299/* Modes for ciphers */
300
301# define EVP_CIPH_STREAM_CIPHER 0x0
302# define EVP_CIPH_ECB_MODE 0x1
303# define EVP_CIPH_CBC_MODE 0x2
304# define EVP_CIPH_CFB_MODE 0x3
305# define EVP_CIPH_OFB_MODE 0x4
306# define EVP_CIPH_CTR_MODE 0x5
307# define EVP_CIPH_GCM_MODE 0x6
308# define EVP_CIPH_CCM_MODE 0x7
309# define EVP_CIPH_XTS_MODE 0x10001
310# define EVP_CIPH_WRAP_MODE 0x10002
311# define EVP_CIPH_OCB_MODE 0x10003
312# define EVP_CIPH_SIV_MODE 0x10004
313# define EVP_CIPH_GCM_SIV_MODE 0x10005
314# define EVP_CIPH_MODE 0xF0007
315/* Set if variable length cipher */
316# define EVP_CIPH_VARIABLE_LENGTH 0x8
317/* Set if the iv handling should be done by the cipher itself */
318# define EVP_CIPH_CUSTOM_IV 0x10
319/* Set if the cipher's init() function should be called if key is NULL */
320# define EVP_CIPH_ALWAYS_CALL_INIT 0x20
321/* Call ctrl() to init cipher parameters */
322# define EVP_CIPH_CTRL_INIT 0x40
323/* Don't use standard key length function */
324# define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80
325/* Don't use standard block padding */
326# define EVP_CIPH_NO_PADDING 0x100
327/* cipher handles random key generation */
328# define EVP_CIPH_RAND_KEY 0x200
329/* cipher has its own additional copying logic */
330# define EVP_CIPH_CUSTOM_COPY 0x400
331/* Don't use standard iv length function */
332# define EVP_CIPH_CUSTOM_IV_LENGTH 0x800
333/* Legacy and no longer relevant: Allow use default ASN1 get/set iv */
334# define EVP_CIPH_FLAG_DEFAULT_ASN1 0
335/* Free: 0x1000 */
336/* Buffer length in bits not bytes: CFB1 mode only */
337# define EVP_CIPH_FLAG_LENGTH_BITS 0x2000
338/* Deprecated FIPS flag: was 0x4000 */
339# define EVP_CIPH_FLAG_FIPS 0
340/* Deprecated FIPS flag: was 0x8000 */
341# define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0
342
343/*
344 * Cipher handles any and all padding logic as well as finalisation.
345 */
346# define EVP_CIPH_FLAG_CTS 0x4000
347# define EVP_CIPH_FLAG_CUSTOM_CIPHER 0x100000
348# define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000
349# define EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK 0x400000
350/* Cipher can handle pipeline operations */
351# define EVP_CIPH_FLAG_PIPELINE 0X800000
352/* For provider implementations that handle ASN1 get/set param themselves */
353# define EVP_CIPH_FLAG_CUSTOM_ASN1 0x1000000
354/* For ciphers generating unprotected CMS attributes */
355# define EVP_CIPH_FLAG_CIPHER_WITH_MAC 0x2000000
356/* For supplementary wrap cipher support */
357# define EVP_CIPH_FLAG_GET_WRAP_CIPHER 0x4000000
358# define EVP_CIPH_FLAG_INVERSE_CIPHER 0x8000000
359
360/*
361 * Cipher context flag to indicate we can handle wrap mode: if allowed in
362 * older applications it could overflow buffers.
363 */
364
365# define EVP_CIPHER_CTX_FLAG_WRAP_ALLOW 0x1
366
367/* ctrl() values */
368
369# define EVP_CTRL_INIT 0x0
370# define EVP_CTRL_SET_KEY_LENGTH 0x1
371# define EVP_CTRL_GET_RC2_KEY_BITS 0x2
372# define EVP_CTRL_SET_RC2_KEY_BITS 0x3
373# define EVP_CTRL_GET_RC5_ROUNDS 0x4
374# define EVP_CTRL_SET_RC5_ROUNDS 0x5
375# define EVP_CTRL_RAND_KEY 0x6
376# define EVP_CTRL_PBE_PRF_NID 0x7
377# define EVP_CTRL_COPY 0x8
378# define EVP_CTRL_AEAD_SET_IVLEN 0x9
379# define EVP_CTRL_AEAD_GET_TAG 0x10
380# define EVP_CTRL_AEAD_SET_TAG 0x11
381# define EVP_CTRL_AEAD_SET_IV_FIXED 0x12
382# define EVP_CTRL_GCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN
383# define EVP_CTRL_GCM_GET_TAG EVP_CTRL_AEAD_GET_TAG
384# define EVP_CTRL_GCM_SET_TAG EVP_CTRL_AEAD_SET_TAG
385# define EVP_CTRL_GCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED
386# define EVP_CTRL_GCM_IV_GEN 0x13
387# define EVP_CTRL_CCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN
388# define EVP_CTRL_CCM_GET_TAG EVP_CTRL_AEAD_GET_TAG
389# define EVP_CTRL_CCM_SET_TAG EVP_CTRL_AEAD_SET_TAG
390# define EVP_CTRL_CCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED
391# define EVP_CTRL_CCM_SET_L 0x14
392# define EVP_CTRL_CCM_SET_MSGLEN 0x15
393/*
394 * AEAD cipher deduces payload length and returns number of bytes required to
395 * store MAC and eventual padding. Subsequent call to EVP_Cipher even
396 * appends/verifies MAC.
397 */
398# define EVP_CTRL_AEAD_TLS1_AAD 0x16
399/* Used by composite AEAD ciphers, no-op in GCM, CCM... */
400# define EVP_CTRL_AEAD_SET_MAC_KEY 0x17
401/* Set the GCM invocation field, decrypt only */
402# define EVP_CTRL_GCM_SET_IV_INV 0x18
403
404# define EVP_CTRL_TLS1_1_MULTIBLOCK_AAD 0x19
405# define EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT 0x1a
406# define EVP_CTRL_TLS1_1_MULTIBLOCK_DECRYPT 0x1b
407# define EVP_CTRL_TLS1_1_MULTIBLOCK_MAX_BUFSIZE 0x1c
408
409# define EVP_CTRL_SSL3_MASTER_SECRET 0x1d
410
411/* EVP_CTRL_SET_SBOX takes the char * specifying S-boxes */
412# define EVP_CTRL_SET_SBOX 0x1e
413/*
414 * EVP_CTRL_SBOX_USED takes a 'size_t' and 'char *', pointing at a
415 * pre-allocated buffer with specified size
416 */
417# define EVP_CTRL_SBOX_USED 0x1f
418/* EVP_CTRL_KEY_MESH takes 'size_t' number of bytes to mesh the key after,
419 * 0 switches meshing off
420 */
421# define EVP_CTRL_KEY_MESH 0x20
422/* EVP_CTRL_BLOCK_PADDING_MODE takes the padding mode */
423# define EVP_CTRL_BLOCK_PADDING_MODE 0x21
424
425/* Set the output buffers to use for a pipelined operation */
426# define EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS 0x22
427/* Set the input buffers to use for a pipelined operation */
428# define EVP_CTRL_SET_PIPELINE_INPUT_BUFS 0x23
429/* Set the input buffer lengths to use for a pipelined operation */
430# define EVP_CTRL_SET_PIPELINE_INPUT_LENS 0x24
431/* Get the IV length used by the cipher */
432# define EVP_CTRL_GET_IVLEN 0x25
433/* 0x26 is unused */
434/* Tell the cipher it's doing a speed test (SIV disallows multiple ops) */
435# define EVP_CTRL_SET_SPEED 0x27
436/* Get the unprotectedAttrs from cipher ctx */
437# define EVP_CTRL_PROCESS_UNPROTECTED 0x28
438/* Get the supplementary wrap cipher */
439#define EVP_CTRL_GET_WRAP_CIPHER 0x29
440/* TLSTREE key diversification */
441#define EVP_CTRL_TLSTREE 0x2A
442
443/* Padding modes */
444#define EVP_PADDING_PKCS7 1
445#define EVP_PADDING_ISO7816_4 2
446#define EVP_PADDING_ANSI923 3
447#define EVP_PADDING_ISO10126 4
448#define EVP_PADDING_ZERO 5
449
450/* RFC 5246 defines additional data to be 13 bytes in length */
451# define EVP_AEAD_TLS1_AAD_LEN 13
452
453typedef struct {
454 unsigned char *out;
455 const unsigned char *inp;
456 size_t len;
457 unsigned int interleave;
458} EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM;
459
460/* GCM TLS constants */
461/* Length of fixed part of IV derived from PRF */
462# define EVP_GCM_TLS_FIXED_IV_LEN 4
463/* Length of explicit part of IV part of TLS records */
464# define EVP_GCM_TLS_EXPLICIT_IV_LEN 8
465/* Length of tag for TLS */
466# define EVP_GCM_TLS_TAG_LEN 16
467
468/* CCM TLS constants */
469/* Length of fixed part of IV derived from PRF */
470# define EVP_CCM_TLS_FIXED_IV_LEN 4
471/* Length of explicit part of IV part of TLS records */
472# define EVP_CCM_TLS_EXPLICIT_IV_LEN 8
473/* Total length of CCM IV length for TLS */
474# define EVP_CCM_TLS_IV_LEN 12
475/* Length of tag for TLS */
476# define EVP_CCM_TLS_TAG_LEN 16
477/* Length of CCM8 tag for TLS */
478# define EVP_CCM8_TLS_TAG_LEN 8
479
480/* Length of tag for TLS */
481# define EVP_CHACHAPOLY_TLS_TAG_LEN 16
482
483typedef struct evp_cipher_info_st {
484 const EVP_CIPHER *cipher;
485 unsigned char iv[EVP_MAX_IV_LENGTH];
486} EVP_CIPHER_INFO;
487
488
489/* Password based encryption function */
490typedef int (EVP_PBE_KEYGEN) (EVP_CIPHER_CTX *ctx, const char *pass,
491 int passlen, ASN1_TYPE *param,
492 const EVP_CIPHER *cipher, const EVP_MD *md,
493 int en_de);
494
495typedef int (EVP_PBE_KEYGEN_EX) (EVP_CIPHER_CTX *ctx, const char *pass,
496 int passlen, ASN1_TYPE *param,
497 const EVP_CIPHER *cipher, const EVP_MD *md,
498 int en_de, OSSL_LIB_CTX *libctx, const char *propq);
499
500# ifndef OPENSSL_NO_DEPRECATED_3_0
501# define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
502 (rsa))
503# endif
504
505# ifndef OPENSSL_NO_DSA
506# define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
507 (dsa))
508# endif
509
510# if !defined(OPENSSL_NO_DH) && !defined(OPENSSL_NO_DEPRECATED_3_0)
511# define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,(dh))
512# endif
513
514# ifndef OPENSSL_NO_DEPRECATED_3_0
515# ifndef OPENSSL_NO_EC
516# define EVP_PKEY_assign_EC_KEY(pkey,eckey) \
517 EVP_PKEY_assign((pkey), EVP_PKEY_EC, (eckey))
518# endif
519# endif
520# ifndef OPENSSL_NO_SIPHASH
521# define EVP_PKEY_assign_SIPHASH(pkey,shkey) EVP_PKEY_assign((pkey),\
522 EVP_PKEY_SIPHASH,(shkey))
523# endif
524
525# ifndef OPENSSL_NO_POLY1305
526# define EVP_PKEY_assign_POLY1305(pkey,polykey) EVP_PKEY_assign((pkey),\
527 EVP_PKEY_POLY1305,(polykey))
528# endif
529
530/* Add some extra combinations */
531# define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
532# define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
533# define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
534# define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
535
536int EVP_MD_get_type(const EVP_MD *md);
537# define EVP_MD_type EVP_MD_get_type
538# define EVP_MD_nid EVP_MD_get_type
539const char *EVP_MD_get0_name(const EVP_MD *md);
540# define EVP_MD_name EVP_MD_get0_name
541const char *EVP_MD_get0_description(const EVP_MD *md);
542int EVP_MD_is_a(const EVP_MD *md, const char *name);
543int EVP_MD_names_do_all(const EVP_MD *md,
544 void (*fn)(const char *name, void *data),
545 void *data);
546const OSSL_PROVIDER *EVP_MD_get0_provider(const EVP_MD *md);
547int EVP_MD_get_pkey_type(const EVP_MD *md);
548# define EVP_MD_pkey_type EVP_MD_get_pkey_type
549int EVP_MD_get_size(const EVP_MD *md);
550# define EVP_MD_size EVP_MD_get_size
551int EVP_MD_get_block_size(const EVP_MD *md);
552# define EVP_MD_block_size EVP_MD_get_block_size
553unsigned long EVP_MD_get_flags(const EVP_MD *md);
554# define EVP_MD_flags EVP_MD_get_flags
555
556const EVP_MD *EVP_MD_CTX_get0_md(const EVP_MD_CTX *ctx);
557EVP_MD *EVP_MD_CTX_get1_md(EVP_MD_CTX *ctx);
558# ifndef OPENSSL_NO_DEPRECATED_3_0
559OSSL_DEPRECATEDIN_3_0
560const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
561OSSL_DEPRECATEDIN_3_0
562int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx,
563 const void *data, size_t count);
564OSSL_DEPRECATEDIN_3_0
565void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx,
566 int (*update) (EVP_MD_CTX *ctx,
567 const void *data, size_t count));
568# endif
569# define EVP_MD_CTX_get0_name(e) EVP_MD_get0_name(EVP_MD_CTX_get0_md(e))
570# define EVP_MD_CTX_get_size(e) EVP_MD_get_size(EVP_MD_CTX_get0_md(e))
571# define EVP_MD_CTX_size EVP_MD_CTX_get_size
572# define EVP_MD_CTX_get_block_size(e) EVP_MD_get_block_size(EVP_MD_CTX_get0_md(e))
573# define EVP_MD_CTX_block_size EVP_MD_CTX_get_block_size
574# define EVP_MD_CTX_get_type(e) EVP_MD_get_type(EVP_MD_CTX_get0_md(e))
575# define EVP_MD_CTX_type EVP_MD_CTX_get_type
576EVP_PKEY_CTX *EVP_MD_CTX_get_pkey_ctx(const EVP_MD_CTX *ctx);
577# define EVP_MD_CTX_pkey_ctx EVP_MD_CTX_get_pkey_ctx
578void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx);
579void *EVP_MD_CTX_get0_md_data(const EVP_MD_CTX *ctx);
580# define EVP_MD_CTX_md_data EVP_MD_CTX_get0_md_data
581
582int EVP_CIPHER_get_nid(const EVP_CIPHER *cipher);
583# define EVP_CIPHER_nid EVP_CIPHER_get_nid
584const char *EVP_CIPHER_get0_name(const EVP_CIPHER *cipher);
585# define EVP_CIPHER_name EVP_CIPHER_get0_name
586const char *EVP_CIPHER_get0_description(const EVP_CIPHER *cipher);
587int EVP_CIPHER_is_a(const EVP_CIPHER *cipher, const char *name);
588int EVP_CIPHER_names_do_all(const EVP_CIPHER *cipher,
589 void (*fn)(const char *name, void *data),
590 void *data);
591const OSSL_PROVIDER *EVP_CIPHER_get0_provider(const EVP_CIPHER *cipher);
592int EVP_CIPHER_get_block_size(const EVP_CIPHER *cipher);
593# define EVP_CIPHER_block_size EVP_CIPHER_get_block_size
594# ifndef OPENSSL_NO_DEPRECATED_3_0
595OSSL_DEPRECATEDIN_3_0
596int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *cipher);
597# endif
598int EVP_CIPHER_get_key_length(const EVP_CIPHER *cipher);
599# define EVP_CIPHER_key_length EVP_CIPHER_get_key_length
600int EVP_CIPHER_get_iv_length(const EVP_CIPHER *cipher);
601# define EVP_CIPHER_iv_length EVP_CIPHER_get_iv_length
602unsigned long EVP_CIPHER_get_flags(const EVP_CIPHER *cipher);
603# define EVP_CIPHER_flags EVP_CIPHER_get_flags
604int EVP_CIPHER_get_mode(const EVP_CIPHER *cipher);
605# define EVP_CIPHER_mode EVP_CIPHER_get_mode
606int EVP_CIPHER_get_type(const EVP_CIPHER *cipher);
607# define EVP_CIPHER_type EVP_CIPHER_get_type
608EVP_CIPHER *EVP_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
609 const char *properties);
610int EVP_CIPHER_up_ref(EVP_CIPHER *cipher);
611void EVP_CIPHER_free(EVP_CIPHER *cipher);
612
613const EVP_CIPHER *EVP_CIPHER_CTX_get0_cipher(const EVP_CIPHER_CTX *ctx);
614EVP_CIPHER *EVP_CIPHER_CTX_get1_cipher(EVP_CIPHER_CTX *ctx);
615int EVP_CIPHER_CTX_is_encrypting(const EVP_CIPHER_CTX *ctx);
616# define EVP_CIPHER_CTX_encrypting EVP_CIPHER_CTX_is_encrypting
617int EVP_CIPHER_CTX_get_nid(const EVP_CIPHER_CTX *ctx);
618# define EVP_CIPHER_CTX_nid EVP_CIPHER_CTX_get_nid
619int EVP_CIPHER_CTX_get_block_size(const EVP_CIPHER_CTX *ctx);
620# define EVP_CIPHER_CTX_block_size EVP_CIPHER_CTX_get_block_size
621int EVP_CIPHER_CTX_get_key_length(const EVP_CIPHER_CTX *ctx);
622# define EVP_CIPHER_CTX_key_length EVP_CIPHER_CTX_get_key_length
623int EVP_CIPHER_CTX_get_iv_length(const EVP_CIPHER_CTX *ctx);
624# define EVP_CIPHER_CTX_iv_length EVP_CIPHER_CTX_get_iv_length
625int EVP_CIPHER_CTX_get_tag_length(const EVP_CIPHER_CTX *ctx);
626# define EVP_CIPHER_CTX_tag_length EVP_CIPHER_CTX_get_tag_length
627# ifndef OPENSSL_NO_DEPRECATED_3_0
628const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx);
629OSSL_DEPRECATEDIN_3_0 const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx);
630OSSL_DEPRECATEDIN_3_0 const unsigned char *EVP_CIPHER_CTX_original_iv(const EVP_CIPHER_CTX *ctx);
631OSSL_DEPRECATEDIN_3_0 unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx);
632# endif
633int EVP_CIPHER_CTX_get_updated_iv(EVP_CIPHER_CTX *ctx, void *buf, size_t len);
634int EVP_CIPHER_CTX_get_original_iv(EVP_CIPHER_CTX *ctx, void *buf, size_t len);
635# ifndef OPENSSL_NO_DEPRECATED_3_0
636OSSL_DEPRECATEDIN_3_0
637unsigned char *EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx);
638# endif
639int EVP_CIPHER_CTX_get_num(const EVP_CIPHER_CTX *ctx);
640# define EVP_CIPHER_CTX_num EVP_CIPHER_CTX_get_num
641int EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num);
642EVP_CIPHER_CTX *EVP_CIPHER_CTX_dup(const EVP_CIPHER_CTX *in);
643int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in);
644void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx);
645void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data);
646void *EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx);
647void *EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data);
648# define EVP_CIPHER_CTX_get0_name(c) EVP_CIPHER_get0_name(EVP_CIPHER_CTX_get0_cipher(c))
649# define EVP_CIPHER_CTX_get_type(c) EVP_CIPHER_get_type(EVP_CIPHER_CTX_get0_cipher(c))
650# define EVP_CIPHER_CTX_type EVP_CIPHER_CTX_get_type
651# ifndef OPENSSL_NO_DEPRECATED_1_1_0
652# define EVP_CIPHER_CTX_flags(c) EVP_CIPHER_get_flags(EVP_CIPHER_CTX_get0_cipher(c))
653# endif
654# define EVP_CIPHER_CTX_get_mode(c) EVP_CIPHER_get_mode(EVP_CIPHER_CTX_get0_cipher(c))
655# define EVP_CIPHER_CTX_mode EVP_CIPHER_CTX_get_mode
656
657# define EVP_ENCODE_LENGTH(l) ((((l)+2)/3*4)+((l)/48+1)*2+80)
658# define EVP_DECODE_LENGTH(l) (((l)+3)/4*3+80)
659
660# define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
661# define EVP_SignInit(a,b) EVP_DigestInit(a,b)
662# define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
663# define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
664# define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
665# define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
666# define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
667# define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
668
669# ifdef CONST_STRICT
670void BIO_set_md(BIO *, const EVP_MD *md);
671# else
672# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(void *)(md))
673# endif
674# define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(mdp))
675# define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(mdcp))
676# define BIO_set_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_SET_MD_CTX,0,(mdcp))
677# define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
678# define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(c_pp))
679
680__owur int EVP_Cipher(EVP_CIPHER_CTX *c,
681 unsigned char *out,
682 const unsigned char *in, unsigned int inl);
683
684# define EVP_add_cipher_alias(n,alias) \
685 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
686# define EVP_add_digest_alias(n,alias) \
687 OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
688# define EVP_delete_cipher_alias(alias) \
689 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
690# define EVP_delete_digest_alias(alias) \
691 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
692
693int EVP_MD_get_params(const EVP_MD *digest, OSSL_PARAM params[]);
694int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[]);
695int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[]);
696const OSSL_PARAM *EVP_MD_gettable_params(const EVP_MD *digest);
697const OSSL_PARAM *EVP_MD_settable_ctx_params(const EVP_MD *md);
698const OSSL_PARAM *EVP_MD_gettable_ctx_params(const EVP_MD *md);
699const OSSL_PARAM *EVP_MD_CTX_settable_params(EVP_MD_CTX *ctx);
700const OSSL_PARAM *EVP_MD_CTX_gettable_params(EVP_MD_CTX *ctx);
701int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
702EVP_MD_CTX *EVP_MD_CTX_new(void);
703int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
704void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
705# define EVP_MD_CTX_create() EVP_MD_CTX_new()
706# define EVP_MD_CTX_init(ctx) EVP_MD_CTX_reset((ctx))
707# define EVP_MD_CTX_destroy(ctx) EVP_MD_CTX_free((ctx))
708__owur EVP_MD_CTX *EVP_MD_CTX_dup(const EVP_MD_CTX *in);
709__owur int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
710void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
711void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
712int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);
713__owur int EVP_DigestInit_ex2(EVP_MD_CTX *ctx, const EVP_MD *type,
714 const OSSL_PARAM params[]);
715__owur int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type,
716 ENGINE *impl);
717__owur int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d,
718 size_t cnt);
719__owur int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md,
720 unsigned int *s);
721__owur int EVP_Digest(const void *data, size_t count,
722 unsigned char *md, unsigned int *size,
723 const EVP_MD *type, ENGINE *impl);
724__owur int EVP_Q_digest(OSSL_LIB_CTX *libctx, const char *name,
725 const char *propq, const void *data, size_t datalen,
726 unsigned char *md, size_t *mdlen);
727
728__owur int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in);
729__owur int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
730__owur int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md,
731 unsigned int *s);
732__owur int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *out,
733 size_t outlen);
734__owur int EVP_DigestSqueeze(EVP_MD_CTX *ctx, unsigned char *out,
735 size_t outlen);
736
737__owur EVP_MD *EVP_MD_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
738 const char *properties);
739
740int EVP_MD_up_ref(EVP_MD *md);
741void EVP_MD_free(EVP_MD *md);
742
743int EVP_read_pw_string(char *buf, int length, const char *prompt, int verify);
744int EVP_read_pw_string_min(char *buf, int minlen, int maxlen,
745 const char *prompt, int verify);
746void EVP_set_pw_prompt(const char *prompt);
747char *EVP_get_pw_prompt(void);
748
749__owur int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
750 const unsigned char *salt,
751 const unsigned char *data, int datal, int count,
752 unsigned char *key, unsigned char *iv);
753
754void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags);
755void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags);
756int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags);
757
758__owur int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
759 const unsigned char *key, const unsigned char *iv);
760__owur int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,
761 const EVP_CIPHER *cipher, ENGINE *impl,
762 const unsigned char *key,
763 const unsigned char *iv);
764__owur int EVP_EncryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
765 const unsigned char *key,
766 const unsigned char *iv,
767 const OSSL_PARAM params[]);
768__owur int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
769 int *outl, const unsigned char *in, int inl);
770__owur int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out,
771 int *outl);
772__owur int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
773 int *outl);
774
775__owur int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
776 const unsigned char *key, const unsigned char *iv);
777__owur int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx,
778 const EVP_CIPHER *cipher, ENGINE *impl,
779 const unsigned char *key,
780 const unsigned char *iv);
781__owur int EVP_DecryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
782 const unsigned char *key,
783 const unsigned char *iv,
784 const OSSL_PARAM params[]);
785__owur int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
786 int *outl, const unsigned char *in, int inl);
787__owur int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
788 int *outl);
789__owur int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
790 int *outl);
791
792__owur int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
793 const unsigned char *key, const unsigned char *iv,
794 int enc);
795__owur int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx,
796 const EVP_CIPHER *cipher, ENGINE *impl,
797 const unsigned char *key,
798 const unsigned char *iv, int enc);
799__owur int EVP_CipherInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
800 const unsigned char *key, const unsigned char *iv,
801 int enc, const OSSL_PARAM params[]);
802__owur int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
803 int *outl, const unsigned char *in, int inl);
804__owur int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
805 int *outl);
806__owur int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
807 int *outl);
808
809__owur int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s,
810 EVP_PKEY *pkey);
811__owur int EVP_SignFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s,
812 EVP_PKEY *pkey, OSSL_LIB_CTX *libctx,
813 const char *propq);
814
815__owur int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret,
816 size_t *siglen, const unsigned char *tbs,
817 size_t tbslen);
818
819__owur int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
820 unsigned int siglen, EVP_PKEY *pkey);
821__owur int EVP_VerifyFinal_ex(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
822 unsigned int siglen, EVP_PKEY *pkey,
823 OSSL_LIB_CTX *libctx, const char *propq);
824
825__owur int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret,
826 size_t siglen, const unsigned char *tbs,
827 size_t tbslen);
828
829__owur int EVP_DigestSignInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
830 const char *mdname, OSSL_LIB_CTX *libctx,
831 const char *props, EVP_PKEY *pkey,
832 const OSSL_PARAM params[]);
833__owur int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
834 const EVP_MD *type, ENGINE *e,
835 EVP_PKEY *pkey);
836__owur int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize);
837__owur int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
838 size_t *siglen);
839
840__owur int EVP_DigestVerifyInit_ex(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
841 const char *mdname, OSSL_LIB_CTX *libctx,
842 const char *props, EVP_PKEY *pkey,
843 const OSSL_PARAM params[]);
844__owur int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
845 const EVP_MD *type, ENGINE *e,
846 EVP_PKEY *pkey);
847int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize);
848__owur int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
849 size_t siglen);
850
851__owur int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
852 const unsigned char *ek, int ekl,
853 const unsigned char *iv, EVP_PKEY *priv);
854__owur int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
855
856__owur int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
857 unsigned char **ek, int *ekl, unsigned char *iv,
858 EVP_PKEY **pubk, int npubk);
859__owur int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
860
861EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void);
862void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx);
863int EVP_ENCODE_CTX_copy(EVP_ENCODE_CTX *dctx, const EVP_ENCODE_CTX *sctx);
864int EVP_ENCODE_CTX_num(EVP_ENCODE_CTX *ctx);
865void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
866int EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
867 const unsigned char *in, int inl);
868void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl);
869int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
870
871void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
872int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
873 const unsigned char *in, int inl);
874int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
875 char *out, int *outl);
876int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
877
878# ifndef OPENSSL_NO_DEPRECATED_1_1_0
879# define EVP_CIPHER_CTX_init(c) EVP_CIPHER_CTX_reset(c)
880# define EVP_CIPHER_CTX_cleanup(c) EVP_CIPHER_CTX_reset(c)
881# endif
882EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void);
883int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c);
884void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *c);
885int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
886int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);
887int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
888int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key);
889int EVP_CIPHER_get_params(EVP_CIPHER *cipher, OSSL_PARAM params[]);
890int EVP_CIPHER_CTX_set_params(EVP_CIPHER_CTX *ctx, const OSSL_PARAM params[]);
891int EVP_CIPHER_CTX_get_params(EVP_CIPHER_CTX *ctx, OSSL_PARAM params[]);
892const OSSL_PARAM *EVP_CIPHER_gettable_params(const EVP_CIPHER *cipher);
893const OSSL_PARAM *EVP_CIPHER_settable_ctx_params(const EVP_CIPHER *cipher);
894const OSSL_PARAM *EVP_CIPHER_gettable_ctx_params(const EVP_CIPHER *cipher);
895const OSSL_PARAM *EVP_CIPHER_CTX_settable_params(EVP_CIPHER_CTX *ctx);
896const OSSL_PARAM *EVP_CIPHER_CTX_gettable_params(EVP_CIPHER_CTX *ctx);
897
898const BIO_METHOD *BIO_f_md(void);
899const BIO_METHOD *BIO_f_base64(void);
900const BIO_METHOD *BIO_f_cipher(void);
901const BIO_METHOD *BIO_f_reliable(void);
902__owur int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k,
903 const unsigned char *i, int enc);
904
905const EVP_MD *EVP_md_null(void);
906# ifndef OPENSSL_NO_MD2
907const EVP_MD *EVP_md2(void);
908# endif
909# ifndef OPENSSL_NO_MD4
910const EVP_MD *EVP_md4(void);
911# endif
912# ifndef OPENSSL_NO_MD5
913const EVP_MD *EVP_md5(void);
914const EVP_MD *EVP_md5_sha1(void);
915# endif
916# ifndef OPENSSL_NO_BLAKE2
917const EVP_MD *EVP_blake2b512(void);
918const EVP_MD *EVP_blake2s256(void);
919# endif
920const EVP_MD *EVP_sha1(void);
921const EVP_MD *EVP_sha224(void);
922const EVP_MD *EVP_sha256(void);
923const EVP_MD *EVP_sha384(void);
924const EVP_MD *EVP_sha512(void);
925const EVP_MD *EVP_sha512_224(void);
926const EVP_MD *EVP_sha512_256(void);
927const EVP_MD *EVP_sha3_224(void);
928const EVP_MD *EVP_sha3_256(void);
929const EVP_MD *EVP_sha3_384(void);
930const EVP_MD *EVP_sha3_512(void);
931const EVP_MD *EVP_shake128(void);
932const EVP_MD *EVP_shake256(void);
933
934# ifndef OPENSSL_NO_MDC2
935const EVP_MD *EVP_mdc2(void);
936# endif
937# ifndef OPENSSL_NO_RMD160
938const EVP_MD *EVP_ripemd160(void);
939# endif
940# ifndef OPENSSL_NO_WHIRLPOOL
941const EVP_MD *EVP_whirlpool(void);
942# endif
943# ifndef OPENSSL_NO_SM3
944const EVP_MD *EVP_sm3(void);
945# endif
946const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
947# ifndef OPENSSL_NO_DES
948const EVP_CIPHER *EVP_des_ecb(void);
949const EVP_CIPHER *EVP_des_ede(void);
950const EVP_CIPHER *EVP_des_ede3(void);
951const EVP_CIPHER *EVP_des_ede_ecb(void);
952const EVP_CIPHER *EVP_des_ede3_ecb(void);
953const EVP_CIPHER *EVP_des_cfb64(void);
954# define EVP_des_cfb EVP_des_cfb64
955const EVP_CIPHER *EVP_des_cfb1(void);
956const EVP_CIPHER *EVP_des_cfb8(void);
957const EVP_CIPHER *EVP_des_ede_cfb64(void);
958# define EVP_des_ede_cfb EVP_des_ede_cfb64
959const EVP_CIPHER *EVP_des_ede3_cfb64(void);
960# define EVP_des_ede3_cfb EVP_des_ede3_cfb64
961const EVP_CIPHER *EVP_des_ede3_cfb1(void);
962const EVP_CIPHER *EVP_des_ede3_cfb8(void);
963const EVP_CIPHER *EVP_des_ofb(void);
964const EVP_CIPHER *EVP_des_ede_ofb(void);
965const EVP_CIPHER *EVP_des_ede3_ofb(void);
966const EVP_CIPHER *EVP_des_cbc(void);
967const EVP_CIPHER *EVP_des_ede_cbc(void);
968const EVP_CIPHER *EVP_des_ede3_cbc(void);
969const EVP_CIPHER *EVP_desx_cbc(void);
970const EVP_CIPHER *EVP_des_ede3_wrap(void);
971/*
972 * This should now be supported through the dev_crypto ENGINE. But also, why
973 * are rc4 and md5 declarations made here inside a "NO_DES" precompiler
974 * branch?
975 */
976# endif
977# ifndef OPENSSL_NO_RC4
978const EVP_CIPHER *EVP_rc4(void);
979const EVP_CIPHER *EVP_rc4_40(void);
980# ifndef OPENSSL_NO_MD5
981const EVP_CIPHER *EVP_rc4_hmac_md5(void);
982# endif
983# endif
984# ifndef OPENSSL_NO_IDEA
985const EVP_CIPHER *EVP_idea_ecb(void);
986const EVP_CIPHER *EVP_idea_cfb64(void);
987# define EVP_idea_cfb EVP_idea_cfb64
988const EVP_CIPHER *EVP_idea_ofb(void);
989const EVP_CIPHER *EVP_idea_cbc(void);
990# endif
991# ifndef OPENSSL_NO_RC2
992const EVP_CIPHER *EVP_rc2_ecb(void);
993const EVP_CIPHER *EVP_rc2_cbc(void);
994const EVP_CIPHER *EVP_rc2_40_cbc(void);
995const EVP_CIPHER *EVP_rc2_64_cbc(void);
996const EVP_CIPHER *EVP_rc2_cfb64(void);
997# define EVP_rc2_cfb EVP_rc2_cfb64
998const EVP_CIPHER *EVP_rc2_ofb(void);
999# endif
1000# ifndef OPENSSL_NO_BF
1001const EVP_CIPHER *EVP_bf_ecb(void);
1002const EVP_CIPHER *EVP_bf_cbc(void);
1003const EVP_CIPHER *EVP_bf_cfb64(void);
1004# define EVP_bf_cfb EVP_bf_cfb64
1005const EVP_CIPHER *EVP_bf_ofb(void);
1006# endif
1007# ifndef OPENSSL_NO_CAST
1008const EVP_CIPHER *EVP_cast5_ecb(void);
1009const EVP_CIPHER *EVP_cast5_cbc(void);
1010const EVP_CIPHER *EVP_cast5_cfb64(void);
1011# define EVP_cast5_cfb EVP_cast5_cfb64
1012const EVP_CIPHER *EVP_cast5_ofb(void);
1013# endif
1014# ifndef OPENSSL_NO_RC5
1015const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
1016const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
1017const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void);
1018# define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64
1019const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
1020# endif
1021const EVP_CIPHER *EVP_aes_128_ecb(void);
1022const EVP_CIPHER *EVP_aes_128_cbc(void);
1023const EVP_CIPHER *EVP_aes_128_cfb1(void);
1024const EVP_CIPHER *EVP_aes_128_cfb8(void);
1025const EVP_CIPHER *EVP_aes_128_cfb128(void);
1026# define EVP_aes_128_cfb EVP_aes_128_cfb128
1027const EVP_CIPHER *EVP_aes_128_ofb(void);
1028const EVP_CIPHER *EVP_aes_128_ctr(void);
1029const EVP_CIPHER *EVP_aes_128_ccm(void);
1030const EVP_CIPHER *EVP_aes_128_gcm(void);
1031const EVP_CIPHER *EVP_aes_128_xts(void);
1032const EVP_CIPHER *EVP_aes_128_wrap(void);
1033const EVP_CIPHER *EVP_aes_128_wrap_pad(void);
1034# ifndef OPENSSL_NO_OCB
1035const EVP_CIPHER *EVP_aes_128_ocb(void);
1036# endif
1037const EVP_CIPHER *EVP_aes_192_ecb(void);
1038const EVP_CIPHER *EVP_aes_192_cbc(void);
1039const EVP_CIPHER *EVP_aes_192_cfb1(void);
1040const EVP_CIPHER *EVP_aes_192_cfb8(void);
1041const EVP_CIPHER *EVP_aes_192_cfb128(void);
1042# define EVP_aes_192_cfb EVP_aes_192_cfb128
1043const EVP_CIPHER *EVP_aes_192_ofb(void);
1044const EVP_CIPHER *EVP_aes_192_ctr(void);
1045const EVP_CIPHER *EVP_aes_192_ccm(void);
1046const EVP_CIPHER *EVP_aes_192_gcm(void);
1047const EVP_CIPHER *EVP_aes_192_wrap(void);
1048const EVP_CIPHER *EVP_aes_192_wrap_pad(void);
1049# ifndef OPENSSL_NO_OCB
1050const EVP_CIPHER *EVP_aes_192_ocb(void);
1051# endif
1052const EVP_CIPHER *EVP_aes_256_ecb(void);
1053const EVP_CIPHER *EVP_aes_256_cbc(void);
1054const EVP_CIPHER *EVP_aes_256_cfb1(void);
1055const EVP_CIPHER *EVP_aes_256_cfb8(void);
1056const EVP_CIPHER *EVP_aes_256_cfb128(void);
1057# define EVP_aes_256_cfb EVP_aes_256_cfb128
1058const EVP_CIPHER *EVP_aes_256_ofb(void);
1059const EVP_CIPHER *EVP_aes_256_ctr(void);
1060const EVP_CIPHER *EVP_aes_256_ccm(void);
1061const EVP_CIPHER *EVP_aes_256_gcm(void);
1062const EVP_CIPHER *EVP_aes_256_xts(void);
1063const EVP_CIPHER *EVP_aes_256_wrap(void);
1064const EVP_CIPHER *EVP_aes_256_wrap_pad(void);
1065# ifndef OPENSSL_NO_OCB
1066const EVP_CIPHER *EVP_aes_256_ocb(void);
1067# endif
1068const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void);
1069const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha1(void);
1070const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha256(void);
1071const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha256(void);
1072# ifndef OPENSSL_NO_ARIA
1073const EVP_CIPHER *EVP_aria_128_ecb(void);
1074const EVP_CIPHER *EVP_aria_128_cbc(void);
1075const EVP_CIPHER *EVP_aria_128_cfb1(void);
1076const EVP_CIPHER *EVP_aria_128_cfb8(void);
1077const EVP_CIPHER *EVP_aria_128_cfb128(void);
1078# define EVP_aria_128_cfb EVP_aria_128_cfb128
1079const EVP_CIPHER *EVP_aria_128_ctr(void);
1080const EVP_CIPHER *EVP_aria_128_ofb(void);
1081const EVP_CIPHER *EVP_aria_128_gcm(void);
1082const EVP_CIPHER *EVP_aria_128_ccm(void);
1083const EVP_CIPHER *EVP_aria_192_ecb(void);
1084const EVP_CIPHER *EVP_aria_192_cbc(void);
1085const EVP_CIPHER *EVP_aria_192_cfb1(void);
1086const EVP_CIPHER *EVP_aria_192_cfb8(void);
1087const EVP_CIPHER *EVP_aria_192_cfb128(void);
1088# define EVP_aria_192_cfb EVP_aria_192_cfb128
1089const EVP_CIPHER *EVP_aria_192_ctr(void);
1090const EVP_CIPHER *EVP_aria_192_ofb(void);
1091const EVP_CIPHER *EVP_aria_192_gcm(void);
1092const EVP_CIPHER *EVP_aria_192_ccm(void);
1093const EVP_CIPHER *EVP_aria_256_ecb(void);
1094const EVP_CIPHER *EVP_aria_256_cbc(void);
1095const EVP_CIPHER *EVP_aria_256_cfb1(void);
1096const EVP_CIPHER *EVP_aria_256_cfb8(void);
1097const EVP_CIPHER *EVP_aria_256_cfb128(void);
1098# define EVP_aria_256_cfb EVP_aria_256_cfb128
1099const EVP_CIPHER *EVP_aria_256_ctr(void);
1100const EVP_CIPHER *EVP_aria_256_ofb(void);
1101const EVP_CIPHER *EVP_aria_256_gcm(void);
1102const EVP_CIPHER *EVP_aria_256_ccm(void);
1103# endif
1104# ifndef OPENSSL_NO_CAMELLIA
1105const EVP_CIPHER *EVP_camellia_128_ecb(void);
1106const EVP_CIPHER *EVP_camellia_128_cbc(void);
1107const EVP_CIPHER *EVP_camellia_128_cfb1(void);
1108const EVP_CIPHER *EVP_camellia_128_cfb8(void);
1109const EVP_CIPHER *EVP_camellia_128_cfb128(void);
1110# define EVP_camellia_128_cfb EVP_camellia_128_cfb128
1111const EVP_CIPHER *EVP_camellia_128_ofb(void);
1112const EVP_CIPHER *EVP_camellia_128_ctr(void);
1113const EVP_CIPHER *EVP_camellia_192_ecb(void);
1114const EVP_CIPHER *EVP_camellia_192_cbc(void);
1115const EVP_CIPHER *EVP_camellia_192_cfb1(void);
1116const EVP_CIPHER *EVP_camellia_192_cfb8(void);
1117const EVP_CIPHER *EVP_camellia_192_cfb128(void);
1118# define EVP_camellia_192_cfb EVP_camellia_192_cfb128
1119const EVP_CIPHER *EVP_camellia_192_ofb(void);
1120const EVP_CIPHER *EVP_camellia_192_ctr(void);
1121const EVP_CIPHER *EVP_camellia_256_ecb(void);
1122const EVP_CIPHER *EVP_camellia_256_cbc(void);
1123const EVP_CIPHER *EVP_camellia_256_cfb1(void);
1124const EVP_CIPHER *EVP_camellia_256_cfb8(void);
1125const EVP_CIPHER *EVP_camellia_256_cfb128(void);
1126# define EVP_camellia_256_cfb EVP_camellia_256_cfb128
1127const EVP_CIPHER *EVP_camellia_256_ofb(void);
1128const EVP_CIPHER *EVP_camellia_256_ctr(void);
1129# endif
1130# ifndef OPENSSL_NO_CHACHA
1131const EVP_CIPHER *EVP_chacha20(void);
1132# ifndef OPENSSL_NO_POLY1305
1133const EVP_CIPHER *EVP_chacha20_poly1305(void);
1134# endif
1135# endif
1136
1137# ifndef OPENSSL_NO_SEED
1138const EVP_CIPHER *EVP_seed_ecb(void);
1139const EVP_CIPHER *EVP_seed_cbc(void);
1140const EVP_CIPHER *EVP_seed_cfb128(void);
1141# define EVP_seed_cfb EVP_seed_cfb128
1142const EVP_CIPHER *EVP_seed_ofb(void);
1143# endif
1144
1145# ifndef OPENSSL_NO_SM4
1146const EVP_CIPHER *EVP_sm4_ecb(void);
1147const EVP_CIPHER *EVP_sm4_cbc(void);
1148const EVP_CIPHER *EVP_sm4_cfb128(void);
1149# define EVP_sm4_cfb EVP_sm4_cfb128
1150const EVP_CIPHER *EVP_sm4_ofb(void);
1151const EVP_CIPHER *EVP_sm4_ctr(void);
1152# endif
1153
1154# ifndef OPENSSL_NO_DEPRECATED_1_1_0
1155# define OPENSSL_add_all_algorithms_conf() \
1156 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
1157 | OPENSSL_INIT_ADD_ALL_DIGESTS \
1158 | OPENSSL_INIT_LOAD_CONFIG, NULL)
1159# define OPENSSL_add_all_algorithms_noconf() \
1160 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
1161 | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL)
1162
1163# ifdef OPENSSL_LOAD_CONF
1164# define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_conf()
1165# else
1166# define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_noconf()
1167# endif
1168
1169# define OpenSSL_add_all_ciphers() \
1170 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL)
1171# define OpenSSL_add_all_digests() \
1172 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL)
1173
1174# define EVP_cleanup() while(0) continue
1175# endif
1176
1177int EVP_add_cipher(const EVP_CIPHER *cipher);
1178int EVP_add_digest(const EVP_MD *digest);
1179
1180const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
1181const EVP_MD *EVP_get_digestbyname(const char *name);
1182
1183void EVP_CIPHER_do_all(void (*fn) (const EVP_CIPHER *ciph,
1184 const char *from, const char *to, void *x),
1185 void *arg);
1186void EVP_CIPHER_do_all_sorted(void (*fn)
1187 (const EVP_CIPHER *ciph, const char *from,
1188 const char *to, void *x), void *arg);
1189void EVP_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx,
1190 void (*fn)(EVP_CIPHER *cipher, void *arg),
1191 void *arg);
1192
1193void EVP_MD_do_all(void (*fn) (const EVP_MD *ciph,
1194 const char *from, const char *to, void *x),
1195 void *arg);
1196void EVP_MD_do_all_sorted(void (*fn)
1197 (const EVP_MD *ciph, const char *from,
1198 const char *to, void *x), void *arg);
1199void EVP_MD_do_all_provided(OSSL_LIB_CTX *libctx,
1200 void (*fn)(EVP_MD *md, void *arg),
1201 void *arg);
1202
1203/* MAC stuff */
1204
1205EVP_MAC *EVP_MAC_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
1206 const char *properties);
1207int EVP_MAC_up_ref(EVP_MAC *mac);
1208void EVP_MAC_free(EVP_MAC *mac);
1209const char *EVP_MAC_get0_name(const EVP_MAC *mac);
1210const char *EVP_MAC_get0_description(const EVP_MAC *mac);
1211int EVP_MAC_is_a(const EVP_MAC *mac, const char *name);
1212const OSSL_PROVIDER *EVP_MAC_get0_provider(const EVP_MAC *mac);
1213int EVP_MAC_get_params(EVP_MAC *mac, OSSL_PARAM params[]);
1214
1215EVP_MAC_CTX *EVP_MAC_CTX_new(EVP_MAC *mac);
1216void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx);
1217EVP_MAC_CTX *EVP_MAC_CTX_dup(const EVP_MAC_CTX *src);
1218EVP_MAC *EVP_MAC_CTX_get0_mac(EVP_MAC_CTX *ctx);
1219int EVP_MAC_CTX_get_params(EVP_MAC_CTX *ctx, OSSL_PARAM params[]);
1220int EVP_MAC_CTX_set_params(EVP_MAC_CTX *ctx, const OSSL_PARAM params[]);
1221
1222size_t EVP_MAC_CTX_get_mac_size(EVP_MAC_CTX *ctx);
1223size_t EVP_MAC_CTX_get_block_size(EVP_MAC_CTX *ctx);
1224unsigned char *EVP_Q_mac(OSSL_LIB_CTX *libctx, const char *name, const char *propq,
1225 const char *subalg, const OSSL_PARAM *params,
1226 const void *key, size_t keylen,
1227 const unsigned char *data, size_t datalen,
1228 unsigned char *out, size_t outsize, size_t *outlen);
1229int EVP_MAC_init(EVP_MAC_CTX *ctx, const unsigned char *key, size_t keylen,
1230 const OSSL_PARAM params[]);
1231int EVP_MAC_update(EVP_MAC_CTX *ctx, const unsigned char *data, size_t datalen);
1232int EVP_MAC_final(EVP_MAC_CTX *ctx,
1233 unsigned char *out, size_t *outl, size_t outsize);
1234int EVP_MAC_finalXOF(EVP_MAC_CTX *ctx, unsigned char *out, size_t outsize);
1235const OSSL_PARAM *EVP_MAC_gettable_params(const EVP_MAC *mac);
1236const OSSL_PARAM *EVP_MAC_gettable_ctx_params(const EVP_MAC *mac);
1237const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac);
1238const OSSL_PARAM *EVP_MAC_CTX_gettable_params(EVP_MAC_CTX *ctx);
1239const OSSL_PARAM *EVP_MAC_CTX_settable_params(EVP_MAC_CTX *ctx);
1240
1241void EVP_MAC_do_all_provided(OSSL_LIB_CTX *libctx,
1242 void (*fn)(EVP_MAC *mac, void *arg),
1243 void *arg);
1244int EVP_MAC_names_do_all(const EVP_MAC *mac,
1245 void (*fn)(const char *name, void *data),
1246 void *data);
1247
1248/* RAND stuff */
1249EVP_RAND *EVP_RAND_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
1250 const char *properties);
1251int EVP_RAND_up_ref(EVP_RAND *rand);
1252void EVP_RAND_free(EVP_RAND *rand);
1253const char *EVP_RAND_get0_name(const EVP_RAND *rand);
1254const char *EVP_RAND_get0_description(const EVP_RAND *md);
1255int EVP_RAND_is_a(const EVP_RAND *rand, const char *name);
1256const OSSL_PROVIDER *EVP_RAND_get0_provider(const EVP_RAND *rand);
1257int EVP_RAND_get_params(EVP_RAND *rand, OSSL_PARAM params[]);
1258
1259EVP_RAND_CTX *EVP_RAND_CTX_new(EVP_RAND *rand, EVP_RAND_CTX *parent);
1260int EVP_RAND_CTX_up_ref(EVP_RAND_CTX *ctx);
1261void EVP_RAND_CTX_free(EVP_RAND_CTX *ctx);
1262EVP_RAND *EVP_RAND_CTX_get0_rand(EVP_RAND_CTX *ctx);
1263int EVP_RAND_CTX_get_params(EVP_RAND_CTX *ctx, OSSL_PARAM params[]);
1264int EVP_RAND_CTX_set_params(EVP_RAND_CTX *ctx, const OSSL_PARAM params[]);
1265const OSSL_PARAM *EVP_RAND_gettable_params(const EVP_RAND *rand);
1266const OSSL_PARAM *EVP_RAND_gettable_ctx_params(const EVP_RAND *rand);
1267const OSSL_PARAM *EVP_RAND_settable_ctx_params(const EVP_RAND *rand);
1268const OSSL_PARAM *EVP_RAND_CTX_gettable_params(EVP_RAND_CTX *ctx);
1269const OSSL_PARAM *EVP_RAND_CTX_settable_params(EVP_RAND_CTX *ctx);
1270
1271void EVP_RAND_do_all_provided(OSSL_LIB_CTX *libctx,
1272 void (*fn)(EVP_RAND *rand, void *arg),
1273 void *arg);
1274int EVP_RAND_names_do_all(const EVP_RAND *rand,
1275 void (*fn)(const char *name, void *data),
1276 void *data);
1277
1278__owur int EVP_RAND_instantiate(EVP_RAND_CTX *ctx, unsigned int strength,
1279 int prediction_resistance,
1280 const unsigned char *pstr, size_t pstr_len,
1281 const OSSL_PARAM params[]);
1282int EVP_RAND_uninstantiate(EVP_RAND_CTX *ctx);
1283__owur int EVP_RAND_generate(EVP_RAND_CTX *ctx, unsigned char *out,
1284 size_t outlen, unsigned int strength,
1285 int prediction_resistance,
1286 const unsigned char *addin, size_t addin_len);
1287int EVP_RAND_reseed(EVP_RAND_CTX *ctx, int prediction_resistance,
1288 const unsigned char *ent, size_t ent_len,
1289 const unsigned char *addin, size_t addin_len);
1290__owur int EVP_RAND_nonce(EVP_RAND_CTX *ctx, unsigned char *out, size_t outlen);
1291__owur int EVP_RAND_enable_locking(EVP_RAND_CTX *ctx);
1292
1293int EVP_RAND_verify_zeroization(EVP_RAND_CTX *ctx);
1294unsigned int EVP_RAND_get_strength(EVP_RAND_CTX *ctx);
1295int EVP_RAND_get_state(EVP_RAND_CTX *ctx);
1296
1297# define EVP_RAND_STATE_UNINITIALISED 0
1298# define EVP_RAND_STATE_READY 1
1299# define EVP_RAND_STATE_ERROR 2
1300
1301/* PKEY stuff */
1302# ifndef OPENSSL_NO_DEPRECATED_3_0
1303OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_decrypt_old(unsigned char *dec_key,
1304 const unsigned char *enc_key,
1305 int enc_key_len,
1306 EVP_PKEY *private_key);
1307OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_encrypt_old(unsigned char *enc_key,
1308 const unsigned char *key,
1309 int key_len, EVP_PKEY *pub_key);
1310# endif
1311int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name);
1312int EVP_PKEY_type_names_do_all(const EVP_PKEY *pkey,
1313 void (*fn)(const char *name, void *data),
1314 void *data);
1315int EVP_PKEY_type(int type);
1316int EVP_PKEY_get_id(const EVP_PKEY *pkey);
1317# define EVP_PKEY_id EVP_PKEY_get_id
1318int EVP_PKEY_get_base_id(const EVP_PKEY *pkey);
1319# define EVP_PKEY_base_id EVP_PKEY_get_base_id
1320int EVP_PKEY_get_bits(const EVP_PKEY *pkey);
1321# define EVP_PKEY_bits EVP_PKEY_get_bits
1322int EVP_PKEY_get_security_bits(const EVP_PKEY *pkey);
1323# define EVP_PKEY_security_bits EVP_PKEY_get_security_bits
1324int EVP_PKEY_get_size(const EVP_PKEY *pkey);
1325# define EVP_PKEY_size EVP_PKEY_get_size
1326int EVP_PKEY_can_sign(const EVP_PKEY *pkey);
1327int EVP_PKEY_set_type(EVP_PKEY *pkey, int type);
1328int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len);
1329int EVP_PKEY_set_type_by_keymgmt(EVP_PKEY *pkey, EVP_KEYMGMT *keymgmt);
1330# ifndef OPENSSL_NO_DEPRECATED_3_0
1331# ifndef OPENSSL_NO_ENGINE
1332OSSL_DEPRECATEDIN_3_0
1333int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *e);
1334OSSL_DEPRECATEDIN_3_0
1335ENGINE *EVP_PKEY_get0_engine(const EVP_PKEY *pkey);
1336# endif
1337OSSL_DEPRECATEDIN_3_0
1338int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key);
1339OSSL_DEPRECATEDIN_3_0
1340void *EVP_PKEY_get0(const EVP_PKEY *pkey);
1341OSSL_DEPRECATEDIN_3_0
1342const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len);
1343# ifndef OPENSSL_NO_POLY1305
1344OSSL_DEPRECATEDIN_3_0
1345const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len);
1346# endif
1347# ifndef OPENSSL_NO_SIPHASH
1348OSSL_DEPRECATEDIN_3_0
1349const unsigned char *EVP_PKEY_get0_siphash(const EVP_PKEY *pkey, size_t *len);
1350# endif
1351
1352struct rsa_st;
1353OSSL_DEPRECATEDIN_3_0
1354int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key);
1355OSSL_DEPRECATEDIN_3_0
1356const struct rsa_st *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey);
1357OSSL_DEPRECATEDIN_3_0
1358struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
1359
1360# ifndef OPENSSL_NO_DSA
1361struct dsa_st;
1362OSSL_DEPRECATEDIN_3_0
1363int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key);
1364OSSL_DEPRECATEDIN_3_0
1365const struct dsa_st *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey);
1366OSSL_DEPRECATEDIN_3_0
1367struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
1368# endif
1369
1370# ifndef OPENSSL_NO_DH
1371struct dh_st;
1372OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key);
1373OSSL_DEPRECATEDIN_3_0 const struct dh_st *EVP_PKEY_get0_DH(const EVP_PKEY *pkey);
1374OSSL_DEPRECATEDIN_3_0 struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
1375# endif
1376
1377# ifndef OPENSSL_NO_EC
1378struct ec_key_st;
1379OSSL_DEPRECATEDIN_3_0
1380int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key);
1381OSSL_DEPRECATEDIN_3_0
1382const struct ec_key_st *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey);
1383OSSL_DEPRECATEDIN_3_0
1384struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
1385# endif
1386# endif /* OPENSSL_NO_DEPRECATED_3_0 */
1387
1388EVP_PKEY *EVP_PKEY_new(void);
1389int EVP_PKEY_up_ref(EVP_PKEY *pkey);
1390EVP_PKEY *EVP_PKEY_dup(EVP_PKEY *pkey);
1391void EVP_PKEY_free(EVP_PKEY *pkey);
1392const char *EVP_PKEY_get0_description(const EVP_PKEY *pkey);
1393const OSSL_PROVIDER *EVP_PKEY_get0_provider(const EVP_PKEY *key);
1394
1395EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
1396 long length);
1397int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp);
1398
1399
1400EVP_PKEY *d2i_PrivateKey_ex(int type, EVP_PKEY **a, const unsigned char **pp,
1401 long length, OSSL_LIB_CTX *libctx,
1402 const char *propq);
1403EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
1404 long length);
1405EVP_PKEY *d2i_AutoPrivateKey_ex(EVP_PKEY **a, const unsigned char **pp,
1406 long length, OSSL_LIB_CTX *libctx,
1407 const char *propq);
1408EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
1409 long length);
1410int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp);
1411
1412int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp);
1413EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp,
1414 long length);
1415int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey);
1416EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in);
1417
1418int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from);
1419int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey);
1420int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode);
1421int EVP_PKEY_parameters_eq(const EVP_PKEY *a, const EVP_PKEY *b);
1422int EVP_PKEY_eq(const EVP_PKEY *a, const EVP_PKEY *b);
1423
1424# ifndef OPENSSL_NO_DEPRECATED_3_0
1425OSSL_DEPRECATEDIN_3_0
1426int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b);
1427OSSL_DEPRECATEDIN_3_0
1428int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
1429# endif
1430
1431int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
1432 int indent, ASN1_PCTX *pctx);
1433int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
1434 int indent, ASN1_PCTX *pctx);
1435int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
1436 int indent, ASN1_PCTX *pctx);
1437# ifndef OPENSSL_NO_STDIO
1438int EVP_PKEY_print_public_fp(FILE *fp, const EVP_PKEY *pkey,
1439 int indent, ASN1_PCTX *pctx);
1440int EVP_PKEY_print_private_fp(FILE *fp, const EVP_PKEY *pkey,
1441 int indent, ASN1_PCTX *pctx);
1442int EVP_PKEY_print_params_fp(FILE *fp, const EVP_PKEY *pkey,
1443 int indent, ASN1_PCTX *pctx);
1444# endif
1445
1446int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid);
1447int EVP_PKEY_get_default_digest_name(EVP_PKEY *pkey,
1448 char *mdname, size_t mdname_sz);
1449int EVP_PKEY_digestsign_supports_digest(EVP_PKEY *pkey, OSSL_LIB_CTX *libctx,
1450 const char *name, const char *propq);
1451
1452# ifndef OPENSSL_NO_DEPRECATED_3_0
1453/*
1454 * For backwards compatibility. Use EVP_PKEY_set1_encoded_public_key in
1455 * preference
1456 */
1457# define EVP_PKEY_set1_tls_encodedpoint(pkey, pt, ptlen) \
1458 EVP_PKEY_set1_encoded_public_key((pkey), (pt), (ptlen))
1459# endif
1460
1461int EVP_PKEY_set1_encoded_public_key(EVP_PKEY *pkey,
1462 const unsigned char *pub, size_t publen);
1463
1464# ifndef OPENSSL_NO_DEPRECATED_3_0
1465/*
1466 * For backwards compatibility. Use EVP_PKEY_get1_encoded_public_key in
1467 * preference
1468 */
1469# define EVP_PKEY_get1_tls_encodedpoint(pkey, ppt) \
1470 EVP_PKEY_get1_encoded_public_key((pkey), (ppt))
1471# endif
1472
1473size_t EVP_PKEY_get1_encoded_public_key(EVP_PKEY *pkey, unsigned char **ppub);
1474
1475/* calls methods */
1476int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
1477int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
1478
1479/* These are used by EVP_CIPHER methods */
1480int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
1481int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
1482
1483/* PKCS5 password based encryption */
1484int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
1485 ASN1_TYPE *param, const EVP_CIPHER *cipher,
1486 const EVP_MD *md, int en_de);
1487int PKCS5_PBE_keyivgen_ex(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
1488 ASN1_TYPE *param, const EVP_CIPHER *cipher,
1489 const EVP_MD *md, int en_de, OSSL_LIB_CTX *libctx,
1490 const char *propq);
1491int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
1492 const unsigned char *salt, int saltlen, int iter,
1493 int keylen, unsigned char *out);
1494int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
1495 const unsigned char *salt, int saltlen, int iter,
1496 const EVP_MD *digest, int keylen, unsigned char *out);
1497int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
1498 ASN1_TYPE *param, const EVP_CIPHER *cipher,
1499 const EVP_MD *md, int en_de);
1500int PKCS5_v2_PBE_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
1501 ASN1_TYPE *param, const EVP_CIPHER *cipher,
1502 const EVP_MD *md, int en_de,
1503 OSSL_LIB_CTX *libctx, const char *propq);
1504
1505#ifndef OPENSSL_NO_SCRYPT
1506int EVP_PBE_scrypt(const char *pass, size_t passlen,
1507 const unsigned char *salt, size_t saltlen,
1508 uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem,
1509 unsigned char *key, size_t keylen);
1510int EVP_PBE_scrypt_ex(const char *pass, size_t passlen,
1511 const unsigned char *salt, size_t saltlen,
1512 uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem,
1513 unsigned char *key, size_t keylen,
1514 OSSL_LIB_CTX *ctx, const char *propq);
1515
1516int PKCS5_v2_scrypt_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass,
1517 int passlen, ASN1_TYPE *param,
1518 const EVP_CIPHER *c, const EVP_MD *md, int en_de);
1519int PKCS5_v2_scrypt_keyivgen_ex(EVP_CIPHER_CTX *ctx, const char *pass,
1520 int passlen, ASN1_TYPE *param,
1521 const EVP_CIPHER *c, const EVP_MD *md, int en_de,
1522 OSSL_LIB_CTX *libctx, const char *propq);
1523#endif
1524
1525void PKCS5_PBE_add(void);
1526
1527int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
1528 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
1529
1530int EVP_PBE_CipherInit_ex(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
1531 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de,
1532 OSSL_LIB_CTX *libctx, const char *propq);
1533
1534/* PBE type */
1535
1536/* Can appear as the outermost AlgorithmIdentifier */
1537# define EVP_PBE_TYPE_OUTER 0x0
1538/* Is an PRF type OID */
1539# define EVP_PBE_TYPE_PRF 0x1
1540/* Is a PKCS#5 v2.0 KDF */
1541# define EVP_PBE_TYPE_KDF 0x2
1542
1543int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid,
1544 int md_nid, EVP_PBE_KEYGEN *keygen);
1545int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
1546 EVP_PBE_KEYGEN *keygen);
1547int EVP_PBE_find(int type, int pbe_nid, int *pcnid, int *pmnid,
1548 EVP_PBE_KEYGEN **pkeygen);
1549int EVP_PBE_find_ex(int type, int pbe_nid, int *pcnid, int *pmnid,
1550 EVP_PBE_KEYGEN **pkeygen, EVP_PBE_KEYGEN_EX **pkeygen_ex);
1551void EVP_PBE_cleanup(void);
1552int EVP_PBE_get(int *ptype, int *ppbe_nid, size_t num);
1553
1554# define ASN1_PKEY_ALIAS 0x1
1555# define ASN1_PKEY_DYNAMIC 0x2
1556# define ASN1_PKEY_SIGPARAM_NULL 0x4
1557
1558# define ASN1_PKEY_CTRL_PKCS7_SIGN 0x1
1559# define ASN1_PKEY_CTRL_PKCS7_ENCRYPT 0x2
1560# define ASN1_PKEY_CTRL_DEFAULT_MD_NID 0x3
1561# define ASN1_PKEY_CTRL_CMS_SIGN 0x5
1562# define ASN1_PKEY_CTRL_CMS_ENVELOPE 0x7
1563# define ASN1_PKEY_CTRL_CMS_RI_TYPE 0x8
1564
1565# define ASN1_PKEY_CTRL_SET1_TLS_ENCPT 0x9
1566# define ASN1_PKEY_CTRL_GET1_TLS_ENCPT 0xa
1567# define ASN1_PKEY_CTRL_CMS_IS_RI_TYPE_SUPPORTED 0xb
1568
1569int EVP_PKEY_asn1_get_count(void);
1570const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx);
1571const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type);
1572const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe,
1573 const char *str, int len);
1574int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth);
1575int EVP_PKEY_asn1_add_alias(int to, int from);
1576int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id,
1577 int *ppkey_flags, const char **pinfo,
1578 const char **ppem_str,
1579 const EVP_PKEY_ASN1_METHOD *ameth);
1580
1581const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(const EVP_PKEY *pkey);
1582EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
1583 const char *pem_str,
1584 const char *info);
1585void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
1586 const EVP_PKEY_ASN1_METHOD *src);
1587void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth);
1588void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
1589 int (*pub_decode) (EVP_PKEY *pk,
1590 const X509_PUBKEY *pub),
1591 int (*pub_encode) (X509_PUBKEY *pub,
1592 const EVP_PKEY *pk),
1593 int (*pub_cmp) (const EVP_PKEY *a,
1594 const EVP_PKEY *b),
1595 int (*pub_print) (BIO *out,
1596 const EVP_PKEY *pkey,
1597 int indent, ASN1_PCTX *pctx),
1598 int (*pkey_size) (const EVP_PKEY *pk),
1599 int (*pkey_bits) (const EVP_PKEY *pk));
1600void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
1601 int (*priv_decode) (EVP_PKEY *pk,
1602 const PKCS8_PRIV_KEY_INFO
1603 *p8inf),
1604 int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8,
1605 const EVP_PKEY *pk),
1606 int (*priv_print) (BIO *out,
1607 const EVP_PKEY *pkey,
1608 int indent,
1609 ASN1_PCTX *pctx));
1610void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
1611 int (*param_decode) (EVP_PKEY *pkey,
1612 const unsigned char **pder,
1613 int derlen),
1614 int (*param_encode) (const EVP_PKEY *pkey,
1615 unsigned char **pder),
1616 int (*param_missing) (const EVP_PKEY *pk),
1617 int (*param_copy) (EVP_PKEY *to,
1618 const EVP_PKEY *from),
1619 int (*param_cmp) (const EVP_PKEY *a,
1620 const EVP_PKEY *b),
1621 int (*param_print) (BIO *out,
1622 const EVP_PKEY *pkey,
1623 int indent,
1624 ASN1_PCTX *pctx));
1625
1626void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
1627 void (*pkey_free) (EVP_PKEY *pkey));
1628void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
1629 int (*pkey_ctrl) (EVP_PKEY *pkey, int op,
1630 long arg1, void *arg2));
1631void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth,
1632 int (*item_verify) (EVP_MD_CTX *ctx,
1633 const ASN1_ITEM *it,
1634 const void *data,
1635 const X509_ALGOR *a,
1636 const ASN1_BIT_STRING *sig,
1637 EVP_PKEY *pkey),
1638 int (*item_sign) (EVP_MD_CTX *ctx,
1639 const ASN1_ITEM *it,
1640 const void *data,
1641 X509_ALGOR *alg1,
1642 X509_ALGOR *alg2,
1643 ASN1_BIT_STRING *sig));
1644
1645void EVP_PKEY_asn1_set_siginf(EVP_PKEY_ASN1_METHOD *ameth,
1646 int (*siginf_set) (X509_SIG_INFO *siginf,
1647 const X509_ALGOR *alg,
1648 const ASN1_STRING *sig));
1649
1650void EVP_PKEY_asn1_set_check(EVP_PKEY_ASN1_METHOD *ameth,
1651 int (*pkey_check) (const EVP_PKEY *pk));
1652
1653void EVP_PKEY_asn1_set_public_check(EVP_PKEY_ASN1_METHOD *ameth,
1654 int (*pkey_pub_check) (const EVP_PKEY *pk));
1655
1656void EVP_PKEY_asn1_set_param_check(EVP_PKEY_ASN1_METHOD *ameth,
1657 int (*pkey_param_check) (const EVP_PKEY *pk));
1658
1659void EVP_PKEY_asn1_set_set_priv_key(EVP_PKEY_ASN1_METHOD *ameth,
1660 int (*set_priv_key) (EVP_PKEY *pk,
1661 const unsigned char
1662 *priv,
1663 size_t len));
1664void EVP_PKEY_asn1_set_set_pub_key(EVP_PKEY_ASN1_METHOD *ameth,
1665 int (*set_pub_key) (EVP_PKEY *pk,
1666 const unsigned char *pub,
1667 size_t len));
1668void EVP_PKEY_asn1_set_get_priv_key(EVP_PKEY_ASN1_METHOD *ameth,
1669 int (*get_priv_key) (const EVP_PKEY *pk,
1670 unsigned char *priv,
1671 size_t *len));
1672void EVP_PKEY_asn1_set_get_pub_key(EVP_PKEY_ASN1_METHOD *ameth,
1673 int (*get_pub_key) (const EVP_PKEY *pk,
1674 unsigned char *pub,
1675 size_t *len));
1676
1677void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth,
1678 int (*pkey_security_bits) (const EVP_PKEY
1679 *pk));
1680
1681int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
1682int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
1683
1684int EVP_PKEY_CTX_set1_id(EVP_PKEY_CTX *ctx, const void *id, int len);
1685int EVP_PKEY_CTX_get1_id(EVP_PKEY_CTX *ctx, void *id);
1686int EVP_PKEY_CTX_get1_id_len(EVP_PKEY_CTX *ctx, size_t *id_len);
1687
1688int EVP_PKEY_CTX_set_kem_op(EVP_PKEY_CTX *ctx, const char *op);
1689
1690const char *EVP_PKEY_get0_type_name(const EVP_PKEY *key);
1691
1692# define EVP_PKEY_OP_UNDEFINED 0
1693# define EVP_PKEY_OP_PARAMGEN (1<<1)
1694# define EVP_PKEY_OP_KEYGEN (1<<2)
1695# define EVP_PKEY_OP_FROMDATA (1<<3)
1696# define EVP_PKEY_OP_SIGN (1<<4)
1697# define EVP_PKEY_OP_VERIFY (1<<5)
1698# define EVP_PKEY_OP_VERIFYRECOVER (1<<6)
1699# define EVP_PKEY_OP_SIGNCTX (1<<7)
1700# define EVP_PKEY_OP_VERIFYCTX (1<<8)
1701# define EVP_PKEY_OP_ENCRYPT (1<<9)
1702# define EVP_PKEY_OP_DECRYPT (1<<10)
1703# define EVP_PKEY_OP_DERIVE (1<<11)
1704# define EVP_PKEY_OP_ENCAPSULATE (1<<12)
1705# define EVP_PKEY_OP_DECAPSULATE (1<<13)
1706
1707# define EVP_PKEY_OP_TYPE_SIG \
1708 (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY | EVP_PKEY_OP_VERIFYRECOVER \
1709 | EVP_PKEY_OP_SIGNCTX | EVP_PKEY_OP_VERIFYCTX)
1710
1711# define EVP_PKEY_OP_TYPE_CRYPT \
1712 (EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT)
1713
1714# define EVP_PKEY_OP_TYPE_NOGEN \
1715 (EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_DERIVE)
1716
1717# define EVP_PKEY_OP_TYPE_GEN \
1718 (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN)
1719
1720
1721int EVP_PKEY_CTX_set_mac_key(EVP_PKEY_CTX *ctx, const unsigned char *key,
1722 int keylen);
1723
1724# define EVP_PKEY_CTRL_MD 1
1725# define EVP_PKEY_CTRL_PEER_KEY 2
1726# define EVP_PKEY_CTRL_SET_MAC_KEY 6
1727# define EVP_PKEY_CTRL_DIGESTINIT 7
1728/* Used by GOST key encryption in TLS */
1729# define EVP_PKEY_CTRL_SET_IV 8
1730# ifndef OPENSSL_NO_DEPRECATED_3_0
1731# define EVP_PKEY_CTRL_PKCS7_ENCRYPT 3
1732# define EVP_PKEY_CTRL_PKCS7_DECRYPT 4
1733# define EVP_PKEY_CTRL_PKCS7_SIGN 5
1734# define EVP_PKEY_CTRL_CMS_ENCRYPT 9
1735# define EVP_PKEY_CTRL_CMS_DECRYPT 10
1736# define EVP_PKEY_CTRL_CMS_SIGN 11
1737# endif
1738# define EVP_PKEY_CTRL_CIPHER 12
1739# define EVP_PKEY_CTRL_GET_MD 13
1740# define EVP_PKEY_CTRL_SET_DIGEST_SIZE 14
1741# define EVP_PKEY_CTRL_SET1_ID 15
1742# define EVP_PKEY_CTRL_GET1_ID 16
1743# define EVP_PKEY_CTRL_GET1_ID_LEN 17
1744
1745# define EVP_PKEY_ALG_CTRL 0x1000
1746
1747# define EVP_PKEY_FLAG_AUTOARGLEN 2
1748/*
1749 * Method handles all operations: don't assume any digest related defaults.
1750 */
1751# define EVP_PKEY_FLAG_SIGCTX_CUSTOM 4
1752# ifndef OPENSSL_NO_DEPRECATED_3_0
1753OSSL_DEPRECATEDIN_3_0 const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type);
1754OSSL_DEPRECATEDIN_3_0 EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags);
1755OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags,
1756 const EVP_PKEY_METHOD *meth);
1757OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst,
1758 const EVP_PKEY_METHOD *src);
1759OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth);
1760OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth);
1761OSSL_DEPRECATEDIN_3_0 int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD *pmeth);
1762OSSL_DEPRECATEDIN_3_0 size_t EVP_PKEY_meth_get_count(void);
1763OSSL_DEPRECATEDIN_3_0 const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx);
1764# endif
1765
1766EVP_KEYMGMT *EVP_KEYMGMT_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
1767 const char *properties);
1768int EVP_KEYMGMT_up_ref(EVP_KEYMGMT *keymgmt);
1769void EVP_KEYMGMT_free(EVP_KEYMGMT *keymgmt);
1770const OSSL_PROVIDER *EVP_KEYMGMT_get0_provider(const EVP_KEYMGMT *keymgmt);
1771const char *EVP_KEYMGMT_get0_name(const EVP_KEYMGMT *keymgmt);
1772const char *EVP_KEYMGMT_get0_description(const EVP_KEYMGMT *keymgmt);
1773int EVP_KEYMGMT_is_a(const EVP_KEYMGMT *keymgmt, const char *name);
1774void EVP_KEYMGMT_do_all_provided(OSSL_LIB_CTX *libctx,
1775 void (*fn)(EVP_KEYMGMT *keymgmt, void *arg),
1776 void *arg);
1777int EVP_KEYMGMT_names_do_all(const EVP_KEYMGMT *keymgmt,
1778 void (*fn)(const char *name, void *data),
1779 void *data);
1780const OSSL_PARAM *EVP_KEYMGMT_gettable_params(const EVP_KEYMGMT *keymgmt);
1781const OSSL_PARAM *EVP_KEYMGMT_settable_params(const EVP_KEYMGMT *keymgmt);
1782const OSSL_PARAM *EVP_KEYMGMT_gen_settable_params(const EVP_KEYMGMT *keymgmt);
1783
1784EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e);
1785EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e);
1786EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_name(OSSL_LIB_CTX *libctx,
1787 const char *name,
1788 const char *propquery);
1789EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_pkey(OSSL_LIB_CTX *libctx,
1790 EVP_PKEY *pkey, const char *propquery);
1791EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *ctx);
1792void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
1793int EVP_PKEY_CTX_is_a(EVP_PKEY_CTX *ctx, const char *keytype);
1794
1795int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params);
1796const OSSL_PARAM *EVP_PKEY_CTX_gettable_params(const EVP_PKEY_CTX *ctx);
1797int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX *ctx, const OSSL_PARAM *params);
1798const OSSL_PARAM *EVP_PKEY_CTX_settable_params(const EVP_PKEY_CTX *ctx);
1799int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
1800 int cmd, int p1, void *p2);
1801int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
1802 const char *value);
1803int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype,
1804 int cmd, uint64_t value);
1805
1806int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str);
1807int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex);
1808
1809int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md);
1810
1811int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx);
1812void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen);
1813
1814EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e,
1815 const unsigned char *key, int keylen);
1816EVP_PKEY *EVP_PKEY_new_raw_private_key_ex(OSSL_LIB_CTX *libctx,
1817 const char *keytype,
1818 const char *propq,
1819 const unsigned char *priv, size_t len);
1820EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e,
1821 const unsigned char *priv,
1822 size_t len);
1823EVP_PKEY *EVP_PKEY_new_raw_public_key_ex(OSSL_LIB_CTX *libctx,
1824 const char *keytype, const char *propq,
1825 const unsigned char *pub, size_t len);
1826EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e,
1827 const unsigned char *pub,
1828 size_t len);
1829int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv,
1830 size_t *len);
1831int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub,
1832 size_t *len);
1833
1834# ifndef OPENSSL_NO_DEPRECATED_3_0
1835OSSL_DEPRECATEDIN_3_0
1836EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
1837 size_t len, const EVP_CIPHER *cipher);
1838# endif
1839
1840void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data);
1841void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX *ctx);
1842EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx);
1843
1844EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx);
1845
1846void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data);
1847void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx);
1848
1849void EVP_SIGNATURE_free(EVP_SIGNATURE *signature);
1850int EVP_SIGNATURE_up_ref(EVP_SIGNATURE *signature);
1851OSSL_PROVIDER *EVP_SIGNATURE_get0_provider(const EVP_SIGNATURE *signature);
1852EVP_SIGNATURE *EVP_SIGNATURE_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
1853 const char *properties);
1854int EVP_SIGNATURE_is_a(const EVP_SIGNATURE *signature, const char *name);
1855const char *EVP_SIGNATURE_get0_name(const EVP_SIGNATURE *signature);
1856const char *EVP_SIGNATURE_get0_description(const EVP_SIGNATURE *signature);
1857void EVP_SIGNATURE_do_all_provided(OSSL_LIB_CTX *libctx,
1858 void (*fn)(EVP_SIGNATURE *signature,
1859 void *data),
1860 void *data);
1861int EVP_SIGNATURE_names_do_all(const EVP_SIGNATURE *signature,
1862 void (*fn)(const char *name, void *data),
1863 void *data);
1864const OSSL_PARAM *EVP_SIGNATURE_gettable_ctx_params(const EVP_SIGNATURE *sig);
1865const OSSL_PARAM *EVP_SIGNATURE_settable_ctx_params(const EVP_SIGNATURE *sig);
1866
1867void EVP_ASYM_CIPHER_free(EVP_ASYM_CIPHER *cipher);
1868int EVP_ASYM_CIPHER_up_ref(EVP_ASYM_CIPHER *cipher);
1869OSSL_PROVIDER *EVP_ASYM_CIPHER_get0_provider(const EVP_ASYM_CIPHER *cipher);
1870EVP_ASYM_CIPHER *EVP_ASYM_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
1871 const char *properties);
1872int EVP_ASYM_CIPHER_is_a(const EVP_ASYM_CIPHER *cipher, const char *name);
1873const char *EVP_ASYM_CIPHER_get0_name(const EVP_ASYM_CIPHER *cipher);
1874const char *EVP_ASYM_CIPHER_get0_description(const EVP_ASYM_CIPHER *cipher);
1875void EVP_ASYM_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx,
1876 void (*fn)(EVP_ASYM_CIPHER *cipher,
1877 void *arg),
1878 void *arg);
1879int EVP_ASYM_CIPHER_names_do_all(const EVP_ASYM_CIPHER *cipher,
1880 void (*fn)(const char *name, void *data),
1881 void *data);
1882const OSSL_PARAM *EVP_ASYM_CIPHER_gettable_ctx_params(const EVP_ASYM_CIPHER *ciph);
1883const OSSL_PARAM *EVP_ASYM_CIPHER_settable_ctx_params(const EVP_ASYM_CIPHER *ciph);
1884
1885void EVP_KEM_free(EVP_KEM *wrap);
1886int EVP_KEM_up_ref(EVP_KEM *wrap);
1887OSSL_PROVIDER *EVP_KEM_get0_provider(const EVP_KEM *wrap);
1888EVP_KEM *EVP_KEM_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
1889 const char *properties);
1890int EVP_KEM_is_a(const EVP_KEM *wrap, const char *name);
1891const char *EVP_KEM_get0_name(const EVP_KEM *wrap);
1892const char *EVP_KEM_get0_description(const EVP_KEM *wrap);
1893void EVP_KEM_do_all_provided(OSSL_LIB_CTX *libctx,
1894 void (*fn)(EVP_KEM *wrap, void *arg), void *arg);
1895int EVP_KEM_names_do_all(const EVP_KEM *wrap,
1896 void (*fn)(const char *name, void *data), void *data);
1897const OSSL_PARAM *EVP_KEM_gettable_ctx_params(const EVP_KEM *kem);
1898const OSSL_PARAM *EVP_KEM_settable_ctx_params(const EVP_KEM *kem);
1899
1900int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
1901int EVP_PKEY_sign_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
1902int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
1903 unsigned char *sig, size_t *siglen,
1904 const unsigned char *tbs, size_t tbslen);
1905int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx);
1906int EVP_PKEY_verify_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
1907int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
1908 const unsigned char *sig, size_t siglen,
1909 const unsigned char *tbs, size_t tbslen);
1910int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx);
1911int EVP_PKEY_verify_recover_init_ex(EVP_PKEY_CTX *ctx,
1912 const OSSL_PARAM params[]);
1913int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx,
1914 unsigned char *rout, size_t *routlen,
1915 const unsigned char *sig, size_t siglen);
1916int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx);
1917int EVP_PKEY_encrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
1918int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
1919 unsigned char *out, size_t *outlen,
1920 const unsigned char *in, size_t inlen);
1921int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx);
1922int EVP_PKEY_decrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
1923int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
1924 unsigned char *out, size_t *outlen,
1925 const unsigned char *in, size_t inlen);
1926
1927int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx);
1928int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
1929int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer,
1930 int validate_peer);
1931int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer);
1932int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
1933
1934int EVP_PKEY_encapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
1935int EVP_PKEY_auth_encapsulate_init(EVP_PKEY_CTX *ctx, EVP_PKEY *authpriv,
1936 const OSSL_PARAM params[]);
1937int EVP_PKEY_encapsulate(EVP_PKEY_CTX *ctx,
1938 unsigned char *wrappedkey, size_t *wrappedkeylen,
1939 unsigned char *genkey, size_t *genkeylen);
1940int EVP_PKEY_decapsulate_init(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
1941int EVP_PKEY_auth_decapsulate_init(EVP_PKEY_CTX *ctx, EVP_PKEY *authpub,
1942 const OSSL_PARAM params[]);
1943int EVP_PKEY_decapsulate(EVP_PKEY_CTX *ctx,
1944 unsigned char *unwrapped, size_t *unwrappedlen,
1945 const unsigned char *wrapped, size_t wrappedlen);
1946typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx);
1947
1948int EVP_PKEY_fromdata_init(EVP_PKEY_CTX *ctx);
1949int EVP_PKEY_fromdata(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, int selection,
1950 OSSL_PARAM param[]);
1951const OSSL_PARAM *EVP_PKEY_fromdata_settable(EVP_PKEY_CTX *ctx, int selection);
1952
1953int EVP_PKEY_todata(const EVP_PKEY *pkey, int selection, OSSL_PARAM **params);
1954int EVP_PKEY_export(const EVP_PKEY *pkey, int selection,
1955 OSSL_CALLBACK *export_cb, void *export_cbarg);
1956
1957const OSSL_PARAM *EVP_PKEY_gettable_params(const EVP_PKEY *pkey);
1958int EVP_PKEY_get_params(const EVP_PKEY *pkey, OSSL_PARAM params[]);
1959int EVP_PKEY_get_int_param(const EVP_PKEY *pkey, const char *key_name,
1960 int *out);
1961int EVP_PKEY_get_size_t_param(const EVP_PKEY *pkey, const char *key_name,
1962 size_t *out);
1963int EVP_PKEY_get_bn_param(const EVP_PKEY *pkey, const char *key_name,
1964 BIGNUM **bn);
1965int EVP_PKEY_get_utf8_string_param(const EVP_PKEY *pkey, const char *key_name,
1966 char *str, size_t max_buf_sz, size_t *out_sz);
1967int EVP_PKEY_get_octet_string_param(const EVP_PKEY *pkey, const char *key_name,
1968 unsigned char *buf, size_t max_buf_sz,
1969 size_t *out_sz);
1970
1971const OSSL_PARAM *EVP_PKEY_settable_params(const EVP_PKEY *pkey);
1972int EVP_PKEY_set_params(EVP_PKEY *pkey, OSSL_PARAM params[]);
1973int EVP_PKEY_set_int_param(EVP_PKEY *pkey, const char *key_name, int in);
1974int EVP_PKEY_set_size_t_param(EVP_PKEY *pkey, const char *key_name, size_t in);
1975int EVP_PKEY_set_bn_param(EVP_PKEY *pkey, const char *key_name,
1976 const BIGNUM *bn);
1977int EVP_PKEY_set_utf8_string_param(EVP_PKEY *pkey, const char *key_name,
1978 const char *str);
1979int EVP_PKEY_set_octet_string_param(EVP_PKEY *pkey, const char *key_name,
1980 const unsigned char *buf, size_t bsize);
1981
1982int EVP_PKEY_get_ec_point_conv_form(const EVP_PKEY *pkey);
1983int EVP_PKEY_get_field_type(const EVP_PKEY *pkey);
1984
1985EVP_PKEY *EVP_PKEY_Q_keygen(OSSL_LIB_CTX *libctx, const char *propq,
1986 const char *type, ...);
1987int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx);
1988int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey);
1989int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx);
1990int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey);
1991int EVP_PKEY_generate(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey);
1992int EVP_PKEY_check(EVP_PKEY_CTX *ctx);
1993int EVP_PKEY_public_check(EVP_PKEY_CTX *ctx);
1994int EVP_PKEY_public_check_quick(EVP_PKEY_CTX *ctx);
1995int EVP_PKEY_param_check(EVP_PKEY_CTX *ctx);
1996int EVP_PKEY_param_check_quick(EVP_PKEY_CTX *ctx);
1997int EVP_PKEY_private_check(EVP_PKEY_CTX *ctx);
1998int EVP_PKEY_pairwise_check(EVP_PKEY_CTX *ctx);
1999
2000# define EVP_PKEY_get_ex_new_index(l, p, newf, dupf, freef) \
2001 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EVP_PKEY, l, p, newf, dupf, freef)
2002int EVP_PKEY_set_ex_data(EVP_PKEY *key, int idx, void *arg);
2003void *EVP_PKEY_get_ex_data(const EVP_PKEY *key, int idx);
2004
2005void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb);
2006EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx);
2007
2008int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx);
2009# ifndef OPENSSL_NO_DEPRECATED_3_0
2010OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
2011 int (*init) (EVP_PKEY_CTX *ctx));
2012OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_copy
2013 (EVP_PKEY_METHOD *pmeth, int (*copy) (EVP_PKEY_CTX *dst,
2014 const EVP_PKEY_CTX *src));
2015OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_cleanup
2016 (EVP_PKEY_METHOD *pmeth, void (*cleanup) (EVP_PKEY_CTX *ctx));
2017OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_paramgen
2018 (EVP_PKEY_METHOD *pmeth, int (*paramgen_init) (EVP_PKEY_CTX *ctx),
2019 int (*paramgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey));
2020OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_keygen
2021 (EVP_PKEY_METHOD *pmeth, int (*keygen_init) (EVP_PKEY_CTX *ctx),
2022 int (*keygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey));
2023OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_sign
2024 (EVP_PKEY_METHOD *pmeth, int (*sign_init) (EVP_PKEY_CTX *ctx),
2025 int (*sign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
2026 const unsigned char *tbs, size_t tbslen));
2027OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_verify
2028 (EVP_PKEY_METHOD *pmeth, int (*verify_init) (EVP_PKEY_CTX *ctx),
2029 int (*verify) (EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen,
2030 const unsigned char *tbs, size_t tbslen));
2031OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_verify_recover
2032 (EVP_PKEY_METHOD *pmeth, int (*verify_recover_init) (EVP_PKEY_CTX *ctx),
2033 int (*verify_recover) (EVP_PKEY_CTX *ctx, unsigned char *sig,
2034 size_t *siglen, const unsigned char *tbs,
2035 size_t tbslen));
2036OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_signctx
2037 (EVP_PKEY_METHOD *pmeth, int (*signctx_init) (EVP_PKEY_CTX *ctx,
2038 EVP_MD_CTX *mctx),
2039 int (*signctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
2040 EVP_MD_CTX *mctx));
2041OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_verifyctx
2042 (EVP_PKEY_METHOD *pmeth, int (*verifyctx_init) (EVP_PKEY_CTX *ctx,
2043 EVP_MD_CTX *mctx),
2044 int (*verifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen,
2045 EVP_MD_CTX *mctx));
2046OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_encrypt
2047 (EVP_PKEY_METHOD *pmeth, int (*encrypt_init) (EVP_PKEY_CTX *ctx),
2048 int (*encryptfn) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
2049 const unsigned char *in, size_t inlen));
2050OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_decrypt
2051 (EVP_PKEY_METHOD *pmeth, int (*decrypt_init) (EVP_PKEY_CTX *ctx),
2052 int (*decrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
2053 const unsigned char *in, size_t inlen));
2054OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_derive
2055 (EVP_PKEY_METHOD *pmeth, int (*derive_init) (EVP_PKEY_CTX *ctx),
2056 int (*derive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen));
2057OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_ctrl
2058 (EVP_PKEY_METHOD *pmeth, int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
2059 void *p2),
2060 int (*ctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value));
2061OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_digestsign
2062 (EVP_PKEY_METHOD *pmeth,
2063 int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
2064 const unsigned char *tbs, size_t tbslen));
2065OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_digestverify
2066 (EVP_PKEY_METHOD *pmeth,
2067 int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
2068 size_t siglen, const unsigned char *tbs,
2069 size_t tbslen));
2070OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_check
2071 (EVP_PKEY_METHOD *pmeth, int (*check) (EVP_PKEY *pkey));
2072OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_public_check
2073 (EVP_PKEY_METHOD *pmeth, int (*check) (EVP_PKEY *pkey));
2074OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_param_check
2075 (EVP_PKEY_METHOD *pmeth, int (*check) (EVP_PKEY *pkey));
2076OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_set_digest_custom
2077 (EVP_PKEY_METHOD *pmeth, int (*digest_custom) (EVP_PKEY_CTX *ctx,
2078 EVP_MD_CTX *mctx));
2079OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_init
2080 (const EVP_PKEY_METHOD *pmeth, int (**pinit) (EVP_PKEY_CTX *ctx));
2081OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_copy
2082 (const EVP_PKEY_METHOD *pmeth, int (**pcopy) (EVP_PKEY_CTX *dst,
2083 const EVP_PKEY_CTX *src));
2084OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_cleanup
2085 (const EVP_PKEY_METHOD *pmeth, void (**pcleanup) (EVP_PKEY_CTX *ctx));
2086OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_paramgen
2087 (const EVP_PKEY_METHOD *pmeth, int (**pparamgen_init) (EVP_PKEY_CTX *ctx),
2088 int (**pparamgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey));
2089OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_keygen
2090 (const EVP_PKEY_METHOD *pmeth, int (**pkeygen_init) (EVP_PKEY_CTX *ctx),
2091 int (**pkeygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey));
2092OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_sign
2093 (const EVP_PKEY_METHOD *pmeth, int (**psign_init) (EVP_PKEY_CTX *ctx),
2094 int (**psign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
2095 const unsigned char *tbs, size_t tbslen));
2096OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_verify
2097 (const EVP_PKEY_METHOD *pmeth, int (**pverify_init) (EVP_PKEY_CTX *ctx),
2098 int (**pverify) (EVP_PKEY_CTX *ctx, const unsigned char *sig,
2099 size_t siglen, const unsigned char *tbs, size_t tbslen));
2100OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_verify_recover
2101 (const EVP_PKEY_METHOD *pmeth,
2102 int (**pverify_recover_init) (EVP_PKEY_CTX *ctx),
2103 int (**pverify_recover) (EVP_PKEY_CTX *ctx, unsigned char *sig,
2104 size_t *siglen, const unsigned char *tbs,
2105 size_t tbslen));
2106OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_signctx
2107 (const EVP_PKEY_METHOD *pmeth,
2108 int (**psignctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
2109 int (**psignctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
2110 EVP_MD_CTX *mctx));
2111OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_verifyctx
2112 (const EVP_PKEY_METHOD *pmeth,
2113 int (**pverifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx),
2114 int (**pverifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig,
2115 int siglen, EVP_MD_CTX *mctx));
2116OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_encrypt
2117 (const EVP_PKEY_METHOD *pmeth, int (**pencrypt_init) (EVP_PKEY_CTX *ctx),
2118 int (**pencryptfn) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
2119 const unsigned char *in, size_t inlen));
2120OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_decrypt
2121 (const EVP_PKEY_METHOD *pmeth, int (**pdecrypt_init) (EVP_PKEY_CTX *ctx),
2122 int (**pdecrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
2123 const unsigned char *in, size_t inlen));
2124OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_derive
2125 (const EVP_PKEY_METHOD *pmeth, int (**pderive_init) (EVP_PKEY_CTX *ctx),
2126 int (**pderive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen));
2127OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_ctrl
2128 (const EVP_PKEY_METHOD *pmeth,
2129 int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2),
2130 int (**pctrl_str) (EVP_PKEY_CTX *ctx, const char *type,
2131 const char *value));
2132OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_digestsign
2133 (const EVP_PKEY_METHOD *pmeth,
2134 int (**digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
2135 const unsigned char *tbs, size_t tbslen));
2136OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_digestverify
2137 (const EVP_PKEY_METHOD *pmeth,
2138 int (**digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
2139 size_t siglen, const unsigned char *tbs,
2140 size_t tbslen));
2141OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_check
2142 (const EVP_PKEY_METHOD *pmeth, int (**pcheck) (EVP_PKEY *pkey));
2143OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_public_check
2144 (const EVP_PKEY_METHOD *pmeth, int (**pcheck) (EVP_PKEY *pkey));
2145OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_param_check
2146 (const EVP_PKEY_METHOD *pmeth, int (**pcheck) (EVP_PKEY *pkey));
2147OSSL_DEPRECATEDIN_3_0 void EVP_PKEY_meth_get_digest_custom
2148 (const EVP_PKEY_METHOD *pmeth,
2149 int (**pdigest_custom) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx));
2150# endif
2151
2152void EVP_KEYEXCH_free(EVP_KEYEXCH *exchange);
2153int EVP_KEYEXCH_up_ref(EVP_KEYEXCH *exchange);
2154EVP_KEYEXCH *EVP_KEYEXCH_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
2155 const char *properties);
2156OSSL_PROVIDER *EVP_KEYEXCH_get0_provider(const EVP_KEYEXCH *exchange);
2157int EVP_KEYEXCH_is_a(const EVP_KEYEXCH *keyexch, const char *name);
2158const char *EVP_KEYEXCH_get0_name(const EVP_KEYEXCH *keyexch);
2159const char *EVP_KEYEXCH_get0_description(const EVP_KEYEXCH *keyexch);
2160void EVP_KEYEXCH_do_all_provided(OSSL_LIB_CTX *libctx,
2161 void (*fn)(EVP_KEYEXCH *keyexch, void *data),
2162 void *data);
2163int EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *keyexch,
2164 void (*fn)(const char *name, void *data),
2165 void *data);
2166const OSSL_PARAM *EVP_KEYEXCH_gettable_ctx_params(const EVP_KEYEXCH *keyexch);
2167const OSSL_PARAM *EVP_KEYEXCH_settable_ctx_params(const EVP_KEYEXCH *keyexch);
2168
2169void EVP_add_alg_module(void);
2170
2171int EVP_PKEY_CTX_set_group_name(EVP_PKEY_CTX *ctx, const char *name);
2172int EVP_PKEY_CTX_get_group_name(EVP_PKEY_CTX *ctx, char *name, size_t namelen);
2173int EVP_PKEY_get_group_name(const EVP_PKEY *pkey, char *name, size_t name_sz,
2174 size_t *gname_len);
2175
2176OSSL_LIB_CTX *EVP_PKEY_CTX_get0_libctx(EVP_PKEY_CTX *ctx);
2177const char *EVP_PKEY_CTX_get0_propq(const EVP_PKEY_CTX *ctx);
2178const OSSL_PROVIDER *EVP_PKEY_CTX_get0_provider(const EVP_PKEY_CTX *ctx);
2179
2180# ifdef __cplusplus
2181}
2182# endif
2183#endif
2184