evp.h revision 280297
1193323Sed/* crypto/evp/evp.h */ 2193323Sed/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3193323Sed * All rights reserved. 4193323Sed * 5193323Sed * This package is an SSL implementation written 6193323Sed * by Eric Young (eay@cryptsoft.com). 7193323Sed * The implementation was written so as to conform with Netscapes SSL. 8193323Sed * 9193323Sed * This library is free for commercial and non-commercial use as long as 10193323Sed * the following conditions are aheared to. The following conditions 11193323Sed * apply to all code found in this distribution, be it the RC4, RSA, 12263508Sdim * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13202375Srdivacky * included with this distribution is covered by the same copyright terms 14263508Sdim * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15263508Sdim * 16263508Sdim * Copyright remains Eric Young's, and as such any Copyright notices in 17263508Sdim * the code are not to be removed. 18193323Sed * If this package is used in a product, Eric Young should be given attribution 19193323Sed * as the author of the parts of the library used. 20193323Sed * This can be in the form of a textual message at program startup or 21193323Sed * in documentation (online or textual) provided with the package. 22249423Sdim * 23249423Sdim * Redistribution and use in source and binary forms, with or without 24249423Sdim * modification, are permitted provided that the following conditions 25249423Sdim * are met: 26198892Srdivacky * 1. Redistributions of source code must retain the copyright 27194612Sed * notice, this list of conditions and the following disclaimer. 28202375Srdivacky * 2. Redistributions in binary form must reproduce the above copyright 29198090Srdivacky * notice, this list of conditions and the following disclaimer in the 30193323Sed * documentation and/or other materials provided with the distribution. 31193323Sed * 3. All advertising materials mentioning features or use of this software 32193323Sed * must display the following acknowledgement: 33193323Sed * "This product includes cryptographic software written by 34263508Sdim * Eric Young (eay@cryptsoft.com)" 35221345Sdim * The word 'cryptographic' can be left out if the rouines from the library 36221345Sdim * being used are not cryptographic related :-). 37221345Sdim * 4. If you include any Windows specific code (or a derivative thereof) from 38221345Sdim * the apps directory (application code) you must include an acknowledgement: 39221345Sdim * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40221345Sdim * 41263508Sdim * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42221345Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43221345Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44221345Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45221345Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46221345Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47221345Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48221345Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49221345Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50193323Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51193323Sed * SUCH DAMAGE. 52263508Sdim * 53263508Sdim * The licence and distribution terms for any publically available version or 54239462Sdim * derivative of this code cannot be changed. i.e. this code cannot simply be 55239462Sdim * copied and put under another distribution licence 56239462Sdim * [including the GNU Public Licence.] 57239462Sdim */ 58263508Sdim 59239462Sdim#ifndef HEADER_ENVELOPE_H 60239462Sdim# define HEADER_ENVELOPE_H 61239462Sdim 62243830Sdim# ifdef OPENSSL_ALGORITHM_DEFINES 63243830Sdim# include <openssl/opensslconf.h> 64243830Sdim# else 65243830Sdim# define OPENSSL_ALGORITHM_DEFINES 66243830Sdim# include <openssl/opensslconf.h> 67243830Sdim# undef OPENSSL_ALGORITHM_DEFINES 68243830Sdim# endif 69243830Sdim 70243830Sdim# include <openssl/ossl_typ.h> 71243830Sdim 72239462Sdim# include <openssl/symhacks.h> 73239462Sdim 74239462Sdim# ifndef OPENSSL_NO_BIO 75239462Sdim# include <openssl/bio.h> 76263508Sdim# endif 77239462Sdim 78239462Sdim/*- 79239462Sdim#define EVP_RC2_KEY_SIZE 16 80263508Sdim#define EVP_RC4_KEY_SIZE 16 81193323Sed#define EVP_BLOWFISH_KEY_SIZE 16 82193323Sed#define EVP_CAST5_KEY_SIZE 16 83193323Sed#define EVP_RC5_32_12_16_KEY_SIZE 16 84193323Sed*/ 85193323Sed# define EVP_MAX_MD_SIZE 64/* longest known is SHA512 */ 86193323Sed# define EVP_MAX_KEY_LENGTH 64 87193323Sed# define EVP_MAX_IV_LENGTH 16 88193323Sed# define EVP_MAX_BLOCK_LENGTH 32 89263508Sdim 90193323Sed# define PKCS5_SALT_LEN 8 91193323Sed/* Default PKCS#5 iteration count */ 92193323Sed# define PKCS5_DEFAULT_ITER 2048 93193323Sed 94193323Sed# include <openssl/objects.h> 95193323Sed 96193323Sed# define EVP_PK_RSA 0x0001 97193323Sed# define EVP_PK_DSA 0x0002 98263508Sdim# define EVP_PK_DH 0x0004 99263508Sdim# define EVP_PK_EC 0x0008 100263508Sdim# define EVP_PKT_SIGN 0x0010 101193323Sed# define EVP_PKT_ENC 0x0020 102193323Sed# define EVP_PKT_EXCH 0x0040 103193323Sed# define EVP_PKS_RSA 0x0100 104193323Sed# define EVP_PKS_DSA 0x0200 105193323Sed# define EVP_PKS_EC 0x0400 106193323Sed# define EVP_PKT_EXP 0x1000 /* <= 512 bit key */ 107193323Sed 108193323Sed# define EVP_PKEY_NONE NID_undef 109193323Sed# define EVP_PKEY_RSA NID_rsaEncryption 110193323Sed# define EVP_PKEY_RSA2 NID_rsa 111263508Sdim# define EVP_PKEY_DSA NID_dsa 112193323Sed# define EVP_PKEY_DSA1 NID_dsa_2 113193323Sed# define EVP_PKEY_DSA2 NID_dsaWithSHA 114193323Sed# define EVP_PKEY_DSA3 NID_dsaWithSHA1 115193323Sed# define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 116193323Sed# define EVP_PKEY_DH NID_dhKeyAgreement 117263508Sdim# define EVP_PKEY_EC NID_X9_62_id_ecPublicKey 118193323Sed# define EVP_PKEY_HMAC NID_hmac 119193323Sed# define EVP_PKEY_CMAC NID_cmac 120193323Sed 121193323Sed#ifdef __cplusplus 122193323Sedextern "C" { 123193323Sed#endif 124193323Sed 125193323Sed/* 126193323Sed * Type needs to be a bit field Sub-type needs to be for variations on the 127193323Sed * method, as in, can it do arbitrary encryption.... 128193323Sed */ 129193323Sedstruct evp_pkey_st { 130193323Sed int type; 131193323Sed int save_type; 132193323Sed int references; 133193323Sed const EVP_PKEY_ASN1_METHOD *ameth; 134193323Sed ENGINE *engine; 135193323Sed union { 136193323Sed char *ptr; 137193323Sed# ifndef OPENSSL_NO_RSA 138193323Sed struct rsa_st *rsa; /* RSA */ 139263508Sdim# endif 140263508Sdim# ifndef OPENSSL_NO_DSA 141263508Sdim struct dsa_st *dsa; /* DSA */ 142243830Sdim# endif 143243830Sdim# ifndef OPENSSL_NO_DH 144243830Sdim struct dh_st *dh; /* DH */ 145243830Sdim# endif 146243830Sdim# ifndef OPENSSL_NO_EC 147243830Sdim struct ec_key_st *ec; /* ECC */ 148243830Sdim# endif 149243830Sdim } pkey; 150243830Sdim int save_parameters; 151243830Sdim STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ 152243830Sdim} /* EVP_PKEY */ ; 153243830Sdim 154243830Sdim# define EVP_PKEY_MO_SIGN 0x0001 155243830Sdim# define EVP_PKEY_MO_VERIFY 0x0002 156243830Sdim# define EVP_PKEY_MO_ENCRYPT 0x0004 157243830Sdim# define EVP_PKEY_MO_DECRYPT 0x0008 158243830Sdim 159243830Sdim# ifndef EVP_MD 160243830Sdimstruct env_md_st { 161243830Sdim int type; 162243830Sdim int pkey_type; 163243830Sdim int md_size; 164243830Sdim unsigned long flags; 165243830Sdim int (*init) (EVP_MD_CTX *ctx); 166243830Sdim int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count); 167243830Sdim int (*final) (EVP_MD_CTX *ctx, unsigned char *md); 168243830Sdim int (*copy) (EVP_MD_CTX *to, const EVP_MD_CTX *from); 169243830Sdim int (*cleanup) (EVP_MD_CTX *ctx); 170243830Sdim /* FIXME: prototype these some day */ 171243830Sdim int (*sign) (int type, const unsigned char *m, unsigned int m_length, 172243830Sdim unsigned char *sigret, unsigned int *siglen, void *key); 173243830Sdim int (*verify) (int type, const unsigned char *m, unsigned int m_length, 174243830Sdim const unsigned char *sigbuf, unsigned int siglen, 175243830Sdim void *key); 176243830Sdim int required_pkey_type[5]; /* EVP_PKEY_xxx */ 177243830Sdim int block_size; 178243830Sdim int ctx_size; /* how big does the ctx->md_data need to be */ 179243830Sdim /* control function */ 180263508Sdim int (*md_ctrl) (EVP_MD_CTX *ctx, int cmd, int p1, void *p2); 181193323Sed} /* EVP_MD */ ; 182263508Sdim 183193323Sedtypedef int evp_sign_method(int type, const unsigned char *m, 184210299Sed unsigned int m_length, unsigned char *sigret, 185210299Sed unsigned int *siglen, void *key); 186193323Sedtypedef int evp_verify_method(int type, const unsigned char *m, 187193323Sed unsigned int m_length, 188212904Sdim const unsigned char *sigbuf, 189212904Sdim unsigned int siglen, void *key); 190212904Sdim 191212904Sdim/* digest can only handle a single block */ 192263508Sdim# define EVP_MD_FLAG_ONESHOT 0x0001 193212904Sdim 194212904Sdim/* 195212904Sdim * digest is a "clone" digest used 196212904Sdim * which is a copy of an existing 197212904Sdim * one for a specific public key type. 198239462Sdim * EVP_dss1() etc 199212904Sdim */ 200212904Sdim# define EVP_MD_FLAG_PKEY_DIGEST 0x0002 201212904Sdim 202212904Sdim/* Digest uses EVP_PKEY_METHOD for signing instead of MD specific signing */ 203212904Sdim 204263508Sdim# define EVP_MD_FLAG_PKEY_METHOD_SIGNATURE 0x0004 205212904Sdim 206212904Sdim/* DigestAlgorithmIdentifier flags... */ 207212904Sdim 208212904Sdim# define EVP_MD_FLAG_DIGALGID_MASK 0x0018 209212904Sdim 210212904Sdim/* NULL or absent parameter accepted. Use NULL */ 211263508Sdim 212212904Sdim# define EVP_MD_FLAG_DIGALGID_NULL 0x0000 213212904Sdim 214212904Sdim/* NULL or absent parameter accepted. Use NULL for PKCS#1 otherwise absent */ 215212904Sdim 216212904Sdim# define EVP_MD_FLAG_DIGALGID_ABSENT 0x0008 217263508Sdim 218263508Sdim/* Custom handling via ctrl */ 219263508Sdim 220263508Sdim# define EVP_MD_FLAG_DIGALGID_CUSTOM 0x0018 221263508Sdim 222193323Sed/* Note if suitable for use in FIPS mode */ 223193323Sed# define EVP_MD_FLAG_FIPS 0x0400 224263508Sdim 225263508Sdim/* Digest ctrls */ 226263508Sdim 227193323Sed# define EVP_MD_CTRL_DIGALGID 0x1 228193323Sed# define EVP_MD_CTRL_MICALG 0x2 229193323Sed 230263508Sdim/* Minimum Algorithm specific ctrl value */ 231193323Sed 232193323Sed# define EVP_MD_CTRL_ALG_CTRL 0x1000 233263508Sdim 234263508Sdim# define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0} 235263508Sdim 236239462Sdim# ifndef OPENSSL_NO_DSA 237239462Sdim# define EVP_PKEY_DSA_method (evp_sign_method *)DSA_sign, \ 238239462Sdim (evp_verify_method *)DSA_verify, \ 239193323Sed {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \ 240239462Sdim EVP_PKEY_DSA4,0} 241263508Sdim# else 242263508Sdim# define EVP_PKEY_DSA_method EVP_PKEY_NULL_method 243193323Sed# endif 244193323Sed 245193323Sed# ifndef OPENSSL_NO_ECDSA 246263508Sdim# define EVP_PKEY_ECDSA_method (evp_sign_method *)ECDSA_sign, \ 247263508Sdim (evp_verify_method *)ECDSA_verify, \ 248263508Sdim {EVP_PKEY_EC,0,0,0} 249263508Sdim# else 250263508Sdim# define EVP_PKEY_ECDSA_method EVP_PKEY_NULL_method 251263508Sdim# endif 252193323Sed 253193323Sed# ifndef OPENSSL_NO_RSA 254263508Sdim# define EVP_PKEY_RSA_method (evp_sign_method *)RSA_sign, \ 255263508Sdim (evp_verify_method *)RSA_verify, \ 256193323Sed {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} 257263508Sdim# define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \ 258193323Sed (evp_sign_method *)RSA_sign_ASN1_OCTET_STRING, \ 259263508Sdim (evp_verify_method *)RSA_verify_ASN1_OCTET_STRING, \ 260193323Sed {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} 261193323Sed# else 262193323Sed# define EVP_PKEY_RSA_method EVP_PKEY_NULL_method 263193323Sed# define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method 264193323Sed# endif 265193323Sed 266263508Sdim# endif /* !EVP_MD */ 267263508Sdim 268193323Sedstruct env_md_ctx_st { 269193323Sed const EVP_MD *digest; 270193323Sed ENGINE *engine; /* functional reference if 'digest' is 271263508Sdim * ENGINE-provided */ 272193323Sed unsigned long flags; 273193323Sed void *md_data; 274193323Sed /* Public key context for sign/verify */ 275193323Sed EVP_PKEY_CTX *pctx; 276193323Sed /* Update function: usually copied from EVP_MD */ 277263508Sdim int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count); 278193323Sed} /* EVP_MD_CTX */ ; 279193323Sed 280193323Sed/* values for EVP_MD_CTX flags */ 281263508Sdim 282263508Sdim# define EVP_MD_CTX_FLAG_ONESHOT 0x0001/* digest update will be 283263508Sdim * called once only */ 284193323Sed# define EVP_MD_CTX_FLAG_CLEANED 0x0002/* context has already been 285263508Sdim * cleaned */ 286263508Sdim# define EVP_MD_CTX_FLAG_REUSE 0x0004/* Don't free up ctx->md_data 287263508Sdim * in EVP_MD_CTX_cleanup */ 288193323Sed/* 289263508Sdim * FIPS and pad options are ignored in 1.0.0, definitions are here so we 290193323Sed * don't accidentally reuse the values for other purposes. 291263508Sdim */ 292193323Sed 293193323Sed# define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008/* Allow use of non FIPS 294193323Sed * digest in FIPS mode */ 295263508Sdim 296193323Sed/* 297193323Sed * The following PAD options are also currently ignored in 1.0.0, digest 298263508Sdim * parameters are handled through EVP_DigestSign*() and EVP_DigestVerify*() 299193323Sed * instead. 300193323Sed */ 301193323Sed# define EVP_MD_CTX_FLAG_PAD_MASK 0xF0/* RSA mode to use */ 302193323Sed# define EVP_MD_CTX_FLAG_PAD_PKCS1 0x00/* PKCS#1 v1.5 mode */ 303263508Sdim# define EVP_MD_CTX_FLAG_PAD_X931 0x10/* X9.31 mode */ 304263508Sdim# define EVP_MD_CTX_FLAG_PAD_PSS 0x20/* PSS mode */ 305263508Sdim 306263508Sdim# define EVP_MD_CTX_FLAG_NO_INIT 0x0100/* Don't initialize md_data */ 307193323Sed 308263508Sdimstruct evp_cipher_st { 309193323Sed int nid; 310263508Sdim int block_size; 311193323Sed /* Default value for variable length ciphers */ 312193323Sed int key_len; 313263508Sdim int iv_len; 314193323Sed /* Various flags */ 315193323Sed unsigned long flags; 316193323Sed /* init key */ 317263508Sdim int (*init) (EVP_CIPHER_CTX *ctx, const unsigned char *key, 318193323Sed const unsigned char *iv, int enc); 319193323Sed /* encrypt/decrypt data */ 320263508Sdim int (*do_cipher) (EVP_CIPHER_CTX *ctx, unsigned char *out, 321193323Sed const unsigned char *in, size_t inl); 322193323Sed /* cleanup ctx */ 323193323Sed int (*cleanup) (EVP_CIPHER_CTX *); 324263508Sdim /* how big ctx->cipher_data needs to be */ 325193323Sed int ctx_size; 326263508Sdim /* Populate a ASN1_TYPE with parameters */ 327193323Sed int (*set_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *); 328193323Sed /* Get parameters from a ASN1_TYPE */ 329263508Sdim int (*get_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *); 330226633Sdim /* Miscellaneous operations */ 331226633Sdim int (*ctrl) (EVP_CIPHER_CTX *, int type, int arg, void *ptr); 332263508Sdim /* Application data */ 333221345Sdim void *app_data; 334221345Sdim} /* EVP_CIPHER */ ; 335226633Sdim 336221345Sdim/* Values for cipher flags */ 337221345Sdim 338221345Sdim/* Modes for ciphers */ 339221345Sdim 340221345Sdim# define EVP_CIPH_STREAM_CIPHER 0x0 341226633Sdim# define EVP_CIPH_ECB_MODE 0x1 342263508Sdim# define EVP_CIPH_CBC_MODE 0x2 343221345Sdim# define EVP_CIPH_CFB_MODE 0x3 344221345Sdim# define EVP_CIPH_OFB_MODE 0x4 345193323Sed# define EVP_CIPH_CTR_MODE 0x5 346263508Sdim# define EVP_CIPH_GCM_MODE 0x6 347263508Sdim# define EVP_CIPH_CCM_MODE 0x7 348263508Sdim# define EVP_CIPH_XTS_MODE 0x10001 349263508Sdim# define EVP_CIPH_MODE 0xF0007 350263508Sdim/* Set if variable length cipher */ 351263508Sdim# define EVP_CIPH_VARIABLE_LENGTH 0x8 352263508Sdim/* Set if the iv handling should be done by the cipher itself */ 353263508Sdim# define EVP_CIPH_CUSTOM_IV 0x10 354263508Sdim/* Set if the cipher's init() function should be called if key is NULL */ 355193323Sed# define EVP_CIPH_ALWAYS_CALL_INIT 0x20 356263508Sdim/* Call ctrl() to init cipher parameters */ 357193323Sed# define EVP_CIPH_CTRL_INIT 0x40 358193323Sed/* Don't use standard key length function */ 359193323Sed# define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80 360193323Sed/* Don't use standard block padding */ 361193323Sed# define EVP_CIPH_NO_PADDING 0x100 362193323Sed/* cipher handles random key generation */ 363193323Sed# define EVP_CIPH_RAND_KEY 0x200 364193323Sed/* cipher has its own additional copying logic */ 365193323Sed# define EVP_CIPH_CUSTOM_COPY 0x400 366193323Sed/* Allow use default ASN1 get/set iv */ 367210299Sed# define EVP_CIPH_FLAG_DEFAULT_ASN1 0x1000 368193323Sed/* Buffer length in bits not bytes: CFB1 mode only */ 369212904Sdim# define EVP_CIPH_FLAG_LENGTH_BITS 0x2000 370212904Sdim/* Note if suitable for use in FIPS mode */ 371193323Sed# define EVP_CIPH_FLAG_FIPS 0x4000 372193323Sed/* Allow non FIPS cipher in FIPS mode */ 373193323Sed# define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0x8000 374263508Sdim/* 375193323Sed * Cipher handles any and all padding logic as well as finalisation. 376193323Sed */ 377193323Sed# define EVP_CIPH_FLAG_CUSTOM_CIPHER 0x100000 378193323Sed# define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000 379193323Sed 380263508Sdim/* ctrl() values */ 381193323Sed 382193323Sed# define EVP_CTRL_INIT 0x0 383193323Sed# define EVP_CTRL_SET_KEY_LENGTH 0x1 384193323Sed# define EVP_CTRL_GET_RC2_KEY_BITS 0x2 385193323Sed# define EVP_CTRL_SET_RC2_KEY_BITS 0x3 386193323Sed# define EVP_CTRL_GET_RC5_ROUNDS 0x4 387263508Sdim# define EVP_CTRL_SET_RC5_ROUNDS 0x5 388198892Srdivacky# define EVP_CTRL_RAND_KEY 0x6 389263508Sdim# define EVP_CTRL_PBE_PRF_NID 0x7 390193323Sed# define EVP_CTRL_COPY 0x8 391193323Sed# define EVP_CTRL_GCM_SET_IVLEN 0x9 392263508Sdim# define EVP_CTRL_GCM_GET_TAG 0x10 393193323Sed# define EVP_CTRL_GCM_SET_TAG 0x11 394193323Sed# define EVP_CTRL_GCM_SET_IV_FIXED 0x12 395263508Sdim# define EVP_CTRL_GCM_IV_GEN 0x13 396193323Sed# define EVP_CTRL_CCM_SET_IVLEN EVP_CTRL_GCM_SET_IVLEN 397263508Sdim# define EVP_CTRL_CCM_GET_TAG EVP_CTRL_GCM_GET_TAG 398193323Sed# define EVP_CTRL_CCM_SET_TAG EVP_CTRL_GCM_SET_TAG 399263508Sdim# define EVP_CTRL_CCM_SET_L 0x14 400263508Sdim# define EVP_CTRL_CCM_SET_MSGLEN 0x15 401193323Sed/* 402193323Sed * AEAD cipher deduces payload length and returns number of bytes required to 403193323Sed * store MAC and eventual padding. Subsequent call to EVP_Cipher even 404263508Sdim * appends/verifies MAC. 405193323Sed */ 406212904Sdim# define EVP_CTRL_AEAD_TLS1_AAD 0x16 407212904Sdim/* Used by composite AEAD ciphers, no-op in GCM, CCM... */ 408193323Sed# define EVP_CTRL_AEAD_SET_MAC_KEY 0x17 409198090Srdivacky/* Set the GCM invocation field, decrypt only */ 410263508Sdim# define EVP_CTRL_GCM_SET_IV_INV 0x18 411263508Sdim 412263508Sdim/* GCM TLS constants */ 413263508Sdim/* Length of fixed part of IV derived from PRF */ 414239462Sdim# define EVP_GCM_TLS_FIXED_IV_LEN 4 415239462Sdim/* Length of explicit part of IV part of TLS records */ 416263508Sdim# define EVP_GCM_TLS_EXPLICIT_IV_LEN 8 417263508Sdim/* Length of tag for TLS */ 418193323Sed# define EVP_GCM_TLS_TAG_LEN 16 419193323Sed 420193323Sedtypedef struct evp_cipher_info_st { 421193323Sed const EVP_CIPHER *cipher; 422193323Sed unsigned char iv[EVP_MAX_IV_LENGTH]; 423193323Sed} EVP_CIPHER_INFO; 424234353Sdim 425193323Sedstruct evp_cipher_ctx_st { 426234353Sdim const EVP_CIPHER *cipher; 427234353Sdim ENGINE *engine; /* functional reference if 'cipher' is 428193323Sed * ENGINE-provided */ 429193323Sed int encrypt; /* encrypt or decrypt */ 430263508Sdim int buf_len; /* number we have left */ 431243830Sdim unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */ 432193323Sed unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */ 433234353Sdim unsigned char buf[EVP_MAX_BLOCK_LENGTH]; /* saved partial block */ 434193323Sed int num; /* used by cfb/ofb/ctr mode */ 435193323Sed void *app_data; /* application stuff */ 436249423Sdim int key_len; /* May change for variable length cipher */ 437234353Sdim unsigned long flags; /* Various flags */ 438234353Sdim void *cipher_data; /* per EVP data */ 439212904Sdim int final_used; 440193323Sed int block_mask; 441263508Sdim unsigned char final[EVP_MAX_BLOCK_LENGTH]; /* possible final block */ 442234353Sdim} /* EVP_CIPHER_CTX */ ; 443234353Sdim 444234353Sdimtypedef struct evp_Encode_Ctx_st { 445193323Sed /* number saved in a partial encode/decode */ 446263508Sdim int num; 447234353Sdim /* 448234353Sdim * The length is either the output line length (in input bytes) or the 449234353Sdim * shortest input line length that is ok. Once decoding begins, the 450193323Sed * length is adjusted up each time a longer line is decoded 451193323Sed */ 452193323Sed int length; 453193323Sed /* data to encode */ 454193323Sed unsigned char enc_data[80]; 455263508Sdim /* number read on current line */ 456234353Sdim int line_num; 457263508Sdim int expect_nl; 458193323Sed} EVP_ENCODE_CTX; 459193323Sed 460249423Sdim/* Password based encryption function */ 461249423Sdimtypedef int (EVP_PBE_KEYGEN) (EVP_CIPHER_CTX *ctx, const char *pass, 462249423Sdim int passlen, ASN1_TYPE *param, 463249423Sdim const EVP_CIPHER *cipher, const EVP_MD *md, 464193323Sed int en_de); 465249423Sdim 466193323Sed# ifndef OPENSSL_NO_RSA 467193323Sed# define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ 468263508Sdim (char *)(rsa)) 469193323Sed# endif 470193323Sed 471193323Sed# ifndef OPENSSL_NO_DSA 472193323Sed# define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ 473193323Sed (char *)(dsa)) 474193323Sed# endif 475212904Sdim 476193323Sed# ifndef OPENSSL_NO_DH 477193323Sed# define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\ 478193323Sed (char *)(dh)) 479193323Sed# endif 480193323Sed 481193323Sed# ifndef OPENSSL_NO_EC 482193323Sed# define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC,\ 483263508Sdim (char *)(eckey)) 484249423Sdim# endif 485249423Sdim 486249423Sdim/* Add some extra combinations */ 487193323Sed# define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) 488193323Sed# define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) 489263508Sdim# define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) 490263508Sdim# define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) 491263508Sdim 492263508Sdimint EVP_MD_type(const EVP_MD *md); 493263508Sdim# define EVP_MD_nid(e) EVP_MD_type(e) 494263508Sdim# define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e)) 495249423Sdimint EVP_MD_pkey_type(const EVP_MD *md); 496249423Sdimint EVP_MD_size(const EVP_MD *md); 497249423Sdimint EVP_MD_block_size(const EVP_MD *md); 498193323Sedunsigned long EVP_MD_flags(const EVP_MD *md); 499193323Sed 500263508Sdimconst EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx); 501263508Sdim# define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) 502263508Sdim# define EVP_MD_CTX_block_size(e) EVP_MD_block_size(EVP_MD_CTX_md(e)) 503263508Sdim# define EVP_MD_CTX_type(e) EVP_MD_type(EVP_MD_CTX_md(e)) 504263508Sdim 505263508Sdimint EVP_CIPHER_nid(const EVP_CIPHER *cipher); 506263508Sdim# define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e)) 507263508Sdimint EVP_CIPHER_block_size(const EVP_CIPHER *cipher); 508249423Sdimint EVP_CIPHER_key_length(const EVP_CIPHER *cipher); 509249423Sdimint EVP_CIPHER_iv_length(const EVP_CIPHER *cipher); 510249423Sdimunsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher); 511249423Sdim# define EVP_CIPHER_mode(e) (EVP_CIPHER_flags(e) & EVP_CIPH_MODE) 512193323Sed 513193323Sedconst EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx); 514193323Sedint EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx); 515193323Sedint EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx); 516263508Sdimint EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx); 517193323Sedint EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx); 518263508Sdimint EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in); 519193323Sedvoid *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx); 520193323Sedvoid EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data); 521193323Sed# define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) 522193323Sedunsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx); 523193323Sed# define EVP_CIPHER_CTX_mode(e) (EVP_CIPHER_CTX_flags(e) & EVP_CIPH_MODE) 524193323Sed 525193323Sed# define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) 526193323Sed# define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) 527193323Sed 528198090Srdivacky# define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) 529193323Sed# define EVP_SignInit(a,b) EVP_DigestInit(a,b) 530193323Sed# define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) 531193323Sed# define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) 532263508Sdim# define EVP_VerifyInit(a,b) EVP_DigestInit(a,b) 533193323Sed# define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) 534263508Sdim# define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) 535263508Sdim# define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) 536212904Sdim# define EVP_DigestSignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) 537193323Sed# define EVP_DigestVerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) 538193323Sed 539263508Sdim# ifdef CONST_STRICT 540263508Sdimvoid BIO_set_md(BIO *, const EVP_MD *md); 541263508Sdim# else 542263508Sdim# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md) 543193323Sed# endif 544193323Sed# define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp) 545263508Sdim# define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp) 546193323Sed# define BIO_set_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_SET_MD_CTX,0,(char *)mdcp) 547263508Sdim# define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) 548193323Sed# define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp) 549193323Sed 550212904Sdimint EVP_Cipher(EVP_CIPHER_CTX *c, 551193323Sed unsigned char *out, const unsigned char *in, unsigned int inl); 552193323Sed 553263508Sdim# define EVP_add_cipher_alias(n,alias) \ 554212904Sdim OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n)) 555263508Sdim# define EVP_add_digest_alias(n,alias) \ 556263508Sdim OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n)) 557193323Sed# define EVP_delete_cipher_alias(alias) \ 558193323Sed OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS); 559263508Sdim# define EVP_delete_digest_alias(alias) \ 560263508Sdim OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS); 561263508Sdim 562263508Sdimvoid EVP_MD_CTX_init(EVP_MD_CTX *ctx); 563193323Sedint EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx); 564193323SedEVP_MD_CTX *EVP_MD_CTX_create(void); 565193323Sedvoid EVP_MD_CTX_destroy(EVP_MD_CTX *ctx); 566212904Sdimint EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); 567212904Sdimvoid EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); 568212904Sdimvoid EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); 569212904Sdimint EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); 570193323Sedint EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); 571193323Sedint EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); 572193323Sedint EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s); 573193323Sedint EVP_Digest(const void *data, size_t count, 574193323Sed unsigned char *md, unsigned int *size, const EVP_MD *type, 575193323Sed ENGINE *impl); 576198090Srdivacky 577193323Sedint EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in); 578193323Sedint EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); 579193323Sedint EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s); 580263508Sdim 581263508Sdimint EVP_read_pw_string(char *buf, int length, const char *prompt, int verify); 582193323Sedint EVP_read_pw_string_min(char *buf, int minlen, int maxlen, 583193323Sed const char *prompt, int verify); 584243830Sdimvoid EVP_set_pw_prompt(const char *prompt); 585263508Sdimchar *EVP_get_pw_prompt(void); 586202375Srdivacky 587193323Sedint EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, 588243830Sdim const unsigned char *salt, const unsigned char *data, 589193323Sed int datal, int count, unsigned char *key, 590263508Sdim unsigned char *iv); 591193323Sed 592239462Sdimvoid EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags); 593193323Sedvoid EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags); 594263508Sdimint EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags); 595210299Sed 596210299Sedint EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 597210299Sed const unsigned char *key, const unsigned char *iv); 598193323Sedint EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 599210299Sed ENGINE *impl, const unsigned char *key, 600193323Sed const unsigned char *iv); 601193323Sedint EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, 602193323Sed const unsigned char *in, int inl); 603193323Sedint EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); 604193323Sedint EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); 605193323Sed 606193323Sedint EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 607193323Sed const unsigned char *key, const unsigned char *iv); 608193323Sedint EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 609194612Sed ENGINE *impl, const unsigned char *key, 610193323Sed const unsigned char *iv); 611193323Sedint EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, 612218893Sdim const unsigned char *in, int inl); 613218893Sdimint EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); 614239462Sdimint EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); 615193323Sed 616193323Sedint EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 617193323Sed const unsigned char *key, const unsigned char *iv, 618193323Sed int enc); 619193323Sedint EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 620263508Sdim ENGINE *impl, const unsigned char *key, 621263508Sdim const unsigned char *iv, int enc); 622263508Sdimint EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, 623263508Sdim const unsigned char *in, int inl); 624263508Sdimint EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); 625243830Sdimint EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); 626263508Sdim 627263508Sdimint EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s, 628263508Sdim EVP_PKEY *pkey); 629263508Sdim 630193323Sedint EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, 631202375Srdivacky unsigned int siglen, EVP_PKEY *pkey); 632193323Sed 633243830Sdimint EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, 634193323Sed const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); 635239462Sdimint EVP_DigestSignFinal(EVP_MD_CTX *ctx, 636263508Sdim unsigned char *sigret, size_t *siglen); 637239462Sdim 638239462Sdimint EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, 639239462Sdim const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); 640239462Sdimint EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t siglen); 641239462Sdim 642263508Sdimint EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, 643239462Sdim const unsigned char *ek, int ekl, const unsigned char *iv, 644239462Sdim EVP_PKEY *priv); 645239462Sdimint EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); 646239462Sdim 647239462Sdimint EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, 648239462Sdim unsigned char **ek, int *ekl, unsigned char *iv, 649239462Sdim EVP_PKEY **pubk, int npubk); 650239462Sdimint EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); 651239462Sdim 652193323Sedvoid EVP_EncodeInit(EVP_ENCODE_CTX *ctx); 653239462Sdimvoid EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, 654249423Sdim const unsigned char *in, int inl); 655249423Sdimvoid EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl); 656249423Sdimint EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n); 657249423Sdim 658249423Sdimvoid EVP_DecodeInit(EVP_ENCODE_CTX *ctx); 659249423Sdimint EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, 660249423Sdim const unsigned char *in, int inl); 661249423Sdimint EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned 662249423Sdim char *out, int *outl); 663249423Sdimint EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n); 664249423Sdim 665249423Sdimvoid EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); 666263508Sdimint EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); 667263508SdimEVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void); 668249423Sdimvoid EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *a); 669249423Sdimint EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); 670263508Sdimint EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad); 671249423Sdimint EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); 672249423Sdimint EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key); 673249423Sdim 674249423Sdim# ifndef OPENSSL_NO_BIO 675249423SdimBIO_METHOD *BIO_f_md(void); 676249423SdimBIO_METHOD *BIO_f_base64(void); 677249423SdimBIO_METHOD *BIO_f_cipher(void); 678249423SdimBIO_METHOD *BIO_f_reliable(void); 679249423Sdimvoid BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k, 680249423Sdim const unsigned char *i, int enc); 681249423Sdim# endif 682249423Sdim 683249423Sdimconst EVP_MD *EVP_md_null(void); 684249423Sdim# ifndef OPENSSL_NO_MD2 685263508Sdimconst EVP_MD *EVP_md2(void); 686263508Sdim# endif 687249423Sdim# ifndef OPENSSL_NO_MD4 688249423Sdimconst EVP_MD *EVP_md4(void); 689249423Sdim# endif 690249423Sdim# ifndef OPENSSL_NO_MD5 691263508Sdimconst EVP_MD *EVP_md5(void); 692263508Sdim# endif 693249423Sdim# ifndef OPENSSL_NO_SHA 694249423Sdimconst EVP_MD *EVP_sha(void); 695263508Sdimconst EVP_MD *EVP_sha1(void); 696249423Sdimconst EVP_MD *EVP_dss(void); 697249423Sdimconst EVP_MD *EVP_dss1(void); 698249423Sdimconst EVP_MD *EVP_ecdsa(void); 699249423Sdim# endif 700249423Sdim# ifndef OPENSSL_NO_SHA256 701263508Sdimconst EVP_MD *EVP_sha224(void); 702249423Sdimconst EVP_MD *EVP_sha256(void); 703249423Sdim# endif 704249423Sdim# ifndef OPENSSL_NO_SHA512 705249423Sdimconst EVP_MD *EVP_sha384(void); 706249423Sdimconst EVP_MD *EVP_sha512(void); 707249423Sdim# endif 708249423Sdim# ifndef OPENSSL_NO_MDC2 709249423Sdimconst EVP_MD *EVP_mdc2(void); 710249423Sdim# endif 711249423Sdim# ifndef OPENSSL_NO_RIPEMD 712263508Sdimconst EVP_MD *EVP_ripemd160(void); 713263508Sdim# endif 714263508Sdim# ifndef OPENSSL_NO_WHIRLPOOL 715249423Sdimconst EVP_MD *EVP_whirlpool(void); 716249423Sdim# endif 717249423Sdimconst EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ 718249423Sdim# ifndef OPENSSL_NO_DES 719249423Sdimconst EVP_CIPHER *EVP_des_ecb(void); 720249423Sdimconst EVP_CIPHER *EVP_des_ede(void); 721249423Sdimconst EVP_CIPHER *EVP_des_ede3(void); 722249423Sdimconst EVP_CIPHER *EVP_des_ede_ecb(void); 723263508Sdimconst EVP_CIPHER *EVP_des_ede3_ecb(void); 724263508Sdimconst EVP_CIPHER *EVP_des_cfb64(void); 725249423Sdim# define EVP_des_cfb EVP_des_cfb64 726249423Sdimconst EVP_CIPHER *EVP_des_cfb1(void); 727249423Sdimconst EVP_CIPHER *EVP_des_cfb8(void); 728249423Sdimconst EVP_CIPHER *EVP_des_ede_cfb64(void); 729249423Sdim# define EVP_des_ede_cfb EVP_des_ede_cfb64 730249423Sdim# if 0 731249423Sdimconst EVP_CIPHER *EVP_des_ede_cfb1(void); 732263508Sdimconst EVP_CIPHER *EVP_des_ede_cfb8(void); 733249423Sdim# endif 734249423Sdimconst EVP_CIPHER *EVP_des_ede3_cfb64(void); 735249423Sdim# define EVP_des_ede3_cfb EVP_des_ede3_cfb64 736249423Sdimconst EVP_CIPHER *EVP_des_ede3_cfb1(void); 737249423Sdimconst EVP_CIPHER *EVP_des_ede3_cfb8(void); 738249423Sdimconst EVP_CIPHER *EVP_des_ofb(void); 739263508Sdimconst EVP_CIPHER *EVP_des_ede_ofb(void); 740249423Sdimconst EVP_CIPHER *EVP_des_ede3_ofb(void); 741249423Sdimconst EVP_CIPHER *EVP_des_cbc(void); 742249423Sdimconst EVP_CIPHER *EVP_des_ede_cbc(void); 743249423Sdimconst EVP_CIPHER *EVP_des_ede3_cbc(void); 744249423Sdimconst EVP_CIPHER *EVP_desx_cbc(void); 745249423Sdim/* 746263508Sdim * This should now be supported through the dev_crypto ENGINE. But also, why 747249423Sdim * are rc4 and md5 declarations made here inside a "NO_DES" precompiler 748249423Sdim * branch? 749249423Sdim */ 750249423Sdim# if 0 751249423Sdim# ifdef OPENSSL_OPENBSD_DEV_CRYPTO 752249423Sdimconst EVP_CIPHER *EVP_dev_crypto_des_ede3_cbc(void); 753249423Sdimconst EVP_CIPHER *EVP_dev_crypto_rc4(void); 754249423Sdimconst EVP_MD *EVP_dev_crypto_md5(void); 755249423Sdim# endif 756249423Sdim# endif 757249423Sdim# endif 758249423Sdim# ifndef OPENSSL_NO_RC4 759249423Sdimconst EVP_CIPHER *EVP_rc4(void); 760249423Sdimconst EVP_CIPHER *EVP_rc4_40(void); 761249423Sdim# ifndef OPENSSL_NO_MD5 762249423Sdimconst EVP_CIPHER *EVP_rc4_hmac_md5(void); 763249423Sdim# endif 764249423Sdim# endif 765249423Sdim# ifndef OPENSSL_NO_IDEA 766249423Sdimconst EVP_CIPHER *EVP_idea_ecb(void); 767249423Sdimconst EVP_CIPHER *EVP_idea_cfb64(void); 768249423Sdim# define EVP_idea_cfb EVP_idea_cfb64 769249423Sdimconst EVP_CIPHER *EVP_idea_ofb(void); 770249423Sdimconst EVP_CIPHER *EVP_idea_cbc(void); 771249423Sdim# endif 772249423Sdim# ifndef OPENSSL_NO_RC2 773249423Sdimconst EVP_CIPHER *EVP_rc2_ecb(void); 774249423Sdimconst EVP_CIPHER *EVP_rc2_cbc(void); 775249423Sdimconst EVP_CIPHER *EVP_rc2_40_cbc(void); 776249423Sdimconst EVP_CIPHER *EVP_rc2_64_cbc(void); 777249423Sdimconst EVP_CIPHER *EVP_rc2_cfb64(void); 778249423Sdim# define EVP_rc2_cfb EVP_rc2_cfb64 779263508Sdimconst EVP_CIPHER *EVP_rc2_ofb(void); 780249423Sdim# endif 781249423Sdim# ifndef OPENSSL_NO_BF 782249423Sdimconst EVP_CIPHER *EVP_bf_ecb(void); 783249423Sdimconst EVP_CIPHER *EVP_bf_cbc(void); 784249423Sdimconst EVP_CIPHER *EVP_bf_cfb64(void); 785249423Sdim# define EVP_bf_cfb EVP_bf_cfb64 786249423Sdimconst EVP_CIPHER *EVP_bf_ofb(void); 787249423Sdim# endif 788249423Sdim# ifndef OPENSSL_NO_CAST 789249423Sdimconst EVP_CIPHER *EVP_cast5_ecb(void); 790263508Sdimconst EVP_CIPHER *EVP_cast5_cbc(void); 791249423Sdimconst EVP_CIPHER *EVP_cast5_cfb64(void); 792263508Sdim# define EVP_cast5_cfb EVP_cast5_cfb64 793263508Sdimconst EVP_CIPHER *EVP_cast5_ofb(void); 794249423Sdim# endif 795249423Sdim# ifndef OPENSSL_NO_RC5 796249423Sdimconst EVP_CIPHER *EVP_rc5_32_12_16_cbc(void); 797249423Sdimconst EVP_CIPHER *EVP_rc5_32_12_16_ecb(void); 798249423Sdimconst EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void); 799249423Sdim# define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64 800249423Sdimconst EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); 801249423Sdim# endif 802249423Sdim# ifndef OPENSSL_NO_AES 803249423Sdimconst EVP_CIPHER *EVP_aes_128_ecb(void); 804263508Sdimconst EVP_CIPHER *EVP_aes_128_cbc(void); 805263508Sdimconst EVP_CIPHER *EVP_aes_128_cfb1(void); 806263508Sdimconst EVP_CIPHER *EVP_aes_128_cfb8(void); 807263508Sdimconst EVP_CIPHER *EVP_aes_128_cfb128(void); 808249423Sdim# define EVP_aes_128_cfb EVP_aes_128_cfb128 809249423Sdimconst EVP_CIPHER *EVP_aes_128_ofb(void); 810249423Sdimconst EVP_CIPHER *EVP_aes_128_ctr(void); 811249423Sdimconst EVP_CIPHER *EVP_aes_128_ccm(void); 812249423Sdimconst EVP_CIPHER *EVP_aes_128_gcm(void); 813249423Sdimconst EVP_CIPHER *EVP_aes_128_xts(void); 814249423Sdimconst EVP_CIPHER *EVP_aes_192_ecb(void); 815249423Sdimconst EVP_CIPHER *EVP_aes_192_cbc(void); 816249423Sdimconst EVP_CIPHER *EVP_aes_192_cfb1(void); 817249423Sdimconst EVP_CIPHER *EVP_aes_192_cfb8(void); 818249423Sdimconst EVP_CIPHER *EVP_aes_192_cfb128(void); 819249423Sdim# define EVP_aes_192_cfb EVP_aes_192_cfb128 820249423Sdimconst EVP_CIPHER *EVP_aes_192_ofb(void); 821249423Sdimconst EVP_CIPHER *EVP_aes_192_ctr(void); 822249423Sdimconst EVP_CIPHER *EVP_aes_192_ccm(void); 823249423Sdimconst EVP_CIPHER *EVP_aes_192_gcm(void); 824249423Sdimconst EVP_CIPHER *EVP_aes_256_ecb(void); 825249423Sdimconst EVP_CIPHER *EVP_aes_256_cbc(void); 826249423Sdimconst EVP_CIPHER *EVP_aes_256_cfb1(void); 827249423Sdimconst EVP_CIPHER *EVP_aes_256_cfb8(void); 828249423Sdimconst EVP_CIPHER *EVP_aes_256_cfb128(void); 829263508Sdim# define EVP_aes_256_cfb EVP_aes_256_cfb128 830249423Sdimconst EVP_CIPHER *EVP_aes_256_ofb(void); 831249423Sdimconst EVP_CIPHER *EVP_aes_256_ctr(void); 832249423Sdimconst EVP_CIPHER *EVP_aes_256_ccm(void); 833263508Sdimconst EVP_CIPHER *EVP_aes_256_gcm(void); 834263508Sdimconst EVP_CIPHER *EVP_aes_256_xts(void); 835249423Sdim# if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1) 836249423Sdimconst EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void); 837249423Sdimconst EVP_CIPHER *EVP_aes_256_cbc_hmac_sha1(void); 838249423Sdim# endif 839249423Sdim# endif 840249423Sdim# ifndef OPENSSL_NO_CAMELLIA 841249423Sdimconst EVP_CIPHER *EVP_camellia_128_ecb(void); 842263508Sdimconst EVP_CIPHER *EVP_camellia_128_cbc(void); 843263508Sdimconst EVP_CIPHER *EVP_camellia_128_cfb1(void); 844249423Sdimconst EVP_CIPHER *EVP_camellia_128_cfb8(void); 845263508Sdimconst EVP_CIPHER *EVP_camellia_128_cfb128(void); 846249423Sdim# define EVP_camellia_128_cfb EVP_camellia_128_cfb128 847249423Sdimconst EVP_CIPHER *EVP_camellia_128_ofb(void); 848263508Sdimconst EVP_CIPHER *EVP_camellia_192_ecb(void); 849249423Sdimconst EVP_CIPHER *EVP_camellia_192_cbc(void); 850249423Sdimconst EVP_CIPHER *EVP_camellia_192_cfb1(void); 851249423Sdimconst EVP_CIPHER *EVP_camellia_192_cfb8(void); 852263508Sdimconst EVP_CIPHER *EVP_camellia_192_cfb128(void); 853249423Sdim# define EVP_camellia_192_cfb EVP_camellia_192_cfb128 854249423Sdimconst EVP_CIPHER *EVP_camellia_192_ofb(void); 855218893Sdimconst EVP_CIPHER *EVP_camellia_256_ecb(void); 856218893Sdimconst EVP_CIPHER *EVP_camellia_256_cbc(void); 857221345Sdimconst EVP_CIPHER *EVP_camellia_256_cfb1(void); 858221345Sdimconst EVP_CIPHER *EVP_camellia_256_cfb8(void); 859218893Sdimconst EVP_CIPHER *EVP_camellia_256_cfb128(void); 860218893Sdim# define EVP_camellia_256_cfb EVP_camellia_256_cfb128 861218893Sdimconst EVP_CIPHER *EVP_camellia_256_ofb(void); 862218893Sdim# endif 863218893Sdim 864218893Sdim# ifndef OPENSSL_NO_SEED 865218893Sdimconst EVP_CIPHER *EVP_seed_ecb(void); 866218893Sdimconst EVP_CIPHER *EVP_seed_cbc(void); 867218893Sdimconst EVP_CIPHER *EVP_seed_cfb128(void); 868218893Sdim# define EVP_seed_cfb EVP_seed_cfb128 869221345Sdimconst EVP_CIPHER *EVP_seed_ofb(void); 870218893Sdim# endif 871218893Sdim 872218893Sdimvoid OPENSSL_add_all_algorithms_noconf(void); 873218893Sdimvoid OPENSSL_add_all_algorithms_conf(void); 874218893Sdim 875221345Sdim# ifdef OPENSSL_LOAD_CONF 876218893Sdim# define OpenSSL_add_all_algorithms() \ 877218893Sdim OPENSSL_add_all_algorithms_conf() 878218893Sdim# else 879218893Sdim# define OpenSSL_add_all_algorithms() \ 880234353Sdim OPENSSL_add_all_algorithms_noconf() 881221345Sdim# endif 882218893Sdim 883218893Sdimvoid OpenSSL_add_all_ciphers(void); 884218893Sdimvoid OpenSSL_add_all_digests(void); 885218893Sdim# define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms() 886218893Sdim# define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers() 887234353Sdim# define SSLeay_add_all_digests() OpenSSL_add_all_digests() 888221345Sdim 889218893Sdimint EVP_add_cipher(const EVP_CIPHER *cipher); 890218893Sdimint EVP_add_digest(const EVP_MD *digest); 891218893Sdim 892218893Sdimconst EVP_CIPHER *EVP_get_cipherbyname(const char *name); 893218893Sdimconst EVP_MD *EVP_get_digestbyname(const char *name); 894221345Sdimvoid EVP_cleanup(void); 895218893Sdim 896221345Sdimvoid EVP_CIPHER_do_all(void (*fn) (const EVP_CIPHER *ciph, 897221345Sdim const char *from, const char *to, void *x), 898218893Sdim void *arg); 899218893Sdimvoid EVP_CIPHER_do_all_sorted(void (*fn) 900221345Sdim (const EVP_CIPHER *ciph, const char *from, 901221345Sdim const char *to, void *x), void *arg); 902218893Sdim 903218893Sdimvoid EVP_MD_do_all(void (*fn) (const EVP_MD *ciph, 904218893Sdim const char *from, const char *to, void *x), 905221345Sdim void *arg); 906221345Sdimvoid EVP_MD_do_all_sorted(void (*fn) 907221345Sdim (const EVP_MD *ciph, const char *from, 908221345Sdim const char *to, void *x), void *arg); 909221345Sdim 910221345Sdimint EVP_PKEY_decrypt_old(unsigned char *dec_key, 911263508Sdim const unsigned char *enc_key, int enc_key_len, 912263508Sdim EVP_PKEY *private_key); 913263508Sdimint EVP_PKEY_encrypt_old(unsigned char *enc_key, 914263508Sdim const unsigned char *key, int key_len, 915263508Sdim EVP_PKEY *pub_key); 916263508Sdimint EVP_PKEY_type(int type); 917263508Sdimint EVP_PKEY_id(const EVP_PKEY *pkey); 918263508Sdimint EVP_PKEY_base_id(const EVP_PKEY *pkey); 919263508Sdimint EVP_PKEY_bits(EVP_PKEY *pkey); 920263508Sdimint EVP_PKEY_size(EVP_PKEY *pkey); 921239462Sdimint EVP_PKEY_set_type(EVP_PKEY *pkey, int type); 922239462Sdimint EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len); 923239462Sdimint EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key); 924239462Sdimvoid *EVP_PKEY_get0(EVP_PKEY *pkey); 925221345Sdim 926221345Sdim# ifndef OPENSSL_NO_RSA 927221345Sdimstruct rsa_st; 928221345Sdimint EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key); 929221345Sdimstruct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); 930218893Sdim# endif 931221345Sdim# ifndef OPENSSL_NO_DSA 932218893Sdimstruct dsa_st; 933218893Sdimint EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key); 934221345Sdimstruct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); 935218893Sdim# endif 936218893Sdim# ifndef OPENSSL_NO_DH 937263508Sdimstruct dh_st; 938218893Sdimint EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key); 939218893Sdimstruct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey); 940218893Sdim# endif 941263508Sdim# ifndef OPENSSL_NO_EC 942218893Sdimstruct ec_key_st; 943218893Sdimint EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); 944218893Sdimstruct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); 945221345Sdim# endif 946218893Sdim 947218893SdimEVP_PKEY *EVP_PKEY_new(void); 948218893Sdimvoid EVP_PKEY_free(EVP_PKEY *pkey); 949221345Sdim 950218893SdimEVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, 951218893Sdim long length); 952218893Sdimint i2d_PublicKey(EVP_PKEY *a, unsigned char **pp); 953218893Sdim 954218893SdimEVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, 955218893Sdim long length); 956218893SdimEVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, 957218893Sdim long length); 958218893Sdimint i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); 959 960int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); 961int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); 962int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode); 963int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b); 964 965int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b); 966 967int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, 968 int indent, ASN1_PCTX *pctx); 969int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, 970 int indent, ASN1_PCTX *pctx); 971int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, 972 int indent, ASN1_PCTX *pctx); 973 974int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid); 975 976int EVP_CIPHER_type(const EVP_CIPHER *ctx); 977 978/* calls methods */ 979int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); 980int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); 981 982/* These are used by EVP_CIPHER methods */ 983int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); 984int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); 985 986/* PKCS5 password based encryption */ 987int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 988 ASN1_TYPE *param, const EVP_CIPHER *cipher, 989 const EVP_MD *md, int en_de); 990int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, 991 const unsigned char *salt, int saltlen, int iter, 992 int keylen, unsigned char *out); 993int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, 994 const unsigned char *salt, int saltlen, int iter, 995 const EVP_MD *digest, int keylen, unsigned char *out); 996int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 997 ASN1_TYPE *param, const EVP_CIPHER *cipher, 998 const EVP_MD *md, int en_de); 999 1000void PKCS5_PBE_add(void); 1001 1002int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, 1003 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de); 1004 1005/* PBE type */ 1006 1007/* Can appear as the outermost AlgorithmIdentifier */ 1008# define EVP_PBE_TYPE_OUTER 0x0 1009/* Is an PRF type OID */ 1010# define EVP_PBE_TYPE_PRF 0x1 1011 1012int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, 1013 int md_nid, EVP_PBE_KEYGEN *keygen); 1014int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md, 1015 EVP_PBE_KEYGEN *keygen); 1016int EVP_PBE_find(int type, int pbe_nid, int *pcnid, int *pmnid, 1017 EVP_PBE_KEYGEN **pkeygen); 1018void EVP_PBE_cleanup(void); 1019 1020# define ASN1_PKEY_ALIAS 0x1 1021# define ASN1_PKEY_DYNAMIC 0x2 1022# define ASN1_PKEY_SIGPARAM_NULL 0x4 1023 1024# define ASN1_PKEY_CTRL_PKCS7_SIGN 0x1 1025# define ASN1_PKEY_CTRL_PKCS7_ENCRYPT 0x2 1026# define ASN1_PKEY_CTRL_DEFAULT_MD_NID 0x3 1027# define ASN1_PKEY_CTRL_CMS_SIGN 0x5 1028# define ASN1_PKEY_CTRL_CMS_ENVELOPE 0x7 1029 1030int EVP_PKEY_asn1_get_count(void); 1031const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx); 1032const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type); 1033const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, 1034 const char *str, int len); 1035int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth); 1036int EVP_PKEY_asn1_add_alias(int to, int from); 1037int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id, 1038 int *ppkey_flags, const char **pinfo, 1039 const char **ppem_str, 1040 const EVP_PKEY_ASN1_METHOD *ameth); 1041 1042const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(EVP_PKEY *pkey); 1043EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags, 1044 const char *pem_str, 1045 const char *info); 1046void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, 1047 const EVP_PKEY_ASN1_METHOD *src); 1048void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth); 1049void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, 1050 int (*pub_decode) (EVP_PKEY *pk, 1051 X509_PUBKEY *pub), 1052 int (*pub_encode) (X509_PUBKEY *pub, 1053 const EVP_PKEY *pk), 1054 int (*pub_cmp) (const EVP_PKEY *a, 1055 const EVP_PKEY *b), 1056 int (*pub_print) (BIO *out, 1057 const EVP_PKEY *pkey, 1058 int indent, ASN1_PCTX *pctx), 1059 int (*pkey_size) (const EVP_PKEY *pk), 1060 int (*pkey_bits) (const EVP_PKEY *pk)); 1061void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, 1062 int (*priv_decode) (EVP_PKEY *pk, 1063 PKCS8_PRIV_KEY_INFO 1064 *p8inf), 1065 int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, 1066 const EVP_PKEY *pk), 1067 int (*priv_print) (BIO *out, 1068 const EVP_PKEY *pkey, 1069 int indent, 1070 ASN1_PCTX *pctx)); 1071void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, 1072 int (*param_decode) (EVP_PKEY *pkey, 1073 const unsigned char **pder, 1074 int derlen), 1075 int (*param_encode) (const EVP_PKEY *pkey, 1076 unsigned char **pder), 1077 int (*param_missing) (const EVP_PKEY *pk), 1078 int (*param_copy) (EVP_PKEY *to, 1079 const EVP_PKEY *from), 1080 int (*param_cmp) (const EVP_PKEY *a, 1081 const EVP_PKEY *b), 1082 int (*param_print) (BIO *out, 1083 const EVP_PKEY *pkey, 1084 int indent, 1085 ASN1_PCTX *pctx)); 1086 1087void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, 1088 void (*pkey_free) (EVP_PKEY *pkey)); 1089void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, 1090 int (*pkey_ctrl) (EVP_PKEY *pkey, int op, 1091 long arg1, void *arg2)); 1092 1093# define EVP_PKEY_OP_UNDEFINED 0 1094# define EVP_PKEY_OP_PARAMGEN (1<<1) 1095# define EVP_PKEY_OP_KEYGEN (1<<2) 1096# define EVP_PKEY_OP_SIGN (1<<3) 1097# define EVP_PKEY_OP_VERIFY (1<<4) 1098# define EVP_PKEY_OP_VERIFYRECOVER (1<<5) 1099# define EVP_PKEY_OP_SIGNCTX (1<<6) 1100# define EVP_PKEY_OP_VERIFYCTX (1<<7) 1101# define EVP_PKEY_OP_ENCRYPT (1<<8) 1102# define EVP_PKEY_OP_DECRYPT (1<<9) 1103# define EVP_PKEY_OP_DERIVE (1<<10) 1104 1105# define EVP_PKEY_OP_TYPE_SIG \ 1106 (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY | EVP_PKEY_OP_VERIFYRECOVER \ 1107 | EVP_PKEY_OP_SIGNCTX | EVP_PKEY_OP_VERIFYCTX) 1108 1109# define EVP_PKEY_OP_TYPE_CRYPT \ 1110 (EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT) 1111 1112# define EVP_PKEY_OP_TYPE_NOGEN \ 1113 (EVP_PKEY_OP_SIG | EVP_PKEY_OP_CRYPT | EVP_PKEY_OP_DERIVE) 1114 1115# define EVP_PKEY_OP_TYPE_GEN \ 1116 (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN) 1117 1118# define EVP_PKEY_CTX_set_signature_md(ctx, md) \ 1119 EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, \ 1120 EVP_PKEY_CTRL_MD, 0, (void *)md) 1121 1122# define EVP_PKEY_CTRL_MD 1 1123# define EVP_PKEY_CTRL_PEER_KEY 2 1124 1125# define EVP_PKEY_CTRL_PKCS7_ENCRYPT 3 1126# define EVP_PKEY_CTRL_PKCS7_DECRYPT 4 1127 1128# define EVP_PKEY_CTRL_PKCS7_SIGN 5 1129 1130# define EVP_PKEY_CTRL_SET_MAC_KEY 6 1131 1132# define EVP_PKEY_CTRL_DIGESTINIT 7 1133 1134/* Used by GOST key encryption in TLS */ 1135# define EVP_PKEY_CTRL_SET_IV 8 1136 1137# define EVP_PKEY_CTRL_CMS_ENCRYPT 9 1138# define EVP_PKEY_CTRL_CMS_DECRYPT 10 1139# define EVP_PKEY_CTRL_CMS_SIGN 11 1140 1141# define EVP_PKEY_CTRL_CIPHER 12 1142 1143# define EVP_PKEY_ALG_CTRL 0x1000 1144 1145# define EVP_PKEY_FLAG_AUTOARGLEN 2 1146/* 1147 * Method handles all operations: don't assume any digest related defaults. 1148 */ 1149# define EVP_PKEY_FLAG_SIGCTX_CUSTOM 4 1150 1151const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type); 1152EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags); 1153void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, 1154 const EVP_PKEY_METHOD *meth); 1155void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src); 1156void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth); 1157int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth); 1158 1159EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); 1160EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e); 1161EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx); 1162void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); 1163 1164int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, 1165 int cmd, int p1, void *p2); 1166int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, 1167 const char *value); 1168 1169int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx); 1170void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen); 1171 1172EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, 1173 const unsigned char *key, int keylen); 1174 1175void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data); 1176void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx); 1177EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx); 1178 1179EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx); 1180 1181void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data); 1182void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx); 1183 1184int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx); 1185int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, 1186 unsigned char *sig, size_t *siglen, 1187 const unsigned char *tbs, size_t tbslen); 1188int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx); 1189int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, 1190 const unsigned char *sig, size_t siglen, 1191 const unsigned char *tbs, size_t tbslen); 1192int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); 1193int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, 1194 unsigned char *rout, size_t *routlen, 1195 const unsigned char *sig, size_t siglen); 1196int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx); 1197int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, 1198 unsigned char *out, size_t *outlen, 1199 const unsigned char *in, size_t inlen); 1200int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); 1201int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, 1202 unsigned char *out, size_t *outlen, 1203 const unsigned char *in, size_t inlen); 1204 1205int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); 1206int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); 1207int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen); 1208 1209typedef int EVP_PKEY_gen_cb (EVP_PKEY_CTX *ctx); 1210 1211int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx); 1212int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); 1213int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); 1214int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); 1215 1216void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb); 1217EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx); 1218 1219int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx); 1220 1221void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth, 1222 int (*init) (EVP_PKEY_CTX *ctx)); 1223 1224void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth, 1225 int (*copy) (EVP_PKEY_CTX *dst, 1226 EVP_PKEY_CTX *src)); 1227 1228void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth, 1229 void (*cleanup) (EVP_PKEY_CTX *ctx)); 1230 1231void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth, 1232 int (*paramgen_init) (EVP_PKEY_CTX *ctx), 1233 int (*paramgen) (EVP_PKEY_CTX *ctx, 1234 EVP_PKEY *pkey)); 1235 1236void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth, 1237 int (*keygen_init) (EVP_PKEY_CTX *ctx), 1238 int (*keygen) (EVP_PKEY_CTX *ctx, 1239 EVP_PKEY *pkey)); 1240 1241void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth, 1242 int (*sign_init) (EVP_PKEY_CTX *ctx), 1243 int (*sign) (EVP_PKEY_CTX *ctx, 1244 unsigned char *sig, size_t *siglen, 1245 const unsigned char *tbs, 1246 size_t tbslen)); 1247 1248void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth, 1249 int (*verify_init) (EVP_PKEY_CTX *ctx), 1250 int (*verify) (EVP_PKEY_CTX *ctx, 1251 const unsigned char *sig, 1252 size_t siglen, 1253 const unsigned char *tbs, 1254 size_t tbslen)); 1255 1256void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth, 1257 int (*verify_recover_init) (EVP_PKEY_CTX 1258 *ctx), 1259 int (*verify_recover) (EVP_PKEY_CTX 1260 *ctx, 1261 unsigned char 1262 *sig, 1263 size_t *siglen, 1264 const unsigned 1265 char *tbs, 1266 size_t tbslen)); 1267 1268void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth, 1269 int (*signctx_init) (EVP_PKEY_CTX *ctx, 1270 EVP_MD_CTX *mctx), 1271 int (*signctx) (EVP_PKEY_CTX *ctx, 1272 unsigned char *sig, 1273 size_t *siglen, 1274 EVP_MD_CTX *mctx)); 1275 1276void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth, 1277 int (*verifyctx_init) (EVP_PKEY_CTX *ctx, 1278 EVP_MD_CTX *mctx), 1279 int (*verifyctx) (EVP_PKEY_CTX *ctx, 1280 const unsigned char *sig, 1281 int siglen, 1282 EVP_MD_CTX *mctx)); 1283 1284void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth, 1285 int (*encrypt_init) (EVP_PKEY_CTX *ctx), 1286 int (*encryptfn) (EVP_PKEY_CTX *ctx, 1287 unsigned char *out, 1288 size_t *outlen, 1289 const unsigned char *in, 1290 size_t inlen)); 1291 1292void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth, 1293 int (*decrypt_init) (EVP_PKEY_CTX *ctx), 1294 int (*decrypt) (EVP_PKEY_CTX *ctx, 1295 unsigned char *out, 1296 size_t *outlen, 1297 const unsigned char *in, 1298 size_t inlen)); 1299 1300void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth, 1301 int (*derive_init) (EVP_PKEY_CTX *ctx), 1302 int (*derive) (EVP_PKEY_CTX *ctx, 1303 unsigned char *key, 1304 size_t *keylen)); 1305 1306void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth, 1307 int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, 1308 void *p2), 1309 int (*ctrl_str) (EVP_PKEY_CTX *ctx, 1310 const char *type, 1311 const char *value)); 1312 1313void EVP_add_alg_module(void); 1314 1315/* BEGIN ERROR CODES */ 1316/* 1317 * The following lines are auto generated by the script mkerr.pl. Any changes 1318 * made after this point may be overwritten when the script is next run. 1319 */ 1320void ERR_load_EVP_strings(void); 1321 1322/* Error codes for the EVP functions. */ 1323 1324/* Function codes. */ 1325# define EVP_F_AESNI_INIT_KEY 165 1326# define EVP_F_AESNI_XTS_CIPHER 176 1327# define EVP_F_AES_INIT_KEY 133 1328# define EVP_F_AES_XTS 172 1329# define EVP_F_AES_XTS_CIPHER 175 1330# define EVP_F_ALG_MODULE_INIT 177 1331# define EVP_F_CAMELLIA_INIT_KEY 159 1332# define EVP_F_CMAC_INIT 173 1333# define EVP_F_D2I_PKEY 100 1334# define EVP_F_DO_SIGVER_INIT 161 1335# define EVP_F_DSAPKEY2PKCS8 134 1336# define EVP_F_DSA_PKEY2PKCS8 135 1337# define EVP_F_ECDSA_PKEY2PKCS8 129 1338# define EVP_F_ECKEY_PKEY2PKCS8 132 1339# define EVP_F_EVP_CIPHERINIT_EX 123 1340# define EVP_F_EVP_CIPHER_CTX_COPY 163 1341# define EVP_F_EVP_CIPHER_CTX_CTRL 124 1342# define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122 1343# define EVP_F_EVP_DECRYPTFINAL_EX 101 1344# define EVP_F_EVP_DIGESTINIT_EX 128 1345# define EVP_F_EVP_ENCRYPTFINAL_EX 127 1346# define EVP_F_EVP_MD_CTX_COPY_EX 110 1347# define EVP_F_EVP_MD_SIZE 162 1348# define EVP_F_EVP_OPENINIT 102 1349# define EVP_F_EVP_PBE_ALG_ADD 115 1350# define EVP_F_EVP_PBE_ALG_ADD_TYPE 160 1351# define EVP_F_EVP_PBE_CIPHERINIT 116 1352# define EVP_F_EVP_PKCS82PKEY 111 1353# define EVP_F_EVP_PKCS82PKEY_BROKEN 136 1354# define EVP_F_EVP_PKEY2PKCS8_BROKEN 113 1355# define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 1356# define EVP_F_EVP_PKEY_CTX_CTRL 137 1357# define EVP_F_EVP_PKEY_CTX_CTRL_STR 150 1358# define EVP_F_EVP_PKEY_CTX_DUP 156 1359# define EVP_F_EVP_PKEY_DECRYPT 104 1360# define EVP_F_EVP_PKEY_DECRYPT_INIT 138 1361# define EVP_F_EVP_PKEY_DECRYPT_OLD 151 1362# define EVP_F_EVP_PKEY_DERIVE 153 1363# define EVP_F_EVP_PKEY_DERIVE_INIT 154 1364# define EVP_F_EVP_PKEY_DERIVE_SET_PEER 155 1365# define EVP_F_EVP_PKEY_ENCRYPT 105 1366# define EVP_F_EVP_PKEY_ENCRYPT_INIT 139 1367# define EVP_F_EVP_PKEY_ENCRYPT_OLD 152 1368# define EVP_F_EVP_PKEY_GET1_DH 119 1369# define EVP_F_EVP_PKEY_GET1_DSA 120 1370# define EVP_F_EVP_PKEY_GET1_ECDSA 130 1371# define EVP_F_EVP_PKEY_GET1_EC_KEY 131 1372# define EVP_F_EVP_PKEY_GET1_RSA 121 1373# define EVP_F_EVP_PKEY_KEYGEN 146 1374# define EVP_F_EVP_PKEY_KEYGEN_INIT 147 1375# define EVP_F_EVP_PKEY_NEW 106 1376# define EVP_F_EVP_PKEY_PARAMGEN 148 1377# define EVP_F_EVP_PKEY_PARAMGEN_INIT 149 1378# define EVP_F_EVP_PKEY_SIGN 140 1379# define EVP_F_EVP_PKEY_SIGN_INIT 141 1380# define EVP_F_EVP_PKEY_VERIFY 142 1381# define EVP_F_EVP_PKEY_VERIFY_INIT 143 1382# define EVP_F_EVP_PKEY_VERIFY_RECOVER 144 1383# define EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT 145 1384# define EVP_F_EVP_RIJNDAEL 126 1385# define EVP_F_EVP_SIGNFINAL 107 1386# define EVP_F_EVP_VERIFYFINAL 108 1387# define EVP_F_FIPS_CIPHERINIT 166 1388# define EVP_F_FIPS_CIPHER_CTX_COPY 170 1389# define EVP_F_FIPS_CIPHER_CTX_CTRL 167 1390# define EVP_F_FIPS_CIPHER_CTX_SET_KEY_LENGTH 171 1391# define EVP_F_FIPS_DIGESTINIT 168 1392# define EVP_F_FIPS_MD_CTX_COPY 169 1393# define EVP_F_HMAC_INIT_EX 174 1394# define EVP_F_INT_CTX_NEW 157 1395# define EVP_F_PKCS5_PBE_KEYIVGEN 117 1396# define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118 1397# define EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN 164 1398# define EVP_F_PKCS8_SET_BROKEN 112 1399# define EVP_F_PKEY_SET_TYPE 158 1400# define EVP_F_RC2_MAGIC_TO_METH 109 1401# define EVP_F_RC5_CTRL 125 1402 1403/* Reason codes. */ 1404# define EVP_R_AES_IV_SETUP_FAILED 162 1405# define EVP_R_AES_KEY_SETUP_FAILED 143 1406# define EVP_R_ASN1_LIB 140 1407# define EVP_R_BAD_BLOCK_LENGTH 136 1408# define EVP_R_BAD_DECRYPT 100 1409# define EVP_R_BAD_KEY_LENGTH 137 1410# define EVP_R_BN_DECODE_ERROR 112 1411# define EVP_R_BN_PUBKEY_ERROR 113 1412# define EVP_R_BUFFER_TOO_SMALL 155 1413# define EVP_R_CAMELLIA_KEY_SETUP_FAILED 157 1414# define EVP_R_CIPHER_PARAMETER_ERROR 122 1415# define EVP_R_COMMAND_NOT_SUPPORTED 147 1416# define EVP_R_CTRL_NOT_IMPLEMENTED 132 1417# define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133 1418# define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138 1419# define EVP_R_DECODE_ERROR 114 1420# define EVP_R_DIFFERENT_KEY_TYPES 101 1421# define EVP_R_DIFFERENT_PARAMETERS 153 1422# define EVP_R_DISABLED_FOR_FIPS 163 1423# define EVP_R_ENCODE_ERROR 115 1424# define EVP_R_ERROR_LOADING_SECTION 165 1425# define EVP_R_ERROR_SETTING_FIPS_MODE 166 1426# define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119 1427# define EVP_R_EXPECTING_AN_RSA_KEY 127 1428# define EVP_R_EXPECTING_A_DH_KEY 128 1429# define EVP_R_EXPECTING_A_DSA_KEY 129 1430# define EVP_R_EXPECTING_A_ECDSA_KEY 141 1431# define EVP_R_EXPECTING_A_EC_KEY 142 1432# define EVP_R_FIPS_MODE_NOT_SUPPORTED 167 1433# define EVP_R_INITIALIZATION_ERROR 134 1434# define EVP_R_INPUT_NOT_INITIALIZED 111 1435# define EVP_R_INVALID_DIGEST 152 1436# define EVP_R_INVALID_FIPS_MODE 168 1437# define EVP_R_INVALID_KEY_LENGTH 130 1438# define EVP_R_INVALID_OPERATION 148 1439# define EVP_R_IV_TOO_LARGE 102 1440# define EVP_R_KEYGEN_FAILURE 120 1441# define EVP_R_MESSAGE_DIGEST_IS_NULL 159 1442# define EVP_R_METHOD_NOT_SUPPORTED 144 1443# define EVP_R_MISSING_PARAMETERS 103 1444# define EVP_R_NO_CIPHER_SET 131 1445# define EVP_R_NO_DEFAULT_DIGEST 158 1446# define EVP_R_NO_DIGEST_SET 139 1447# define EVP_R_NO_DSA_PARAMETERS 116 1448# define EVP_R_NO_KEY_SET 154 1449# define EVP_R_NO_OPERATION_SET 149 1450# define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 1451# define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 1452# define EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 150 1453# define EVP_R_OPERATON_NOT_INITIALIZED 151 1454# define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117 1455# define EVP_R_PRIVATE_KEY_DECODE_ERROR 145 1456# define EVP_R_PRIVATE_KEY_ENCODE_ERROR 146 1457# define EVP_R_PUBLIC_KEY_NOT_RSA 106 1458# define EVP_R_TOO_LARGE 164 1459# define EVP_R_UNKNOWN_CIPHER 160 1460# define EVP_R_UNKNOWN_DIGEST 161 1461# define EVP_R_UNKNOWN_OPTION 169 1462# define EVP_R_UNKNOWN_PBE_ALGORITHM 121 1463# define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135 1464# define EVP_R_UNSUPPORTED_ALGORITHM 156 1465# define EVP_R_UNSUPPORTED_CIPHER 107 1466# define EVP_R_UNSUPPORTED_KEYLENGTH 123 1467# define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124 1468# define EVP_R_UNSUPPORTED_KEY_SIZE 108 1469# define EVP_R_UNSUPPORTED_PRF 125 1470# define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118 1471# define EVP_R_UNSUPPORTED_SALT_TYPE 126 1472# define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 1473# define EVP_R_WRONG_PUBLIC_KEY_TYPE 110 1474 1475#ifdef __cplusplus 1476} 1477#endif 1478#endif 1479