155714Skris/* crypto/crypto.h */
2160814Ssimon/* ====================================================================
3160814Ssimon * Copyright (c) 1998-2003 The OpenSSL Project.  All rights reserved.
4160814Ssimon *
5160814Ssimon * Redistribution and use in source and binary forms, with or without
6160814Ssimon * modification, are permitted provided that the following conditions
7160814Ssimon * are met:
8160814Ssimon *
9160814Ssimon * 1. Redistributions of source code must retain the above copyright
10296465Sdelphij *    notice, this list of conditions and the following disclaimer.
11160814Ssimon *
12160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright
13160814Ssimon *    notice, this list of conditions and the following disclaimer in
14160814Ssimon *    the documentation and/or other materials provided with the
15160814Ssimon *    distribution.
16160814Ssimon *
17160814Ssimon * 3. All advertising materials mentioning features or use of this
18160814Ssimon *    software must display the following acknowledgment:
19160814Ssimon *    "This product includes software developed by the OpenSSL Project
20160814Ssimon *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21160814Ssimon *
22160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23160814Ssimon *    endorse or promote products derived from this software without
24160814Ssimon *    prior written permission. For written permission, please contact
25160814Ssimon *    openssl-core@openssl.org.
26160814Ssimon *
27160814Ssimon * 5. Products derived from this software may not be called "OpenSSL"
28160814Ssimon *    nor may "OpenSSL" appear in their names without prior written
29160814Ssimon *    permission of the OpenSSL Project.
30160814Ssimon *
31160814Ssimon * 6. Redistributions of any form whatsoever must retain the following
32160814Ssimon *    acknowledgment:
33160814Ssimon *    "This product includes software developed by the OpenSSL Project
34160814Ssimon *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35160814Ssimon *
36160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39160814Ssimon * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
40160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE.
48160814Ssimon * ====================================================================
49160814Ssimon *
50160814Ssimon * This product includes cryptographic software written by Eric Young
51160814Ssimon * (eay@cryptsoft.com).  This product includes software written by Tim
52160814Ssimon * Hudson (tjh@cryptsoft.com).
53160814Ssimon *
54160814Ssimon */
5555714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5655714Skris * All rights reserved.
5755714Skris *
5855714Skris * This package is an SSL implementation written
5955714Skris * by Eric Young (eay@cryptsoft.com).
6055714Skris * The implementation was written so as to conform with Netscapes SSL.
61296465Sdelphij *
6255714Skris * This library is free for commercial and non-commercial use as long as
6355714Skris * the following conditions are aheared to.  The following conditions
6455714Skris * apply to all code found in this distribution, be it the RC4, RSA,
6555714Skris * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
6655714Skris * included with this distribution is covered by the same copyright terms
6755714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com).
68296465Sdelphij *
6955714Skris * Copyright remains Eric Young's, and as such any Copyright notices in
7055714Skris * the code are not to be removed.
7155714Skris * If this package is used in a product, Eric Young should be given attribution
7255714Skris * as the author of the parts of the library used.
7355714Skris * This can be in the form of a textual message at program startup or
7455714Skris * in documentation (online or textual) provided with the package.
75296465Sdelphij *
7655714Skris * Redistribution and use in source and binary forms, with or without
7755714Skris * modification, are permitted provided that the following conditions
7855714Skris * are met:
7955714Skris * 1. Redistributions of source code must retain the copyright
8055714Skris *    notice, this list of conditions and the following disclaimer.
8155714Skris * 2. Redistributions in binary form must reproduce the above copyright
8255714Skris *    notice, this list of conditions and the following disclaimer in the
8355714Skris *    documentation and/or other materials provided with the distribution.
8455714Skris * 3. All advertising materials mentioning features or use of this software
8555714Skris *    must display the following acknowledgement:
8655714Skris *    "This product includes cryptographic software written by
8755714Skris *     Eric Young (eay@cryptsoft.com)"
8855714Skris *    The word 'cryptographic' can be left out if the rouines from the library
8955714Skris *    being used are not cryptographic related :-).
90296465Sdelphij * 4. If you include any Windows specific code (or a derivative thereof) from
9155714Skris *    the apps directory (application code) you must include an acknowledgement:
9255714Skris *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
93296465Sdelphij *
9455714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
9555714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9655714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9755714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
9855714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
9955714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
10055714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
10155714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
10255714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
10355714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
10455714Skris * SUCH DAMAGE.
105296465Sdelphij *
10655714Skris * The licence and distribution terms for any publically available version or
10755714Skris * derivative of this code cannot be changed.  i.e. this code cannot simply be
10855714Skris * copied and put under another distribution licence
10955714Skris * [including the GNU Public Licence.]
11055714Skris */
111160814Ssimon/* ====================================================================
112160814Ssimon * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113296465Sdelphij * ECDH support in OpenSSL originally developed by
114160814Ssimon * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115160814Ssimon */
11655714Skris
11755714Skris#ifndef HEADER_CRYPTO_H
118296465Sdelphij# define HEADER_CRYPTO_H
11955714Skris
120296465Sdelphij# include <stdlib.h>
12159191Skris
122296465Sdelphij# include <openssl/e_os2.h>
123160814Ssimon
124296465Sdelphij# ifndef OPENSSL_NO_FP_API
125296465Sdelphij#  include <stdio.h>
126296465Sdelphij# endif
12755714Skris
128296465Sdelphij# include <openssl/stack.h>
129296465Sdelphij# include <openssl/safestack.h>
130296465Sdelphij# include <openssl/opensslv.h>
131296465Sdelphij# include <openssl/ossl_typ.h>
13255714Skris
133296465Sdelphij# ifdef CHARSET_EBCDIC
134296465Sdelphij#  include <openssl/ebcdic.h>
135296465Sdelphij# endif
13655714Skris
137296465Sdelphij/*
138296465Sdelphij * Resolve problems on some operating systems with symbol names that clash
139296465Sdelphij * one way or another
140296465Sdelphij */
141296465Sdelphij# include <openssl/symhacks.h>
14268651Skris
14368651Skris#ifdef  __cplusplus
14468651Skrisextern "C" {
14559191Skris#endif
14659191Skris
14755714Skris/* Backward compatibility to SSLeay */
148296465Sdelphij/*
149296465Sdelphij * This is more to be used to check the correct DLL is being used in the MS
150296465Sdelphij * world.
151296465Sdelphij */
152296465Sdelphij# define SSLEAY_VERSION_NUMBER   OPENSSL_VERSION_NUMBER
153296465Sdelphij# define SSLEAY_VERSION          0
154296465Sdelphij/* #define SSLEAY_OPTIONS       1 no longer supported */
155296465Sdelphij# define SSLEAY_CFLAGS           2
156296465Sdelphij# define SSLEAY_BUILT_ON         3
157296465Sdelphij# define SSLEAY_PLATFORM         4
158296465Sdelphij# define SSLEAY_DIR              5
15955714Skris
160160814Ssimon/* Already declared in ossl_typ.h */
161296465Sdelphij# if 0
162160814Ssimontypedef struct crypto_ex_data_st CRYPTO_EX_DATA;
163160814Ssimon/* Called when a new object is created */
164296465Sdelphijtypedef int CRYPTO_EX_new (void *parent, void *ptr, CRYPTO_EX_DATA *ad,
165296465Sdelphij                           int idx, long argl, void *argp);
166160814Ssimon/* Called when an object is free()ed */
167296465Sdelphijtypedef void CRYPTO_EX_free (void *parent, void *ptr, CRYPTO_EX_DATA *ad,
168296465Sdelphij                             int idx, long argl, void *argp);
169160814Ssimon/* Called when we need to dup an object */
170296465Sdelphijtypedef int CRYPTO_EX_dup (CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from,
171296465Sdelphij                           void *from_d, int idx, long argl, void *argp);
172296465Sdelphij# endif
173160814Ssimon
174160814Ssimon/* A generic structure to pass assorted data in a expandable way */
175296465Sdelphijtypedef struct openssl_item_st {
176296465Sdelphij    int code;
177296465Sdelphij    void *value;                /* Not used for flag attributes */
178296465Sdelphij    size_t value_size;          /* Max size of value for output, length for
179296465Sdelphij                                 * input */
180296465Sdelphij    size_t *value_length;       /* Returned length of value for output */
181296465Sdelphij} OPENSSL_ITEM;
182160814Ssimon
183296465Sdelphij/*
184296465Sdelphij * When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock
18555714Skris * names in cryptlib.c
18655714Skris */
18755714Skris
188296465Sdelphij# define CRYPTO_LOCK_ERR                 1
189296465Sdelphij# define CRYPTO_LOCK_EX_DATA             2
190296465Sdelphij# define CRYPTO_LOCK_X509                3
191296465Sdelphij# define CRYPTO_LOCK_X509_INFO           4
192296465Sdelphij# define CRYPTO_LOCK_X509_PKEY           5
193296465Sdelphij# define CRYPTO_LOCK_X509_CRL            6
194296465Sdelphij# define CRYPTO_LOCK_X509_REQ            7
195296465Sdelphij# define CRYPTO_LOCK_DSA                 8
196296465Sdelphij# define CRYPTO_LOCK_RSA                 9
197296465Sdelphij# define CRYPTO_LOCK_EVP_PKEY            10
198296465Sdelphij# define CRYPTO_LOCK_X509_STORE          11
199296465Sdelphij# define CRYPTO_LOCK_SSL_CTX             12
200296465Sdelphij# define CRYPTO_LOCK_SSL_CERT            13
201296465Sdelphij# define CRYPTO_LOCK_SSL_SESSION         14
202296465Sdelphij# define CRYPTO_LOCK_SSL_SESS_CERT       15
203296465Sdelphij# define CRYPTO_LOCK_SSL                 16
204296465Sdelphij# define CRYPTO_LOCK_SSL_METHOD          17
205296465Sdelphij# define CRYPTO_LOCK_RAND                18
206296465Sdelphij# define CRYPTO_LOCK_RAND2               19
207296465Sdelphij# define CRYPTO_LOCK_MALLOC              20
208296465Sdelphij# define CRYPTO_LOCK_BIO                 21
209296465Sdelphij# define CRYPTO_LOCK_GETHOSTBYNAME       22
210296465Sdelphij# define CRYPTO_LOCK_GETSERVBYNAME       23
211296465Sdelphij# define CRYPTO_LOCK_READDIR             24
212296465Sdelphij# define CRYPTO_LOCK_RSA_BLINDING        25
213296465Sdelphij# define CRYPTO_LOCK_DH                  26
214296465Sdelphij# define CRYPTO_LOCK_MALLOC2             27
215296465Sdelphij# define CRYPTO_LOCK_DSO                 28
216296465Sdelphij# define CRYPTO_LOCK_DYNLOCK             29
217296465Sdelphij# define CRYPTO_LOCK_ENGINE              30
218296465Sdelphij# define CRYPTO_LOCK_UI                  31
219296465Sdelphij# define CRYPTO_LOCK_ECDSA               32
220296465Sdelphij# define CRYPTO_LOCK_EC                  33
221296465Sdelphij# define CRYPTO_LOCK_ECDH                34
222296465Sdelphij# define CRYPTO_LOCK_BN                  35
223296465Sdelphij# define CRYPTO_LOCK_EC_PRE_COMP         36
224296465Sdelphij# define CRYPTO_LOCK_STORE               37
225296465Sdelphij# define CRYPTO_LOCK_COMP                38
226296465Sdelphij# ifndef OPENSSL_FIPS
227296465Sdelphij#  define CRYPTO_NUM_LOCKS                39
228296465Sdelphij# else
229296465Sdelphij#  define CRYPTO_LOCK_FIPS                39
230296465Sdelphij#  define CRYPTO_LOCK_FIPS2               40
231296465Sdelphij#  define CRYPTO_NUM_LOCKS                41
232296465Sdelphij# endif
23355714Skris
234296465Sdelphij# define CRYPTO_LOCK             1
235296465Sdelphij# define CRYPTO_UNLOCK           2
236296465Sdelphij# define CRYPTO_READ             4
237296465Sdelphij# define CRYPTO_WRITE            8
23855714Skris
239296465Sdelphij# ifndef OPENSSL_NO_LOCKING
240296465Sdelphij#  ifndef CRYPTO_w_lock
241296465Sdelphij#   define CRYPTO_w_lock(type)     \
242296465Sdelphij        CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
243296465Sdelphij#   define CRYPTO_w_unlock(type)   \
244296465Sdelphij        CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
245296465Sdelphij#   define CRYPTO_r_lock(type)     \
246296465Sdelphij        CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
247296465Sdelphij#   define CRYPTO_r_unlock(type)   \
248296465Sdelphij        CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
249296465Sdelphij#   define CRYPTO_add(addr,amount,type)    \
250296465Sdelphij        CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
251296465Sdelphij#  endif
252296465Sdelphij# else
253296465Sdelphij#  define CRYPTO_w_lock(a)
254296465Sdelphij#  define CRYPTO_w_unlock(a)
255296465Sdelphij#  define CRYPTO_r_lock(a)
256296465Sdelphij#  define CRYPTO_r_unlock(a)
257296465Sdelphij#  define CRYPTO_add(a,b,c)       ((*(a))+=(b))
258296465Sdelphij# endif
25955714Skris
260296465Sdelphij/*
261296465Sdelphij * Some applications as well as some parts of OpenSSL need to allocate and
262296465Sdelphij * deallocate locks in a dynamic fashion.  The following typedef makes this
263296465Sdelphij * possible in a type-safe manner.
264296465Sdelphij */
26568651Skris/* struct CRYPTO_dynlock_value has to be defined by the application. */
266296465Sdelphijtypedef struct {
267296465Sdelphij    int references;
268296465Sdelphij    struct CRYPTO_dynlock_value *data;
269296465Sdelphij} CRYPTO_dynlock;
27068651Skris
271296465Sdelphij/*
272296465Sdelphij * The following can be used to detect memory leaks in the SSLeay library. It
273296465Sdelphij * used, it turns on malloc checking
274296465Sdelphij */
27568651Skris
276296465Sdelphij# define CRYPTO_MEM_CHECK_OFF    0x0/* an enume */
277296465Sdelphij# define CRYPTO_MEM_CHECK_ON     0x1/* a bit */
278296465Sdelphij# define CRYPTO_MEM_CHECK_ENABLE 0x2/* a bit */
279296465Sdelphij# define CRYPTO_MEM_CHECK_DISABLE 0x3/* an enume */
28055714Skris
281296465Sdelphij/*
282296465Sdelphij * The following are bit values to turn on or off options connected to the
283296465Sdelphij * malloc checking functionality
284296465Sdelphij */
28555714Skris
28659191Skris/* Adds time to the memory checking information */
287296465Sdelphij# define V_CRYPTO_MDEBUG_TIME    0x1/* a bit */
28859191Skris/* Adds thread number to the memory checking information */
289296465Sdelphij# define V_CRYPTO_MDEBUG_THREAD  0x2/* a bit */
29059191Skris
291296465Sdelphij# define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD)
29259191Skris
29355714Skris/* predec of the BIO type */
29455714Skristypedef struct bio_st BIO_dummy;
29555714Skris
296296465Sdelphijstruct crypto_ex_data_st {
297296465Sdelphij    STACK *sk;
298296465Sdelphij    /* gcc is screwing up this data structure :-( */
299296465Sdelphij    int dummy;
300296465Sdelphij};
30155714Skris
302296465Sdelphij/*
303296465Sdelphij * This stuff is basically class callback functions The current classes are
304296465Sdelphij * SSL_CTX, SSL, SSL_SESSION, and a few more
305296465Sdelphij */
30659191Skris
307296465Sdelphijtypedef struct crypto_ex_data_func_st {
308296465Sdelphij    long argl;                  /* Arbitary long */
309296465Sdelphij    void *argp;                 /* Arbitary void * */
310296465Sdelphij    CRYPTO_EX_new *new_func;
311296465Sdelphij    CRYPTO_EX_free *free_func;
312296465Sdelphij    CRYPTO_EX_dup *dup_func;
313296465Sdelphij} CRYPTO_EX_DATA_FUNCS;
31455714Skris
31559191SkrisDECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
31659191Skris
317296465Sdelphij/*
318296465Sdelphij * Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA
31955714Skris * entry.
32055714Skris */
32155714Skris
322296465Sdelphij# define CRYPTO_EX_INDEX_BIO             0
323296465Sdelphij# define CRYPTO_EX_INDEX_SSL             1
324296465Sdelphij# define CRYPTO_EX_INDEX_SSL_CTX         2
325296465Sdelphij# define CRYPTO_EX_INDEX_SSL_SESSION     3
326296465Sdelphij# define CRYPTO_EX_INDEX_X509_STORE      4
327296465Sdelphij# define CRYPTO_EX_INDEX_X509_STORE_CTX  5
328296465Sdelphij# define CRYPTO_EX_INDEX_RSA             6
329296465Sdelphij# define CRYPTO_EX_INDEX_DSA             7
330296465Sdelphij# define CRYPTO_EX_INDEX_DH              8
331296465Sdelphij# define CRYPTO_EX_INDEX_ENGINE          9
332296465Sdelphij# define CRYPTO_EX_INDEX_X509            10
333296465Sdelphij# define CRYPTO_EX_INDEX_UI              11
334296465Sdelphij# define CRYPTO_EX_INDEX_ECDSA           12
335296465Sdelphij# define CRYPTO_EX_INDEX_ECDH            13
336296465Sdelphij# define CRYPTO_EX_INDEX_COMP            14
337296465Sdelphij# define CRYPTO_EX_INDEX_STORE           15
33855714Skris
339296465Sdelphij/*
340296465Sdelphij * Dynamically assigned indexes start from this value (don't use directly,
341296465Sdelphij * use via CRYPTO_ex_data_new_class).
342296465Sdelphij */
343296465Sdelphij# define CRYPTO_EX_INDEX_USER            100
34459191Skris
345296465Sdelphij/*
346296465Sdelphij * This is the default callbacks, but we can have others as well: this is
347296465Sdelphij * needed in Win32 where the application malloc and the library malloc may
348296465Sdelphij * not be the same.
34959191Skris */
350296465Sdelphij# define CRYPTO_malloc_init()    CRYPTO_set_mem_functions(\
351296465Sdelphij        malloc, realloc, free)
35255714Skris
353296465Sdelphij# if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
354296465Sdelphij#  ifndef CRYPTO_MDEBUG         /* avoid duplicate #define */
355296465Sdelphij#   define CRYPTO_MDEBUG
356296465Sdelphij#  endif
35755714Skris# endif
35855714Skris
359296465Sdelphij/*
360296465Sdelphij * Set standard debugging functions (not done by default unless CRYPTO_MDEBUG
361296465Sdelphij * is defined)
362296465Sdelphij */
363194206Ssimonvoid CRYPTO_malloc_debug_init(void);
36459191Skris
36559191Skrisint CRYPTO_mem_ctrl(int mode);
36659191Skrisint CRYPTO_is_mem_check_on(void);
36759191Skris
36859191Skris/* for applications */
369296465Sdelphij# define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
370296465Sdelphij# define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
37159191Skris
37259191Skris/* for library-internal use */
373296465Sdelphij# define MemCheck_on()   CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
374296465Sdelphij# define MemCheck_off()  CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
375296465Sdelphij# define is_MemCheck_on() CRYPTO_is_mem_check_on()
37659191Skris
377296465Sdelphij# define OPENSSL_malloc(num)     CRYPTO_malloc((int)num,__FILE__,__LINE__)
378296465Sdelphij# define OPENSSL_strdup(str)     CRYPTO_strdup((str),__FILE__,__LINE__)
379296465Sdelphij# define OPENSSL_realloc(addr,num) \
380296465Sdelphij        CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__)
381296465Sdelphij# define OPENSSL_realloc_clean(addr,old_num,num) \
382296465Sdelphij        CRYPTO_realloc_clean(addr,old_num,num,__FILE__,__LINE__)
383296465Sdelphij# define OPENSSL_remalloc(addr,num) \
384296465Sdelphij        CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
385296465Sdelphij# define OPENSSL_freeFunc        CRYPTO_free
386296465Sdelphij# define OPENSSL_free(addr)      CRYPTO_free(addr)
38759191Skris
388296465Sdelphij# define OPENSSL_malloc_locked(num) \
389296465Sdelphij        CRYPTO_malloc_locked((int)num,__FILE__,__LINE__)
390296465Sdelphij# define OPENSSL_free_locked(addr) CRYPTO_free_locked(addr)
39155714Skris
39255714Skrisconst char *SSLeay_version(int type);
39355714Skrisunsigned long SSLeay(void);
39455714Skris
39576866Skrisint OPENSSL_issetugid(void);
39676866Skris
397109998Smarkm/* An opaque type representing an implementation of "ex_data" support */
398296465Sdelphijtypedef struct st_CRYPTO_EX_DATA_IMPL CRYPTO_EX_DATA_IMPL;
399109998Smarkm/* Return an opaque pointer to the current "ex_data" implementation */
400109998Smarkmconst CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void);
401109998Smarkm/* Sets the "ex_data" implementation to be used (if it's not too late) */
402109998Smarkmint CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i);
403109998Smarkm/* Get a new "ex_data" class, and return the corresponding "class_index" */
404109998Smarkmint CRYPTO_ex_data_new_class(void);
405109998Smarkm/* Within a given class, get/register a new index */
406109998Smarkmint CRYPTO_get_ex_new_index(int class_index, long argl, void *argp,
407296465Sdelphij                            CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
408296465Sdelphij                            CRYPTO_EX_free *free_func);
409296465Sdelphij/*
410296465Sdelphij * Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a
411296465Sdelphij * given class (invokes whatever per-class callbacks are applicable)
412296465Sdelphij */
413109998Smarkmint CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
414109998Smarkmint CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
415296465Sdelphij                       CRYPTO_EX_DATA *from);
416109998Smarkmvoid CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
417296465Sdelphij/*
418296465Sdelphij * Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular
419296465Sdelphij * index (relative to the class type involved)
420296465Sdelphij */
42159191Skrisint CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val);
422296465Sdelphijvoid *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx);
423296465Sdelphij/*
424296465Sdelphij * This function cleans up all "ex_data" state. It mustn't be called under
425296465Sdelphij * potential race-conditions.
426296465Sdelphij */
427109998Smarkmvoid CRYPTO_cleanup_all_ex_data(void);
42855714Skris
42955714Skrisint CRYPTO_get_new_lockid(char *name);
43055714Skris
431296465Sdelphijint CRYPTO_num_locks(void);     /* return CRYPTO_NUM_LOCKS (shared libs!) */
432296465Sdelphijvoid CRYPTO_lock(int mode, int type, const char *file, int line);
433296465Sdelphijvoid CRYPTO_set_locking_callback(void (*func) (int mode, int type,
434296465Sdelphij                                               const char *file, int line));
435296465Sdelphijvoid (*CRYPTO_get_locking_callback(void)) (int mode, int type,
436296465Sdelphij                                           const char *file, int line);
437296465Sdelphijvoid CRYPTO_set_add_lock_callback(int (*func)
438296465Sdelphij                                   (int *num, int mount, int type,
439296465Sdelphij                                    const char *file, int line));
440296465Sdelphijint (*CRYPTO_get_add_lock_callback(void)) (int *num, int mount, int type,
441296465Sdelphij                                           const char *file, int line);
442296465Sdelphijvoid CRYPTO_set_id_callback(unsigned long (*func) (void));
443296465Sdelphijunsigned long (*CRYPTO_get_id_callback(void)) (void);
44455714Skrisunsigned long CRYPTO_thread_id(void);
44555714Skrisconst char *CRYPTO_get_lock_name(int type);
446296465Sdelphijint CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
447296465Sdelphij                    int line);
44855714Skris
449296465Sdelphijvoid int_CRYPTO_set_do_dynlock_callback(void (*do_dynlock_cb)
450296465Sdelphij                                         (int mode, int type,
451296465Sdelphij                                          const char *file, int line));
452194206Ssimon
45368651Skrisint CRYPTO_get_new_dynlockid(void);
45468651Skrisvoid CRYPTO_destroy_dynlockid(int i);
45568651Skrisstruct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i);
456296465Sdelphijvoid CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value
457296465Sdelphij                                        *(*dyn_create_function) (const char
458296465Sdelphij                                                                 *file,
459296465Sdelphij                                                                 int line));
460296465Sdelphijvoid CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)
461296465Sdelphij                                       (int mode,
462296465Sdelphij                                        struct CRYPTO_dynlock_value *l,
463296465Sdelphij                                        const char *file, int line));
464296465Sdelphijvoid CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)
465296465Sdelphij                                          (struct CRYPTO_dynlock_value *l,
466296465Sdelphij                                           const char *file, int line));
467296465Sdelphijstruct CRYPTO_dynlock_value
468296465Sdelphij*(*CRYPTO_get_dynlock_create_callback(void)) (const char *file, int line);
469296465Sdelphijvoid (*CRYPTO_get_dynlock_lock_callback(void)) (int mode,
470296465Sdelphij                                                struct CRYPTO_dynlock_value
471296465Sdelphij                                                *l, const char *file,
472296465Sdelphij                                                int line);
473296465Sdelphijvoid (*CRYPTO_get_dynlock_destroy_callback(void)) (struct CRYPTO_dynlock_value
474296465Sdelphij                                                   *l, const char *file,
475296465Sdelphij                                                   int line);
47668651Skris
477296465Sdelphij/*
478296465Sdelphij * CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions -- call
479296465Sdelphij * the latter last if you need different functions
480296465Sdelphij */
481296465Sdelphijint CRYPTO_set_mem_functions(void *(*m) (size_t), void *(*r) (void *, size_t),
482296465Sdelphij                             void (*f) (void *));
483296465Sdelphijint CRYPTO_set_locked_mem_functions(void *(*m) (size_t),
484296465Sdelphij                                    void (*free_func) (void *));
485296465Sdelphijint CRYPTO_set_mem_ex_functions(void *(*m) (size_t, const char *, int),
486296465Sdelphij                                void *(*r) (void *, size_t, const char *,
487296465Sdelphij                                            int), void (*f) (void *));
488296465Sdelphijint CRYPTO_set_locked_mem_ex_functions(void *(*m) (size_t, const char *, int),
489296465Sdelphij                                       void (*free_func) (void *));
490296465Sdelphijint CRYPTO_set_mem_debug_functions(void (*m)
491296465Sdelphij                                    (void *, int, const char *, int, int),
492296465Sdelphij                                   void (*r) (void *, void *, int,
493296465Sdelphij                                              const char *, int, int),
494296465Sdelphij                                   void (*f) (void *, int), void (*so) (long),
495296465Sdelphij                                   long (*go) (void));
496296465Sdelphijvoid CRYPTO_set_mem_info_functions(int (*push_info_fn)
497296465Sdelphij                                    (const char *info, const char *file,
498296465Sdelphij                                     int line), int (*pop_info_fn) (void),
499296465Sdelphij                                   int (*remove_all_info_fn) (void));
500296465Sdelphijvoid CRYPTO_get_mem_functions(void *(**m) (size_t),
501296465Sdelphij                              void *(**r) (void *, size_t),
502296465Sdelphij                              void (**f) (void *));
503296465Sdelphijvoid CRYPTO_get_locked_mem_functions(void *(**m) (size_t),
504296465Sdelphij                                     void (**f) (void *));
505296465Sdelphijvoid CRYPTO_get_mem_ex_functions(void *(**m) (size_t, const char *, int),
506296465Sdelphij                                 void *(**r) (void *, size_t, const char *,
507296465Sdelphij                                              int), void (**f) (void *));
508296465Sdelphijvoid CRYPTO_get_locked_mem_ex_functions(void
509296465Sdelphij                                        *(**m) (size_t, const char *, int),
510296465Sdelphij                                        void (**f) (void *));
511296465Sdelphijvoid CRYPTO_get_mem_debug_functions(void (**m)
512296465Sdelphij                                     (void *, int, const char *, int, int),
513296465Sdelphij                                    void (**r) (void *, void *, int,
514296465Sdelphij                                                const char *, int, int),
515296465Sdelphij                                    void (**f) (void *, int),
516296465Sdelphij                                    void (**so) (long), long (**go) (void));
51755714Skris
51859191Skrisvoid *CRYPTO_malloc_locked(int num, const char *file, int line);
51955714Skrisvoid CRYPTO_free_locked(void *);
52059191Skrisvoid *CRYPTO_malloc(int num, const char *file, int line);
521194206Ssimonchar *CRYPTO_strdup(const char *str, const char *file, int line);
52255714Skrisvoid CRYPTO_free(void *);
523296465Sdelphijvoid *CRYPTO_realloc(void *addr, int num, const char *file, int line);
524296465Sdelphijvoid *CRYPTO_realloc_clean(void *addr, int old_num, int num, const char *file,
525296465Sdelphij                           int line);
526296465Sdelphijvoid *CRYPTO_remalloc(void *addr, int num, const char *file, int line);
52755714Skris
528109998Smarkmvoid OPENSSL_cleanse(void *ptr, size_t len);
529109998Smarkm
53059191Skrisvoid CRYPTO_set_mem_debug_options(long bits);
53159191Skrislong CRYPTO_get_mem_debug_options(void);
53259191Skris
533296465Sdelphij# define CRYPTO_push_info(info) \
53459191Skris        CRYPTO_push_info_(info, __FILE__, __LINE__);
53559191Skrisint CRYPTO_push_info_(const char *info, const char *file, int line);
53659191Skrisint CRYPTO_pop_info(void);
53759191Skrisint CRYPTO_remove_all_info(void);
53859191Skris
539296465Sdelphij/*
540296465Sdelphij * Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro;
541296465Sdelphij * used as default in CRYPTO_MDEBUG compilations):
542296465Sdelphij */
543296465Sdelphij/*-
544296465Sdelphij * The last argument has the following significance:
54559191Skris *
546296465Sdelphij * 0:   called before the actual memory allocation has taken place
547296465Sdelphij * 1:   called after the actual memory allocation has taken place
54859191Skris */
549296465Sdelphijvoid CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
550296465Sdelphij                       int before_p);
551296465Sdelphijvoid CRYPTO_dbg_realloc(void *addr1, void *addr2, int num, const char *file,
552296465Sdelphij                        int line, int before_p);
553296465Sdelphijvoid CRYPTO_dbg_free(void *addr, int before_p);
554296465Sdelphij/*-
555296465Sdelphij * Tell the debugging code about options.  By default, the following values
55659191Skris * apply:
55759191Skris *
55889837Skris * 0:                           Clear all options.
55989837Skris * V_CRYPTO_MDEBUG_TIME (1):    Set the "Show Time" option.
56089837Skris * V_CRYPTO_MDEBUG_THREAD (2):  Set the "Show Thread Number" option.
56189837Skris * V_CRYPTO_MDEBUG_ALL (3):     1 + 2
56259191Skris */
56359191Skrisvoid CRYPTO_dbg_set_options(long bits);
56459191Skrislong CRYPTO_dbg_get_options(void);
56559191Skris
566194206Ssimonint CRYPTO_dbg_push_info(const char *info, const char *file, int line);
567194206Ssimonint CRYPTO_dbg_pop_info(void);
568194206Ssimonint CRYPTO_dbg_remove_all_info(void);
56989837Skris
570296465Sdelphij# ifndef OPENSSL_NO_FP_API
57155714Skrisvoid CRYPTO_mem_leaks_fp(FILE *);
572296465Sdelphij# endif
57355714Skrisvoid CRYPTO_mem_leaks(struct bio_st *bio);
57455714Skris/* unsigned long order, char *file, int line, int num_bytes, char *addr */
575296465Sdelphijtypedef void *CRYPTO_MEM_LEAK_CB (unsigned long, const char *, int, int,
576296465Sdelphij                                  void *);
577109998Smarkmvoid CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb);
57855714Skris
579109998Smarkm/* die if we have to */
580296465Sdelphijvoid OpenSSLDie(const char *file, int line, const char *assertion);
581296465Sdelphij# define OPENSSL_assert(e)       (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1))
582109998Smarkm
583160814Ssimonunsigned long *OPENSSL_ia32cap_loc(void);
584296465Sdelphij# define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc()))
585194206Ssimonint OPENSSL_isservice(void);
586142425Snectar
587296465Sdelphij# ifdef OPENSSL_FIPS
588296465Sdelphij#  define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \
589296465Sdelphij                alg " previous FIPS forbidden algorithm error ignored");
590194206Ssimon
591296465Sdelphij#  define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \
592296465Sdelphij                #alg " Algorithm forbidden in FIPS mode");
593194206Ssimon
594296465Sdelphij#  ifdef OPENSSL_FIPS_STRICT
595296465Sdelphij#   define FIPS_BAD_ALGORITHM(alg) FIPS_BAD_ABORT(alg)
596296465Sdelphij#  else
597296465Sdelphij#   define FIPS_BAD_ALGORITHM(alg) \
598296465Sdelphij        { \
599296465Sdelphij        FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD); \
600296465Sdelphij        ERR_add_error_data(2, "Algorithm=", #alg); \
601296465Sdelphij        return 0; \
602296465Sdelphij        }
603296465Sdelphij#  endif
604194206Ssimon
605194206Ssimon/* Low level digest API blocking macro */
606194206Ssimon
607296465Sdelphij#  define FIPS_NON_FIPS_MD_Init(alg) \
608296465Sdelphij        int alg##_Init(alg##_CTX *c) \
609296465Sdelphij                { \
610296465Sdelphij                if (FIPS_mode()) \
611296465Sdelphij                        FIPS_BAD_ALGORITHM(alg) \
612296465Sdelphij                return private_##alg##_Init(c); \
613296465Sdelphij                } \
614296465Sdelphij        int private_##alg##_Init(alg##_CTX *c)
615194206Ssimon
616296465Sdelphij/*
617296465Sdelphij * For ciphers the API often varies from cipher to cipher and each needs to
618194206Ssimon * be treated as a special case. Variable key length ciphers (Blowfish, RC4,
619194206Ssimon * CAST) however are very similar and can use a blocking macro.
620194206Ssimon */
621194206Ssimon
622296465Sdelphij#  define FIPS_NON_FIPS_VCIPHER_Init(alg) \
623296465Sdelphij        void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) \
624296465Sdelphij                { \
625296465Sdelphij                if (FIPS_mode()) \
626296465Sdelphij                        FIPS_BAD_ABORT(alg) \
627296465Sdelphij                private_##alg##_set_key(key, len, data); \
628296465Sdelphij                } \
629296465Sdelphij        void private_##alg##_set_key(alg##_KEY *key, int len, \
630296465Sdelphij                                        const unsigned char *data)
631194206Ssimon
632296465Sdelphij# else
633194206Ssimon
634296465Sdelphij#  define FIPS_NON_FIPS_VCIPHER_Init(alg) \
635296465Sdelphij        void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data)
636194206Ssimon
637296465Sdelphij#  define FIPS_NON_FIPS_MD_Init(alg) \
638296465Sdelphij        int alg##_Init(alg##_CTX *c)
639194206Ssimon
640296465Sdelphij# endif                         /* def OPENSSL_FIPS */
641194206Ssimon
642296465Sdelphij# define OPENSSL_HAVE_INIT       1
643237998Sjkimvoid OPENSSL_init(void);
644237998Sjkim
645296465Sdelphij/*
646296465Sdelphij * CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal.
647296465Sdelphij * It takes an amount of time dependent on |len|, but independent of the
648296465Sdelphij * contents of |a| and |b|. Unlike memcmp, it cannot be used to put elements
649296465Sdelphij * into a defined order as the return value when a != b is undefined, other
650296465Sdelphij * than to be non-zero.
651296465Sdelphij */
652248272Sdelphijint CRYPTO_memcmp(const void *a, const void *b, size_t len);
653248272Sdelphij
65455714Skris/* BEGIN ERROR CODES */
655296465Sdelphij/*
656296465Sdelphij * The following lines are auto generated by the script mkerr.pl. Any changes
65755714Skris * made after this point may be overwritten when the script is next run.
65855714Skris */
65989837Skrisvoid ERR_load_CRYPTO_strings(void);
66055714Skris
66155714Skris/* Error codes for the CRYPTO functions. */
66255714Skris
66355714Skris/* Function codes. */
664296465Sdelphij# define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX                 100
665296465Sdelphij# define CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID                103
666296465Sdelphij# define CRYPTO_F_CRYPTO_GET_NEW_LOCKID                   101
667296465Sdelphij# define CRYPTO_F_CRYPTO_SET_EX_DATA                      102
668296465Sdelphij# define CRYPTO_F_DEF_ADD_INDEX                           104
669296465Sdelphij# define CRYPTO_F_DEF_GET_CLASS                           105
670296465Sdelphij# define CRYPTO_F_INT_DUP_EX_DATA                         106
671296465Sdelphij# define CRYPTO_F_INT_FREE_EX_DATA                        107
672296465Sdelphij# define CRYPTO_F_INT_NEW_EX_DATA                         108
67355714Skris
67455714Skris/* Reason codes. */
675296465Sdelphij# define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK              100
67655714Skris
67755714Skris#ifdef  __cplusplus
67855714Skris}
67955714Skris#endif
68055714Skris#endif
681