1 /* crypto/evp/evp.h */ 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay@cryptsoft.com). 7 * The implementation was written so as to conform with Netscapes SSL. 8 * 9 * This library is free for commercial and non-commercial use as long as 10 * the following conditions are aheared to. The following conditions 11 * apply to all code found in this distribution, be it the RC4, RSA, 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 * included with this distribution is covered by the same copyright terms 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 * 16 * Copyright remains Eric Young's, and as such any Copyright notices in 17 * the code are not to be removed. 18 * If this package is used in a product, Eric Young should be given attribution 19 * as the author of the parts of the library used. 20 * This can be in the form of a textual message at program startup or 21 * in documentation (online or textual) provided with the package. 22 * 23 * Redistribution and use in source and binary forms, with or without 24 * modification, are permitted provided that the following conditions 25 * are met: 26 * 1. Redistributions of source code must retain the copyright 27 * notice, this list of conditions and the following disclaimer. 28 * 2. Redistributions in binary form must reproduce the above copyright 29 * notice, this list of conditions and the following disclaimer in the 30 * documentation and/or other materials provided with the distribution. 31 * 3. All advertising materials mentioning features or use of this software 32 * must display the following acknowledgement: 33 * "This product includes cryptographic software written by 34 * Eric Young (eay@cryptsoft.com)" 35 * The word 'cryptographic' can be left out if the rouines from the library 36 * being used are not cryptographic related :-). 37 * 4. If you include any Windows specific code (or a derivative thereof) from 38 * the apps directory (application code) you must include an acknowledgement: 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 * 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * 53 * The licence and distribution terms for any publically available version or 54 * derivative of this code cannot be changed. i.e. this code cannot simply be 55 * copied and put under another distribution licence 56 * [including the GNU Public Licence.] 57 */ 58 59 module deimos.openssl.evp; 60 61 import deimos.openssl._d_util; 62 63 import deimos.openssl.x509; // Needed for X509_ATTRIBUTE. 64 65 //#ifdef OPENSSL_ALGORITHM_DEFINES 66 public import deimos.openssl.opensslconf; 67 //#else 68 //# define OPENSSL_ALGORITHM_DEFINES 69 //public import deimos.openssl.opensslconf; 70 //# undef OPENSSL_ALGORITHM_DEFINES 71 //#endif 72 73 public import deimos.openssl.ossl_typ; 74 75 public import deimos.openssl.symhacks; 76 public import deimos.openssl.bytestring; 77 78 version(OPENSSL_NO_BIO) {} else { 79 public import deimos.openssl.bio; 80 } 81 82 /* 83 enum EVP_RC2_KEY_SIZE = 16; 84 enum EVP_RC4_KEY_SIZE = 16; 85 enum EVP_BLOWFISH_KEY_SIZE = 16; 86 enum EVP_CAST5_KEY_SIZE = 16; 87 enum EVP_RC5_32_12_16_KEY_SIZE = 16; 88 */ 89 enum EVP_MAX_MD_SIZE = 64; /* longest known is SHA512 */ 90 enum EVP_MAX_KEY_LENGTH = 64; 91 enum EVP_MAX_IV_LENGTH = 16; 92 enum EVP_MAX_BLOCK_LENGTH = 32; 93 94 enum PKCS5_SALT_LEN = 8; 95 /* Default PKCS#5 iteration count */ 96 enum PKCS5_DEFAULT_ITER = 2048; 97 98 public import deimos.openssl.objects; 99 100 enum EVP_PK_RSA = 0x0001; 101 enum EVP_PK_DSA = 0x0002; 102 enum EVP_PK_DH = 0x0004; 103 enum EVP_PK_EC = 0x0008; 104 enum EVP_PKT_SIGN = 0x0010; 105 enum EVP_PKT_ENC = 0x0020; 106 enum EVP_PKT_EXCH = 0x0040; 107 enum EVP_PKS_RSA = 0x0100; 108 enum EVP_PKS_DSA = 0x0200; 109 enum EVP_PKS_EC = 0x0400; 110 enum EVP_PKT_EXP = 0x1000; /* <= 512 bit key */ 111 112 alias NID_undef EVP_PKEY_NONE; 113 alias NID_rsaEncryption EVP_PKEY_RSA; 114 alias NID_rsa EVP_PKEY_RSA2; 115 alias NID_dsa EVP_PKEY_DSA; 116 alias NID_dsa_2 EVP_PKEY_DSA1; 117 alias NID_dsaWithSHA EVP_PKEY_DSA2; 118 alias NID_dsaWithSHA1 EVP_PKEY_DSA3; 119 alias NID_dsaWithSHA1_2 EVP_PKEY_DSA4; 120 alias NID_dhKeyAgreement EVP_PKEY_DH; 121 alias NID_X9_62_id_ecPublicKey EVP_PKEY_EC; 122 alias NID_hmac EVP_PKEY_HMAC; 123 alias NID_cmac EVP_PKEY_CMAC; 124 125 extern (C): 126 nothrow: 127 128 /* Type needs to be a bit field 129 * Sub-type needs to be for variations on the method, as in_, can it do 130 * arbitrary encryption.... */ 131 struct evp_pkey_st 132 { 133 int type; 134 int save_type; 135 int references; 136 const(EVP_PKEY_ASN1_METHOD)* ameth; 137 ENGINE* engine; 138 union pkey_ { 139 char* ptr; 140 version(OPENSSL_NO_RSA) {} else { 141 rsa_st* rsa; /* RSA */ 142 } 143 version(OPENSSL_NO_DSA) {} else { 144 dsa_st* dsa; /* DSA */ 145 } 146 version(OPENSSL_NO_DH) {} else { 147 dh_st* dh; /* DH */ 148 } 149 version(OPENSSL_NO_EC) {} else { 150 ec_key_st* ec; /* ECC */ 151 } 152 } 153 pkey_ pkey; 154 int save_parameters; 155 STACK_OF!(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ 156 } /* EVP_PKEY */; 157 158 enum EVP_PKEY_MO_SIGN = 0x0001; 159 enum EVP_PKEY_MO_VERIFY = 0x0002; 160 enum EVP_PKEY_MO_ENCRYPT = 0x0004; 161 enum EVP_PKEY_MO_DECRYPT = 0x0008; 162 163 // #ifndef EVP_MD 164 struct env_md_st 165 { 166 int type; 167 int pkey_type; 168 int md_size; 169 c_ulong flags; 170 ExternC!(int function(EVP_MD_CTX* ctx)) init_; 171 ExternC!(int function(EVP_MD_CTX* ctx,const(void)* data,size_t count)) update; 172 ExternC!(int function(EVP_MD_CTX* ctx,ubyte* md)) final_; 173 ExternC!(int function(EVP_MD_CTX* to,const(EVP_MD_CTX)* from)) copy; 174 ExternC!(int function(EVP_MD_CTX* ctx)) cleanup; 175 176 /* FIXME: prototype these some day */ 177 ExternC!(int function(int type, const(ubyte)* m, uint m_length, 178 ubyte* sigret, uint* siglen, void* key)) sign; 179 ExternC!(int function(int type, const(ubyte)* m, uint m_length, 180 const(ubyte)* sigbuf, uint siglen, 181 void* key)) verify; 182 int[5] required_pkey_type; /*EVP_PKEY_xxx */ 183 int block_size; 184 int ctx_size; /* how big does the ctx->md_data need to be */ 185 /* control function */ 186 ExternC!(int function(EVP_MD_CTX* ctx, int cmd, int p1, void* p2)) md_ctrl; 187 } /* EVP_MD */; 188 189 alias typeof(*(ExternC!(int function(int type,const(ubyte)* m, 190 uint m_length,ubyte* sigret, 191 uint* siglen, void* key))).init) evp_sign_method; 192 alias typeof(*(ExternC!(int function(int type,const(ubyte)* m, 193 uint m_length,const(ubyte)* sigbuf, 194 uint siglen, void* key))).init) evp_verify_method; 195 196 enum EVP_MD_FLAG_ONESHOT = 0x0001; /* digest can only handle a single 197 * block */ 198 199 enum EVP_MD_FLAG_PKEY_DIGEST = 0x0002; /* digest is a "clone" digest used 200 * which is a copy of an existing 201 * one for a specific public key type. 202 * EVP_dss1() etc */ 203 204 /* Digest uses EVP_PKEY_METHOD for signing instead of MD specific signing */ 205 206 enum EVP_MD_FLAG_PKEY_METHOD_SIGNATURE = 0x0004; 207 208 /* DigestAlgorithmIdentifier flags... */ 209 210 enum EVP_MD_FLAG_DIGALGID_MASK = 0x0018; 211 212 /* NULL or absent parameter accepted. Use NULL */ 213 214 enum EVP_MD_FLAG_DIGALGID_NULL = 0x0000; 215 216 /* NULL or absent parameter accepted. Use NULL for PKCS#1 otherwise absent */ 217 218 enum EVP_MD_FLAG_DIGALGID_ABSENT = 0x0008; 219 220 /* Custom handling via ctrl */ 221 222 enum EVP_MD_FLAG_DIGALGID_CUSTOM = 0x0018; 223 224 enum EVP_MD_FLAG_FIPS = 0x0400; /* Note if suitable for use in FIPS mode */ 225 226 /* Digest ctrls */ 227 228 enum EVP_MD_CTRL_DIGALGID = 0x1; 229 enum EVP_MD_CTRL_MICALG = 0x2; 230 231 /* Minimum Algorithm specific ctrl value */ 232 233 enum EVP_MD_CTRL_ALG_CTRL = 0x1000; 234 235 enum EVP_PKEY_NULL_method = "null,null,{0,0,0,0}"; 236 237 version (OPENSSL_NO_DSA) { 238 alias EVP_PKEY_NULL_method EVP_PKEY_DSA_method; 239 } else { 240 enum EVP_PKEY_DSA_method = "cast(evp_sign_method*)&DSA_sign," ~ 241 "cast(evp_verify_method*)&DSA_verify,{EVP_PKEY_DSA,EVP_PKEY_DSA2," ~ 242 "EVP_PKEY_DSA3, EVP_PKEY_DSA4,0}"; 243 } 244 245 version(OPENSSL_NO_ECDSA) { 246 alias EVP_PKEY_NULL_method EVP_PKEY_ECDSA_method; 247 } else { 248 enum EVP_PKEY_ECDSA_method = "cast(evp_sign_method*)&ECDSA_sign," ~ 249 "cast(evp_verify_method*)&ECDSA_verify,{EVP_PKEY_EC,0,0,0}"; 250 } 251 252 version (OPENSSL_NO_RSA) { 253 alias EVP_PKEY_NULL_method EVP_PKEY_RSA_method; 254 alias EVP_PKEY_NULL_method EVP_PKEY_RSA_ASN1_OCTET_STRING_method; 255 } else { 256 enum EVP_PKEY_RSA_method = "cast(evp_sign_method*)&RSA_sign," ~ 257 "cast(evp_verify_method*)RSA_verify,{EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}"; 258 enum EVP_PKEY_RSA_ASN1_OCTET_STRING_method = 259 "cast(evp_sign_method*)&RSA_sign_ASN1_OCTET_STRING," ~ 260 "cast(evp_verify_method*)RSA_verify_ASN1_OCTET_STRING," ~ 261 "{EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}"; 262 } 263 264 // #endif /* !EVP_MD */ 265 266 struct env_md_ctx_st 267 { 268 const(EVP_MD)* digest; 269 ENGINE* engine; /* functional reference if 'digest' is ENGINE-provided */ 270 c_ulong flags; 271 void* md_data; 272 /* Public key context for sign/verify */ 273 EVP_PKEY_CTX* pctx; 274 /* Update function: usually copied from EVP_MD */ 275 ExternC!(int function(EVP_MD_CTX* ctx,const(void)* data,size_t count)) update; 276 } /* EVP_MD_CTX */; 277 278 /* values for EVP_MD_CTX flags */ 279 280 enum EVP_MD_CTX_FLAG_ONESHOT = 0x0001; /* digest update will be called 281 * once only */ 282 enum EVP_MD_CTX_FLAG_CLEANED = 0x0002; /* context has already been 283 * cleaned */ 284 enum EVP_MD_CTX_FLAG_REUSE = 0x0004; /* Don't free up ctx->md_data 285 * in EVP_MD_CTX_cleanup */ 286 /* FIPS and pad options are ignored in 1.0.0, definitions are here 287 * so we don't accidentally reuse the values for other purposes. 288 */ 289 290 enum EVP_MD_CTX_FLAG_NON_FIPS_ALLOW = 0x0008; /* Allow use of non FIPS digest 291 * in FIPS mode */ 292 293 /* The following PAD options are also currently ignored in 1.0.0, digest 294 * parameters are handled through EVP_DigestSign*() and EVP_DigestVerify*() 295 * instead. 296 */ 297 enum EVP_MD_CTX_FLAG_PAD_MASK = 0xF0; /* RSA mode to use */ 298 enum EVP_MD_CTX_FLAG_PAD_PKCS1 = 0x00; /* PKCS#1 v1.5 mode */ 299 enum EVP_MD_CTX_FLAG_PAD_X931 = 0x10; /* X9.31 mode */ 300 enum EVP_MD_CTX_FLAG_PAD_PSS = 0x20; /* PSS mode */ 301 302 enum EVP_MD_CTX_FLAG_NO_INIT = 0x0100; /* Don't initialize md_data */ 303 304 struct evp_cipher_st 305 { 306 int nid; 307 int block_size; 308 int key_len; /* Default value for variable length ciphers */ 309 int iv_len; 310 c_ulong flags; /* Various flags */ 311 ExternC!(int function(EVP_CIPHER_CTX* ctx, const(ubyte)* key, 312 const(ubyte)* iv, int enc)) init_; /* init key */ 313 ExternC!(int function(EVP_CIPHER_CTX* ctx, ubyte* out_, 314 const(ubyte)* in_, size_t inl)) do_cipher;/* encrypt/decrypt data */ 315 ExternC!(int function(EVP_CIPHER_CTX*)) cleanup; /* cleanup ctx */ 316 int ctx_size; /* how big ctx->cipher_data needs to be */ 317 ExternC!(int function(EVP_CIPHER_CTX*, ASN1_TYPE*)) set_asn1_parameters; /* Populate a ASN1_TYPE with parameters */ 318 ExternC!(int function(EVP_CIPHER_CTX*, ASN1_TYPE*)) get_asn1_parameters; /* Get parameters from a ASN1_TYPE */ 319 ExternC!(int function(EVP_CIPHER_CTX*, int type, int arg, void* ptr)) ctrl; /* Miscellaneous operations */ 320 void* app_data; /* Application data */ 321 } /* EVP_CIPHER */; 322 323 /* Values for cipher flags */ 324 325 /* Modes for ciphers */ 326 327 enum EVP_CIPH_STREAM_CIPHER = 0x0; 328 enum EVP_CIPH_ECB_MODE = 0x1; 329 enum EVP_CIPH_CBC_MODE = 0x2; 330 enum EVP_CIPH_CFB_MODE = 0x3; 331 enum EVP_CIPH_OFB_MODE = 0x4; 332 enum EVP_CIPH_CTR_MODE = 0x5; 333 enum EVP_CIPH_GCM_MODE = 0x6; 334 enum EVP_CIPH_CCM_MODE = 0x7; 335 enum EVP_CIPH_XTS_MODE = 0x10001; 336 enum EVP_CIPH_MODE = 0xF0007; 337 /* Set if variable length cipher */ 338 enum EVP_CIPH_VARIABLE_LENGTH = 0x8; 339 /* Set if the iv handling should be done by the cipher itself */ 340 enum EVP_CIPH_CUSTOM_IV = 0x10; 341 /* Set if the cipher's init() function should be called if key is NULL */ 342 enum EVP_CIPH_ALWAYS_CALL_INIT = 0x20; 343 /* Call ctrl() to init cipher parameters */ 344 enum EVP_CIPH_CTRL_INIT = 0x40; 345 /* Don't use standard key length function */ 346 enum EVP_CIPH_CUSTOM_KEY_LENGTH = 0x80; 347 /* Don't use standard block padding */ 348 enum EVP_CIPH_NO_PADDING = 0x100; 349 /* cipher handles random key generation */ 350 enum EVP_CIPH_RAND_KEY = 0x200; 351 /* cipher has its own additional copying logic */ 352 enum EVP_CIPH_CUSTOM_COPY = 0x400; 353 /* Allow use default ASN1 get/set iv */ 354 enum EVP_CIPH_FLAG_DEFAULT_ASN1 = 0x1000; 355 /* Buffer length in bits not bytes: CFB1 mode only */ 356 enum EVP_CIPH_FLAG_LENGTH_BITS = 0x2000; 357 /* Note if suitable for use in FIPS mode */ 358 enum EVP_CIPH_FLAG_FIPS = 0x4000; 359 /* Allow non FIPS cipher in FIPS mode */ 360 enum EVP_CIPH_FLAG_NON_FIPS_ALLOW = 0x8000; 361 /* Cipher handles any and all padding logic as well 362 * as finalisation. 363 */ 364 enum EVP_CIPH_FLAG_CUSTOM_CIPHER = 0x100000; 365 enum EVP_CIPH_FLAG_AEAD_CIPHER = 0x200000; 366 367 /* ctrl() values */ 368 369 enum EVP_CTRL_INIT = 0x0; 370 enum EVP_CTRL_SET_KEY_LENGTH = 0x1; 371 enum EVP_CTRL_GET_RC2_KEY_BITS = 0x2; 372 enum EVP_CTRL_SET_RC2_KEY_BITS = 0x3; 373 enum EVP_CTRL_GET_RC5_ROUNDS = 0x4; 374 enum EVP_CTRL_SET_RC5_ROUNDS = 0x5; 375 enum EVP_CTRL_RAND_KEY = 0x6; 376 enum EVP_CTRL_PBE_PRF_NID = 0x7; 377 enum EVP_CTRL_COPY = 0x8; 378 enum EVP_CTRL_GCM_SET_IVLEN = 0x9; 379 enum EVP_CTRL_GCM_GET_TAG = 0x10; 380 enum EVP_CTRL_GCM_SET_TAG = 0x11; 381 enum EVP_CTRL_GCM_SET_IV_FIXED = 0x12; 382 enum EVP_CTRL_GCM_IV_GEN = 0x13; 383 alias EVP_CTRL_CCM_SET_IVLEN = EVP_CTRL_GCM_SET_IVLEN; 384 alias EVP_CTRL_CCM_GET_TAG = EVP_CTRL_GCM_GET_TAG; 385 alias EVP_CTRL_CCM_SET_TAG = EVP_CTRL_GCM_SET_TAG; 386 enum EVP_CTRL_CCM_SET_L = 0x14; 387 enum EVP_CTRL_CCM_SET_MSGLEN = 0x15; 388 /* AEAD cipher deduces payload length and returns number of bytes 389 * required to store MAC and eventual padding. Subsequent call to 390 * EVP_Cipher even appends/verifies MAC. 391 */ 392 enum EVP_CTRL_AEAD_TLS1_AAD = 0x16; 393 /* Used by composite AEAD ciphers, no-op in GCM, CCM... */ 394 enum EVP_CTRL_AEAD_SET_MAC_KEY = 0x17; 395 /* Set the GCM invocation field, decrypt only */ 396 enum EVP_CTRL_GCM_SET_IV_INV = 0x18; 397 398 /* GCM TLS constants */ 399 /* Length of fixed part of IV derived from PRF */ 400 enum EVP_GCM_TLS_FIXED_IV_LEN = 4; 401 /* Length of explicit part of IV part of TLS records */ 402 enum EVP_GCM_TLS_EXPLICIT_IV_LEN = 8; 403 /* Length of tag for TLS */ 404 enum EVP_GCM_TLS_TAG_LEN = 16; 405 406 struct evp_cipher_info_st { 407 const(EVP_CIPHER)* cipher; 408 ubyte[EVP_MAX_IV_LENGTH] iv; 409 } 410 alias evp_cipher_info_st EVP_CIPHER_INFO; 411 412 struct evp_cipher_ctx_st 413 { 414 const(EVP_CIPHER)* cipher; 415 ENGINE* engine; /* functional reference if 'cipher' is ENGINE-provided */ 416 int encrypt; /* encrypt or decrypt */ 417 int buf_len; /* number we have left */ 418 419 ubyte[EVP_MAX_IV_LENGTH] oiv; /* original iv */ 420 ubyte[EVP_MAX_IV_LENGTH] iv; /* working iv */ 421 ubyte[EVP_MAX_BLOCK_LENGTH] buf;/* saved partial block */ 422 int num; /* used by cfb/ofb mode */ 423 424 void* app_data; /* application stuff */ 425 int key_len; /* May change for variable length cipher */ 426 c_ulong flags; /* Various flags */ 427 void* cipher_data; /* per EVP data */ 428 int final_used; 429 int block_mask; 430 ubyte[EVP_MAX_BLOCK_LENGTH] final_;/* possible final block */ 431 } /* EVP_CIPHER_CTX */; 432 433 struct evp_Encode_Ctx_st { 434 int num; /* number saved in a partial encode/decode */ 435 int length; /* The length is either the output line length 436 * (in input bytes) or the shortest input line 437 * length that is ok. Once decoding begins, 438 * the length is adjusted up each time a longer 439 * line is decoded */ 440 ubyte[80] enc_data; /* data to encode */ 441 int line_num; /* number read on current line */ 442 int expect_nl; 443 } 444 alias evp_Encode_Ctx_st EVP_ENCODE_CTX; 445 446 /* Password based encryption function */ 447 alias typeof(*(ExternC!(int function(EVP_CIPHER_CTX* ctx, const(char)* pass, int passlen, 448 ASN1_TYPE* param, const(EVP_CIPHER)* cipher, 449 const(EVP_MD)* md, int en_de))).init) EVP_PBE_KEYGEN; 450 451 version(OPENSSL_NO_RSA) {} else { 452 auto EVP_PKEY_assign_RSA()(EVP_PKEY* pkey, RSA* key) { 453 return EVP_PKEY_assign(pkey,EVP_PKEY_RSA,cast(void*)key); 454 } 455 } 456 457 version(OPENSSL_NO_DSA) {} else { 458 auto EVP_PKEY_assign_RSA()(EVP_PKEY* pkey, DSA* key) { 459 return EVP_PKEY_assign(pkey,EVP_PKEY_DSA,cast(void*)key); 460 } 461 } 462 463 version(OPENSSL_NO_DH) {} else { 464 auto EVP_PKEY_assign_DH()(EVP_PKEY* pkey, DH* key) { 465 return EVP_PKEY_assign(pkey,EVP_PKEY_DH,cast(void*)key); 466 } 467 } 468 469 version(OPENSSL_NO_EC) {} else { 470 auto EVP_PKEY_assign_EC_KEY()(EVP_PKEY* pkey, EC_KEY* key) { 471 return EVP_PKEY_assign(pkey,EVP_PKEY_EC,cast(void*)key); 472 } 473 } 474 475 /* Add some extra combinations */ 476 auto EVP_get_digestbynid()(int a) { return EVP_get_digestbyname(OBJ_nid2sn(a)); } 477 auto EVP_get_digestbyobj()(const(ASN1_OBJECT)* a) { return EVP_get_digestbynid(OBJ_obj2nid(a)); } 478 auto EVP_get_cipherbynid()(int a) { return EVP_get_cipherbyname(OBJ_nid2sn(a)); } 479 auto EVP_get_cipherbyobj()(const(ASN1_OBJECT)* a) { return EVP_get_cipherbynid(OBJ_obj2nid(a)); } 480 481 int EVP_MD_type(const(EVP_MD)* md); 482 alias EVP_MD_type EVP_MD_nid; 483 auto EVP_MD_name()(const(EVP_MD)* e) { return OBJ_nid2sn(EVP_MD_nid(e)); } 484 int EVP_MD_pkey_type(const(EVP_MD)* md); 485 int EVP_MD_size(const(EVP_MD)* md); 486 int EVP_MD_block_size(const(EVP_MD)* md); 487 c_ulong EVP_MD_flags(const(EVP_MD)* md); 488 489 const(EVP_MD)* EVP_MD_CTX_md(const(EVP_MD_CTX)* ctx); 490 auto EVP_MD_CTX_size()(const(EVP_MD_CTX)* e) { return EVP_MD_size(EVP_MD_CTX_md(e)); } 491 auto EVP_MD_CTX_block_size()(const(EVP_MD_CTX)* e) { return EVP_MD_block_size(EVP_MD_CTX_md(e)); } 492 auto EVP_MD_CTX_type()(const(EVP_MD_CTX)* e) { return EVP_MD_type(EVP_MD_CTX_md(e)); } 493 494 int EVP_CIPHER_nid(const(EVP_CIPHER)* cipher); 495 auto EVP_CIPHER_name()(const(EVP_CIPHER)* e){ return OBJ_nid2sn(EVP_CIPHER_nid(e)); } 496 int EVP_CIPHER_block_size(const(EVP_CIPHER)* cipher); 497 int EVP_CIPHER_key_length(const(EVP_CIPHER)* cipher); 498 int EVP_CIPHER_iv_length(const(EVP_CIPHER)* cipher); 499 c_ulong EVP_CIPHER_flags(const(EVP_CIPHER)* cipher); 500 auto EVP_CIPHER_mode()(const(EVP_CIPHER)* e) { return (EVP_CIPHER_flags(e) & EVP_CIPH_MODE); } 501 502 const(EVP_CIPHER)* EVP_CIPHER_CTX_cipher(const(EVP_CIPHER_CTX)* ctx); 503 int EVP_CIPHER_CTX_nid(const(EVP_CIPHER_CTX)* ctx); 504 int EVP_CIPHER_CTX_block_size(const(EVP_CIPHER_CTX)* ctx); 505 int EVP_CIPHER_CTX_key_length(const(EVP_CIPHER_CTX)* ctx); 506 int EVP_CIPHER_CTX_iv_length(const(EVP_CIPHER_CTX)* ctx); 507 int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX* out_, const(EVP_CIPHER_CTX)* in_); 508 void* EVP_CIPHER_CTX_get_app_data(const(EVP_CIPHER_CTX)* ctx); 509 void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX* ctx, void* data); 510 auto EVP_CIPHER_CTX_type()(const(EVP_CIPHER_CTX)* c) { return EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)); } 511 c_ulong EVP_CIPHER_CTX_flags(const(EVP_CIPHER_CTX)* ctx); 512 auto EVP_CIPHER_CTX_mode()(const(EVP_CIPHER_CTX)* e) { return (EVP_CIPHER_CTX_flags(e) & EVP_CIPH_MODE); } 513 514 auto EVP_ENCODE_LENGTH(T)(T l) { return (((l+2)/3*4)+(l/48+1)*2+80); } 515 auto EVP_DECODE_LENGTH(T)(T l) { return ((l+3)/4*3+80); } 516 517 alias EVP_DigestInit_ex EVP_SignInit_ex; 518 alias EVP_DigestInit EVP_SignInit; 519 alias EVP_DigestUpdate EVP_SignUpdate; 520 alias EVP_DigestInit_ex EVP_VerifyInit_ex; 521 alias EVP_DigestInit EVP_VerifyInit; 522 alias EVP_DigestUpdate EVP_VerifyUpdate; 523 alias EVP_DecryptUpdate EVP_OpenUpdate; 524 alias EVP_EncryptUpdate EVP_SealUpdate; 525 alias EVP_DigestUpdate EVP_DigestSignUpdate; 526 alias EVP_DigestUpdate EVP_DigestVerifyUpdate; 527 528 void BIO_set_md()(BIO* b,const(EVP_MD)* md) { return BIO_ctrl(b,BIO_C_SET_MD,0,md); } 529 auto BIO_get_md()(BIO* b,EVP_MD** mdp) { return BIO_ctrl(b,BIO_C_GET_MD,0,mdp); } 530 auto BIO_get_md_ctx()(BIO* b,EVP_MD_CTX** mdcp) { return BIO_ctrl(b,BIO_C_GET_MD_CTX,0,mdcp); } 531 auto BIO_set_md_ctx()(BIO* b,EVP_MD_CTX** mdcp) { return BIO_ctrl(b,BIO_C_SET_MD_CTX,0,mdcp); } 532 auto BIO_get_cipher_status()(BIO* b) { return BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,null); } 533 auto BIO_get_cipher_ctx()(BIO* b,EVP_CIPHER_CTX** c_pp) { return BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,c_pp); } 534 535 int EVP_Cipher(EVP_CIPHER_CTX* c, 536 ubyte* out_, 537 const(ubyte)* in_, 538 uint inl); 539 540 auto EVP_add_cipher_alias()(const(char)* n,const(char)* alias_) { 541 return OBJ_NAME_add(alias_,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n)); 542 } 543 auto EVP_add_digest_alias()(const(char)* n,const(char)* alias_) { 544 return OBJ_NAME_add(alias_,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n)); 545 } 546 auto EVP_delete_cipher_alias()(const(char)* alias_) { 547 return OBJ_NAME_remove(alias_,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS); 548 } 549 auto EVP_delete_digest_alias()(const(char)* alias_) { 550 return OBJ_NAME_remove(alias_,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS); 551 } 552 553 void EVP_MD_CTX_init(EVP_MD_CTX* ctx); 554 int EVP_MD_CTX_cleanup(EVP_MD_CTX* ctx); 555 EVP_MD_CTX* EVP_MD_CTX_create(); 556 void EVP_MD_CTX_destroy(EVP_MD_CTX* ctx); 557 int EVP_MD_CTX_copy_ex(EVP_MD_CTX* out_,const(EVP_MD_CTX)* in_); 558 void EVP_MD_CTX_set_flags(EVP_MD_CTX* ctx, int flags); 559 void EVP_MD_CTX_clear_flags(EVP_MD_CTX* ctx, int flags); 560 int EVP_MD_CTX_test_flags(const(EVP_MD_CTX)* ctx,int flags); 561 int EVP_DigestInit_ex(EVP_MD_CTX* ctx, const(EVP_MD)* type, ENGINE* impl); 562 int EVP_DigestUpdate(EVP_MD_CTX* ctx,const(void)* d, 563 size_t cnt); 564 int EVP_DigestFinal_ex(EVP_MD_CTX* ctx,ubyte* md,uint* s); 565 int EVP_Digest(const(void)* data, size_t count, 566 ubyte* md, uint* size, const(EVP_MD)* type, ENGINE* impl); 567 568 int EVP_MD_CTX_copy(EVP_MD_CTX* out_,const(EVP_MD_CTX)* in_); 569 int EVP_DigestInit(EVP_MD_CTX* ctx, const(EVP_MD)* type); 570 int EVP_DigestFinal(EVP_MD_CTX* ctx,ubyte* md,uint* s); 571 572 int EVP_read_pw_string(char* buf,int length,const(char)* prompt,int verify); 573 int EVP_read_pw_string_min(char* buf,int minlen,int maxlen,const(char)* prompt,int verify); 574 void EVP_set_pw_prompt(const(char)* prompt); 575 char* EVP_get_pw_prompt(); 576 577 int EVP_BytesToKey(const(EVP_CIPHER)* type,const(EVP_MD)* md, 578 const(ubyte)* salt, const(ubyte)* data, 579 int datal, int count, ubyte* key,ubyte* iv); 580 581 void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX* ctx, int flags); 582 void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX* ctx, int flags); 583 int EVP_CIPHER_CTX_test_flags(const(EVP_CIPHER_CTX)* ctx,int flags); 584 585 int EVP_EncryptInit(EVP_CIPHER_CTX* ctx,const(EVP_CIPHER)* cipher, 586 const(ubyte)* key, const(ubyte)* iv); 587 int EVP_EncryptInit_ex(EVP_CIPHER_CTX* ctx,const(EVP_CIPHER)* cipher, ENGINE* impl, 588 const(ubyte)* key, const(ubyte)* iv); 589 int EVP_EncryptUpdate(EVP_CIPHER_CTX* ctx, ubyte* out_, 590 int* outl, const(ubyte)* in_, int inl); 591 int EVP_EncryptFinal_ex(EVP_CIPHER_CTX* ctx, ubyte* out_, int* outl); 592 int EVP_EncryptFinal(EVP_CIPHER_CTX* ctx, ubyte* out_, int* outl); 593 594 int EVP_DecryptInit(EVP_CIPHER_CTX* ctx,const(EVP_CIPHER)* cipher, 595 const(ubyte)* key, const(ubyte)* iv); 596 int EVP_DecryptInit_ex(EVP_CIPHER_CTX* ctx,const(EVP_CIPHER)* cipher, ENGINE* impl, 597 const(ubyte)* key, const(ubyte)* iv); 598 int EVP_DecryptUpdate(EVP_CIPHER_CTX* ctx, ubyte* out_, 599 int* outl, const(ubyte)* in_, int inl); 600 int EVP_DecryptFinal(EVP_CIPHER_CTX* ctx, ubyte* outm, int* outl); 601 int EVP_DecryptFinal_ex(EVP_CIPHER_CTX* ctx, ubyte* outm, int* outl); 602 603 int EVP_CipherInit(EVP_CIPHER_CTX* ctx,const(EVP_CIPHER)* cipher, 604 const(ubyte)* key,const(ubyte)* iv, 605 int enc); 606 int EVP_CipherInit_ex(EVP_CIPHER_CTX* ctx,const(EVP_CIPHER)* cipher, ENGINE* impl, 607 const(ubyte)* key,const(ubyte)* iv, 608 int enc); 609 int EVP_CipherUpdate(EVP_CIPHER_CTX* ctx, ubyte* out_, 610 int* outl, const(ubyte)* in_, int inl); 611 int EVP_CipherFinal(EVP_CIPHER_CTX* ctx, ubyte* outm, int* outl); 612 int EVP_CipherFinal_ex(EVP_CIPHER_CTX* ctx, ubyte* outm, int* outl); 613 614 int EVP_SignFinal(EVP_MD_CTX* ctx,ubyte* md,uint* s, 615 EVP_PKEY* pkey); 616 617 int EVP_VerifyFinal(EVP_MD_CTX* ctx,const(ubyte)* sigbuf, 618 uint siglen,EVP_PKEY* pkey); 619 620 621 622 // ASN.1 functions 623 624 // EVP_parse_public_key decodes a DER-encoded SubjectPublicKeyInfo structure 625 // (RFC 5280) from |cbs| and advances |cbs|. It returns a newly-allocated 626 // |EVP_PKEY| or NULL on error. 627 // 628 // The caller must check the type of the parsed public key to ensure it is 629 // suitable and validate other desired key properties such as RSA modulus size 630 // or EC curve. 631 EVP_PKEY *EVP_parse_public_key(CBS *cbs); 632 633 // EVP_marshal_public_key marshals |key| as a DER-encoded SubjectPublicKeyInfo 634 // structure (RFC 5280) and appends the result to |cbb|. It returns one on 635 // success and zero on error. 636 int EVP_marshal_public_key(CBB *cbb, const(EVP_PKEY) *key); 637 638 // EVP_parse_private_key decodes a DER-encoded PrivateKeyInfo structure (RFC 639 // 5208) from |cbs| and advances |cbs|. It returns a newly-allocated |EVP_PKEY| 640 // or NULL on error. 641 // 642 // The caller must check the type of the parsed private key to ensure it is 643 // suitable and validate other desired key properties such as RSA modulus size 644 // or EC curve. 645 // 646 // A PrivateKeyInfo ends with an optional set of attributes. These are not 647 // processed and so this function will silently ignore any trailing data in the 648 // structure. 649 EVP_PKEY *EVP_parse_private_key(CBS *cbs); 650 651 // EVP_marshal_private_key marshals |key| as a DER-encoded PrivateKeyInfo 652 // structure (RFC 5208) and appends the result to |cbb|. It returns one on 653 // success and zero on error. 654 int EVP_marshal_private_key(CBB *cbb, const(EVP_PKEY) *key); 655 656 657 // Signing 658 // EVP_DigestSignInit sets up |ctx| for a signing operation with |type| and 659 // |pkey|. The |ctx| argument must have been initialised with 660 // |EVP_MD_CTX_init|. If |pctx| is not NULL, the |EVP_PKEY_CTX| of the signing 661 // operation will be written to |*pctx|; this can be used to set alternative 662 // signing options. 663 // 664 // For single-shot signing algorithms which do not use a pre-hash, such as 665 // Ed25519, |type| should be NULL. The |EVP_MD_CTX| itself is unused but is 666 // present so the API is uniform. See |EVP_DigestSign|. 667 // 668 // It returns one on success, or zero on error. 669 int EVP_DigestSignInit(EVP_MD_CTX* ctx, EVP_PKEY_CTX** pctx, 670 const(EVP_MD)* type, ENGINE* e, EVP_PKEY* pkey); 671 int EVP_DigestSignFinal(EVP_MD_CTX* ctx, 672 ubyte* sigret, size_t* siglen); 673 674 int EVP_DigestVerifyInit(EVP_MD_CTX* ctx, EVP_PKEY_CTX** pctx, 675 const(EVP_MD)* type, ENGINE* e, EVP_PKEY* pkey); 676 int EVP_DigestVerifyFinal(EVP_MD_CTX* ctx, 677 ubyte* sig, size_t siglen); 678 679 int EVP_OpenInit(EVP_CIPHER_CTX* ctx,const(EVP_CIPHER)* type, 680 const(ubyte)* ek, int ekl, const(ubyte)* iv, 681 EVP_PKEY* priv); 682 int EVP_OpenFinal(EVP_CIPHER_CTX* ctx, ubyte* out_, int* outl); 683 684 int EVP_SealInit(EVP_CIPHER_CTX* ctx, const(EVP_CIPHER)* type, 685 ubyte** ek, int* ekl, ubyte* iv, 686 EVP_PKEY** pubk, int npubk); 687 int EVP_SealFinal(EVP_CIPHER_CTX* ctx,ubyte* out_,int* outl); 688 689 void EVP_EncodeInit(EVP_ENCODE_CTX* ctx); 690 void EVP_EncodeUpdate(EVP_ENCODE_CTX* ctx,ubyte* out_,int* outl, 691 const(ubyte)* in_,int inl); 692 void EVP_EncodeFinal(EVP_ENCODE_CTX* ctx,ubyte* out_,int* outl); 693 int EVP_EncodeBlock(ubyte* t, const(ubyte)* f, int n); 694 695 void EVP_DecodeInit(EVP_ENCODE_CTX* ctx); 696 int EVP_DecodeUpdate(EVP_ENCODE_CTX* ctx,ubyte* out_,int* outl, 697 const(ubyte)* in_, int inl); 698 int EVP_DecodeFinal(EVP_ENCODE_CTX* ctx, ubyte* out_, int* outl); 699 int EVP_DecodeBlock(ubyte* t, const(ubyte)* f, int n); 700 701 void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX* a); 702 int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX* a); 703 EVP_CIPHER_CTX* EVP_CIPHER_CTX_new(); 704 void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX* a); 705 int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX* x, int keylen); 706 int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX* c, int pad); 707 int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX* ctx, int type, int arg, void* ptr); 708 int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX* ctx, ubyte* key); 709 710 version(OPENSSL_NO_BIO) {} else { 711 BIO_METHOD* BIO_f_md(); 712 BIO_METHOD* BIO_f_base64(); 713 BIO_METHOD* BIO_f_cipher(); 714 BIO_METHOD* BIO_f_reliable(); 715 void BIO_set_cipher(BIO* b,const(EVP_CIPHER)* c,const(ubyte)* k, 716 const(ubyte)* i, int enc); 717 } 718 719 const(EVP_MD)* EVP_md_null(); 720 version(OPENSSL_NO_MD2) {} else { 721 const(EVP_MD)* EVP_md2(); 722 } 723 version(OPENSSL_NO_MD4) {} else { 724 const(EVP_MD)* EVP_md4(); 725 } 726 version(OPENSSL_NO_MD5) {} else { 727 const(EVP_MD)* EVP_md5(); 728 } 729 version(OPENSSL_NO_SHA) {} else { 730 const(EVP_MD)* EVP_sha(); 731 const(EVP_MD)* EVP_sha1(); 732 const(EVP_MD)* EVP_dss(); 733 const(EVP_MD)* EVP_dss1(); 734 const(EVP_MD)* EVP_ecdsa(); 735 } 736 version(OPENSSL_NO_SHA256) {} else { 737 const(EVP_MD)* EVP_sha224(); 738 const(EVP_MD)* EVP_sha256(); 739 } 740 version(OPENSSL_NO_SHA512) {} else { 741 const(EVP_MD)* EVP_sha384(); 742 const(EVP_MD)* EVP_sha512(); 743 } 744 version(OPENSSL_NO_MDC2) {} else { 745 const(EVP_MD)* EVP_mdc2(); 746 } 747 version(OPENSSL_NO_RIPEMD) {} else { 748 const(EVP_MD)* EVP_ripemd160(); 749 } 750 version(OPENSSL_NO_WHIRLPOOL) {} else { 751 const(EVP_MD)* EVP_whirlpool(); 752 } 753 const(EVP_CIPHER)* EVP_enc_null(); /* does nothing :-) */ 754 version (OPENSSL_NO_DES) {} else { 755 const(EVP_CIPHER)* EVP_des_ecb(); 756 const(EVP_CIPHER)* EVP_des_ede(); 757 const(EVP_CIPHER)* EVP_des_ede3(); 758 const(EVP_CIPHER)* EVP_des_ede_ecb(); 759 const(EVP_CIPHER)* EVP_des_ede3_ecb(); 760 const(EVP_CIPHER)* EVP_des_cfb64(); 761 alias EVP_des_cfb64 EVP_des_cfb; 762 const(EVP_CIPHER)* EVP_des_cfb1(); 763 const(EVP_CIPHER)* EVP_des_cfb8(); 764 const(EVP_CIPHER)* EVP_des_ede_cfb64(); 765 alias EVP_des_ede_cfb64 EVP_des_ede_cfb; 766 version (none) { 767 const(EVP_CIPHER)* EVP_des_ede_cfb1(); 768 const(EVP_CIPHER)* EVP_des_ede_cfb8(); 769 } 770 const(EVP_CIPHER)* EVP_des_ede3_cfb64(); 771 alias EVP_des_ede3_cfb64 EVP_des_ede3_cfb; 772 const(EVP_CIPHER)* EVP_des_ede3_cfb1(); 773 const(EVP_CIPHER)* EVP_des_ede3_cfb8(); 774 const(EVP_CIPHER)* EVP_des_ofb(); 775 const(EVP_CIPHER)* EVP_des_ede_ofb(); 776 const(EVP_CIPHER)* EVP_des_ede3_ofb(); 777 const(EVP_CIPHER)* EVP_des_cbc(); 778 const(EVP_CIPHER)* EVP_des_ede_cbc(); 779 const(EVP_CIPHER)* EVP_des_ede3_cbc(); 780 const(EVP_CIPHER)* EVP_desx_cbc(); 781 /* This should now be supported through the dev_crypto ENGINE. But also, why are 782 * rc4 and md5 declarations made here inside a "NO_DES" precompiler branch? */ 783 //#if 0 784 //# ifdef OPENSSL_OPENBSD_DEV_CRYPTO 785 //const(EVP_CIPHER)* EVP_dev_crypto_des_ede3_cbc(); 786 //const(EVP_CIPHER)* EVP_dev_crypto_rc4(); 787 //const(EVP_MD)* EVP_dev_crypto_md5(); 788 //# endif 789 //#endif 790 } 791 version(OPENSSL_NO_RC4) {} else { 792 const(EVP_CIPHER)* EVP_rc4(); 793 const(EVP_CIPHER)* EVP_rc4_40(); 794 version(OPENSSL_NO_MD5) {} else { 795 const(EVP_CIPHER)* EVP_rc4_hmac_md5(); 796 } 797 } 798 version(OPENSSL_NO_IDEA) {} else { 799 const(EVP_CIPHER)* EVP_idea_ecb(); 800 const(EVP_CIPHER)* EVP_idea_cfb64(); 801 alias EVP_idea_cfb64 EVP_idea_cfb; 802 const(EVP_CIPHER)* EVP_idea_ofb(); 803 const(EVP_CIPHER)* EVP_idea_cbc(); 804 } 805 version(OPENSSL_NO_RC2) {} else { 806 const(EVP_CIPHER)* EVP_rc2_ecb(); 807 const(EVP_CIPHER)* EVP_rc2_cbc(); 808 const(EVP_CIPHER)* EVP_rc2_40_cbc(); 809 const(EVP_CIPHER)* EVP_rc2_64_cbc(); 810 const(EVP_CIPHER)* EVP_rc2_cfb64(); 811 alias EVP_rc2_cfb64 EVP_rc2_cfb; 812 const(EVP_CIPHER)* EVP_rc2_ofb(); 813 } 814 version(OPENSSL_NO_BF) {} else { 815 const(EVP_CIPHER)* EVP_bf_ecb(); 816 const(EVP_CIPHER)* EVP_bf_cbc(); 817 const(EVP_CIPHER)* EVP_bf_cfb64(); 818 alias EVP_bf_cfb64 EVP_bf_cfb; 819 const(EVP_CIPHER)* EVP_bf_ofb(); 820 } 821 version(OPENSSL_NO_CAST) {} else { 822 const(EVP_CIPHER)* EVP_cast5_ecb(); 823 const(EVP_CIPHER)* EVP_cast5_cbc(); 824 const(EVP_CIPHER)* EVP_cast5_cfb64(); 825 alias EVP_cast5_cfb64 EVP_cast5_cfb; 826 const(EVP_CIPHER)* EVP_cast5_ofb(); 827 } 828 version(OPENSSL_NO_RC5) {} else { 829 const(EVP_CIPHER)* EVP_rc5_32_12_16_cbc(); 830 const(EVP_CIPHER)* EVP_rc5_32_12_16_ecb(); 831 const(EVP_CIPHER)* EVP_rc5_32_12_16_cfb64(); 832 alias EVP_rc5_32_12_16_cfb64 EVP_rc5_32_12_16_cfb; 833 const(EVP_CIPHER)* EVP_rc5_32_12_16_ofb(); 834 } 835 version(OPENSSL_NO_AES) {} else { 836 const(EVP_CIPHER)* EVP_aes_128_ecb(); 837 const(EVP_CIPHER)* EVP_aes_128_cbc(); 838 const(EVP_CIPHER)* EVP_aes_128_cfb1(); 839 const(EVP_CIPHER)* EVP_aes_128_cfb8(); 840 const(EVP_CIPHER)* EVP_aes_128_cfb128(); 841 alias EVP_aes_128_cfb128 EVP_aes_128_cfb; 842 const(EVP_CIPHER)* EVP_aes_128_ofb(); 843 const(EVP_CIPHER)* EVP_aes_128_ctr(); 844 const(EVP_CIPHER)* EVP_aes_128_ccm(); 845 const(EVP_CIPHER)* EVP_aes_128_gcm(); 846 const(EVP_CIPHER)* EVP_aes_128_xts(); 847 const(EVP_CIPHER)* EVP_aes_192_ecb(); 848 const(EVP_CIPHER)* EVP_aes_192_cbc(); 849 const(EVP_CIPHER)* EVP_aes_192_cfb1(); 850 const(EVP_CIPHER)* EVP_aes_192_cfb8(); 851 const(EVP_CIPHER)* EVP_aes_192_cfb128(); 852 alias EVP_aes_192_cfb128 EVP_aes_192_cfb; 853 const(EVP_CIPHER)* EVP_aes_192_ofb(); 854 const(EVP_CIPHER)* EVP_aes_192_ctr(); 855 const(EVP_CIPHER)* EVP_aes_192_ccm(); 856 const(EVP_CIPHER)* EVP_aes_192_gcm(); 857 const(EVP_CIPHER)* EVP_aes_256_ecb(); 858 const(EVP_CIPHER)* EVP_aes_256_cbc(); 859 const(EVP_CIPHER)* EVP_aes_256_cfb1(); 860 const(EVP_CIPHER)* EVP_aes_256_cfb8(); 861 const(EVP_CIPHER)* EVP_aes_256_cfb128(); 862 alias EVP_aes_256_cfb128 EVP_aes_256_cfb; 863 const(EVP_CIPHER)* EVP_aes_256_ofb(); 864 const(EVP_CIPHER)* EVP_aes_256_ctr(); 865 const(EVP_CIPHER)* EVP_aes_256_ccm(); 866 const(EVP_CIPHER)* EVP_aes_256_gcm(); 867 const(EVP_CIPHER)* EVP_aes_256_xts(); 868 version(OPENSSL_NO_SHA) {} else version(OPENSSL_NO_SHA1) {} else { 869 const(EVP_CIPHER)* EVP_aes_128_cbc_hmac_sha1(); 870 const(EVP_CIPHER)* EVP_aes_256_cbc_hmac_sha1(); 871 } 872 } 873 version(OPENSSL_NO_CAMELLIA) {} else { 874 const(EVP_CIPHER)* EVP_camellia_128_ecb(); 875 const(EVP_CIPHER)* EVP_camellia_128_cbc(); 876 const(EVP_CIPHER)* EVP_camellia_128_cfb1(); 877 const(EVP_CIPHER)* EVP_camellia_128_cfb8(); 878 const(EVP_CIPHER)* EVP_camellia_128_cfb128(); 879 alias EVP_camellia_128_cfb128 EVP_camellia_128_cfb; 880 const(EVP_CIPHER)* EVP_camellia_128_ofb(); 881 const(EVP_CIPHER)* EVP_camellia_192_ecb(); 882 const(EVP_CIPHER)* EVP_camellia_192_cbc(); 883 const(EVP_CIPHER)* EVP_camellia_192_cfb1(); 884 const(EVP_CIPHER)* EVP_camellia_192_cfb8(); 885 const(EVP_CIPHER)* EVP_camellia_192_cfb128(); 886 alias EVP_camellia_192_cfb128 EVP_camellia_192_cfb; 887 const(EVP_CIPHER)* EVP_camellia_192_ofb(); 888 const(EVP_CIPHER)* EVP_camellia_256_ecb(); 889 const(EVP_CIPHER)* EVP_camellia_256_cbc(); 890 const(EVP_CIPHER)* EVP_camellia_256_cfb1(); 891 const(EVP_CIPHER)* EVP_camellia_256_cfb8(); 892 const(EVP_CIPHER)* EVP_camellia_256_cfb128(); 893 alias EVP_camellia_256_cfb128 EVP_camellia_256_cfb; 894 const(EVP_CIPHER)* EVP_camellia_256_ofb(); 895 } 896 897 version(OPENSSL_NO_SEED) {} else { 898 const(EVP_CIPHER)* EVP_seed_ecb(); 899 const(EVP_CIPHER)* EVP_seed_cbc(); 900 const(EVP_CIPHER)* EVP_seed_cfb128(); 901 alias EVP_seed_cfb128 EVP_seed_cfb; 902 const(EVP_CIPHER)* EVP_seed_ofb(); 903 } 904 905 void OPENSSL_add_all_algorithms_noconf(); 906 void OPENSSL_add_all_algorithms_conf(); 907 908 version (OPENSSL_LOAD_CONF) { 909 alias OPENSSL_add_all_algorithms_conf OpenSSL_add_all_algorithms; 910 } else { 911 alias OPENSSL_add_all_algorithms_noconf OpenSSL_add_all_algorithms; 912 } 913 914 void OpenSSL_add_all_ciphers(); 915 void OpenSSL_add_all_digests(); 916 alias OpenSSL_add_all_algorithms SSLeay_add_all_algorithms; 917 alias OpenSSL_add_all_ciphers SSLeay_add_all_ciphers; 918 alias OpenSSL_add_all_digests SSLeay_add_all_digests; 919 920 int EVP_add_cipher(const(EVP_CIPHER)* cipher); 921 int EVP_add_digest(const(EVP_MD)* digest); 922 923 const(EVP_CIPHER)* EVP_get_cipherbyname(const(char)* name); 924 const(EVP_MD)* EVP_get_digestbyname(const(char)* name); 925 void EVP_cleanup(); 926 927 void EVP_CIPHER_do_all(ExternC!(void function(const(EVP_CIPHER)* ciph, 928 const(char)* from, const(char)* to, void* x)) fn, void* arg); 929 void EVP_CIPHER_do_all_sorted(ExternC!(void function(const(EVP_CIPHER)* ciph, 930 const(char)* from, const(char)* to, void* x)) fn, void* arg); 931 932 void EVP_MD_do_all(ExternC!(void function(const(EVP_MD)* ciph, 933 const(char)* from, const(char)* to, void* x)) fn, void* arg); 934 void EVP_MD_do_all_sorted(ExternC!(void function(const(EVP_MD)* ciph, 935 const(char)* from, const(char)* to, void* x)) fn, void* arg); 936 937 int EVP_PKEY_decrypt_old(ubyte* dec_key, 938 const(ubyte)* enc_key,int enc_key_len, 939 EVP_PKEY* private_key); 940 int EVP_PKEY_encrypt_old(ubyte* enc_key, 941 const(ubyte)* key,int key_len, 942 EVP_PKEY* pub_key); 943 int EVP_PKEY_type(int type); 944 int EVP_PKEY_id(const(EVP_PKEY)* pkey); 945 int EVP_PKEY_base_id(const(EVP_PKEY)* pkey); 946 int EVP_PKEY_bits(EVP_PKEY* pkey); 947 int EVP_PKEY_size(EVP_PKEY* pkey); 948 int EVP_PKEY_set_type(EVP_PKEY* pkey,int type); 949 int EVP_PKEY_set_type_str(EVP_PKEY* pkey, const(char)* str, int len); 950 int EVP_PKEY_assign(EVP_PKEY* pkey,int type,void* key); 951 void* EVP_PKEY_get0(EVP_PKEY* pkey); 952 953 version(OPENSSL_NO_RSA) {} else { 954 import deimos.openssl.rsa; /*struct rsa_st;*/ 955 int EVP_PKEY_set1_RSA(EVP_PKEY* pkey,rsa_st* key); 956 rsa_st* EVP_PKEY_get1_RSA(EVP_PKEY* pkey); 957 } 958 version(OPENSSL_NO_DSA) {} else { 959 import deimos.openssl.dsa; /*struct dsa_st;*/ 960 int EVP_PKEY_set1_DSA(EVP_PKEY* pkey,dsa_st* key); 961 dsa_st* EVP_PKEY_get1_DSA(EVP_PKEY* pkey); 962 } 963 version(OPENSSL_NO_DH) {} else { 964 import deimos.openssl.dh; /*struct dh_st;*/ 965 int EVP_PKEY_set1_DH(EVP_PKEY* pkey,dh_st* key); 966 dh_st* EVP_PKEY_get1_DH(EVP_PKEY* pkey); 967 } 968 version(OPENSSL_NO_EC) {} else { 969 struct ec_key_st; 970 int EVP_PKEY_set1_EC_KEY(EVP_PKEY* pkey,ec_key_st* key); 971 ec_key_st* EVP_PKEY_get1_EC_KEY(EVP_PKEY* pkey); 972 } 973 974 EVP_PKEY* EVP_PKEY_new(); 975 void EVP_PKEY_free(EVP_PKEY* pkey); 976 977 EVP_PKEY* d2i_PublicKey(int type,EVP_PKEY** a, const(ubyte)** pp, 978 c_long length); 979 int i2d_PublicKey(EVP_PKEY* a, ubyte** pp); 980 981 EVP_PKEY* d2i_PrivateKey(int type,EVP_PKEY** a, const(ubyte)** pp, 982 c_long length); 983 EVP_PKEY* d2i_AutoPrivateKey(EVP_PKEY** a, const(ubyte)** pp, 984 c_long length); 985 int i2d_PrivateKey(EVP_PKEY* a, ubyte** pp); 986 987 int EVP_PKEY_copy_parameters(EVP_PKEY* to, const(EVP_PKEY)* from); 988 int EVP_PKEY_missing_parameters(const(EVP_PKEY)* pkey); 989 int EVP_PKEY_save_parameters(EVP_PKEY* pkey,int mode); 990 int EVP_PKEY_cmp_parameters(const(EVP_PKEY)* a, const(EVP_PKEY)* b); 991 992 int EVP_PKEY_cmp(const(EVP_PKEY)* a, const(EVP_PKEY)* b); 993 994 int EVP_PKEY_print_public(BIO* out_, const(EVP_PKEY)* pkey, 995 int indent, ASN1_PCTX* pctx); 996 int EVP_PKEY_print_private(BIO* out_, const(EVP_PKEY)* pkey, 997 int indent, ASN1_PCTX* pctx); 998 int EVP_PKEY_print_params(BIO* out_, const(EVP_PKEY)* pkey, 999 int indent, ASN1_PCTX* pctx); 1000 1001 int EVP_PKEY_get_default_digest_nid(EVP_PKEY* pkey, int* pnid); 1002 1003 int EVP_CIPHER_type(const(EVP_CIPHER)* ctx); 1004 1005 /* calls methods */ 1006 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX* c, ASN1_TYPE* type); 1007 int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX* c, ASN1_TYPE* type); 1008 1009 /* These are used by EVP_CIPHER methods */ 1010 int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX* c,ASN1_TYPE* type); 1011 int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX* c,ASN1_TYPE* type); 1012 1013 /* PKCS5 password based encryption */ 1014 int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX* ctx, const(char)* pass, int passlen, 1015 ASN1_TYPE* param, const(EVP_CIPHER)* cipher, const(EVP_MD)* md, 1016 int en_de); 1017 int PKCS5_PBKDF2_HMAC_SHA1(const(char)* pass, int passlen, 1018 const(ubyte)* salt, int saltlen, int iter, 1019 int keylen, ubyte* out_); 1020 int PKCS5_PBKDF2_HMAC(const(char)* pass, int passlen, 1021 const(ubyte)* salt, int saltlen, int iter, 1022 const(EVP_MD)* digest, 1023 int keylen, ubyte* out_); 1024 int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX* ctx, const(char)* pass, int passlen, 1025 ASN1_TYPE* param, const(EVP_CIPHER)* cipher, const(EVP_MD)* md, 1026 int en_de); 1027 1028 void PKCS5_PBE_add(); 1029 1030 int EVP_PBE_CipherInit (ASN1_OBJECT* pbe_obj, const(char)* pass, int passlen, 1031 ASN1_TYPE* param, EVP_CIPHER_CTX* ctx, int en_de); 1032 1033 /* PBE type */ 1034 1035 /* Can appear as the outermost AlgorithmIdentifier */ 1036 enum EVP_PBE_TYPE_OUTER = 0x0; 1037 /* Is an PRF type OID */ 1038 enum EVP_PBE_TYPE_PRF = 0x1; 1039 1040 int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, int md_nid, 1041 EVP_PBE_KEYGEN* keygen); 1042 int EVP_PBE_alg_add(int nid, const(EVP_CIPHER)* cipher, const(EVP_MD)* md, 1043 EVP_PBE_KEYGEN* keygen); 1044 int EVP_PBE_find(int type, int pbe_nid, 1045 int* pcnid, int* pmnid, EVP_PBE_KEYGEN** pkeygen); 1046 void EVP_PBE_cleanup(); 1047 1048 enum ASN1_PKEY_ALIAS = 0x1; 1049 enum ASN1_PKEY_DYNAMIC = 0x2; 1050 enum ASN1_PKEY_SIGPARAM_NULL = 0x4; 1051 1052 enum ASN1_PKEY_CTRL_PKCS7_SIGN = 0x1; 1053 enum ASN1_PKEY_CTRL_PKCS7_ENCRYPT = 0x2; 1054 enum ASN1_PKEY_CTRL_DEFAULT_MD_NID = 0x3; 1055 enum ASN1_PKEY_CTRL_CMS_SIGN = 0x5; 1056 enum ASN1_PKEY_CTRL_CMS_ENVELOPE = 0x7; 1057 1058 int EVP_PKEY_asn1_get_count(); 1059 const(EVP_PKEY_ASN1_METHOD)* EVP_PKEY_asn1_get0(int idx); 1060 const(EVP_PKEY_ASN1_METHOD)* EVP_PKEY_asn1_find(ENGINE** pe, int type); 1061 const(EVP_PKEY_ASN1_METHOD)* EVP_PKEY_asn1_find_str(ENGINE** pe, 1062 const(char)* str, int len); 1063 int EVP_PKEY_asn1_add0(const(EVP_PKEY_ASN1_METHOD)* ameth); 1064 int EVP_PKEY_asn1_add_alias(int to, int from); 1065 int EVP_PKEY_asn1_get0_info(int* ppkey_id, int* pkey_base_id, int* ppkey_flags, 1066 const(char)** pinfo, const(char)** ppem_str, 1067 const(EVP_PKEY_ASN1_METHOD)* ameth); 1068 1069 const(EVP_PKEY_ASN1_METHOD)* EVP_PKEY_get0_asn1(EVP_PKEY* pkey); 1070 EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, 1071 const(char)* pem_str, const(char)* info); 1072 void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD* dst, 1073 const(EVP_PKEY_ASN1_METHOD)* src); 1074 void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD* ameth); 1075 void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD* ameth, 1076 ExternC!(int function(EVP_PKEY* pk, X509_PUBKEY* pub)) pub_decode, 1077 ExternC!(int function(X509_PUBKEY* pub, const(EVP_PKEY)* pk)) pub_encode, 1078 ExternC!(int function(const(EVP_PKEY)* a, const(EVP_PKEY)* b)) pub_cmp, 1079 ExternC!(int function(BIO* out_, const(EVP_PKEY)* pkey, int indent, 1080 ASN1_PCTX* pctx)) pub_print, 1081 ExternC!(int function(const(EVP_PKEY)* pk)) pkey_size, 1082 ExternC!(int function(const(EVP_PKEY)* pk)) pkey_bits); 1083 void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD* ameth, 1084 ExternC!(int function(EVP_PKEY* pk, PKCS8_PRIV_KEY_INFO* p8inf)) priv_decode, 1085 ExternC!(int function(PKCS8_PRIV_KEY_INFO* p8, const(EVP_PKEY)* pk)) priv_encode, 1086 ExternC!(int function(BIO* out_, const(EVP_PKEY)* pkey, int indent, 1087 ASN1_PCTX* pctx)) priv_print); 1088 void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD* ameth, 1089 ExternC!(int function(EVP_PKEY* pkey, 1090 const(ubyte)** pder, int derlen)) param_decode, 1091 ExternC!(int function(const(EVP_PKEY)* pkey, ubyte** pder)) param_encode, 1092 ExternC!(int function(const(EVP_PKEY)* pk)) param_missing, 1093 ExternC!(int function(EVP_PKEY* to, const(EVP_PKEY)* from)) param_copy, 1094 ExternC!(int function(const(EVP_PKEY)* a, const(EVP_PKEY)* b)) param_cmp, 1095 ExternC!(int function(BIO* out_, const(EVP_PKEY)* pkey, int indent, 1096 ASN1_PCTX* pctx)) param_print); 1097 1098 void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD* ameth, 1099 ExternC!(void function(EVP_PKEY* pkey)) pkey_free); 1100 void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD* ameth, 1101 ExternC!(int function(EVP_PKEY* pkey, int op, 1102 c_long arg1, void* arg2)) pkey_ctrl); 1103 1104 1105 enum EVP_PKEY_OP_UNDEFINED = 0; 1106 enum EVP_PKEY_OP_PARAMGEN = (1<<1); 1107 enum EVP_PKEY_OP_KEYGEN = (1<<2); 1108 enum EVP_PKEY_OP_SIGN = (1<<3); 1109 enum EVP_PKEY_OP_VERIFY = (1<<4); 1110 enum EVP_PKEY_OP_VERIFYRECOVER = (1<<5); 1111 enum EVP_PKEY_OP_SIGNCTX = (1<<6); 1112 enum EVP_PKEY_OP_VERIFYCTX = (1<<7); 1113 enum EVP_PKEY_OP_ENCRYPT = (1<<8); 1114 enum EVP_PKEY_OP_DECRYPT = (1<<9); 1115 enum EVP_PKEY_OP_DERIVE = (1<<10); 1116 1117 enum EVP_PKEY_OP_TYPE_SIG = 1118 (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY | EVP_PKEY_OP_VERIFYRECOVER 1119 | EVP_PKEY_OP_SIGNCTX | EVP_PKEY_OP_VERIFYCTX); 1120 1121 enum EVP_PKEY_OP_TYPE_CRYPT = 1122 (EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT); 1123 1124 /+ BUG in original headers: EVP_PKEY_OP_SIG, EVP_PKEY_OP_CRYPT are not defined. 1125 enum EVP_PKEY_OP_TYPE_NOGEN = 1126 (EVP_PKEY_OP_SIG | EVP_PKEY_OP_CRYPT | EVP_PKEY_OP_DERIVE); 1127 +/ 1128 1129 enum EVP_PKEY_OP_TYPE_GEN = 1130 (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN); 1131 1132 auto EVP_PKEY_CTX_set_signature_md()(EVP_PKEY_CTX* ctx, void* md) { 1133 return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, 1134 EVP_PKEY_CTRL_MD, 0, md); 1135 } 1136 1137 enum EVP_PKEY_CTRL_MD = 1; 1138 enum EVP_PKEY_CTRL_PEER_KEY = 2; 1139 1140 enum EVP_PKEY_CTRL_PKCS7_ENCRYPT = 3; 1141 enum EVP_PKEY_CTRL_PKCS7_DECRYPT = 4; 1142 1143 enum EVP_PKEY_CTRL_PKCS7_SIGN = 5; 1144 1145 enum EVP_PKEY_CTRL_SET_MAC_KEY = 6; 1146 1147 enum EVP_PKEY_CTRL_DIGESTINIT = 7; 1148 1149 /* Used by GOST key encryption in TLS */ 1150 enum EVP_PKEY_CTRL_SET_IV = 8; 1151 1152 enum EVP_PKEY_CTRL_CMS_ENCRYPT = 9; 1153 enum EVP_PKEY_CTRL_CMS_DECRYPT = 10; 1154 enum EVP_PKEY_CTRL_CMS_SIGN = 11; 1155 1156 enum EVP_PKEY_CTRL_CIPHER = 12; 1157 1158 enum EVP_PKEY_ALG_CTRL = 0x1000; 1159 1160 1161 enum EVP_PKEY_FLAG_AUTOARGLEN = 2; 1162 /* Method handles all operations: don't assume any digest related 1163 * defaults. 1164 */ 1165 enum EVP_PKEY_FLAG_SIGCTX_CUSTOM = 4; 1166 1167 const(EVP_PKEY_METHOD)* EVP_PKEY_meth_find(int type); 1168 EVP_PKEY_METHOD* EVP_PKEY_meth_new(int id, int flags); 1169 void EVP_PKEY_meth_get0_info(int* ppkey_id, int* pflags, 1170 const(EVP_PKEY_METHOD)* meth); 1171 void EVP_PKEY_meth_copy(EVP_PKEY_METHOD* dst, const(EVP_PKEY_METHOD)* src); 1172 void EVP_PKEY_meth_free(EVP_PKEY_METHOD* pmeth); 1173 int EVP_PKEY_meth_add0(const(EVP_PKEY_METHOD)* pmeth); 1174 1175 EVP_PKEY_CTX* EVP_PKEY_CTX_new(EVP_PKEY* pkey, ENGINE* e); 1176 EVP_PKEY_CTX* EVP_PKEY_CTX_new_id(int id, ENGINE* e); 1177 EVP_PKEY_CTX* EVP_PKEY_CTX_dup(EVP_PKEY_CTX* ctx); 1178 void EVP_PKEY_CTX_free(EVP_PKEY_CTX* ctx); 1179 1180 int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX* ctx, int keytype, int optype, 1181 int cmd, int p1, void* p2); 1182 int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX* ctx, const(char)* type, 1183 const(char)* value); 1184 1185 int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX* ctx); 1186 void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX* ctx, int* dat, int datlen); 1187 1188 EVP_PKEY* EVP_PKEY_new_mac_key(int type, ENGINE* e, 1189 const(ubyte)* key, int keylen); 1190 1191 void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX* ctx, void* data); 1192 void* EVP_PKEY_CTX_get_data(EVP_PKEY_CTX* ctx); 1193 EVP_PKEY* EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX* ctx); 1194 1195 EVP_PKEY* EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX* ctx); 1196 1197 void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX* ctx, void* data); 1198 void* EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX* ctx); 1199 1200 int EVP_PKEY_sign_init(EVP_PKEY_CTX* ctx); 1201 int EVP_PKEY_sign(EVP_PKEY_CTX* ctx, 1202 ubyte* sig, size_t* siglen, 1203 const(ubyte)* tbs, size_t tbslen); 1204 int EVP_PKEY_verify_init(EVP_PKEY_CTX* ctx); 1205 int EVP_PKEY_verify(EVP_PKEY_CTX* ctx, 1206 const(ubyte)* sig, size_t siglen, 1207 const(ubyte)* tbs, size_t tbslen); 1208 int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX* ctx); 1209 int EVP_PKEY_verify_recover(EVP_PKEY_CTX* ctx, 1210 ubyte* rout, size_t* routlen, 1211 const(ubyte)* sig, size_t siglen); 1212 int EVP_PKEY_encrypt_init(EVP_PKEY_CTX* ctx); 1213 int EVP_PKEY_encrypt(EVP_PKEY_CTX* ctx, 1214 ubyte* out_, size_t* outlen, 1215 const(ubyte)* in_, size_t inlen); 1216 int EVP_PKEY_decrypt_init(EVP_PKEY_CTX* ctx); 1217 int EVP_PKEY_decrypt(EVP_PKEY_CTX* ctx, 1218 ubyte* out_, size_t* outlen, 1219 const(ubyte)* in_, size_t inlen); 1220 1221 int EVP_PKEY_derive_init(EVP_PKEY_CTX* ctx); 1222 int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX* ctx, EVP_PKEY* peer); 1223 int EVP_PKEY_derive(EVP_PKEY_CTX* ctx, ubyte* key, size_t* keylen); 1224 1225 alias typeof(*(ExternC!(int function(EVP_PKEY_CTX* ctx))).init) EVP_PKEY_gen_cb; 1226 1227 int EVP_PKEY_paramgen_init(EVP_PKEY_CTX* ctx); 1228 int EVP_PKEY_paramgen(EVP_PKEY_CTX* ctx, EVP_PKEY** ppkey); 1229 int EVP_PKEY_keygen_init(EVP_PKEY_CTX* ctx); 1230 int EVP_PKEY_keygen(EVP_PKEY_CTX* ctx, EVP_PKEY** ppkey); 1231 1232 void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX* ctx, EVP_PKEY_gen_cb* cb); 1233 EVP_PKEY_gen_cb* EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX* ctx); 1234 1235 int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX* ctx, int idx); 1236 1237 void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD* pmeth, 1238 ExternC!(int function(EVP_PKEY_CTX* ctx)) init); 1239 1240 void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD* pmeth, 1241 ExternC!(int function(EVP_PKEY_CTX* dst, EVP_PKEY_CTX* src)) copy); 1242 1243 void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD* pmeth, 1244 ExternC!(void function(EVP_PKEY_CTX* ctx)) cleanup); 1245 1246 void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD* pmeth, 1247 ExternC!(int function(EVP_PKEY_CTX* ctx)) paramgen_init, 1248 ExternC!(int function(EVP_PKEY_CTX* ctx, EVP_PKEY* pkey)) paramgen); 1249 1250 void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD* pmeth, 1251 ExternC!(int function(EVP_PKEY_CTX* ctx)) keygen_init, 1252 ExternC!(int function(EVP_PKEY_CTX* ctx, EVP_PKEY* pkey)) keygen); 1253 1254 void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD* pmeth, 1255 ExternC!(int function(EVP_PKEY_CTX* ctx)) sign_init, 1256 ExternC!(int function(EVP_PKEY_CTX* ctx, ubyte* sig, size_t* siglen, 1257 const(ubyte)* tbs, size_t tbslen)) sign); 1258 1259 void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD* pmeth, 1260 ExternC!(int function(EVP_PKEY_CTX* ctx)) verify_init, 1261 ExternC!(int function(EVP_PKEY_CTX* ctx, const(ubyte)* sig, size_t siglen, 1262 const(ubyte)* tbs, size_t tbslen)) verify); 1263 1264 void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD* pmeth, 1265 ExternC!(int function(EVP_PKEY_CTX* ctx)) verify_recover_init, 1266 ExternC!(int function(EVP_PKEY_CTX* ctx, 1267 ubyte* sig, size_t* siglen, 1268 const(ubyte)* tbs, size_t tbslen)) verify_recover); 1269 1270 void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD* pmeth, 1271 ExternC!(int function(EVP_PKEY_CTX* ctx, EVP_MD_CTX* mctx)) signctx_init, 1272 ExternC!(int function(EVP_PKEY_CTX* ctx, ubyte* sig, size_t* siglen, 1273 EVP_MD_CTX* mctx)) signctx); 1274 1275 void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD* pmeth, 1276 ExternC!(int function(EVP_PKEY_CTX* ctx, EVP_MD_CTX* mctx)) verifyctx_init, 1277 ExternC!(int function(EVP_PKEY_CTX* ctx, const(ubyte)* sig,int siglen, 1278 EVP_MD_CTX* mctx)) verifyctx); 1279 1280 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD* pmeth, 1281 ExternC!(int function(EVP_PKEY_CTX* ctx)) encrypt_init, 1282 ExternC!(int function(EVP_PKEY_CTX* ctx, ubyte* out_, size_t* outlen, 1283 const(ubyte)* in_, size_t inlen)) encryptfn); 1284 1285 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD* pmeth, 1286 ExternC!(int function(EVP_PKEY_CTX* ctx)) decrypt_init, 1287 ExternC!(int function(EVP_PKEY_CTX* ctx, ubyte* out_, size_t* outlen, 1288 const(ubyte)* in_, size_t inlen)) decrypt); 1289 1290 void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD* pmeth, 1291 ExternC!(int function(EVP_PKEY_CTX* ctx)) derive_init, 1292 ExternC!(int function(EVP_PKEY_CTX* ctx, ubyte* key, size_t* keylen)) derive); 1293 1294 void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD* pmeth, 1295 ExternC!(int function(EVP_PKEY_CTX* ctx, int type, int p1, void* p2)) ctrl, 1296 ExternC!(int function(EVP_PKEY_CTX* ctx, 1297 const(char)* type, const(char)* value)) ctrl_str); 1298 1299 void EVP_add_alg_module(); 1300 1301 /* BEGIN ERROR CODES */ 1302 /* The following lines are auto generated by the script mkerr.pl. Any changes 1303 * made after this point may be overwritten when the script is next run. 1304 */ 1305 void ERR_load_EVP_strings(); 1306 1307 /* Error codes for the EVP functions. */ 1308 1309 /* Function codes. */ 1310 enum EVP_F_AESNI_INIT_KEY = 165; 1311 enum EVP_F_AESNI_XTS_CIPHER = 176; 1312 enum EVP_F_AES_INIT_KEY = 133; 1313 enum EVP_F_AES_XTS = 172; 1314 enum EVP_F_AES_XTS_CIPHER = 175; 1315 enum EVP_F_ALG_MODULE_INIT = 177; 1316 enum EVP_F_CAMELLIA_INIT_KEY = 159; 1317 enum EVP_F_CMAC_INIT = 173; 1318 enum EVP_F_D2I_PKEY = 100; 1319 enum EVP_F_DO_SIGVER_INIT = 161; 1320 enum EVP_F_DSAPKEY2PKCS8 = 134; 1321 enum EVP_F_DSA_PKEY2PKCS8 = 135; 1322 enum EVP_F_ECDSA_PKEY2PKCS8 = 129; 1323 enum EVP_F_ECKEY_PKEY2PKCS8 = 132; 1324 enum EVP_F_EVP_CIPHERINIT_EX = 123; 1325 enum EVP_F_EVP_CIPHER_CTX_COPY = 163; 1326 enum EVP_F_EVP_CIPHER_CTX_CTRL = 124; 1327 enum EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH = 122; 1328 enum EVP_F_EVP_DECRYPTFINAL_EX = 101; 1329 enum EVP_F_EVP_DIGESTINIT_EX = 128; 1330 enum EVP_F_EVP_ENCRYPTFINAL_EX = 127; 1331 enum EVP_F_EVP_MD_CTX_COPY_EX = 110; 1332 enum EVP_F_EVP_MD_SIZE = 162; 1333 enum EVP_F_EVP_OPENINIT = 102; 1334 enum EVP_F_EVP_PBE_ALG_ADD = 115; 1335 enum EVP_F_EVP_PBE_ALG_ADD_TYPE = 160; 1336 enum EVP_F_EVP_PBE_CIPHERINIT = 116; 1337 enum EVP_F_EVP_PKCS82PKEY = 111; 1338 enum EVP_F_EVP_PKCS82PKEY_BROKEN = 136; 1339 enum EVP_F_EVP_PKEY2PKCS8_BROKEN = 113; 1340 enum EVP_F_EVP_PKEY_COPY_PARAMETERS = 103; 1341 enum EVP_F_EVP_PKEY_CTX_CTRL = 137; 1342 enum EVP_F_EVP_PKEY_CTX_CTRL_STR = 150; 1343 enum EVP_F_EVP_PKEY_CTX_DUP = 156; 1344 enum EVP_F_EVP_PKEY_DECRYPT = 104; 1345 enum EVP_F_EVP_PKEY_DECRYPT_INIT = 138; 1346 enum EVP_F_EVP_PKEY_DECRYPT_OLD = 151; 1347 enum EVP_F_EVP_PKEY_DERIVE = 153; 1348 enum EVP_F_EVP_PKEY_DERIVE_INIT = 154; 1349 enum EVP_F_EVP_PKEY_DERIVE_SET_PEER = 155; 1350 enum EVP_F_EVP_PKEY_ENCRYPT = 105; 1351 enum EVP_F_EVP_PKEY_ENCRYPT_INIT = 139; 1352 enum EVP_F_EVP_PKEY_ENCRYPT_OLD = 152; 1353 enum EVP_F_EVP_PKEY_GET1_DH = 119; 1354 enum EVP_F_EVP_PKEY_GET1_DSA = 120; 1355 enum EVP_F_EVP_PKEY_GET1_ECDSA = 130; 1356 enum EVP_F_EVP_PKEY_GET1_EC_KEY = 131; 1357 enum EVP_F_EVP_PKEY_GET1_RSA = 121; 1358 enum EVP_F_EVP_PKEY_KEYGEN = 146; 1359 enum EVP_F_EVP_PKEY_KEYGEN_INIT = 147; 1360 enum EVP_F_EVP_PKEY_NEW = 106; 1361 enum EVP_F_EVP_PKEY_PARAMGEN = 148; 1362 enum EVP_F_EVP_PKEY_PARAMGEN_INIT = 149; 1363 enum EVP_F_EVP_PKEY_SIGN = 140; 1364 enum EVP_F_EVP_PKEY_SIGN_INIT = 141; 1365 enum EVP_F_EVP_PKEY_VERIFY = 142; 1366 enum EVP_F_EVP_PKEY_VERIFY_INIT = 143; 1367 enum EVP_F_EVP_PKEY_VERIFY_RECOVER = 144; 1368 enum EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT = 145; 1369 enum EVP_F_EVP_RIJNDAEL = 126; 1370 enum EVP_F_EVP_SIGNFINAL = 107; 1371 enum EVP_F_EVP_VERIFYFINAL = 108; 1372 enum EVP_F_FIPS_CIPHERINIT = 166; 1373 enum EVP_F_FIPS_CIPHER_CTX_COPY = 170; 1374 enum EVP_F_FIPS_CIPHER_CTX_CTRL = 167; 1375 enum EVP_F_FIPS_CIPHER_CTX_SET_KEY_LENGTH = 171; 1376 enum EVP_F_FIPS_DIGESTINIT = 168; 1377 enum EVP_F_FIPS_MD_CTX_COPY = 169; 1378 enum EVP_F_HMAC_INIT_EX = 174; 1379 enum EVP_F_INT_CTX_NEW = 157; 1380 enum EVP_F_PKCS5_PBE_KEYIVGEN = 117; 1381 enum EVP_F_PKCS5_V2_PBE_KEYIVGEN = 118; 1382 enum EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN = 164; 1383 enum EVP_F_PKCS8_SET_BROKEN = 112; 1384 enum EVP_F_PKEY_SET_TYPE = 158; 1385 enum EVP_F_RC2_MAGIC_TO_METH = 109; 1386 enum EVP_F_RC5_CTRL = 125; 1387 1388 /* Reason codes. */ 1389 enum EVP_R_AES_IV_SETUP_FAILED = 162; 1390 enum EVP_R_AES_KEY_SETUP_FAILED = 143; 1391 enum EVP_R_ASN1_LIB = 140; 1392 enum EVP_R_BAD_BLOCK_LENGTH = 136; 1393 enum EVP_R_BAD_DECRYPT = 100; 1394 enum EVP_R_BAD_KEY_LENGTH = 137; 1395 enum EVP_R_BN_DECODE_ERROR = 112; 1396 enum EVP_R_BN_PUBKEY_ERROR = 113; 1397 enum EVP_R_BUFFER_TOO_SMALL = 155; 1398 enum EVP_R_CAMELLIA_KEY_SETUP_FAILED = 157; 1399 enum EVP_R_CIPHER_PARAMETER_ERROR = 122; 1400 enum EVP_R_COMMAND_NOT_SUPPORTED = 147; 1401 enum EVP_R_CTRL_NOT_IMPLEMENTED = 132; 1402 enum EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED = 133; 1403 enum EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH = 138; 1404 enum EVP_R_DECODE_ERROR = 114; 1405 enum EVP_R_DIFFERENT_KEY_TYPES = 101; 1406 enum EVP_R_DIFFERENT_PARAMETERS = 153; 1407 enum EVP_R_DISABLED_FOR_FIPS = 163; 1408 enum EVP_R_ENCODE_ERROR = 115; 1409 enum EVP_R_ERROR_LOADING_SECTION = 165; 1410 enum EVP_R_ERROR_SETTING_FIPS_MODE = 166; 1411 enum EVP_R_EVP_PBE_CIPHERINIT_ERROR = 119; 1412 enum EVP_R_EXPECTING_AN_RSA_KEY = 127; 1413 enum EVP_R_EXPECTING_A_DH_KEY = 128; 1414 enum EVP_R_EXPECTING_A_DSA_KEY = 129; 1415 enum EVP_R_EXPECTING_A_ECDSA_KEY = 141; 1416 enum EVP_R_EXPECTING_A_EC_KEY = 142; 1417 enum EVP_R_FIPS_MODE_NOT_SUPPORTED = 167; 1418 enum EVP_R_INITIALIZATION_ERROR = 134; 1419 enum EVP_R_INPUT_NOT_INITIALIZED = 111; 1420 enum EVP_R_INVALID_DIGEST = 152; 1421 enum EVP_R_INVALID_FIPS_MODE = 168; 1422 enum EVP_R_INVALID_KEY_LENGTH = 130; 1423 enum EVP_R_INVALID_OPERATION = 148; 1424 enum EVP_R_IV_TOO_LARGE = 102; 1425 enum EVP_R_KEYGEN_FAILURE = 120; 1426 enum EVP_R_MESSAGE_DIGEST_IS_NULL = 159; 1427 enum EVP_R_METHOD_NOT_SUPPORTED = 144; 1428 enum EVP_R_MISSING_PARAMETERS = 103; 1429 enum EVP_R_NO_CIPHER_SET = 131; 1430 enum EVP_R_NO_DEFAULT_DIGEST = 158; 1431 enum EVP_R_NO_DIGEST_SET = 139; 1432 enum EVP_R_NO_DSA_PARAMETERS = 116; 1433 enum EVP_R_NO_KEY_SET = 154; 1434 enum EVP_R_NO_OPERATION_SET = 149; 1435 enum EVP_R_NO_SIGN_FUNCTION_CONFIGURED = 104; 1436 enum EVP_R_NO_VERIFY_FUNCTION_CONFIGURED = 105; 1437 enum EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE = 150; 1438 enum EVP_R_OPERATON_NOT_INITIALIZED = 151; 1439 enum EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE = 117; 1440 enum EVP_R_PRIVATE_KEY_DECODE_ERROR = 145; 1441 enum EVP_R_PRIVATE_KEY_ENCODE_ERROR = 146; 1442 enum EVP_R_PUBLIC_KEY_NOT_RSA = 106; 1443 enum EVP_R_TOO_LARGE = 164; 1444 enum EVP_R_UNKNOWN_CIPHER = 160; 1445 enum EVP_R_UNKNOWN_DIGEST = 161; 1446 enum EVP_R_UNKNOWN_OPTION = 169; 1447 enum EVP_R_UNKNOWN_PBE_ALGORITHM = 121; 1448 enum EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS = 135; 1449 enum EVP_R_UNSUPPORTED_ALGORITHM = 156; 1450 enum EVP_R_UNSUPPORTED_CIPHER = 107; 1451 enum EVP_R_UNSUPPORTED_KEYLENGTH = 123; 1452 enum EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION = 124; 1453 enum EVP_R_UNSUPPORTED_KEY_SIZE = 108; 1454 enum EVP_R_UNSUPPORTED_PRF = 125; 1455 enum EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM = 118; 1456 enum EVP_R_UNSUPPORTED_SALT_TYPE = 126; 1457 enum EVP_R_WRONG_FINAL_BLOCK_LENGTH = 109; 1458 enum EVP_R_WRONG_PUBLIC_KEY_TYPE = 110;