OSDN Git Service

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