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