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.types; 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 alias OPENSSL_buf2hexstr = char* function(const ubyte*, long); 146 alias OPENSSL_hexstr2buf = ubyte* function(const char*, long*); 147 148 /* Backward compatibility to SSLeay */ 149 /* This is more to be used to check the correct DLL is being used 150 * in the MS world. */ 151 alias OPENSSL_VERSION_NUMBER SSLEAY_VERSION_NUMBER; 152 enum SSLEAY_VERSION = 0; 153 /* enum SSLEAY_OPTIONS = 1; no longer supported */ 154 enum SSLEAY_CFLAGS = 2; 155 enum SSLEAY_BUILT_ON = 3; 156 enum SSLEAY_PLATFORM = 4; 157 enum SSLEAY_DIR = 5; 158 159 /* A generic structure to pass assorted data in a expandable way */ 160 struct openssl_item_st { 161 int code; 162 void* value; /* Not used for flag attributes */ 163 size_t value_size; /* Max size of value for output, length for input */ 164 size_t* value_length; /* Returned length of value for output */ 165 } 166 alias openssl_item_st OPENSSL_ITEM; 167 168 169 /* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock 170 * names in cryptlib.c 171 */ 172 173 enum CRYPTO_LOCK_ERR = 1; 174 enum CRYPTO_LOCK_EX_DATA = 2; 175 enum CRYPTO_LOCK_X509 = 3; 176 enum CRYPTO_LOCK_X509_INFO = 4; 177 enum CRYPTO_LOCK_X509_PKEY = 5; 178 enum CRYPTO_LOCK_X509_CRL = 6; 179 enum CRYPTO_LOCK_X509_REQ = 7; 180 enum CRYPTO_LOCK_DSA = 8; 181 enum CRYPTO_LOCK_RSA = 9; 182 enum CRYPTO_LOCK_EVP_PKEY = 10; 183 enum CRYPTO_LOCK_X509_STORE = 11; 184 enum CRYPTO_LOCK_SSL_CTX = 12; 185 enum CRYPTO_LOCK_SSL_CERT = 13; 186 enum CRYPTO_LOCK_SSL_SESSION = 14; 187 enum CRYPTO_LOCK_SSL_SESS_CERT = 15; 188 enum CRYPTO_LOCK_SSL = 16; 189 enum CRYPTO_LOCK_SSL_METHOD = 17; 190 enum CRYPTO_LOCK_RAND = 18; 191 enum CRYPTO_LOCK_RAND2 = 19; 192 enum CRYPTO_LOCK_MALLOC = 20; 193 enum CRYPTO_LOCK_BIO = 21; 194 enum CRYPTO_LOCK_GETHOSTBYNAME = 22; 195 enum CRYPTO_LOCK_GETSERVBYNAME = 23; 196 enum CRYPTO_LOCK_READDIR = 24; 197 enum CRYPTO_LOCK_RSA_BLINDING = 25; 198 enum CRYPTO_LOCK_DH = 26; 199 enum CRYPTO_LOCK_MALLOC2 = 27; 200 enum CRYPTO_LOCK_DSO = 28; 201 enum CRYPTO_LOCK_DYNLOCK = 29; 202 enum CRYPTO_LOCK_ENGINE = 30; 203 enum CRYPTO_LOCK_UI = 31; 204 enum CRYPTO_LOCK_ECDSA = 32; 205 enum CRYPTO_LOCK_EC = 33; 206 enum CRYPTO_LOCK_ECDH = 34; 207 enum CRYPTO_LOCK_BN = 35; 208 enum CRYPTO_LOCK_EC_PRE_COMP = 36; 209 enum CRYPTO_LOCK_STORE = 37; 210 enum CRYPTO_LOCK_COMP = 38; 211 enum CRYPTO_LOCK_FIPS = 39; 212 enum CRYPTO_LOCK_FIPS2 = 40; 213 enum CRYPTO_NUM_LOCKS = 41; 214 215 enum CRYPTO_LOCK = 1; 216 enum CRYPTO_UNLOCK = 2; 217 enum CRYPTO_READ = 4; 218 enum CRYPTO_WRITE = 8; 219 220 version (OPENSSL_NO_LOCKING) { 221 void CRYPTO_w_lock()(int type) {} 222 void CRYPTO_w_unlock()(int type) {} 223 void CRYPTO_r_lock()(int type) {} 224 void CRYPTO_r_unlock()(int type) {} 225 void CRYPTO_add()(int* addr, int amount, int type) { *addr += amount; } 226 } else { 227 void CRYPTO_w_lock(string file = __FILE__, size_t line = __LINE__)(int type) { 228 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file.ptr,line); 229 } 230 void CRYPTO_w_unlock(string file = __FILE__, size_t line = __LINE__)(int type) { 231 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file.ptr,line); 232 } 233 void CRYPTO_r_lock(string file = __FILE__, size_t line = __LINE__)(int type) { 234 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,file.ptr,line); 235 } 236 void CRYPTO_r_unlock(string file = __FILE__, size_t line = __LINE__)(int type) { 237 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,file.ptr,line); 238 } 239 void CRYPTO_add(string file = __FILE__, size_t line = __LINE__)(int* addr, int amount, int type) { 240 CRYPTO_add_lock(addr,amount,type,file.ptr,line); 241 } 242 } 243 244 /* Some applications as well as some parts of OpenSSL need to allocate 245 and deallocate locks in a dynamic fashion. The following typedef 246 makes this possible in a type-safe manner. */ 247 /* CRYPTO_dynlock_value has to be defined by the application. */ 248 // FIXME: struct CRYPTO_dynlock_value; 249 struct CRYPTO_dynlock 250 { 251 int references; 252 CRYPTO_dynlock_value* data; 253 } 254 255 256 /* The following can be used to detect memory leaks in the SSLeay library. 257 * It used, it turns on malloc checking */ 258 259 enum CRYPTO_MEM_CHECK_OFF = 0x0; /* an enume */ 260 enum CRYPTO_MEM_CHECK_ON = 0x1; /* a bit */ 261 enum CRYPTO_MEM_CHECK_ENABLE = 0x2; /* a bit */ 262 enum CRYPTO_MEM_CHECK_DISABLE = 0x3; /* an enume */ 263 264 /* The following are bit values to turn on or off options connected to the 265 * malloc checking functionality */ 266 267 /* Adds time to the memory checking information */ 268 enum V_CRYPTO_MDEBUG_TIME = 0x1; /* a bit */ 269 /* Adds thread number to the memory checking information */ 270 enum V_CRYPTO_MDEBUG_THREAD = 0x2; /* a bit */ 271 272 enum V_CRYPTO_MDEBUG_ALL = (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD); 273 274 275 /* predec of the BIO type */ 276 import deimos.openssl.bio; /*struct bio_st;*/ 277 alias bio_st BIO_dummy; 278 279 struct crypto_ex_data_st 280 { 281 STACK_OF!() *sk; 282 int dummy; /* gcc is screwing up this data structure :-( */ 283 }; 284 /+mixin DECLARE_STACK_OF!();+/ 285 286 /* This stuff is basically class callback functions 287 * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */ 288 289 struct crypto_ex_data_func_st { 290 c_long argl; /* Arbitary c_long */ 291 void* argp; /* Arbitary void* */ 292 CRYPTO_EX_new* new_func; 293 CRYPTO_EX_free* free_func; 294 CRYPTO_EX_dup* dup_func; 295 } 296 alias crypto_ex_data_func_st CRYPTO_EX_DATA_FUNCS; 297 298 /+mixin DECLARE_STACK_OF!(CRYPTO_EX_DATA_FUNCS);+/ 299 300 /* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA 301 * entry. 302 */ 303 304 enum CRYPTO_EX_INDEX_BIO = 0; 305 enum CRYPTO_EX_INDEX_SSL = 1; 306 enum CRYPTO_EX_INDEX_SSL_CTX = 2; 307 enum CRYPTO_EX_INDEX_SSL_SESSION = 3; 308 enum CRYPTO_EX_INDEX_X509_STORE = 4; 309 enum CRYPTO_EX_INDEX_X509_STORE_CTX = 5; 310 enum CRYPTO_EX_INDEX_RSA = 6; 311 enum CRYPTO_EX_INDEX_DSA = 7; 312 enum CRYPTO_EX_INDEX_DH = 8; 313 enum CRYPTO_EX_INDEX_ENGINE = 9; 314 enum CRYPTO_EX_INDEX_X509 = 10; 315 enum CRYPTO_EX_INDEX_UI = 11; 316 enum CRYPTO_EX_INDEX_ECDSA = 12; 317 enum CRYPTO_EX_INDEX_ECDH = 13; 318 enum CRYPTO_EX_INDEX_COMP = 14; 319 enum CRYPTO_EX_INDEX_STORE = 15; 320 321 /* Dynamically assigned indexes start from this value (don't use directly, use 322 * via CRYPTO_ex_data_new_class). */ 323 enum CRYPTO_EX_INDEX_USER = 100; 324 325 326 /* This is the default callbacks, but we can have others as well: 327 * this is needed in Win32 where the application malloc and the 328 * library malloc may not be the same. 329 */ 330 void CRYPTO_malloc_init()() { 331 CRYPTO_set_mem_functions(&malloc, &realloc, &free); 332 } 333 334 /+#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD 335 # ifndef CRYPTO_MDEBUG /* avoid duplicate #define */ 336 # define CRYPTO_MDEBUG 337 # endif 338 #endif+/ 339 340 /* Set standard debugging functions (not done by default 341 * unless CRYPTO_MDEBUG is defined) */ 342 void CRYPTO_malloc_debug_init()() { 343 CRYPTO_set_mem_debug_functions(&CRYPTO_dbg_malloc, &CRYPTO_dbg_realloc, 344 &CRYPTO_dbg_free, &CRYPTO_dbg_set_options, &CRYPTO_dbg_get_options); 345 } 346 347 int CRYPTO_mem_ctrl(int mode); 348 int CRYPTO_is_mem_check_on(); 349 350 /* for applications */ 351 int MemCheck_start()() { return CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); } 352 int MemCheck_stop()(){ return CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF); } 353 354 /* for library-internal use */ 355 int MemCheck_on()() { return CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); } 356 int MemCheck_off()() { return CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); } 357 alias CRYPTO_is_mem_check_on is_MemCheck_on; 358 359 auto OPENSSL_malloc(string file = __FILE__, size_t line = __LINE__)(int num) { 360 return CRYPTO_malloc(num,file.ptr,line); 361 } 362 auto OPENSSL_strdup(string file = __FILE__, size_t line = __LINE__)(const(char)* str) { 363 return CRYPTO_strdup(str,file.ptr,line); 364 } 365 auto OPENSSL_realloc(string file = __FILE__, size_t line = __LINE__)(void* addr, int num) { 366 return CRYPTO_realloc(addr,num,file.ptr,line); 367 } 368 auto OPENSSL_realloc_clean(string file = __FILE__, size_t line = __LINE__)(void* addr,int old_num,int num) { 369 CRYPTO_realloc_clean(addr,old_num,num,file.ptr,line); 370 } 371 auto OPENSSL_remalloc(string file = __FILE__, size_t line = __LINE__)(void** addr, int num) { 372 return CRYPTO_remalloc(cast(char**)addr,num,file.ptr,line); 373 } 374 alias CRYPTO_free OPENSSL_freeFunc; 375 alias CRYPTO_free OPENSSL_free; 376 377 auto OPENSSL_malloc_locked(string file = __FILE__, size_t line = __LINE__)(int num) { 378 return CRYPTO_malloc_locked(num, file.ptr, line); 379 } 380 alias CRYPTO_free_locked OPENSSL_free_locked; 381 382 383 const(char)* SSLeay_version(int type); 384 c_ulong SSLeay(); 385 386 int OPENSSL_issetugid(); 387 388 /* An opaque type representing an implementation of "ex_data" support */ 389 struct st_CRYPTO_EX_DATA_IMPL; 390 alias st_CRYPTO_EX_DATA_IMPL CRYPTO_EX_DATA_IMPL; 391 /* Return an opaque pointer to the current "ex_data" implementation */ 392 const(CRYPTO_EX_DATA_IMPL)* CRYPTO_get_ex_data_implementation(); 393 /* Sets the "ex_data" implementation to be used (if it's not too late) */ 394 int CRYPTO_set_ex_data_implementation(const(CRYPTO_EX_DATA_IMPL)* i); 395 /* Get a new "ex_data" class, and return the corresponding "class_index" */ 396 int CRYPTO_ex_data_new_class(); 397 /* Within a given class, get/register a new index */ 398 int CRYPTO_get_ex_new_index(int class_index, c_long argl, void* argp, 399 CRYPTO_EX_new* new_func, CRYPTO_EX_dup* dup_func, 400 CRYPTO_EX_free* free_func); 401 static if (OPENSSL_VERSION_AT_LEAST(1, 1, 0)) 402 { 403 /* No longer use an index. */ 404 int CRYPTO_free_ex_index(int class_index, int idx); 405 } 406 /* Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a given 407 * class (invokes whatever per-class callbacks are applicable) */ 408 int CRYPTO_new_ex_data(int class_index, void* obj, CRYPTO_EX_DATA* ad); 409 int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA* to, 410 CRYPTO_EX_DATA* from); 411 void CRYPTO_free_ex_data(int class_index, void* obj, CRYPTO_EX_DATA* ad); 412 /* Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular index 413 * (relative to the class type involved) */ 414 int CRYPTO_set_ex_data(CRYPTO_EX_DATA* ad, int idx, void* val); 415 void* CRYPTO_get_ex_data(const(CRYPTO_EX_DATA)* ad,int idx); 416 417 int CRYPTO_get_new_lockid(char* name); 418 419 void CRYPTO_lock(int mode, int type,const(char)* file,int line); 420 421 /* Don't use this structure directly. */ 422 struct crypto_threadid_st { 423 void* ptr; 424 c_ulong val; 425 } 426 alias crypto_threadid_st CRYPTO_THREADID; 427 /* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */ 428 void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID* id, c_ulong val); 429 void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID* id, void* ptr); 430 int CRYPTO_THREADID_set_callback(ExternC!(void function(CRYPTO_THREADID*)) threadid_func); 431 ExternC!(void function(CRYPTO_THREADID*)) CRYPTO_THREADID_get_callback(); 432 void CRYPTO_THREADID_current(CRYPTO_THREADID* id); 433 int CRYPTO_THREADID_cmp(const(CRYPTO_THREADID)* a, const(CRYPTO_THREADID)* b); 434 void CRYPTO_THREADID_cpy(CRYPTO_THREADID* dest, const(CRYPTO_THREADID)* src); 435 c_ulong CRYPTO_THREADID_hash(const(CRYPTO_THREADID)* id); 436 version(OPENSSL_NO_DEPRECATED) {} else { 437 void CRYPTO_set_id_callback(ExternC!(c_ulong function()) func); 438 ExternC!(c_ulong function()) CRYPTO_get_id_callback(); 439 c_ulong CRYPTO_thread_id(); 440 } 441 442 const(char)* CRYPTO_get_lock_name(int type); 443 int CRYPTO_add_lock(int* pointer,int amount,int type, const(char)* file, 444 int line); 445 446 int CRYPTO_get_new_dynlockid(); 447 void CRYPTO_destroy_dynlockid(int i); 448 struct CRYPTO_dynlock_value; 449 CRYPTO_dynlock_value* CRYPTO_get_dynlock_value(int i); 450 451 /* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions -- 452 * call the latter last if you need different functions */ 453 int CRYPTO_set_mem_functions(ExternC!(void* function(size_t)) m,ExternC!(void* function(void*,size_t)) r, ExternC!(void function(void*)) f); 454 int CRYPTO_set_locked_mem_functions(ExternC!(void* function(size_t)) m, ExternC!(void function(void*)) free_func); 455 int CRYPTO_set_mem_ex_functions(ExternC!(void* function(size_t,const(char)*,int)) m, 456 ExternC!(void* function(void*,size_t,const(char)*,int)) r, 457 ExternC!(void function(void*)) f); 458 int CRYPTO_set_locked_mem_ex_functions(ExternC!(void* function(size_t,const(char)*,int)) m, 459 ExternC!(void function(void*)) free_func); 460 int CRYPTO_set_mem_debug_functions(ExternC!(void function(void*,int,const(char)*,int,int)) m, 461 ExternC!(void function(void*,void*,int,const(char)*,int,int)) r, 462 ExternC!(void function(void*,int)) f, 463 ExternC!(void function(c_long)) so, 464 ExternC!(c_long function()) go); 465 void CRYPTO_get_mem_functions(ExternC!(void* function(size_t))* m,ExternC!(void* function(void*, size_t))* r, ExternC!(void function(void*))* f); 466 void CRYPTO_get_locked_mem_functions(ExternC!(void* function(size_t))* m, ExternC!(void function(void*))* f); 467 void CRYPTO_get_mem_ex_functions(ExternC!(void* function(size_t,const(char)*,int))* m, 468 ExternC!(void* function(void*, size_t,const(char)*,int))* r, 469 ExternC!(void function(void*))* f); 470 void CRYPTO_get_locked_mem_ex_functions(ExternC!(void* function(size_t,const(char)*,int))* m, 471 ExternC!(void function(void*))* f); 472 void CRYPTO_get_mem_debug_functions(ExternC!(void function(void*,int,const(char)*,int,int))* m, 473 ExternC!(void function(void*,void*,int,const(char)*,int,int))* r, 474 ExternC!(void function(void*,int))* f, 475 ExternC!(void function(c_long))* so, 476 ExternC!(c_long function())* go); 477 478 void* CRYPTO_malloc_locked(int num, const(char)* file, int line); 479 void CRYPTO_free_locked(void* ptr); 480 void* CRYPTO_malloc(int num, const(char)* file, int line); 481 char* CRYPTO_strdup(const(char)* str, const(char)* file, int line); 482 void CRYPTO_free(void* ptr); 483 void* CRYPTO_realloc(void* addr,int num, const(char)* file, int line); 484 void* CRYPTO_realloc_clean(void* addr,int old_num,int num,const(char)* file, 485 int line); 486 void* CRYPTO_remalloc(void* addr,int num, const(char)* file, int line); 487 488 void OPENSSL_cleanse(void* ptr, size_t len); 489 490 void CRYPTO_set_mem_debug_options(c_long bits); 491 c_long CRYPTO_get_mem_debug_options(); 492 493 auto CRYPTO_push_info(string file = __FILE__, size_t line = __LINE__)(const(char)* info) { 494 return CRYPTO_push_info_(info, file.ptr, line); 495 } 496 int CRYPTO_push_info_(const(char)* info, const(char)* file, int line); 497 int CRYPTO_pop_info(); 498 int CRYPTO_remove_all_info(); 499 500 501 /* Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro; 502 * used as default in CRYPTO_MDEBUG compilations): */ 503 /* The last argument has the following significance: 504 * 505 * 0: called before the actual memory allocation has taken place 506 * 1: called after the actual memory allocation has taken place 507 */ 508 void CRYPTO_dbg_malloc(void* addr,int num,const(char)* file,int line,int before_p); 509 void CRYPTO_dbg_realloc(void* addr1,void* addr2,int num,const(char)* file,int line,int before_p); 510 void CRYPTO_dbg_free(void* addr,int before_p); 511 /* Tell the debugging code about options. By default, the following values 512 * apply: 513 * 514 * 0: Clear all options. 515 * V_CRYPTO_MDEBUG_TIME (1): Set the "Show Time" option. 516 * V_CRYPTO_MDEBUG_THREAD (2): Set the "Show Thread Number" option. 517 * V_CRYPTO_MDEBUG_ALL (3): 1 + 2 518 */ 519 void CRYPTO_dbg_set_options(c_long bits); 520 c_long CRYPTO_dbg_get_options(); 521 522 523 version(OPENSSL_NO_FP_API) {} else { 524 void CRYPTO_mem_leaks_fp(FILE*); 525 } 526 void CRYPTO_mem_leaks(bio_st* bio); 527 /* c_ulong order, char* file, int line, int num_bytes, char* addr */ 528 alias typeof(*(void* function (c_ulong, const(char)*, int, int, void*)).init) CRYPTO_MEM_LEAK_CB; 529 void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB* cb); 530 531 /* die if we have to */ 532 void OpenSSLDie(const(char)* file,int line,const(char)* assertion); 533 void OPENSSL_assert(string file = __FILE__, size_t line = __LINE__)(int e) { 534 if (!e) OpenSSLDie(file.ptr, line, "assertion failed"); // No good way to translate. 535 } 536 537 c_ulong* OPENSSL_ia32cap_loc(); 538 auto OPENSSL_ia32cap()(){ return* OPENSSL_ia32cap_loc(); } 539 int OPENSSL_isservice(); 540 541 int FIPS_mode(); 542 int FIPS_mode_set(int r); 543 544 void OPENSSL_init(); 545 546 /+ // TODO: only needed for implementation 547 #define fips_md_init(alg) fips_md_init_ctx(alg, alg) 548 549 #ifdef OPENSSL_FIPS 550 #define fips_md_init_ctx(alg, cx) \ 551 int alg##_Init(cx##_CTX *c) \ 552 { \ 553 if (FIPS_mode()) OpenSSLDie(__FILE__, __LINE__, \ 554 "Low level API call to digest " #alg " forbidden in FIPS mode!"); \ 555 return private_##alg##_Init(c); \ 556 } \ 557 int private_##alg##_Init(cx##_CTX *c) 558 559 #define fips_cipher_abort(alg) \ 560 if (FIPS_mode()) OpenSSLDie(__FILE__, __LINE__, \ 561 "Low level API call to cipher " #alg " forbidden in FIPS mode!") 562 563 #else 564 #define fips_md_init_ctx(alg, cx) \ 565 int alg##_Init(cx##_CTX *c) 566 #define fips_cipher_abort(alg) while(0) 567 #endif 568 +/ 569 570 /* CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal. It 571 * takes an amount of time dependent on |len|, but independent of the contents 572 * of |a| and |b|. Unlike memcmp, it cannot be used to put elements into a 573 * defined order as the return value when a != b is undefined, other than to be 574 * non-zero. */ 575 int CRYPTO_memcmp(const(void)* a, const(void)* b, size_t len); 576 577 /* BEGIN ERROR CODES */ 578 /* The following lines are auto generated by the script mkerr.pl. Any changes 579 * made after this point may be overwritten when the script is next run. 580 */ 581 void ERR_load_CRYPTO_strings(); 582 583 /* Error codes for the CRYPTO functions. */ 584 585 /* Function codes. */ 586 enum CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX = 100; 587 enum CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID = 103; 588 enum CRYPTO_F_CRYPTO_GET_NEW_LOCKID = 101; 589 enum CRYPTO_F_CRYPTO_SET_EX_DATA = 102; 590 enum CRYPTO_F_DEF_ADD_INDEX = 104; 591 enum CRYPTO_F_DEF_GET_CLASS = 105; 592 enum CRYPTO_F_FIPS_MODE_SET = 109; 593 enum CRYPTO_F_GET_AND_LOCK = 113; 594 enum CRYPTO_F_INT_DUP_EX_DATA = 106; 595 enum CRYPTO_F_INT_FREE_EX_DATA = 107; 596 enum CRYPTO_F_INT_NEW_EX_DATA = 108; 597 598 /* Reason codes. */ 599 enum CRYPTO_R_FIPS_MODE_NOT_SUPPORTED = 101; 600 enum CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK = 100;