OSDN Git Service

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