dd02077e05af861073a2d63e7e158879102c61d5
[openssl.git] / include / openssl / evp.h
1 /*
2  * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (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 HEADER_ENVELOPE_H
11 # define HEADER_ENVELOPE_H
12
13 # include <openssl/opensslconf.h>
14 # include <openssl/ossl_typ.h>
15 # include <openssl/symhacks.h>
16 # include <openssl/bio.h>
17 # include <openssl/evperr.h>
18
19 # define EVP_MAX_MD_SIZE                 64/* longest known is SHA512 */
20 # define EVP_MAX_KEY_LENGTH              64
21 # define EVP_MAX_IV_LENGTH               16
22 # define EVP_MAX_BLOCK_LENGTH            32
23
24 # define PKCS5_SALT_LEN                  8
25 /* Default PKCS#5 iteration count */
26 # define PKCS5_DEFAULT_ITER              2048
27
28 # include <openssl/objects.h>
29
30 # define EVP_PK_RSA      0x0001
31 # define EVP_PK_DSA      0x0002
32 # define EVP_PK_DH       0x0004
33 # define EVP_PK_EC       0x0008
34 # define EVP_PKT_SIGN    0x0010
35 # define EVP_PKT_ENC     0x0020
36 # define EVP_PKT_EXCH    0x0040
37 # define EVP_PKS_RSA     0x0100
38 # define EVP_PKS_DSA     0x0200
39 # define EVP_PKS_EC      0x0400
40
41 # define EVP_PKEY_NONE   NID_undef
42 # define EVP_PKEY_RSA    NID_rsaEncryption
43 # define EVP_PKEY_RSA2   NID_rsa
44 # define EVP_PKEY_RSA_PSS NID_rsassaPss
45 # define EVP_PKEY_DSA    NID_dsa
46 # define EVP_PKEY_DSA1   NID_dsa_2
47 # define EVP_PKEY_DSA2   NID_dsaWithSHA
48 # define EVP_PKEY_DSA3   NID_dsaWithSHA1
49 # define EVP_PKEY_DSA4   NID_dsaWithSHA1_2
50 # define EVP_PKEY_DH     NID_dhKeyAgreement
51 # define EVP_PKEY_DHX    NID_dhpublicnumber
52 # define EVP_PKEY_EC     NID_X9_62_id_ecPublicKey
53 # define EVP_PKEY_HMAC   NID_hmac
54 # define EVP_PKEY_CMAC   NID_cmac
55 # define EVP_PKEY_SCRYPT NID_id_scrypt
56 # define EVP_PKEY_TLS1_PRF NID_tls1_prf
57 # define EVP_PKEY_HKDF   NID_hkdf
58 # define EVP_PKEY_POLY1305 NID_poly1305
59 # define EVP_PKEY_SIPHASH NID_siphash
60 # define EVP_PKEY_X25519 NID_X25519
61 # define EVP_PKEY_ED25519 NID_ED25519
62
63 #ifdef  __cplusplus
64 extern "C" {
65 #endif
66
67 # define EVP_PKEY_MO_SIGN        0x0001
68 # define EVP_PKEY_MO_VERIFY      0x0002
69 # define EVP_PKEY_MO_ENCRYPT     0x0004
70 # define EVP_PKEY_MO_DECRYPT     0x0008
71
72 # ifndef EVP_MD
73 EVP_MD *EVP_MD_meth_new(int md_type, int pkey_type);
74 EVP_MD *EVP_MD_meth_dup(const EVP_MD *md);
75 void EVP_MD_meth_free(EVP_MD *md);
76
77 int EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize);
78 int EVP_MD_meth_set_result_size(EVP_MD *md, int resultsize);
79 int EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize);
80 int EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags);
81 int EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx));
82 int EVP_MD_meth_set_update(EVP_MD *md, int (*update)(EVP_MD_CTX *ctx,
83                                                      const void *data,
84                                                      size_t count));
85 int EVP_MD_meth_set_final(EVP_MD *md, int (*final)(EVP_MD_CTX *ctx,
86                                                    unsigned char *md));
87 int EVP_MD_meth_set_copy(EVP_MD *md, int (*copy)(EVP_MD_CTX *to,
88                                                  const EVP_MD_CTX *from));
89 int EVP_MD_meth_set_cleanup(EVP_MD *md, int (*cleanup)(EVP_MD_CTX *ctx));
90 int EVP_MD_meth_set_ctrl(EVP_MD *md, int (*ctrl)(EVP_MD_CTX *ctx, int cmd,
91                                                  int p1, void *p2));
92
93 int EVP_MD_meth_get_input_blocksize(const EVP_MD *md);
94 int EVP_MD_meth_get_result_size(const EVP_MD *md);
95 int EVP_MD_meth_get_app_datasize(const EVP_MD *md);
96 unsigned long EVP_MD_meth_get_flags(const EVP_MD *md);
97 int (*EVP_MD_meth_get_init(const EVP_MD *md))(EVP_MD_CTX *ctx);
98 int (*EVP_MD_meth_get_update(const EVP_MD *md))(EVP_MD_CTX *ctx,
99                                                 const void *data,
100                                                 size_t count);
101 int (*EVP_MD_meth_get_final(const EVP_MD *md))(EVP_MD_CTX *ctx,
102                                                unsigned char *md);
103 int (*EVP_MD_meth_get_copy(const EVP_MD *md))(EVP_MD_CTX *to,
104                                               const EVP_MD_CTX *from);
105 int (*EVP_MD_meth_get_cleanup(const EVP_MD *md))(EVP_MD_CTX *ctx);
106 int (*EVP_MD_meth_get_ctrl(const EVP_MD *md))(EVP_MD_CTX *ctx, int cmd,
107                                               int p1, void *p2);
108
109 /* digest can only handle a single block */
110 #  define EVP_MD_FLAG_ONESHOT     0x0001
111
112 /* DigestAlgorithmIdentifier flags... */
113
114 #  define EVP_MD_FLAG_DIGALGID_MASK               0x0018
115
116 /* NULL or absent parameter accepted. Use NULL */
117
118 #  define EVP_MD_FLAG_DIGALGID_NULL               0x0000
119
120 /* NULL or absent parameter accepted. Use NULL for PKCS#1 otherwise absent */
121
122 #  define EVP_MD_FLAG_DIGALGID_ABSENT             0x0008
123
124 /* Custom handling via ctrl */
125
126 #  define EVP_MD_FLAG_DIGALGID_CUSTOM             0x0018
127
128 /* Note if suitable for use in FIPS mode */
129 #  define EVP_MD_FLAG_FIPS        0x0400
130
131 /* Digest ctrls */
132
133 #  define EVP_MD_CTRL_DIGALGID                    0x1
134 #  define EVP_MD_CTRL_MICALG                      0x2
135
136 /* Minimum Algorithm specific ctrl value */
137
138 #  define EVP_MD_CTRL_ALG_CTRL                    0x1000
139
140 # endif                         /* !EVP_MD */
141
142 /* values for EVP_MD_CTX flags */
143
144 # define EVP_MD_CTX_FLAG_ONESHOT         0x0001/* digest update will be
145                                                 * called once only */
146 # define EVP_MD_CTX_FLAG_CLEANED         0x0002/* context has already been
147                                                 * cleaned */
148 # define EVP_MD_CTX_FLAG_REUSE           0x0004/* Don't free up ctx->md_data
149                                                 * in EVP_MD_CTX_reset */
150 /*
151  * FIPS and pad options are ignored in 1.0.0, definitions are here so we
152  * don't accidentally reuse the values for other purposes.
153  */
154
155 # define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW  0x0008/* Allow use of non FIPS
156                                                 * digest in FIPS mode */
157
158 /*
159  * The following PAD options are also currently ignored in 1.0.0, digest
160  * parameters are handled through EVP_DigestSign*() and EVP_DigestVerify*()
161  * instead.
162  */
163 # define EVP_MD_CTX_FLAG_PAD_MASK        0xF0/* RSA mode to use */
164 # define EVP_MD_CTX_FLAG_PAD_PKCS1       0x00/* PKCS#1 v1.5 mode */
165 # define EVP_MD_CTX_FLAG_PAD_X931        0x10/* X9.31 mode */
166 # define EVP_MD_CTX_FLAG_PAD_PSS         0x20/* PSS mode */
167
168 # define EVP_MD_CTX_FLAG_NO_INIT         0x0100/* Don't initialize md_data */
169 /*
170  * Some functions such as EVP_DigestSign only finalise copies of internal
171  * contexts so additional data can be included after the finalisation call.
172  * This is inefficient if this functionality is not required: it is disabled
173  * if the following flag is set.
174  */
175 # define EVP_MD_CTX_FLAG_FINALISE        0x0200
176
177 EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len);
178 EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher);
179 void EVP_CIPHER_meth_free(EVP_CIPHER *cipher);
180
181 int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len);
182 int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags);
183 int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size);
184 int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher,
185                              int (*init) (EVP_CIPHER_CTX *ctx,
186                                           const unsigned char *key,
187                                           const unsigned char *iv,
188                                           int enc));
189 int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher,
190                                   int (*do_cipher) (EVP_CIPHER_CTX *ctx,
191                                                     unsigned char *out,
192                                                     const unsigned char *in,
193                                                     size_t inl));
194 int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher,
195                                 int (*cleanup) (EVP_CIPHER_CTX *));
196 int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher,
197                                         int (*set_asn1_parameters) (EVP_CIPHER_CTX *,
198                                                                     ASN1_TYPE *));
199 int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher,
200                                         int (*get_asn1_parameters) (EVP_CIPHER_CTX *,
201                                                                     ASN1_TYPE *));
202 int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher,
203                              int (*ctrl) (EVP_CIPHER_CTX *, int type,
204                                           int arg, void *ptr));
205
206 int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
207                                                           const unsigned char *key,
208                                                           const unsigned char *iv,
209                                                           int enc);
210 int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx,
211                                                                unsigned char *out,
212                                                                const unsigned char *in,
213                                                                size_t inl);
214 int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *);
215 int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
216                                                                      ASN1_TYPE *);
217 int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
218                                                                ASN1_TYPE *);
219 int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *,
220                                                           int type, int arg,
221                                                           void *ptr);
222
223 /* Values for cipher flags */
224
225 /* Modes for ciphers */
226
227 # define         EVP_CIPH_STREAM_CIPHER          0x0
228 # define         EVP_CIPH_ECB_MODE               0x1
229 # define         EVP_CIPH_CBC_MODE               0x2
230 # define         EVP_CIPH_CFB_MODE               0x3
231 # define         EVP_CIPH_OFB_MODE               0x4
232 # define         EVP_CIPH_CTR_MODE               0x5
233 # define         EVP_CIPH_GCM_MODE               0x6
234 # define         EVP_CIPH_CCM_MODE               0x7
235 # define         EVP_CIPH_XTS_MODE               0x10001
236 # define         EVP_CIPH_WRAP_MODE              0x10002
237 # define         EVP_CIPH_OCB_MODE               0x10003
238 # define         EVP_CIPH_MODE                   0xF0007
239 /* Set if variable length cipher */
240 # define         EVP_CIPH_VARIABLE_LENGTH        0x8
241 /* Set if the iv handling should be done by the cipher itself */
242 # define         EVP_CIPH_CUSTOM_IV              0x10
243 /* Set if the cipher's init() function should be called if key is NULL */
244 # define         EVP_CIPH_ALWAYS_CALL_INIT       0x20
245 /* Call ctrl() to init cipher parameters */
246 # define         EVP_CIPH_CTRL_INIT              0x40
247 /* Don't use standard key length function */
248 # define         EVP_CIPH_CUSTOM_KEY_LENGTH      0x80
249 /* Don't use standard block padding */
250 # define         EVP_CIPH_NO_PADDING             0x100
251 /* cipher handles random key generation */
252 # define         EVP_CIPH_RAND_KEY               0x200
253 /* cipher has its own additional copying logic */
254 # define         EVP_CIPH_CUSTOM_COPY            0x400
255 /* Allow use default ASN1 get/set iv */
256 # define         EVP_CIPH_FLAG_DEFAULT_ASN1      0x1000
257 /* Buffer length in bits not bytes: CFB1 mode only */
258 # define         EVP_CIPH_FLAG_LENGTH_BITS       0x2000
259 /* Note if suitable for use in FIPS mode */
260 # define         EVP_CIPH_FLAG_FIPS              0x4000
261 /* Allow non FIPS cipher in FIPS mode */
262 # define         EVP_CIPH_FLAG_NON_FIPS_ALLOW    0x8000
263 /*
264  * Cipher handles any and all padding logic as well as finalisation.
265  */
266 # define         EVP_CIPH_FLAG_CUSTOM_CIPHER     0x100000
267 # define         EVP_CIPH_FLAG_AEAD_CIPHER       0x200000
268 # define         EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK 0x400000
269 /* Cipher can handle pipeline operations */
270 # define         EVP_CIPH_FLAG_PIPELINE          0X800000
271
272 /*
273  * Cipher context flag to indicate we can handle wrap mode: if allowed in
274  * older applications it could overflow buffers.
275  */
276
277 # define         EVP_CIPHER_CTX_FLAG_WRAP_ALLOW  0x1
278
279 /* ctrl() values */
280
281 # define         EVP_CTRL_INIT                   0x0
282 # define         EVP_CTRL_SET_KEY_LENGTH         0x1
283 # define         EVP_CTRL_GET_RC2_KEY_BITS       0x2
284 # define         EVP_CTRL_SET_RC2_KEY_BITS       0x3
285 # define         EVP_CTRL_GET_RC5_ROUNDS         0x4
286 # define         EVP_CTRL_SET_RC5_ROUNDS         0x5
287 # define         EVP_CTRL_RAND_KEY               0x6
288 # define         EVP_CTRL_PBE_PRF_NID            0x7
289 # define         EVP_CTRL_COPY                   0x8
290 # define         EVP_CTRL_AEAD_SET_IVLEN         0x9
291 # define         EVP_CTRL_AEAD_GET_TAG           0x10
292 # define         EVP_CTRL_AEAD_SET_TAG           0x11
293 # define         EVP_CTRL_AEAD_SET_IV_FIXED      0x12
294 # define         EVP_CTRL_GCM_SET_IVLEN          EVP_CTRL_AEAD_SET_IVLEN
295 # define         EVP_CTRL_GCM_GET_TAG            EVP_CTRL_AEAD_GET_TAG
296 # define         EVP_CTRL_GCM_SET_TAG            EVP_CTRL_AEAD_SET_TAG
297 # define         EVP_CTRL_GCM_SET_IV_FIXED       EVP_CTRL_AEAD_SET_IV_FIXED
298 # define         EVP_CTRL_GCM_IV_GEN             0x13
299 # define         EVP_CTRL_CCM_SET_IVLEN          EVP_CTRL_AEAD_SET_IVLEN
300 # define         EVP_CTRL_CCM_GET_TAG            EVP_CTRL_AEAD_GET_TAG
301 # define         EVP_CTRL_CCM_SET_TAG            EVP_CTRL_AEAD_SET_TAG
302 # define         EVP_CTRL_CCM_SET_IV_FIXED       EVP_CTRL_AEAD_SET_IV_FIXED
303 # define         EVP_CTRL_CCM_SET_L              0x14
304 # define         EVP_CTRL_CCM_SET_MSGLEN         0x15
305 /*
306  * AEAD cipher deduces payload length and returns number of bytes required to
307  * store MAC and eventual padding. Subsequent call to EVP_Cipher even
308  * appends/verifies MAC.
309  */
310 # define         EVP_CTRL_AEAD_TLS1_AAD          0x16
311 /* Used by composite AEAD ciphers, no-op in GCM, CCM... */
312 # define         EVP_CTRL_AEAD_SET_MAC_KEY       0x17
313 /* Set the GCM invocation field, decrypt only */
314 # define         EVP_CTRL_GCM_SET_IV_INV         0x18
315
316 # define         EVP_CTRL_TLS1_1_MULTIBLOCK_AAD  0x19
317 # define         EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT      0x1a
318 # define         EVP_CTRL_TLS1_1_MULTIBLOCK_DECRYPT      0x1b
319 # define         EVP_CTRL_TLS1_1_MULTIBLOCK_MAX_BUFSIZE  0x1c
320
321 # define         EVP_CTRL_SSL3_MASTER_SECRET             0x1d
322
323 /* EVP_CTRL_SET_SBOX takes the char * specifying S-boxes */
324 # define         EVP_CTRL_SET_SBOX                       0x1e
325 /*
326  * EVP_CTRL_SBOX_USED takes a 'size_t' and 'char *', pointing at a
327  * pre-allocated buffer with specified size
328  */
329 # define         EVP_CTRL_SBOX_USED                      0x1f
330 /* EVP_CTRL_KEY_MESH takes 'size_t' number of bytes to mesh the key after,
331  * 0 switches meshing off
332  */
333 # define         EVP_CTRL_KEY_MESH                       0x20
334 /* EVP_CTRL_BLOCK_PADDING_MODE takes the padding mode */
335 # define         EVP_CTRL_BLOCK_PADDING_MODE             0x21
336
337 /* Set the output buffers to use for a pipelined operation */
338 # define         EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS       0x22
339 /* Set the input buffers to use for a pipelined operation */
340 # define         EVP_CTRL_SET_PIPELINE_INPUT_BUFS        0x23
341 /* Set the input buffer lengths to use for a pipelined operation */
342 # define         EVP_CTRL_SET_PIPELINE_INPUT_LENS        0x24
343
344 /* Padding modes */
345 #define EVP_PADDING_PKCS7       1
346 #define EVP_PADDING_ISO7816_4   2
347 #define EVP_PADDING_ANSI923     3
348 #define EVP_PADDING_ISO10126    4
349 #define EVP_PADDING_ZERO        5
350
351 /* RFC 5246 defines additional data to be 13 bytes in length */
352 # define         EVP_AEAD_TLS1_AAD_LEN           13
353
354 typedef struct {
355     unsigned char *out;
356     const unsigned char *inp;
357     size_t len;
358     unsigned int interleave;
359 } EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM;
360
361 /* GCM TLS constants */
362 /* Length of fixed part of IV derived from PRF */
363 # define EVP_GCM_TLS_FIXED_IV_LEN                        4
364 /* Length of explicit part of IV part of TLS records */
365 # define EVP_GCM_TLS_EXPLICIT_IV_LEN                     8
366 /* Length of tag for TLS */
367 # define EVP_GCM_TLS_TAG_LEN                             16
368
369 /* CCM TLS constants */
370 /* Length of fixed part of IV derived from PRF */
371 # define EVP_CCM_TLS_FIXED_IV_LEN                        4
372 /* Length of explicit part of IV part of TLS records */
373 # define EVP_CCM_TLS_EXPLICIT_IV_LEN                     8
374 /* Total length of CCM IV length for TLS */
375 # define EVP_CCM_TLS_IV_LEN                              12
376 /* Length of tag for TLS */
377 # define EVP_CCM_TLS_TAG_LEN                             16
378 /* Length of CCM8 tag for TLS */
379 # define EVP_CCM8_TLS_TAG_LEN                            8
380
381 /* Length of tag for TLS */
382 # define EVP_CHACHAPOLY_TLS_TAG_LEN                      16
383
384 typedef struct evp_cipher_info_st {
385     const EVP_CIPHER *cipher;
386     unsigned char iv[EVP_MAX_IV_LENGTH];
387 } EVP_CIPHER_INFO;
388
389
390 /* Password based encryption function */
391 typedef int (EVP_PBE_KEYGEN) (EVP_CIPHER_CTX *ctx, const char *pass,
392                               int passlen, ASN1_TYPE *param,
393                               const EVP_CIPHER *cipher, const EVP_MD *md,
394                               int en_de);
395
396 # ifndef OPENSSL_NO_RSA
397 #  define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
398                                         (char *)(rsa))
399 # endif
400
401 # ifndef OPENSSL_NO_DSA
402 #  define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
403                                         (char *)(dsa))
404 # endif
405
406 # ifndef OPENSSL_NO_DH
407 #  define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\
408                                         (char *)(dh))
409 # endif
410
411 # ifndef OPENSSL_NO_EC
412 #  define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC,\
413                                         (char *)(eckey))
414 # endif
415 # ifndef OPENSSL_NO_SIPHASH
416 #  define EVP_PKEY_assign_SIPHASH(pkey,shkey) EVP_PKEY_assign((pkey),EVP_PKEY_SIPHASH,\
417                                         (char *)(shkey))
418 # endif
419
420 # ifndef OPENSSL_NO_POLY1305
421 #  define EVP_PKEY_assign_POLY1305(pkey,polykey) EVP_PKEY_assign((pkey),EVP_PKEY_POLY1305,\
422                                         (char *)(polykey))
423 # endif
424
425 /* Add some extra combinations */
426 # define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
427 # define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
428 # define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
429 # define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
430
431 int EVP_MD_type(const EVP_MD *md);
432 # define EVP_MD_nid(e)                   EVP_MD_type(e)
433 # define EVP_MD_name(e)                  OBJ_nid2sn(EVP_MD_nid(e))
434 int EVP_MD_pkey_type(const EVP_MD *md);
435 int EVP_MD_size(const EVP_MD *md);
436 int EVP_MD_block_size(const EVP_MD *md);
437 unsigned long EVP_MD_flags(const EVP_MD *md);
438
439 const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
440 int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx,
441                                              const void *data, size_t count);
442 void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx,
443                               int (*update) (EVP_MD_CTX *ctx,
444                                              const void *data, size_t count));
445 # define EVP_MD_CTX_size(e)              EVP_MD_size(EVP_MD_CTX_md(e))
446 # define EVP_MD_CTX_block_size(e)        EVP_MD_block_size(EVP_MD_CTX_md(e))
447 # define EVP_MD_CTX_type(e)              EVP_MD_type(EVP_MD_CTX_md(e))
448 EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx);
449 void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx);
450
451 int EVP_CIPHER_nid(const EVP_CIPHER *cipher);
452 # define EVP_CIPHER_name(e)              OBJ_nid2sn(EVP_CIPHER_nid(e))
453 int EVP_CIPHER_block_size(const EVP_CIPHER *cipher);
454 int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *cipher);
455 int EVP_CIPHER_key_length(const EVP_CIPHER *cipher);
456 int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher);
457 unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher);
458 # define EVP_CIPHER_mode(e)              (EVP_CIPHER_flags(e) & EVP_CIPH_MODE)
459
460 const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx);
461 int EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx);
462 int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx);
463 int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx);
464 int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx);
465 int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx);
466 const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx);
467 const unsigned char *EVP_CIPHER_CTX_original_iv(const EVP_CIPHER_CTX *ctx);
468 unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx);
469 unsigned char *EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx);
470 int EVP_CIPHER_CTX_num(const EVP_CIPHER_CTX *ctx);
471 void EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num);
472 int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in);
473 void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx);
474 void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data);
475 void *EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx);
476 void *EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data);
477 # define EVP_CIPHER_CTX_type(c)         EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
478 # if OPENSSL_API_COMPAT < 0x10100000L
479 #  define EVP_CIPHER_CTX_flags(c)       EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(c))
480 # endif
481 # define EVP_CIPHER_CTX_mode(c)         EVP_CIPHER_mode(EVP_CIPHER_CTX_cipher(c))
482
483 # define EVP_ENCODE_LENGTH(l)    ((((l)+2)/3*4)+((l)/48+1)*2+80)
484 # define EVP_DECODE_LENGTH(l)    (((l)+3)/4*3+80)
485
486 # define EVP_SignInit_ex(a,b,c)          EVP_DigestInit_ex(a,b,c)
487 # define EVP_SignInit(a,b)               EVP_DigestInit(a,b)
488 # define EVP_SignUpdate(a,b,c)           EVP_DigestUpdate(a,b,c)
489 # define EVP_VerifyInit_ex(a,b,c)        EVP_DigestInit_ex(a,b,c)
490 # define EVP_VerifyInit(a,b)             EVP_DigestInit(a,b)
491 # define EVP_VerifyUpdate(a,b,c)         EVP_DigestUpdate(a,b,c)
492 # define EVP_OpenUpdate(a,b,c,d,e)       EVP_DecryptUpdate(a,b,c,d,e)
493 # define EVP_SealUpdate(a,b,c,d,e)       EVP_EncryptUpdate(a,b,c,d,e)
494 # define EVP_DigestSignUpdate(a,b,c)     EVP_DigestUpdate(a,b,c)
495 # define EVP_DigestVerifyUpdate(a,b,c)   EVP_DigestUpdate(a,b,c)
496
497 # ifdef CONST_STRICT
498 void BIO_set_md(BIO *, const EVP_MD *md);
499 # else
500 #  define BIO_set_md(b,md)          BIO_ctrl(b,BIO_C_SET_MD,0,(char *)(md))
501 # endif
502 # define BIO_get_md(b,mdp)          BIO_ctrl(b,BIO_C_GET_MD,0,(char *)(mdp))
503 # define BIO_get_md_ctx(b,mdcp)     BIO_ctrl(b,BIO_C_GET_MD_CTX,0, \
504                                              (char *)(mdcp))
505 # define BIO_set_md_ctx(b,mdcp)     BIO_ctrl(b,BIO_C_SET_MD_CTX,0, \
506                                              (char *)(mdcp))
507 # define BIO_get_cipher_status(b)   BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
508 # define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0, \
509                                              (char *)(c_pp))
510
511 /*__owur*/ int EVP_Cipher(EVP_CIPHER_CTX *c,
512                           unsigned char *out,
513                           const unsigned char *in, unsigned int inl);
514
515 # define EVP_add_cipher_alias(n,alias) \
516         OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
517 # define EVP_add_digest_alias(n,alias) \
518         OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
519 # define EVP_delete_cipher_alias(alias) \
520         OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
521 # define EVP_delete_digest_alias(alias) \
522         OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
523
524 int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
525 EVP_MD_CTX *EVP_MD_CTX_new(void);
526 int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
527 void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
528 # define EVP_MD_CTX_create()     EVP_MD_CTX_new()
529 # define EVP_MD_CTX_init(ctx)    EVP_MD_CTX_reset((ctx))
530 # define EVP_MD_CTX_destroy(ctx) EVP_MD_CTX_free((ctx))
531 __owur int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
532 void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
533 void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
534 int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);
535 __owur int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type,
536                                  ENGINE *impl);
537 __owur int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d,
538                                 size_t cnt);
539 __owur int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md,
540                                   unsigned int *s);
541 __owur int EVP_Digest(const void *data, size_t count,
542                           unsigned char *md, unsigned int *size,
543                           const EVP_MD *type, ENGINE *impl);
544
545 __owur int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in);
546 __owur int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
547 __owur int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md,
548                            unsigned int *s);
549
550 int EVP_read_pw_string(char *buf, int length, const char *prompt, int verify);
551 int EVP_read_pw_string_min(char *buf, int minlen, int maxlen,
552                            const char *prompt, int verify);
553 void EVP_set_pw_prompt(const char *prompt);
554 char *EVP_get_pw_prompt(void);
555
556 __owur int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
557                           const unsigned char *salt,
558                           const unsigned char *data, int datal, int count,
559                           unsigned char *key, unsigned char *iv);
560
561 void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags);
562 void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags);
563 int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags);
564
565 __owur int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
566                            const unsigned char *key, const unsigned char *iv);
567 /*__owur*/ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,
568                                   const EVP_CIPHER *cipher, ENGINE *impl,
569                                   const unsigned char *key,
570                                   const unsigned char *iv);
571 /*__owur*/ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
572                                  int *outl, const unsigned char *in, int inl);
573 /*__owur*/ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out,
574                                    int *outl);
575 /*__owur*/ int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
576                                 int *outl);
577
578 __owur int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
579                            const unsigned char *key, const unsigned char *iv);
580 /*__owur*/ int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx,
581                                   const EVP_CIPHER *cipher, ENGINE *impl,
582                                   const unsigned char *key,
583                                   const unsigned char *iv);
584 /*__owur*/ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
585                                  int *outl, const unsigned char *in, int inl);
586 __owur int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
587                             int *outl);
588 /*__owur*/ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
589                                    int *outl);
590
591 __owur int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
592                           const unsigned char *key, const unsigned char *iv,
593                           int enc);
594 /*__owur*/ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx,
595                                  const EVP_CIPHER *cipher, ENGINE *impl,
596                                  const unsigned char *key,
597                                  const unsigned char *iv, int enc);
598 __owur int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
599                             int *outl, const unsigned char *in, int inl);
600 __owur int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm,
601                            int *outl);
602 __owur int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm,
603                               int *outl);
604
605 __owur int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s,
606                          EVP_PKEY *pkey);
607
608 __owur int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret,
609                           size_t *siglen, const unsigned char *tbs,
610                           size_t tbslen);
611
612 __owur int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,
613                            unsigned int siglen, EVP_PKEY *pkey);
614
615 __owur int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret,
616                             size_t siglen, const unsigned char *tbs,
617                             size_t tbslen);
618
619 /*__owur*/ int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
620                                   const EVP_MD *type, ENGINE *e,
621                                   EVP_PKEY *pkey);
622 __owur int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
623                                size_t *siglen);
624
625 __owur int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
626                                 const EVP_MD *type, ENGINE *e,
627                                 EVP_PKEY *pkey);
628 __owur int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
629                                  size_t siglen);
630
631 # ifndef OPENSSL_NO_RSA
632 __owur int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
633                         const unsigned char *ek, int ekl,
634                         const unsigned char *iv, EVP_PKEY *priv);
635 __owur int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
636
637 __owur int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
638                         unsigned char **ek, int *ekl, unsigned char *iv,
639                         EVP_PKEY **pubk, int npubk);
640 __owur int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
641 # endif
642
643 EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void);
644 void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx);
645 int EVP_ENCODE_CTX_copy(EVP_ENCODE_CTX *dctx, EVP_ENCODE_CTX *sctx);
646 int EVP_ENCODE_CTX_num(EVP_ENCODE_CTX *ctx);
647 void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
648 int EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
649                      const unsigned char *in, int inl);
650 void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl);
651 int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
652
653 void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
654 int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
655                      const unsigned char *in, int inl);
656 int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
657                     char *out, int *outl);
658 int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
659
660 # if OPENSSL_API_COMPAT < 0x10100000L
661 #  define EVP_CIPHER_CTX_init(c)      EVP_CIPHER_CTX_reset(c)
662 #  define EVP_CIPHER_CTX_cleanup(c)   EVP_CIPHER_CTX_reset(c)
663 # endif
664 EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void);
665 int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c);
666 void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *c);
667 int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
668 int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);
669 int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
670 int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key);
671
672 const BIO_METHOD *BIO_f_md(void);
673 const BIO_METHOD *BIO_f_base64(void);
674 const BIO_METHOD *BIO_f_cipher(void);
675 const BIO_METHOD *BIO_f_reliable(void);
676 __owur int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k,
677                           const unsigned char *i, int enc);
678
679 const EVP_MD *EVP_md_null(void);
680 # ifndef OPENSSL_NO_MD2
681 const EVP_MD *EVP_md2(void);
682 # endif
683 # ifndef OPENSSL_NO_MD4
684 const EVP_MD *EVP_md4(void);
685 # endif
686 # ifndef OPENSSL_NO_MD5
687 const EVP_MD *EVP_md5(void);
688 const EVP_MD *EVP_md5_sha1(void);
689 # endif
690 # ifndef OPENSSL_NO_BLAKE2
691 const EVP_MD *EVP_blake2b512(void);
692 const EVP_MD *EVP_blake2s256(void);
693 # endif
694 const EVP_MD *EVP_sha1(void);
695 const EVP_MD *EVP_sha224(void);
696 const EVP_MD *EVP_sha256(void);
697 const EVP_MD *EVP_sha384(void);
698 const EVP_MD *EVP_sha512(void);
699 const EVP_MD *EVP_sha3_224(void);
700 const EVP_MD *EVP_sha3_256(void);
701 const EVP_MD *EVP_sha3_384(void);
702 const EVP_MD *EVP_sha3_512(void);
703 const EVP_MD *EVP_shake128(void);
704 const EVP_MD *EVP_shake256(void);
705 # ifndef OPENSSL_NO_MDC2
706 const EVP_MD *EVP_mdc2(void);
707 # endif
708 # ifndef OPENSSL_NO_RMD160
709 const EVP_MD *EVP_ripemd160(void);
710 # endif
711 # ifndef OPENSSL_NO_WHIRLPOOL
712 const EVP_MD *EVP_whirlpool(void);
713 # endif
714 const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
715 # ifndef OPENSSL_NO_DES
716 const EVP_CIPHER *EVP_des_ecb(void);
717 const EVP_CIPHER *EVP_des_ede(void);
718 const EVP_CIPHER *EVP_des_ede3(void);
719 const EVP_CIPHER *EVP_des_ede_ecb(void);
720 const EVP_CIPHER *EVP_des_ede3_ecb(void);
721 const EVP_CIPHER *EVP_des_cfb64(void);
722 #  define EVP_des_cfb EVP_des_cfb64
723 const EVP_CIPHER *EVP_des_cfb1(void);
724 const EVP_CIPHER *EVP_des_cfb8(void);
725 const EVP_CIPHER *EVP_des_ede_cfb64(void);
726 #  define EVP_des_ede_cfb EVP_des_ede_cfb64
727 const EVP_CIPHER *EVP_des_ede3_cfb64(void);
728 #  define EVP_des_ede3_cfb EVP_des_ede3_cfb64
729 const EVP_CIPHER *EVP_des_ede3_cfb1(void);
730 const EVP_CIPHER *EVP_des_ede3_cfb8(void);
731 const EVP_CIPHER *EVP_des_ofb(void);
732 const EVP_CIPHER *EVP_des_ede_ofb(void);
733 const EVP_CIPHER *EVP_des_ede3_ofb(void);
734 const EVP_CIPHER *EVP_des_cbc(void);
735 const EVP_CIPHER *EVP_des_ede_cbc(void);
736 const EVP_CIPHER *EVP_des_ede3_cbc(void);
737 const EVP_CIPHER *EVP_desx_cbc(void);
738 const EVP_CIPHER *EVP_des_ede3_wrap(void);
739 /*
740  * This should now be supported through the dev_crypto ENGINE. But also, why
741  * are rc4 and md5 declarations made here inside a "NO_DES" precompiler
742  * branch?
743  */
744 # endif
745 # ifndef OPENSSL_NO_RC4
746 const EVP_CIPHER *EVP_rc4(void);
747 const EVP_CIPHER *EVP_rc4_40(void);
748 #  ifndef OPENSSL_NO_MD5
749 const EVP_CIPHER *EVP_rc4_hmac_md5(void);
750 #  endif
751 # endif
752 # ifndef OPENSSL_NO_IDEA
753 const EVP_CIPHER *EVP_idea_ecb(void);
754 const EVP_CIPHER *EVP_idea_cfb64(void);
755 #  define EVP_idea_cfb EVP_idea_cfb64
756 const EVP_CIPHER *EVP_idea_ofb(void);
757 const EVP_CIPHER *EVP_idea_cbc(void);
758 # endif
759 # ifndef OPENSSL_NO_RC2
760 const EVP_CIPHER *EVP_rc2_ecb(void);
761 const EVP_CIPHER *EVP_rc2_cbc(void);
762 const EVP_CIPHER *EVP_rc2_40_cbc(void);
763 const EVP_CIPHER *EVP_rc2_64_cbc(void);
764 const EVP_CIPHER *EVP_rc2_cfb64(void);
765 #  define EVP_rc2_cfb EVP_rc2_cfb64
766 const EVP_CIPHER *EVP_rc2_ofb(void);
767 # endif
768 # ifndef OPENSSL_NO_BF
769 const EVP_CIPHER *EVP_bf_ecb(void);
770 const EVP_CIPHER *EVP_bf_cbc(void);
771 const EVP_CIPHER *EVP_bf_cfb64(void);
772 #  define EVP_bf_cfb EVP_bf_cfb64
773 const EVP_CIPHER *EVP_bf_ofb(void);
774 # endif
775 # ifndef OPENSSL_NO_CAST
776 const EVP_CIPHER *EVP_cast5_ecb(void);
777 const EVP_CIPHER *EVP_cast5_cbc(void);
778 const EVP_CIPHER *EVP_cast5_cfb64(void);
779 #  define EVP_cast5_cfb EVP_cast5_cfb64
780 const EVP_CIPHER *EVP_cast5_ofb(void);
781 # endif
782 # ifndef OPENSSL_NO_RC5
783 const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
784 const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
785 const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void);
786 #  define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64
787 const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
788 # endif
789 const EVP_CIPHER *EVP_aes_128_ecb(void);
790 const EVP_CIPHER *EVP_aes_128_cbc(void);
791 const EVP_CIPHER *EVP_aes_128_cfb1(void);
792 const EVP_CIPHER *EVP_aes_128_cfb8(void);
793 const EVP_CIPHER *EVP_aes_128_cfb128(void);
794 # define EVP_aes_128_cfb EVP_aes_128_cfb128
795 const EVP_CIPHER *EVP_aes_128_ofb(void);
796 const EVP_CIPHER *EVP_aes_128_ctr(void);
797 const EVP_CIPHER *EVP_aes_128_ccm(void);
798 const EVP_CIPHER *EVP_aes_128_gcm(void);
799 const EVP_CIPHER *EVP_aes_128_xts(void);
800 const EVP_CIPHER *EVP_aes_128_wrap(void);
801 const EVP_CIPHER *EVP_aes_128_wrap_pad(void);
802 # ifndef OPENSSL_NO_OCB
803 const EVP_CIPHER *EVP_aes_128_ocb(void);
804 # endif
805 const EVP_CIPHER *EVP_aes_192_ecb(void);
806 const EVP_CIPHER *EVP_aes_192_cbc(void);
807 const EVP_CIPHER *EVP_aes_192_cfb1(void);
808 const EVP_CIPHER *EVP_aes_192_cfb8(void);
809 const EVP_CIPHER *EVP_aes_192_cfb128(void);
810 # define EVP_aes_192_cfb EVP_aes_192_cfb128
811 const EVP_CIPHER *EVP_aes_192_ofb(void);
812 const EVP_CIPHER *EVP_aes_192_ctr(void);
813 const EVP_CIPHER *EVP_aes_192_ccm(void);
814 const EVP_CIPHER *EVP_aes_192_gcm(void);
815 const EVP_CIPHER *EVP_aes_192_wrap(void);
816 const EVP_CIPHER *EVP_aes_192_wrap_pad(void);
817 # ifndef OPENSSL_NO_OCB
818 const EVP_CIPHER *EVP_aes_192_ocb(void);
819 # endif
820 const EVP_CIPHER *EVP_aes_256_ecb(void);
821 const EVP_CIPHER *EVP_aes_256_cbc(void);
822 const EVP_CIPHER *EVP_aes_256_cfb1(void);
823 const EVP_CIPHER *EVP_aes_256_cfb8(void);
824 const EVP_CIPHER *EVP_aes_256_cfb128(void);
825 # define EVP_aes_256_cfb EVP_aes_256_cfb128
826 const EVP_CIPHER *EVP_aes_256_ofb(void);
827 const EVP_CIPHER *EVP_aes_256_ctr(void);
828 const EVP_CIPHER *EVP_aes_256_ccm(void);
829 const EVP_CIPHER *EVP_aes_256_gcm(void);
830 const EVP_CIPHER *EVP_aes_256_xts(void);
831 const EVP_CIPHER *EVP_aes_256_wrap(void);
832 const EVP_CIPHER *EVP_aes_256_wrap_pad(void);
833 # ifndef OPENSSL_NO_OCB
834 const EVP_CIPHER *EVP_aes_256_ocb(void);
835 # endif
836 const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void);
837 const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha1(void);
838 const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha256(void);
839 const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha256(void);
840 # ifndef OPENSSL_NO_ARIA
841 const EVP_CIPHER *EVP_aria_128_ecb(void);
842 const EVP_CIPHER *EVP_aria_128_cbc(void);
843 const EVP_CIPHER *EVP_aria_128_cfb1(void);
844 const EVP_CIPHER *EVP_aria_128_cfb8(void);
845 const EVP_CIPHER *EVP_aria_128_cfb128(void);
846 #  define EVP_aria_128_cfb EVP_aria_128_cfb128
847 const EVP_CIPHER *EVP_aria_128_ctr(void);
848 const EVP_CIPHER *EVP_aria_128_ofb(void);
849 const EVP_CIPHER *EVP_aria_192_ecb(void);
850 const EVP_CIPHER *EVP_aria_192_cbc(void);
851 const EVP_CIPHER *EVP_aria_192_cfb1(void);
852 const EVP_CIPHER *EVP_aria_192_cfb8(void);
853 const EVP_CIPHER *EVP_aria_192_cfb128(void);
854 #  define EVP_aria_192_cfb EVP_aria_192_cfb128
855 const EVP_CIPHER *EVP_aria_192_ctr(void);
856 const EVP_CIPHER *EVP_aria_192_ofb(void);
857 const EVP_CIPHER *EVP_aria_256_ecb(void);
858 const EVP_CIPHER *EVP_aria_256_cbc(void);
859 const EVP_CIPHER *EVP_aria_256_cfb1(void);
860 const EVP_CIPHER *EVP_aria_256_cfb8(void);
861 const EVP_CIPHER *EVP_aria_256_cfb128(void);
862 #  define EVP_aria_256_cfb EVP_aria_256_cfb128
863 const EVP_CIPHER *EVP_aria_256_ctr(void);
864 const EVP_CIPHER *EVP_aria_256_ofb(void);
865 # endif
866 # ifndef OPENSSL_NO_CAMELLIA
867 const EVP_CIPHER *EVP_camellia_128_ecb(void);
868 const EVP_CIPHER *EVP_camellia_128_cbc(void);
869 const EVP_CIPHER *EVP_camellia_128_cfb1(void);
870 const EVP_CIPHER *EVP_camellia_128_cfb8(void);
871 const EVP_CIPHER *EVP_camellia_128_cfb128(void);
872 #  define EVP_camellia_128_cfb EVP_camellia_128_cfb128
873 const EVP_CIPHER *EVP_camellia_128_ofb(void);
874 const EVP_CIPHER *EVP_camellia_128_ctr(void);
875 const EVP_CIPHER *EVP_camellia_192_ecb(void);
876 const EVP_CIPHER *EVP_camellia_192_cbc(void);
877 const EVP_CIPHER *EVP_camellia_192_cfb1(void);
878 const EVP_CIPHER *EVP_camellia_192_cfb8(void);
879 const EVP_CIPHER *EVP_camellia_192_cfb128(void);
880 #  define EVP_camellia_192_cfb EVP_camellia_192_cfb128
881 const EVP_CIPHER *EVP_camellia_192_ofb(void);
882 const EVP_CIPHER *EVP_camellia_192_ctr(void);
883 const EVP_CIPHER *EVP_camellia_256_ecb(void);
884 const EVP_CIPHER *EVP_camellia_256_cbc(void);
885 const EVP_CIPHER *EVP_camellia_256_cfb1(void);
886 const EVP_CIPHER *EVP_camellia_256_cfb8(void);
887 const EVP_CIPHER *EVP_camellia_256_cfb128(void);
888 #  define EVP_camellia_256_cfb EVP_camellia_256_cfb128
889 const EVP_CIPHER *EVP_camellia_256_ofb(void);
890 const EVP_CIPHER *EVP_camellia_256_ctr(void);
891 # endif
892 # ifndef OPENSSL_NO_CHACHA
893 const EVP_CIPHER *EVP_chacha20(void);
894 #  ifndef OPENSSL_NO_POLY1305
895 const EVP_CIPHER *EVP_chacha20_poly1305(void);
896 #  endif
897 # endif
898
899 # ifndef OPENSSL_NO_SEED
900 const EVP_CIPHER *EVP_seed_ecb(void);
901 const EVP_CIPHER *EVP_seed_cbc(void);
902 const EVP_CIPHER *EVP_seed_cfb128(void);
903 #  define EVP_seed_cfb EVP_seed_cfb128
904 const EVP_CIPHER *EVP_seed_ofb(void);
905 # endif
906
907 # if OPENSSL_API_COMPAT < 0x10100000L
908 #  define OPENSSL_add_all_algorithms_conf() \
909     OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
910                         | OPENSSL_INIT_ADD_ALL_DIGESTS \
911                         | OPENSSL_INIT_LOAD_CONFIG, NULL)
912 #  define OPENSSL_add_all_algorithms_noconf() \
913     OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
914                         | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL)
915
916 #  ifdef OPENSSL_LOAD_CONF
917 #   define OpenSSL_add_all_algorithms() \
918     OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
919                         | OPENSSL_INIT_ADD_ALL_DIGESTS \
920                         | OPENSSL_INIT_LOAD_CONFIG, NULL)
921 #  else
922 #   define OpenSSL_add_all_algorithms() \
923     OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
924                         | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL)
925 #  endif
926
927 #  define OpenSSL_add_all_ciphers() \
928     OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL)
929 #  define OpenSSL_add_all_digests() \
930     OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL)
931
932 #  define EVP_cleanup() while(0) continue
933 # endif
934
935 int EVP_add_cipher(const EVP_CIPHER *cipher);
936 int EVP_add_digest(const EVP_MD *digest);
937
938 const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
939 const EVP_MD *EVP_get_digestbyname(const char *name);
940
941 void EVP_CIPHER_do_all(void (*fn) (const EVP_CIPHER *ciph,
942                                    const char *from, const char *to, void *x),
943                        void *arg);
944 void EVP_CIPHER_do_all_sorted(void (*fn)
945                                (const EVP_CIPHER *ciph, const char *from,
946                                 const char *to, void *x), void *arg);
947
948 void EVP_MD_do_all(void (*fn) (const EVP_MD *ciph,
949                                const char *from, const char *to, void *x),
950                    void *arg);
951 void EVP_MD_do_all_sorted(void (*fn)
952                            (const EVP_MD *ciph, const char *from,
953                             const char *to, void *x), void *arg);
954
955 int EVP_PKEY_decrypt_old(unsigned char *dec_key,
956                          const unsigned char *enc_key, int enc_key_len,
957                          EVP_PKEY *private_key);
958 int EVP_PKEY_encrypt_old(unsigned char *enc_key,
959                          const unsigned char *key, int key_len,
960                          EVP_PKEY *pub_key);
961 int EVP_PKEY_type(int type);
962 int EVP_PKEY_id(const EVP_PKEY *pkey);
963 int EVP_PKEY_base_id(const EVP_PKEY *pkey);
964 int EVP_PKEY_bits(const EVP_PKEY *pkey);
965 int EVP_PKEY_security_bits(const EVP_PKEY *pkey);
966 int EVP_PKEY_size(EVP_PKEY *pkey);
967 int EVP_PKEY_set_type(EVP_PKEY *pkey, int type);
968 int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len);
969 int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key);
970 void *EVP_PKEY_get0(const EVP_PKEY *pkey);
971 const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len);
972 # ifndef OPENSSL_NO_POLY1305
973 const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len);
974 # endif
975 # ifndef OPENSSL_NO_SIPHASH
976 const unsigned char *EVP_PKEY_get0_siphash(const EVP_PKEY *pkey, size_t *len);
977 # endif
978
979 # ifndef OPENSSL_NO_RSA
980 struct rsa_st;
981 int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key);
982 struct rsa_st *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
983 struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
984 # endif
985 # ifndef OPENSSL_NO_DSA
986 struct dsa_st;
987 int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key);
988 struct dsa_st *EVP_PKEY_get0_DSA(EVP_PKEY *pkey);
989 struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
990 # endif
991 # ifndef OPENSSL_NO_DH
992 struct dh_st;
993 int EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key);
994 struct dh_st *EVP_PKEY_get0_DH(EVP_PKEY *pkey);
995 struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
996 # endif
997 # ifndef OPENSSL_NO_EC
998 struct ec_key_st;
999 int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key);
1000 struct ec_key_st *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey);
1001 struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
1002 # endif
1003
1004 EVP_PKEY *EVP_PKEY_new(void);
1005 int EVP_PKEY_up_ref(EVP_PKEY *pkey);
1006 void EVP_PKEY_free(EVP_PKEY *pkey);
1007
1008 EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
1009                         long length);
1010 int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
1011
1012 EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
1013                          long length);
1014 EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
1015                              long length);
1016 int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
1017
1018 int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from);
1019 int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey);
1020 int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode);
1021 int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b);
1022
1023 int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
1024
1025 int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
1026                           int indent, ASN1_PCTX *pctx);
1027 int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
1028                            int indent, ASN1_PCTX *pctx);
1029 int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
1030                           int indent, ASN1_PCTX *pctx);
1031
1032 int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid);
1033
1034 int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey,
1035                                    const unsigned char *pt, size_t ptlen);
1036 size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt);
1037
1038 int EVP_CIPHER_type(const EVP_CIPHER *ctx);
1039
1040 /* calls methods */
1041 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
1042 int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
1043
1044 /* These are used by EVP_CIPHER methods */
1045 int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
1046 int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
1047
1048 /* PKCS5 password based encryption */
1049 int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
1050                        ASN1_TYPE *param, const EVP_CIPHER *cipher,
1051                        const EVP_MD *md, int en_de);
1052 int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
1053                            const unsigned char *salt, int saltlen, int iter,
1054                            int keylen, unsigned char *out);
1055 int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
1056                       const unsigned char *salt, int saltlen, int iter,
1057                       const EVP_MD *digest, int keylen, unsigned char *out);
1058 int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
1059                           ASN1_TYPE *param, const EVP_CIPHER *cipher,
1060                           const EVP_MD *md, int en_de);
1061
1062 #ifndef OPENSSL_NO_SCRYPT
1063 int EVP_PBE_scrypt(const char *pass, size_t passlen,
1064                    const unsigned char *salt, size_t saltlen,
1065                    uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem,
1066                    unsigned char *key, size_t keylen);
1067
1068 int PKCS5_v2_scrypt_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass,
1069                              int passlen, ASN1_TYPE *param,
1070                              const EVP_CIPHER *c, const EVP_MD *md, int en_de);
1071 #endif
1072
1073 void PKCS5_PBE_add(void);
1074
1075 int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
1076                        ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
1077
1078 /* PBE type */
1079
1080 /* Can appear as the outermost AlgorithmIdentifier */
1081 # define EVP_PBE_TYPE_OUTER      0x0
1082 /* Is an PRF type OID */
1083 # define EVP_PBE_TYPE_PRF        0x1
1084 /* Is a PKCS#5 v2.0 KDF */
1085 # define EVP_PBE_TYPE_KDF        0x2
1086
1087 int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid,
1088                          int md_nid, EVP_PBE_KEYGEN *keygen);
1089 int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
1090                     EVP_PBE_KEYGEN *keygen);
1091 int EVP_PBE_find(int type, int pbe_nid, int *pcnid, int *pmnid,
1092                  EVP_PBE_KEYGEN **pkeygen);
1093 void EVP_PBE_cleanup(void);
1094 int EVP_PBE_get(int *ptype, int *ppbe_nid, size_t num);
1095
1096 # define ASN1_PKEY_ALIAS         0x1
1097 # define ASN1_PKEY_DYNAMIC       0x2
1098 # define ASN1_PKEY_SIGPARAM_NULL 0x4
1099
1100 # define ASN1_PKEY_CTRL_PKCS7_SIGN       0x1
1101 # define ASN1_PKEY_CTRL_PKCS7_ENCRYPT    0x2
1102 # define ASN1_PKEY_CTRL_DEFAULT_MD_NID   0x3
1103 # define ASN1_PKEY_CTRL_CMS_SIGN         0x5
1104 # define ASN1_PKEY_CTRL_CMS_ENVELOPE     0x7
1105 # define ASN1_PKEY_CTRL_CMS_RI_TYPE      0x8
1106
1107 # define ASN1_PKEY_CTRL_SET1_TLS_ENCPT   0x9
1108 # define ASN1_PKEY_CTRL_GET1_TLS_ENCPT   0xa
1109
1110 int EVP_PKEY_asn1_get_count(void);
1111 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx);
1112 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type);
1113 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe,
1114                                                    const char *str, int len);
1115 int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth);
1116 int EVP_PKEY_asn1_add_alias(int to, int from);
1117 int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id,
1118                             int *ppkey_flags, const char **pinfo,
1119                             const char **ppem_str,
1120                             const EVP_PKEY_ASN1_METHOD *ameth);
1121
1122 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(const EVP_PKEY *pkey);
1123 EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
1124                                         const char *pem_str,
1125                                         const char *info);
1126 void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
1127                         const EVP_PKEY_ASN1_METHOD *src);
1128 void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth);
1129 void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
1130                               int (*pub_decode) (EVP_PKEY *pk,
1131                                                  X509_PUBKEY *pub),
1132                               int (*pub_encode) (X509_PUBKEY *pub,
1133                                                  const EVP_PKEY *pk),
1134                               int (*pub_cmp) (const EVP_PKEY *a,
1135                                               const EVP_PKEY *b),
1136                               int (*pub_print) (BIO *out,
1137                                                 const EVP_PKEY *pkey,
1138                                                 int indent, ASN1_PCTX *pctx),
1139                               int (*pkey_size) (const EVP_PKEY *pk),
1140                               int (*pkey_bits) (const EVP_PKEY *pk));
1141 void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
1142                                int (*priv_decode) (EVP_PKEY *pk,
1143                                                    const PKCS8_PRIV_KEY_INFO
1144                                                    *p8inf),
1145                                int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8,
1146                                                    const EVP_PKEY *pk),
1147                                int (*priv_print) (BIO *out,
1148                                                   const EVP_PKEY *pkey,
1149                                                   int indent,
1150                                                   ASN1_PCTX *pctx));
1151 void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
1152                              int (*param_decode) (EVP_PKEY *pkey,
1153                                                   const unsigned char **pder,
1154                                                   int derlen),
1155                              int (*param_encode) (const EVP_PKEY *pkey,
1156                                                   unsigned char **pder),
1157                              int (*param_missing) (const EVP_PKEY *pk),
1158                              int (*param_copy) (EVP_PKEY *to,
1159                                                 const EVP_PKEY *from),
1160                              int (*param_cmp) (const EVP_PKEY *a,
1161                                                const EVP_PKEY *b),
1162                              int (*param_print) (BIO *out,
1163                                                  const EVP_PKEY *pkey,
1164                                                  int indent,
1165                                                  ASN1_PCTX *pctx));
1166
1167 void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
1168                             void (*pkey_free) (EVP_PKEY *pkey));
1169 void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
1170                             int (*pkey_ctrl) (EVP_PKEY *pkey, int op,
1171                                               long arg1, void *arg2));
1172 void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth,
1173                             int (*item_verify) (EVP_MD_CTX *ctx,
1174                                                 const ASN1_ITEM *it,
1175                                                 void *asn,
1176                                                 X509_ALGOR *a,
1177                                                 ASN1_BIT_STRING *sig,
1178                                                 EVP_PKEY *pkey),
1179                             int (*item_sign) (EVP_MD_CTX *ctx,
1180                                               const ASN1_ITEM *it,
1181                                               void *asn,
1182                                               X509_ALGOR *alg1,
1183                                               X509_ALGOR *alg2,
1184                                               ASN1_BIT_STRING *sig));
1185
1186 void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth,
1187                                      int (*pkey_security_bits) (const EVP_PKEY
1188                                                                 *pk));
1189
1190 # define EVP_PKEY_OP_UNDEFINED           0
1191 # define EVP_PKEY_OP_PARAMGEN            (1<<1)
1192 # define EVP_PKEY_OP_KEYGEN              (1<<2)
1193 # define EVP_PKEY_OP_SIGN                (1<<3)
1194 # define EVP_PKEY_OP_VERIFY              (1<<4)
1195 # define EVP_PKEY_OP_VERIFYRECOVER       (1<<5)
1196 # define EVP_PKEY_OP_SIGNCTX             (1<<6)
1197 # define EVP_PKEY_OP_VERIFYCTX           (1<<7)
1198 # define EVP_PKEY_OP_ENCRYPT             (1<<8)
1199 # define EVP_PKEY_OP_DECRYPT             (1<<9)
1200 # define EVP_PKEY_OP_DERIVE              (1<<10)
1201
1202 # define EVP_PKEY_OP_TYPE_SIG    \
1203         (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY | EVP_PKEY_OP_VERIFYRECOVER \
1204                 | EVP_PKEY_OP_SIGNCTX | EVP_PKEY_OP_VERIFYCTX)
1205
1206 # define EVP_PKEY_OP_TYPE_CRYPT \
1207         (EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT)
1208
1209 # define EVP_PKEY_OP_TYPE_NOGEN \
1210         (EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_DERIVE)
1211
1212 # define EVP_PKEY_OP_TYPE_GEN \
1213                 (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN)
1214
1215 # define  EVP_PKEY_CTX_set_signature_md(ctx, md) \
1216                 EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,  \
1217                                         EVP_PKEY_CTRL_MD, 0, (void *)(md))
1218
1219 # define  EVP_PKEY_CTX_get_signature_md(ctx, pmd)        \
1220                 EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,  \
1221                                         EVP_PKEY_CTRL_GET_MD, 0, (void *)(pmd))
1222
1223 # define  EVP_PKEY_CTX_set_mac_key(ctx, key, len)        \
1224                 EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_KEYGEN,  \
1225                                   EVP_PKEY_CTRL_SET_MAC_KEY, len, (void *)(key))
1226
1227 # define EVP_PKEY_CTRL_MD                1
1228 # define EVP_PKEY_CTRL_PEER_KEY          2
1229
1230 # define EVP_PKEY_CTRL_PKCS7_ENCRYPT     3
1231 # define EVP_PKEY_CTRL_PKCS7_DECRYPT     4
1232
1233 # define EVP_PKEY_CTRL_PKCS7_SIGN        5
1234
1235 # define EVP_PKEY_CTRL_SET_MAC_KEY       6
1236
1237 # define EVP_PKEY_CTRL_DIGESTINIT        7
1238
1239 /* Used by GOST key encryption in TLS */
1240 # define EVP_PKEY_CTRL_SET_IV            8
1241
1242 # define EVP_PKEY_CTRL_CMS_ENCRYPT       9
1243 # define EVP_PKEY_CTRL_CMS_DECRYPT       10
1244 # define EVP_PKEY_CTRL_CMS_SIGN          11
1245
1246 # define EVP_PKEY_CTRL_CIPHER            12
1247
1248 # define EVP_PKEY_CTRL_GET_MD            13
1249
1250 # define EVP_PKEY_CTRL_SET_DIGEST_SIZE   14
1251
1252 # define EVP_PKEY_ALG_CTRL               0x1000
1253
1254 # define EVP_PKEY_FLAG_AUTOARGLEN        2
1255 /*
1256  * Method handles all operations: don't assume any digest related defaults.
1257  */
1258 # define EVP_PKEY_FLAG_SIGCTX_CUSTOM     4
1259
1260 const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type);
1261 EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags);
1262 void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags,
1263                              const EVP_PKEY_METHOD *meth);
1264 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src);
1265 void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth);
1266 int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth);
1267 size_t EVP_PKEY_meth_get_count(void);
1268 const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx);
1269
1270 EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e);
1271 EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e);
1272 EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx);
1273 void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx);
1274
1275 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
1276                       int cmd, int p1, void *p2);
1277 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
1278                           const char *value);
1279 int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype,
1280                                 int cmd, uint64_t value);
1281
1282 int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str);
1283 int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex);
1284
1285 int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md);
1286
1287 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx);
1288 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen);
1289
1290 EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e,
1291                                const unsigned char *key, int keylen);
1292
1293 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data);
1294 void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx);
1295 EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx);
1296
1297 EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx);
1298
1299 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data);
1300 void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx);
1301
1302 int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
1303 int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
1304                   unsigned char *sig, size_t *siglen,
1305                   const unsigned char *tbs, size_t tbslen);
1306 int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx);
1307 int EVP_PKEY_verify(EVP_PKEY_CTX *ctx,
1308                     const unsigned char *sig, size_t siglen,
1309                     const unsigned char *tbs, size_t tbslen);
1310 int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx);
1311 int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx,
1312                             unsigned char *rout, size_t *routlen,
1313                             const unsigned char *sig, size_t siglen);
1314 int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx);
1315 int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
1316                      unsigned char *out, size_t *outlen,
1317                      const unsigned char *in, size_t inlen);
1318 int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx);
1319 int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx,
1320                      unsigned char *out, size_t *outlen,
1321                      const unsigned char *in, size_t inlen);
1322
1323 int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx);
1324 int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer);
1325 int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
1326
1327 typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx);
1328
1329 int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx);
1330 int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey);
1331 int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx);
1332 int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey);
1333
1334 void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb);
1335 EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx);
1336
1337 int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx);
1338
1339 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
1340                             int (*init) (EVP_PKEY_CTX *ctx));
1341
1342 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
1343                             int (*copy) (EVP_PKEY_CTX *dst,
1344                                          EVP_PKEY_CTX *src));
1345
1346 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth,
1347                                void (*cleanup) (EVP_PKEY_CTX *ctx));
1348
1349 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth,
1350                                 int (*paramgen_init) (EVP_PKEY_CTX *ctx),
1351                                 int (*paramgen) (EVP_PKEY_CTX *ctx,
1352                                                  EVP_PKEY *pkey));
1353
1354 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth,
1355                               int (*keygen_init) (EVP_PKEY_CTX *ctx),
1356                               int (*keygen) (EVP_PKEY_CTX *ctx,
1357                                              EVP_PKEY *pkey));
1358
1359 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth,
1360                             int (*sign_init) (EVP_PKEY_CTX *ctx),
1361                             int (*sign) (EVP_PKEY_CTX *ctx,
1362                                          unsigned char *sig, size_t *siglen,
1363                                          const unsigned char *tbs,
1364                                          size_t tbslen));
1365
1366 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth,
1367                               int (*verify_init) (EVP_PKEY_CTX *ctx),
1368                               int (*verify) (EVP_PKEY_CTX *ctx,
1369                                              const unsigned char *sig,
1370                                              size_t siglen,
1371                                              const unsigned char *tbs,
1372                                              size_t tbslen));
1373
1374 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth,
1375                                       int (*verify_recover_init) (EVP_PKEY_CTX
1376                                                                   *ctx),
1377                                       int (*verify_recover) (EVP_PKEY_CTX
1378                                                              *ctx,
1379                                                              unsigned char
1380                                                              *sig,
1381                                                              size_t *siglen,
1382                                                              const unsigned
1383                                                              char *tbs,
1384                                                              size_t tbslen));
1385
1386 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth,
1387                                int (*signctx_init) (EVP_PKEY_CTX *ctx,
1388                                                     EVP_MD_CTX *mctx),
1389                                int (*signctx) (EVP_PKEY_CTX *ctx,
1390                                                unsigned char *sig,
1391                                                size_t *siglen,
1392                                                EVP_MD_CTX *mctx));
1393
1394 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
1395                                  int (*verifyctx_init) (EVP_PKEY_CTX *ctx,
1396                                                         EVP_MD_CTX *mctx),
1397                                  int (*verifyctx) (EVP_PKEY_CTX *ctx,
1398                                                    const unsigned char *sig,
1399                                                    int siglen,
1400                                                    EVP_MD_CTX *mctx));
1401
1402 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
1403                                int (*encrypt_init) (EVP_PKEY_CTX *ctx),
1404                                int (*encryptfn) (EVP_PKEY_CTX *ctx,
1405                                                  unsigned char *out,
1406                                                  size_t *outlen,
1407                                                  const unsigned char *in,
1408                                                  size_t inlen));
1409
1410 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,
1411                                int (*decrypt_init) (EVP_PKEY_CTX *ctx),
1412                                int (*decrypt) (EVP_PKEY_CTX *ctx,
1413                                                unsigned char *out,
1414                                                size_t *outlen,
1415                                                const unsigned char *in,
1416                                                size_t inlen));
1417
1418 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth,
1419                               int (*derive_init) (EVP_PKEY_CTX *ctx),
1420                               int (*derive) (EVP_PKEY_CTX *ctx,
1421                                              unsigned char *key,
1422                                              size_t *keylen));
1423
1424 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth,
1425                             int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
1426                                          void *p2),
1427                             int (*ctrl_str) (EVP_PKEY_CTX *ctx,
1428                                              const char *type,
1429                                              const char *value));
1430
1431 void EVP_PKEY_meth_get_init(EVP_PKEY_METHOD *pmeth,
1432                             int (**pinit) (EVP_PKEY_CTX *ctx));
1433
1434 void EVP_PKEY_meth_get_copy(EVP_PKEY_METHOD *pmeth,
1435                             int (**pcopy) (EVP_PKEY_CTX *dst,
1436                                            EVP_PKEY_CTX *src));
1437
1438 void EVP_PKEY_meth_get_cleanup(EVP_PKEY_METHOD *pmeth,
1439                                void (**pcleanup) (EVP_PKEY_CTX *ctx));
1440
1441 void EVP_PKEY_meth_get_paramgen(EVP_PKEY_METHOD *pmeth,
1442                                 int (**pparamgen_init) (EVP_PKEY_CTX *ctx),
1443                                 int (**pparamgen) (EVP_PKEY_CTX *ctx,
1444                                                    EVP_PKEY *pkey));
1445
1446 void EVP_PKEY_meth_get_keygen(EVP_PKEY_METHOD *pmeth,
1447                               int (**pkeygen_init) (EVP_PKEY_CTX *ctx),
1448                               int (**pkeygen) (EVP_PKEY_CTX *ctx,
1449                                                EVP_PKEY *pkey));
1450
1451 void EVP_PKEY_meth_get_sign(EVP_PKEY_METHOD *pmeth,
1452                             int (**psign_init) (EVP_PKEY_CTX *ctx),
1453                             int (**psign) (EVP_PKEY_CTX *ctx,
1454                                            unsigned char *sig, size_t *siglen,
1455                                            const unsigned char *tbs,
1456                                            size_t tbslen));
1457
1458 void EVP_PKEY_meth_get_verify(EVP_PKEY_METHOD *pmeth,
1459                               int (**pverify_init) (EVP_PKEY_CTX *ctx),
1460                               int (**pverify) (EVP_PKEY_CTX *ctx,
1461                                                const unsigned char *sig,
1462                                                size_t siglen,
1463                                                const unsigned char *tbs,
1464                                                size_t tbslen));
1465
1466 void EVP_PKEY_meth_get_verify_recover(EVP_PKEY_METHOD *pmeth,
1467                                       int (**pverify_recover_init) (EVP_PKEY_CTX
1468                                                                     *ctx),
1469                                       int (**pverify_recover) (EVP_PKEY_CTX
1470                                                                *ctx,
1471                                                                unsigned char
1472                                                                *sig,
1473                                                                size_t *siglen,
1474                                                                const unsigned
1475                                                                char *tbs,
1476                                                                size_t tbslen));
1477
1478 void EVP_PKEY_meth_get_signctx(EVP_PKEY_METHOD *pmeth,
1479                                int (**psignctx_init) (EVP_PKEY_CTX *ctx,
1480                                                       EVP_MD_CTX *mctx),
1481                                int (**psignctx) (EVP_PKEY_CTX *ctx,
1482                                                  unsigned char *sig,
1483                                                  size_t *siglen,
1484                                                  EVP_MD_CTX *mctx));
1485
1486 void EVP_PKEY_meth_get_verifyctx(EVP_PKEY_METHOD *pmeth,
1487                                  int (**pverifyctx_init) (EVP_PKEY_CTX *ctx,
1488                                                           EVP_MD_CTX *mctx),
1489                                  int (**pverifyctx) (EVP_PKEY_CTX *ctx,
1490                                                      const unsigned char *sig,
1491                                                      int siglen,
1492                                                      EVP_MD_CTX *mctx));
1493
1494 void EVP_PKEY_meth_get_encrypt(EVP_PKEY_METHOD *pmeth,
1495                                int (**pencrypt_init) (EVP_PKEY_CTX *ctx),
1496                                int (**pencryptfn) (EVP_PKEY_CTX *ctx,
1497                                                    unsigned char *out,
1498                                                    size_t *outlen,
1499                                                    const unsigned char *in,
1500                                                    size_t inlen));
1501
1502 void EVP_PKEY_meth_get_decrypt(EVP_PKEY_METHOD *pmeth,
1503                                int (**pdecrypt_init) (EVP_PKEY_CTX *ctx),
1504                                int (**pdecrypt) (EVP_PKEY_CTX *ctx,
1505                                                  unsigned char *out,
1506                                                  size_t *outlen,
1507                                                  const unsigned char *in,
1508                                                  size_t inlen));
1509
1510 void EVP_PKEY_meth_get_derive(EVP_PKEY_METHOD *pmeth,
1511                               int (**pderive_init) (EVP_PKEY_CTX *ctx),
1512                               int (**pderive) (EVP_PKEY_CTX *ctx,
1513                                                unsigned char *key,
1514                                                size_t *keylen));
1515
1516 void EVP_PKEY_meth_get_ctrl(EVP_PKEY_METHOD *pmeth,
1517                             int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1,
1518                                            void *p2),
1519                             int (**pctrl_str) (EVP_PKEY_CTX *ctx,
1520                                                const char *type,
1521                                                const char *value));
1522
1523 void EVP_add_alg_module(void);
1524
1525 int ERR_load_EVP_strings(void);
1526
1527 # ifdef  __cplusplus
1528 }
1529 # endif
1530 #endif