1 /* crypto/crypto.h */ 2 /* ==================================================================== 3 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * 17 * 3. All advertising materials mentioning features or use of this 18 * software must display the following acknowledgment: 19 * "This product includes software developed by the OpenSSL Project 20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 21 * 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23 * endorse or promote products derived from this software without 24 * prior written permission. For written permission, please contact 25 * openssl-core@openssl.org. 26 * 27 * 5. Products derived from this software may not be called "OpenSSL" 28 * nor may "OpenSSL" appear in their names without prior written 29 * permission of the OpenSSL Project. 30 * 31 * 6. Redistributions of any form whatsoever must retain the following 32 * acknowledgment: 33 * "This product includes software developed by the OpenSSL Project 34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 35 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47 * OF THE POSSIBILITY OF SUCH DAMAGE. 48 * ==================================================================== 49 * 50 * This product includes cryptographic software written by Eric Young 51 * (eay@cryptsoft.com). This product includes software written by Tim 52 * Hudson (tjh@cryptsoft.com). 53 * 54 */ 55 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 56 * All rights reserved. 57 * 58 * This package is an SSL implementation written 59 * by Eric Young (eay@cryptsoft.com). 60 * The implementation was written so as to conform with Netscapes SSL. 61 * 62 * This library is free for commercial and non-commercial use as long as 63 * the following conditions are aheared to. The following conditions 64 * apply to all code found in this distribution, be it the RC4, RSA, 65 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 66 * included with this distribution is covered by the same copyright terms 67 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 68 * 69 * Copyright remains Eric Young's, and as such any Copyright notices in 70 * the code are not to be removed. 71 * If this package is used in a product, Eric Young should be given attribution 72 * as the author of the parts of the library used. 73 * This can be in the form of a textual message at program startup or 74 * in documentation (online or textual) provided with the package. 75 * 76 * Redistribution and use in source and binary forms, with or without 77 * modification, are permitted provided that the following conditions 78 * are met: 79 * 1. Redistributions of source code must retain the copyright 80 * notice, this list of conditions and the following disclaimer. 81 * 2. Redistributions in binary form must reproduce the above copyright 82 * notice, this list of conditions and the following disclaimer in the 83 * documentation and/or other materials provided with the distribution. 84 * 3. All advertising materials mentioning features or use of this software 85 * must display the following acknowledgement: 86 * "This product includes cryptographic software written by 87 * Eric Young (eay@cryptsoft.com)" 88 * The word 'cryptographic' can be left out if the rouines from the library 89 * being used are not cryptographic related :-). 90 * 4. If you include any Windows specific code (or a derivative thereof) from 91 * the apps directory (application code) you must include an acknowledgement: 92 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 93 * 94 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 95 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 96 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 97 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 98 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 99 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 100 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 101 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 102 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 103 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 104 * SUCH DAMAGE. 105 * 106 * The licence and distribution terms for any publically available version or 107 * derivative of this code cannot be changed. i.e. this code cannot simply be 108 * copied and put under another distribution licence 109 * [including the GNU Public Licence.] 110 */ 111 /* ==================================================================== 112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 113 * ECDH support in OpenSSL originally developed by 114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. 115 */ 116 117 module deimos.openssl.crypto; 118 119 import deimos.openssl._d_util; 120 121 import core.stdc.stdlib; 122 123 public import deimos.openssl.e_os2; 124 125 version(OPENSSL_NO_FP_API) {} else { 126 import core.stdc.stdio; 127 } 128 129 public import deimos.openssl.stack; 130 public import deimos.openssl.safestack; 131 public import deimos.openssl.opensslv; 132 public import deimos.openssl.ossl_typ; 133 134 version (CHARSET_EBCDIC) { 135 public import deimos.openssl.ebcdic; 136 } 137 138 /* Resolve problems on some operating systems with symbol names that clash 139 one way or another */ 140 public import deimos.openssl.symhacks; 141 142 extern (C): 143 nothrow: 144 145 /* Backward compatibility to SSLeay */ 146 /* This is more to be used to check the correct DLL is being used 147 * in the MS world. */ 148 alias OPENSSL_VERSION_NUMBER SSLEAY_VERSION_NUMBER; 149 enum SSLEAY_VERSION = 0; 150 /* enum SSLEAY_OPTIONS = 1; no longer supported */ 151 enum SSLEAY_CFLAGS = 2; 152 enum SSLEAY_BUILT_ON = 3; 153 enum SSLEAY_PLATFORM = 4; 154 enum SSLEAY_DIR = 5; 155 156 /* Already declared in ossl_typ.h */ 157 /+#if 0 158 alias crypto_ex_data_st CRYPTO_EX_DATA; 159 /* Called when a new object is created */ 160 typedef int CRYPTO_EX_new(void* parent, void* ptr, CRYPTO_EX_DATA* ad, 161 int idx, c_long argl, void* argp); 162 /* Called when an object is free()ed */ 163 typedef void CRYPTO_EX_free(void* parent, void* ptr, CRYPTO_EX_DATA* ad, 164 int idx, c_long argl, void* argp); 165 /* Called when we need to dup an object */ 166 typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA* to, CRYPTO_EX_DATA* from, void* from_d, 167 int idx, c_long argl, void* argp); 168 #endif+/ 169 170 /* A generic structure to pass assorted data in a expandable way */ 171 struct openssl_item_st { 172 int code; 173 void* value; /* Not used for flag attributes */ 174 size_t value_size; /* Max size of value for output, length for input */ 175 size_t* value_length; /* Returned length of value for output */ 176 } 177 alias openssl_item_st OPENSSL_ITEM; 178 179 180 /* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock 181 * names in cryptlib.c 182 */ 183 184 enum CRYPTO_LOCK_ERR = 1; 185 enum CRYPTO_LOCK_EX_DATA = 2; 186 enum CRYPTO_LOCK_X509 = 3; 187 enum CRYPTO_LOCK_X509_INFO = 4; 188 enum CRYPTO_LOCK_X509_PKEY = 5; 189 enum CRYPTO_LOCK_X509_CRL = 6; 190 enum CRYPTO_LOCK_X509_REQ = 7; 191 enum CRYPTO_LOCK_DSA = 8; 192 enum CRYPTO_LOCK_RSA = 9; 193 enum CRYPTO_LOCK_EVP_PKEY = 10; 194 enum CRYPTO_LOCK_X509_STORE = 11; 195 enum CRYPTO_LOCK_SSL_CTX = 12; 196 enum CRYPTO_LOCK_SSL_CERT = 13; 197 enum CRYPTO_LOCK_SSL_SESSION = 14; 198 enum CRYPTO_LOCK_SSL_SESS_CERT = 15; 199 enum CRYPTO_LOCK_SSL = 16; 200 enum CRYPTO_LOCK_SSL_METHOD = 17; 201 enum CRYPTO_LOCK_RAND = 18; 202 enum CRYPTO_LOCK_RAND2 = 19; 203 enum CRYPTO_LOCK_MALLOC = 20; 204 enum CRYPTO_LOCK_BIO = 21; 205 enum CRYPTO_LOCK_GETHOSTBYNAME = 22; 206 enum CRYPTO_LOCK_GETSERVBYNAME = 23; 207 enum CRYPTO_LOCK_READDIR = 24; 208 enum CRYPTO_LOCK_RSA_BLINDING = 25; 209 enum CRYPTO_LOCK_DH = 26; 210 enum CRYPTO_LOCK_MALLOC2 = 27; 211 enum CRYPTO_LOCK_DSO = 28; 212 enum CRYPTO_LOCK_DYNLOCK = 29; 213 enum CRYPTO_LOCK_ENGINE = 30; 214 enum CRYPTO_LOCK_UI = 31; 215 enum CRYPTO_LOCK_ECDSA = 32; 216 enum CRYPTO_LOCK_EC = 33; 217 enum CRYPTO_LOCK_ECDH = 34; 218 enum CRYPTO_LOCK_BN = 35; 219 enum CRYPTO_LOCK_EC_PRE_COMP = 36; 220 enum CRYPTO_LOCK_STORE = 37; 221 enum CRYPTO_LOCK_COMP = 38; 222 enum CRYPTO_LOCK_FIPS = 39; 223 enum CRYPTO_LOCK_FIPS2 = 40; 224 enum CRYPTO_NUM_LOCKS = 41; 225 226 enum CRYPTO_LOCK = 1; 227 enum CRYPTO_UNLOCK = 2; 228 enum CRYPTO_READ = 4; 229 enum CRYPTO_WRITE = 8; 230 231 version (OPENSSL_NO_LOCKING) { 232 void CRYPTO_w_lock()(int type) {} 233 void CRYPTO_w_unlock()(int type) {} 234 void CRYPTO_r_lock()(int type) {} 235 void CRYPTO_r_unlock()(int type) {} 236 void CRYPTO_add()(int* addr, int amount, int type) { *addr += amount; } 237 } else { 238 void CRYPTO_w_lock(string file = __FILE__, size_t line = __LINE__)(int type) { 239 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file.ptr,line); 240 } 241 void CRYPTO_w_unlock(string file = __FILE__, size_t line = __LINE__)(int type) { 242 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file.ptr,line); 243 } 244 void CRYPTO_r_lock(string file = __FILE__, size_t line = __LINE__)(int type) { 245 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,file.ptr,line); 246 } 247 void CRYPTO_r_unlock(string file = __FILE__, size_t line = __LINE__)(int type) { 248 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,file.ptr,line); 249 } 250 void CRYPTO_add(string file = __FILE__, size_t line = __LINE__)(int* addr, int amount, int type) { 251 CRYPTO_add_lock(addr,amount,type,file.ptr,line); 252 } 253 } 254 255 /* Some applications as well as some parts of OpenSSL need to allocate 256 and deallocate locks in a dynamic fashion. The following typedef 257 makes this possible in a type-safe manner. */ 258 /* CRYPTO_dynlock_value has to be defined by the application. */ 259 // FIXME: struct CRYPTO_dynlock_value; 260 struct CRYPTO_dynlock 261 { 262 int references; 263 CRYPTO_dynlock_value* data; 264 } 265 266 267 /* The following can be used to detect memory leaks in the SSLeay library. 268 * It used, it turns on malloc checking */ 269 270 enum CRYPTO_MEM_CHECK_OFF = 0x0; /* an enume */ 271 enum CRYPTO_MEM_CHECK_ON = 0x1; /* a bit */ 272 enum CRYPTO_MEM_CHECK_ENABLE = 0x2; /* a bit */ 273 enum CRYPTO_MEM_CHECK_DISABLE = 0x3; /* an enume */ 274 275 /* The following are bit values to turn on or off options connected to the 276 * malloc checking functionality */ 277 278 /* Adds time to the memory checking information */ 279 enum V_CRYPTO_MDEBUG_TIME = 0x1; /* a bit */ 280 /* Adds thread number to the memory checking information */ 281 enum V_CRYPTO_MDEBUG_THREAD = 0x2; /* a bit */ 282 283 enum V_CRYPTO_MDEBUG_ALL = (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD); 284 285 286 /* predec of the BIO type */ 287 import deimos.openssl.bio; /*struct bio_st;*/ 288 alias bio_st BIO_dummy; 289 290 struct crypto_ex_data_st 291 { 292 STACK_OF!() *sk; 293 int dummy; /* gcc is screwing up this data structure :-( */ 294 }; 295 /+mixin DECLARE_STACK_OF!();+/ 296 297 /* This stuff is basically class callback functions 298 * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */ 299 300 struct crypto_ex_data_func_st { 301 c_long argl; /* Arbitary c_long */ 302 void* argp; /* Arbitary void* */ 303 CRYPTO_EX_new* new_func; 304 CRYPTO_EX_free* free_func; 305 CRYPTO_EX_dup* dup_func; 306 } 307 alias crypto_ex_data_func_st CRYPTO_EX_DATA_FUNCS; 308 309 /+mixin DECLARE_STACK_OF!(CRYPTO_EX_DATA_FUNCS);+/ 310 311 /* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA 312 * entry. 313 */ 314 315 enum CRYPTO_EX_INDEX_BIO = 0; 316 enum CRYPTO_EX_INDEX_SSL = 1; 317 enum CRYPTO_EX_INDEX_SSL_CTX = 2; 318 enum CRYPTO_EX_INDEX_SSL_SESSION = 3; 319 enum CRYPTO_EX_INDEX_X509_STORE = 4; 320 enum CRYPTO_EX_INDEX_X509_STORE_CTX = 5; 321 enum CRYPTO_EX_INDEX_RSA = 6; 322 enum CRYPTO_EX_INDEX_DSA = 7; 323 enum CRYPTO_EX_INDEX_DH = 8; 324 enum CRYPTO_EX_INDEX_ENGINE = 9; 325 enum CRYPTO_EX_INDEX_X509 = 10; 326 enum CRYPTO_EX_INDEX_UI = 11; 327 enum CRYPTO_EX_INDEX_ECDSA = 12; 328 enum CRYPTO_EX_INDEX_ECDH = 13; 329 enum CRYPTO_EX_INDEX_COMP = 14; 330 enum CRYPTO_EX_INDEX_STORE = 15; 331 332 /* Dynamically assigned indexes start from this value (don't use directly, use 333 * via CRYPTO_ex_data_new_class). */ 334 enum CRYPTO_EX_INDEX_USER = 100; 335 336 337 /* This is the default callbacks, but we can have others as well: 338 * this is needed in Win32 where the application malloc and the 339 * library malloc may not be the same. 340 */ 341 void CRYPTO_malloc_init()() { 342 CRYPTO_set_mem_functions(&malloc, &realloc, &free); 343 } 344 345 /+#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD 346 # ifndef CRYPTO_MDEBUG /* avoid duplicate #define */ 347 # define CRYPTO_MDEBUG 348 # endif 349 #endif+/ 350 351 /* Set standard debugging functions (not done by default 352 * unless CRYPTO_MDEBUG is defined) */ 353 void CRYPTO_malloc_debug_init()() { 354 CRYPTO_set_mem_debug_functions(&CRYPTO_dbg_malloc, &CRYPTO_dbg_realloc, 355 &CRYPTO_dbg_free, &CRYPTO_dbg_set_options, &CRYPTO_dbg_get_options); 356 } 357 358 int CRYPTO_mem_ctrl(int mode); 359 int CRYPTO_is_mem_check_on(); 360 361 /* for applications */ 362 int MemCheck_start()() { return CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); } 363 int MemCheck_stop()(){ return CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF); } 364 365 /* for library-internal use */ 366 int MemCheck_on()() { return CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); } 367 int MemCheck_off()() { return CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); } 368 alias CRYPTO_is_mem_check_on is_MemCheck_on; 369 370 auto OPENSSL_malloc(string file = __FILE__, size_t line = __LINE__)(int num) { 371 return CRYPTO_malloc(num,file.ptr,line); 372 } 373 auto OPENSSL_strdup(string file = __FILE__, size_t line = __LINE__)(const(char)* str) { 374 return CRYPTO_strdup(str,file.ptr,line); 375 } 376 auto OPENSSL_realloc(string file = __FILE__, size_t line = __LINE__)(void* addr, int num) { 377 return CRYPTO_realloc(addr,num,file.ptr,line); 378 } 379 auto OPENSSL_realloc_clean(string file = __FILE__, size_t line = __LINE__)(void* addr,int old_num,int num) { 380 CRYPTO_realloc_clean(addr,old_num,num,file.ptr,line); 381 } 382 auto OPENSSL_remalloc(string file = __FILE__, size_t line = __LINE__)(void** addr, int num) { 383 return CRYPTO_remalloc(cast(char**)addr,num,file.ptr,line); 384 } 385 alias CRYPTO_free OPENSSL_freeFunc; 386 alias CRYPTO_free OPENSSL_free; 387 388 auto OPENSSL_malloc_locked(string file = __FILE__, size_t line = __LINE__)(int num) { 389 return CRYPTO_malloc_locked(num, file.ptr, line); 390 } 391 alias CRYPTO_free_locked OPENSSL_free_locked; 392 393 394 const(char)* SSLeay_version(int type); 395 c_ulong SSLeay(); 396 397 int OPENSSL_issetugid(); 398 399 /* An opaque type representing an implementation of "ex_data" support */ 400 struct st_CRYPTO_EX_DATA_IMPL; 401 alias st_CRYPTO_EX_DATA_IMPL CRYPTO_EX_DATA_IMPL; 402 /* Return an opaque pointer to the current "ex_data" implementation */ 403 const(CRYPTO_EX_DATA_IMPL)* CRYPTO_get_ex_data_implementation(); 404 /* Sets the "ex_data" implementation to be used (if it's not too late) */ 405 int CRYPTO_set_ex_data_implementation(const(CRYPTO_EX_DATA_IMPL)* i); 406 /* Get a new "ex_data" class, and return the corresponding "class_index" */ 407 int CRYPTO_ex_data_new_class(); 408 /* Within a given class, get/register a new index */ 409 int CRYPTO_get_ex_new_index(int class_index, c_long argl, void* argp, 410 CRYPTO_EX_new* new_func, CRYPTO_EX_dup* dup_func, 411 CRYPTO_EX_free* free_func); 412 /* Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a given 413 * class (invokes whatever per-class callbacks are applicable) */ 414 int CRYPTO_new_ex_data(int class_index, void* obj, CRYPTO_EX_DATA* ad); 415 int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA* to, 416 CRYPTO_EX_DATA* from); 417 void CRYPTO_free_ex_data(int class_index, void* obj, CRYPTO_EX_DATA* ad); 418 /* Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular index 419 * (relative to the class type involved) */ 420 int CRYPTO_set_ex_data(CRYPTO_EX_DATA* ad, int idx, void* val); 421 void* CRYPTO_get_ex_data(const(CRYPTO_EX_DATA)* ad,int idx); 422 423 int CRYPTO_get_new_lockid(char* name); 424 425 void CRYPTO_lock(int mode, int type,const(char)* file,int line); 426 427 /* Don't use this structure directly. */ 428 struct crypto_threadid_st { 429 void* ptr; 430 c_ulong val; 431 } 432 alias crypto_threadid_st CRYPTO_THREADID; 433 /* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */ 434 void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID* id, c_ulong val); 435 void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID* id, void* ptr); 436 int CRYPTO_THREADID_set_callback(ExternC!(void function(CRYPTO_THREADID*)) threadid_func); 437 ExternC!(void function(CRYPTO_THREADID*)) CRYPTO_THREADID_get_callback(); 438 void CRYPTO_THREADID_current(CRYPTO_THREADID* id); 439 int CRYPTO_THREADID_cmp(const(CRYPTO_THREADID)* a, const(CRYPTO_THREADID)* b); 440 void CRYPTO_THREADID_cpy(CRYPTO_THREADID* dest, const(CRYPTO_THREADID)* src); 441 c_ulong CRYPTO_THREADID_hash(const(CRYPTO_THREADID)* id); 442 version(OPENSSL_NO_DEPRECATED) {} else { 443 void CRYPTO_set_id_callback(ExternC!(c_ulong function()) func); 444 ExternC!(c_ulong function()) CRYPTO_get_id_callback(); 445 c_ulong CRYPTO_thread_id(); 446 } 447 448 const(char)* CRYPTO_get_lock_name(int type); 449 int CRYPTO_add_lock(int* pointer,int amount,int type, const(char)* file, 450 int line); 451 452 int CRYPTO_get_new_dynlockid(); 453 void CRYPTO_destroy_dynlockid(int i); 454 struct CRYPTO_dynlock_value; 455 CRYPTO_dynlock_value* CRYPTO_get_dynlock_value(int i); 456 457 /* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions -- 458 * call the latter last if you need different functions */ 459 int CRYPTO_set_mem_functions(ExternC!(void* function(size_t)) m,ExternC!(void* function(void*,size_t)) r, ExternC!(void function(void*)) f); 460 int CRYPTO_set_locked_mem_functions(ExternC!(void* function(size_t)) m, ExternC!(void function(void*)) free_func); 461 int CRYPTO_set_mem_ex_functions(ExternC!(void* function(size_t,const(char)*,int)) m, 462 ExternC!(void* function(void*,size_t,const(char)*,int)) r, 463 ExternC!(void function(void*)) f); 464 int CRYPTO_set_locked_mem_ex_functions(ExternC!(void* function(size_t,const(char)*,int)) m, 465 ExternC!(void function(void*)) free_func); 466 int CRYPTO_set_mem_debug_functions(ExternC!(void function(void*,int,const(char)*,int,int)) m, 467 ExternC!(void function(void*,void*,int,const(char)*,int,int)) r, 468 ExternC!(void function(void*,int)) f, 469 ExternC!(void function(c_long)) so, 470 ExternC!(c_long function()) go); 471 void CRYPTO_get_mem_functions(ExternC!(void* function(size_t))* m,ExternC!(void* function(void*, size_t))* r, ExternC!(void function(void*))* f); 472 void CRYPTO_get_locked_mem_functions(ExternC!(void* function(size_t))* m, ExternC!(void function(void*))* f); 473 void CRYPTO_get_mem_ex_functions(ExternC!(void* function(size_t,const(char)*,int))* m, 474 ExternC!(void* function(void*, size_t,const(char)*,int))* r, 475 ExternC!(void function(void*))* f); 476 void CRYPTO_get_locked_mem_ex_functions(ExternC!(void* function(size_t,const(char)*,int))* m, 477 ExternC!(void function(void*))* f); 478 void CRYPTO_get_mem_debug_functions(ExternC!(void function(void*,int,const(char)*,int,int))* m, 479 ExternC!(void function(void*,void*,int,const(char)*,int,int))* r, 480 ExternC!(void function(void*,int))* f, 481 ExternC!(void function(c_long))* so, 482 ExternC!(c_long function())* go); 483 484 void* CRYPTO_malloc_locked(int num, const(char)* file, int line); 485 void CRYPTO_free_locked(void* ptr); 486 void* CRYPTO_malloc(int num, const(char)* file, int line); 487 char* CRYPTO_strdup(const(char)* str, const(char)* file, int line); 488 void CRYPTO_free(void* ptr); 489 void* CRYPTO_realloc(void* addr,int num, const(char)* file, int line); 490 void* CRYPTO_realloc_clean(void* addr,int old_num,int num,const(char)* file, 491 int line); 492 void* CRYPTO_remalloc(void* addr,int num, const(char)* file, int line); 493 494 void OPENSSL_cleanse(void* ptr, size_t len); 495 496 void CRYPTO_set_mem_debug_options(c_long bits); 497 c_long CRYPTO_get_mem_debug_options(); 498 499 auto CRYPTO_push_info(string file = __FILE__, size_t line = __LINE__)(const(char)* info) { 500 return CRYPTO_push_info_(info, file.ptr, line); 501 } 502 int CRYPTO_push_info_(const(char)* info, const(char)* file, int line); 503 int CRYPTO_pop_info(); 504 int CRYPTO_remove_all_info(); 505 506 507 /* Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro; 508 * used as default in CRYPTO_MDEBUG compilations): */ 509 /* The last argument has the following significance: 510 * 511 * 0: called before the actual memory allocation has taken place 512 * 1: called after the actual memory allocation has taken place 513 */ 514 void CRYPTO_dbg_malloc(void* addr,int num,const(char)* file,int line,int before_p); 515 void CRYPTO_dbg_realloc(void* addr1,void* addr2,int num,const(char)* file,int line,int before_p); 516 void CRYPTO_dbg_free(void* addr,int before_p); 517 /* Tell the debugging code about options. By default, the following values 518 * apply: 519 * 520 * 0: Clear all options. 521 * V_CRYPTO_MDEBUG_TIME (1): Set the "Show Time" option. 522 * V_CRYPTO_MDEBUG_THREAD (2): Set the "Show Thread Number" option. 523 * V_CRYPTO_MDEBUG_ALL (3): 1 + 2 524 */ 525 void CRYPTO_dbg_set_options(c_long bits); 526 c_long CRYPTO_dbg_get_options(); 527 528 529 version(OPENSSL_NO_FP_API) {} else { 530 void CRYPTO_mem_leaks_fp(FILE*); 531 } 532 void CRYPTO_mem_leaks(bio_st* bio); 533 /* c_ulong order, char* file, int line, int num_bytes, char* addr */ 534 alias typeof(*(void* function (c_ulong, const(char)*, int, int, void*)).init) CRYPTO_MEM_LEAK_CB; 535 void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB* cb); 536 537 /* die if we have to */ 538 void OpenSSLDie(const(char)* file,int line,const(char)* assertion); 539 void OPENSSL_assert(string file = __FILE__, size_t line = __LINE__)(int e) { 540 if (!e) OpenSSLDie(file.ptr, line, "assertion failed"); // No good way to translate. 541 } 542 543 c_ulong* OPENSSL_ia32cap_loc(); 544 auto OPENSSL_ia32cap()(){ return* OPENSSL_ia32cap_loc(); } 545 int OPENSSL_isservice(); 546 547 int FIPS_mode(); 548 int FIPS_mode_set(int r); 549 550 void OPENSSL_init(); 551 552 /+ // TODO: only needed for implementation 553 #define fips_md_init(alg) fips_md_init_ctx(alg, alg) 554 555 #ifdef OPENSSL_FIPS 556 #define fips_md_init_ctx(alg, cx) \ 557 int alg##_Init(cx##_CTX *c) \ 558 { \ 559 if (FIPS_mode()) OpenSSLDie(__FILE__, __LINE__, \ 560 "Low level API call to digest " #alg " forbidden in FIPS mode!"); \ 561 return private_##alg##_Init(c); \ 562 } \ 563 int private_##alg##_Init(cx##_CTX *c) 564 565 #define fips_cipher_abort(alg) \ 566 if (FIPS_mode()) OpenSSLDie(__FILE__, __LINE__, \ 567 "Low level API call to cipher " #alg " forbidden in FIPS mode!") 568 569 #else 570 #define fips_md_init_ctx(alg, cx) \ 571 int alg##_Init(cx##_CTX *c) 572 #define fips_cipher_abort(alg) while(0) 573 #endif 574 +/ 575 576 /* CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal. It 577 * takes an amount of time dependent on |len|, but independent of the contents 578 * of |a| and |b|. Unlike memcmp, it cannot be used to put elements into a 579 * defined order as the return value when a != b is undefined, other than to be 580 * non-zero. */ 581 int CRYPTO_memcmp(const(void)* a, const(void)* b, size_t len); 582 583 /* BEGIN ERROR CODES */ 584 /* The following lines are auto generated by the script mkerr.pl. Any changes 585 * made after this point may be overwritten when the script is next run. 586 */ 587 void ERR_load_CRYPTO_strings(); 588 589 /* Error codes for the CRYPTO functions. */ 590 591 /* Function codes. */ 592 enum CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX = 100; 593 enum CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID = 103; 594 enum CRYPTO_F_CRYPTO_GET_NEW_LOCKID = 101; 595 enum CRYPTO_F_CRYPTO_SET_EX_DATA = 102; 596 enum CRYPTO_F_DEF_ADD_INDEX = 104; 597 enum CRYPTO_F_DEF_GET_CLASS = 105; 598 enum CRYPTO_F_FIPS_MODE_SET = 109; 599 enum CRYPTO_F_INT_DUP_EX_DATA = 106; 600 enum CRYPTO_F_INT_FREE_EX_DATA = 107; 601 enum CRYPTO_F_INT_NEW_EX_DATA = 108; 602 603 /* Reason codes. */ 604 enum CRYPTO_R_FIPS_MODE_NOT_SUPPORTED = 101; 605 enum CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK = 100;