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