]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/crypto.h
Small error fix.
[thirdparty/openssl.git] / crypto / crypto.h
CommitLineData
d02b48c6 1/* crypto/crypto.h */
58964a49 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
d02b48c6
RE
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_CRYPTO_H
60#define HEADER_CRYPTO_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
0cd08cce
BM
66#include <stdlib.h>
67
0b86eb3e
BM
68#ifndef NO_FP_API
69#include <stdio.h>
70#endif
71
ec577822 72#include <openssl/stack.h>
dd9d233e 73#include <openssl/safestack.h>
ec577822 74#include <openssl/opensslv.h>
5f326803 75
a53955d8
UM
76#ifdef CHARSET_EBCDIC
77#include <openssl/ebcdic.h>
78#endif
79
5f326803 80/* Backward compatibility to SSLeay */
d02b48c6
RE
81/* This is more to be used to check the correct DLL is being used
82 * in the MS world. */
5f326803 83#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
d02b48c6
RE
84#define SSLEAY_VERSION 0
85/* #define SSLEAY_OPTIONS 1 no longer supported */
86#define SSLEAY_CFLAGS 2
87#define SSLEAY_BUILT_ON 3
dfeab068 88#define SSLEAY_PLATFORM 4
d02b48c6
RE
89
90/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock
91 * names in cryptlib.c
92 */
93
94#define CRYPTO_LOCK_ERR 1
95#define CRYPTO_LOCK_ERR_HASH 2
96#define CRYPTO_LOCK_X509 3
97#define CRYPTO_LOCK_X509_INFO 4
98#define CRYPTO_LOCK_X509_PKEY 5
99#define CRYPTO_LOCK_X509_CRL 6
100#define CRYPTO_LOCK_X509_REQ 7
101#define CRYPTO_LOCK_DSA 8
102#define CRYPTO_LOCK_RSA 9
103#define CRYPTO_LOCK_EVP_PKEY 10
104#define CRYPTO_LOCK_X509_STORE 11
105#define CRYPTO_LOCK_SSL_CTX 12
106#define CRYPTO_LOCK_SSL_CERT 13
107#define CRYPTO_LOCK_SSL_SESSION 14
b56bce4f
BM
108#define CRYPTO_LOCK_SSL_SESS_CERT 15
109#define CRYPTO_LOCK_SSL 16
110#define CRYPTO_LOCK_RAND 17
111#define CRYPTO_LOCK_MALLOC 18
112#define CRYPTO_LOCK_BIO 19
2a82c7cf
BM
113#define CRYPTO_LOCK_GETHOSTBYNAME 20
114#define CRYPTO_LOCK_GETSERVBYNAME 21
115#define CRYPTO_LOCK_READDIR 22
116#define CRYPTO_LOCK_RSA_BLINDING 23
13066cee 117#define CRYPTO_LOCK_DH 24
1f575f1b
RL
118#define CRYPTO_LOCK_MALLOC2 25
119#define CRYPTO_NUM_LOCKS 26
d02b48c6
RE
120
121#define CRYPTO_LOCK 1
122#define CRYPTO_UNLOCK 2
123#define CRYPTO_READ 4
124#define CRYPTO_WRITE 8
125
dfeab068 126#ifndef NO_LOCKING
d02b48c6
RE
127#ifndef CRYPTO_w_lock
128#define CRYPTO_w_lock(type) \
129 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
130#define CRYPTO_w_unlock(type) \
131 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
132#define CRYPTO_r_lock(type) \
133 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
134#define CRYPTO_r_unlock(type) \
135 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
136#define CRYPTO_add(addr,amount,type) \
137 CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
dfeab068
RE
138#endif
139#else
140#define CRYPTO_w_lock(a)
141#define CRYPTO_w_unlock(a)
142#define CRYPTO_r_lock(a)
143#define CRYPTO_r_unlock(a)
144#define CRYPTO_add(a,b,c) ((*(a))+=(b))
d02b48c6
RE
145#endif
146
147/* The following can be used to detect memory leaks in the SSLeay library.
148 * It used, it turns on malloc checking */
149
dfeab068
RE
150#define CRYPTO_MEM_CHECK_OFF 0x0 /* an enume */
151#define CRYPTO_MEM_CHECK_ON 0x1 /* a bit */
152#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */
153#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */
d02b48c6 154
d8df48a9
RL
155/* The following are bit values to turn on or off options connected to the
156 * malloc checking functionality */
157
158/* Adds time to the memory checking information */
159#define V_CRYPTO_MDEBUG_TIME 0x1 /* a bit */
160/* Adds thread number to the memory checking information */
161#define V_CRYPTO_MDEBUG_THREAD 0x2 /* a bit */
162
b64e735b
BM
163#define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD)
164
d02b48c6 165
58964a49
RE
166/* predec of the BIO type */
167typedef struct bio_st BIO_dummy;
168
169typedef struct crypto_ex_data_st
170 {
171 STACK *sk;
172 int dummy; /* gcc is screwing up this data structure :-( */
173 } CRYPTO_EX_DATA;
174
dd9d233e
DSH
175/* Called when a new object is created */
176typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
177 int idx, long argl, void *argp);
178/* Called when an object is free()ed */
179typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
180 int idx, long argl, void *argp);
181/* Called when we need to dup an object */
182typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
183 int idx, long argl, void *argp);
184
58964a49
RE
185/* This stuff is basically class callback functions
186 * The current classes are SSL_CTX, SSL, SSL_SESION, and a few more */
dd9d233e 187
58964a49
RE
188typedef struct crypto_ex_data_func_st
189 {
190 long argl; /* Arbitary long */
dd9d233e
DSH
191 void *argp; /* Arbitary void * */
192 CRYPTO_EX_new *new_func;
193 CRYPTO_EX_free *free_func;
194 CRYPTO_EX_dup *dup_func;
58964a49
RE
195 } CRYPTO_EX_DATA_FUNCS;
196
dd9d233e
DSH
197DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
198
58964a49
RE
199/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA
200 * entry.
201 */
202
203#define CRYPTO_EX_INDEX_BIO 0
204#define CRYPTO_EX_INDEX_SSL 1
205#define CRYPTO_EX_INDEX_SSL_CTX 2
206#define CRYPTO_EX_INDEX_SSL_SESSION 3
207#define CRYPTO_EX_INDEX_X509_STORE 4
208#define CRYPTO_EX_INDEX_X509_STORE_CTX 5
d02b48c6 209
d8df48a9 210
3d14b9d0
DSH
211/* This is the default callbacks, but we can have others as well:
212 * this is needed in Win32 where the application malloc and the
213 * library malloc may not be the same.
214 */
d02b48c6 215#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\
0cd08cce 216 malloc, realloc, free)
0cd08cce
BM
217
218#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
219# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
220# define CRYPTO_MDEBUG
221# endif
222#endif
d02b48c6 223
0cd08cce 224/* Set standard debugging functions (not done by default
75acc288 225 * unless CRYPTO_MDEBUG is defined) */
9ac42ed8
RL
226#define CRYPTO_malloc_debug_init() do {\
227 CRYPTO_set_mem_debug_functions(\
228 (void (*)())CRYPTO_dbg_malloc,\
229 (void (*)())CRYPTO_dbg_realloc,\
230 (void (*)())CRYPTO_dbg_free,\
231 (void (*)())CRYPTO_dbg_set_options,\
0cd08cce 232 (long (*)())CRYPTO_dbg_get_options);\
f3a2a044 233 } while(0)
9ac42ed8 234
0cd08cce
BM
235int CRYPTO_mem_ctrl(int mode);
236int CRYPTO_is_mem_check_on(void);
458cddc1 237
0cd08cce 238/* for applications */
dfeab068
RE
239#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
240#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
0cd08cce
BM
241
242/* for library-internal use */
dfeab068
RE
243#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
244#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
0cd08cce 245#define is_MemCheck_on() CRYPTO_is_mem_check_on()
9ac42ed8
RL
246
247#define Malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__)
d02b48c6 248#define Realloc(addr,num) \
9ac42ed8 249 CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__)
d02b48c6 250#define Remalloc(addr,num) \
9ac42ed8 251 CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
d02b48c6 252#define FreeFunc CRYPTO_free
5a88a6ea 253#define Free(addr) CRYPTO_free(addr)
9ac42ed8
RL
254
255#define Malloc_locked(num) CRYPTO_malloc_locked((int)num,__FILE__,__LINE__)
5a88a6ea 256#define Free_locked(addr) CRYPTO_free_locked(addr)
9ac42ed8 257
d02b48c6 258
58964a49 259/* Case insensiteve linking causes problems.... */
7d7d2cbc 260#if defined(WIN16) || defined(VMS)
58964a49
RE
261#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings
262#endif
263
d02b48c6 264
e778802f 265const char *SSLeay_version(int type);
d02b48c6
RE
266unsigned long SSLeay(void);
267
dd9d233e
DSH
268int CRYPTO_get_ex_new_index(int idx, STACK_OF(CRYPTO_EX_DATA_FUNCS) **skp, long argl, void *argp,
269 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
270int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val);
271void *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad,int idx);
272int CRYPTO_dup_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, CRYPTO_EX_DATA *to,
273 CRYPTO_EX_DATA *from);
274void CRYPTO_free_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad);
275void CRYPTO_new_ex_data(STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth, void *obj, CRYPTO_EX_DATA *ad);
58964a49 276
58964a49 277int CRYPTO_get_new_lockid(char *name);
a111306b
BM
278
279int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */
e778802f
BL
280void CRYPTO_lock(int mode, int type,const char *file,int line);
281void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
282 const char *file,int line));
283void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
d02b48c6 284 int line);
e778802f
BL
285void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
286 const char *file, int line));
287int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
288 const char *file,int line);
d02b48c6
RE
289void CRYPTO_set_id_callback(unsigned long (*func)(void));
290unsigned long (*CRYPTO_get_id_callback(void))(void);
291unsigned long CRYPTO_thread_id(void);
e778802f
BL
292const char *CRYPTO_get_lock_name(int type);
293int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
294 int line);
d02b48c6 295
0cd08cce
BM
296/* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions --
297 * call the latter last if you need different functions */
298int CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *));
299int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *));
300int CRYPTO_set_mem_debug_functions(void (*m)(),void (*r)(),void (*f)(),void (*so)(),long (*go)());
301void CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *));
302void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *));
303void CRYPTO_get_mem_debug_functions(void (**m)(),void (**r)(),void (**f)(),void (**so)(),long (**go)());
d02b48c6 304
9d1a01be 305void *CRYPTO_malloc_locked(int num, const char *file, int line);
5a88a6ea 306void CRYPTO_free_locked(void *);
9d1a01be 307void *CRYPTO_malloc(int num, const char *file, int line);
5a88a6ea 308void CRYPTO_free(void *);
9d1a01be
UM
309void *CRYPTO_realloc(void *addr,int num, const char *file, int line);
310void *CRYPTO_remalloc(void *addr,int num, const char *file, int line);
5a88a6ea 311
0cd08cce 312void CRYPTO_set_mem_debug_options(long bits);
667ac4ec 313long CRYPTO_get_mem_debug_options(void);
0cd08cce 314
2b6313d0
BM
315#define CRYPTO_push_info(info) \
316 CRYPTO_push_info_(info, __FILE__, __LINE__);
317int CRYPTO_push_info_(const char *info, const char *file, int line);
318int CRYPTO_pop_info(void);
9ac42ed8
RL
319int CRYPTO_remove_all_info(void);
320
321/* The last argument has the following significance:
322 *
323 * 0: called before the actual memory allocation has taken place
324 * 1: called after the actual memory allocation has taken place
325 */
326void CRYPTO_dbg_malloc(void *addr,int num,const char *file,int line,int before_p);
327void CRYPTO_dbg_realloc(void *addr1,void *addr2,int num,const char *file,int line,int before_p);
d8df48a9 328void CRYPTO_dbg_free(void *addr,int before_p);
9ac42ed8
RL
329
330/* Tell the debugging code about options. By default, the following values
331 * apply:
332 *
333 * 0: Clear all options.
334 * 1: Set the "Show Time" option.
335 * 2: Set the "Show Thread Number" option.
336 * 3: 1 + 2
337 */
0cd08cce 338void CRYPTO_dbg_set_options(long bits);
667ac4ec 339long CRYPTO_dbg_get_options(void);
1f575f1b 340
58964a49 341#ifndef NO_FP_API
d02b48c6
RE
342void CRYPTO_mem_leaks_fp(FILE *);
343#endif
58964a49 344void CRYPTO_mem_leaks(struct bio_st *bio);
d02b48c6
RE
345/* unsigned long order, char *file, int line, int num_bytes, char *addr */
346void CRYPTO_mem_leaks_cb(void (*cb)());
347
667ac4ec 348void ERR_load_CRYPTO_strings(void);
58964a49 349
58964a49 350/* BEGIN ERROR CODES */
6d311938
DSH
351/* The following lines are auto generated by the script mkerr.pl. Any changes
352 * made after this point may be overwritten when the script is next run.
353 */
354
58964a49
RE
355/* Error codes for the CRYPTO functions. */
356
357/* Function codes. */
358#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100
359#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101
360#define CRYPTO_F_CRYPTO_SET_EX_DATA 102
361
362/* Reason codes. */
6d311938 363
d02b48c6
RE
364#ifdef __cplusplus
365}
366#endif
d02b48c6 367#endif
58964a49 368