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