crypto.h revision 248272
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 10160814Ssimon * 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. 6155714Skris * 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). 6855714Skris * 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. 7555714Skris * 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 :-). 9055714Skris * 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)" 9355714Skris * 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. 10555714Skris * 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. 113160814Ssimon * ECDH support in OpenSSL originally developed by 114160814Ssimon * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. 115160814Ssimon */ 11655714Skris 11755714Skris#ifndef HEADER_CRYPTO_H 11855714Skris#define HEADER_CRYPTO_H 11955714Skris 12059191Skris#include <stdlib.h> 12159191Skris 122160814Ssimon#include <openssl/e_os2.h> 123160814Ssimon 124109998Smarkm#ifndef OPENSSL_NO_FP_API 12555714Skris#include <stdio.h> 12655714Skris#endif 12755714Skris 12855714Skris#include <openssl/stack.h> 12959191Skris#include <openssl/safestack.h> 13055714Skris#include <openssl/opensslv.h> 131160814Ssimon#include <openssl/ossl_typ.h> 13255714Skris 13355714Skris#ifdef CHARSET_EBCDIC 13455714Skris#include <openssl/ebcdic.h> 13555714Skris#endif 13655714Skris 13768651Skris/* Resolve problems on some operating systems with symbol names that clash 13868651Skris one way or another */ 13968651Skris#include <openssl/symhacks.h> 14068651Skris 14168651Skris#ifdef __cplusplus 14268651Skrisextern "C" { 14359191Skris#endif 14459191Skris 14555714Skris/* Backward compatibility to SSLeay */ 14655714Skris/* This is more to be used to check the correct DLL is being used 14755714Skris * in the MS world. */ 14855714Skris#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER 14955714Skris#define SSLEAY_VERSION 0 15055714Skris/* #define SSLEAY_OPTIONS 1 no longer supported */ 15155714Skris#define SSLEAY_CFLAGS 2 15255714Skris#define SSLEAY_BUILT_ON 3 15355714Skris#define SSLEAY_PLATFORM 4 154109998Smarkm#define SSLEAY_DIR 5 15555714Skris 156160814Ssimon/* Already declared in ossl_typ.h */ 157160814Ssimon#if 0 158160814Ssimontypedef struct crypto_ex_data_st CRYPTO_EX_DATA; 159160814Ssimon/* Called when a new object is created */ 160160814Ssimontypedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, 161160814Ssimon int idx, long argl, void *argp); 162160814Ssimon/* Called when an object is free()ed */ 163160814Ssimontypedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, 164160814Ssimon int idx, long argl, void *argp); 165160814Ssimon/* Called when we need to dup an object */ 166160814Ssimontypedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d, 167160814Ssimon int idx, long argl, void *argp); 168160814Ssimon#endif 169160814Ssimon 170160814Ssimon/* A generic structure to pass assorted data in a expandable way */ 171160814Ssimontypedef struct openssl_item_st 172160814Ssimon { 173160814Ssimon int code; 174160814Ssimon void *value; /* Not used for flag attributes */ 175160814Ssimon size_t value_size; /* Max size of value for output, length for input */ 176160814Ssimon size_t *value_length; /* Returned length of value for output */ 177160814Ssimon } OPENSSL_ITEM; 178160814Ssimon 179160814Ssimon 18055714Skris/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock 18155714Skris * names in cryptlib.c 18255714Skris */ 18355714Skris 184160814Ssimon#define CRYPTO_LOCK_ERR 1 185160814Ssimon#define CRYPTO_LOCK_EX_DATA 2 186160814Ssimon#define CRYPTO_LOCK_X509 3 187160814Ssimon#define CRYPTO_LOCK_X509_INFO 4 188160814Ssimon#define CRYPTO_LOCK_X509_PKEY 5 18955714Skris#define CRYPTO_LOCK_X509_CRL 6 19055714Skris#define CRYPTO_LOCK_X509_REQ 7 19155714Skris#define CRYPTO_LOCK_DSA 8 19255714Skris#define CRYPTO_LOCK_RSA 9 19355714Skris#define CRYPTO_LOCK_EVP_PKEY 10 194109998Smarkm#define CRYPTO_LOCK_X509_STORE 11 195109998Smarkm#define CRYPTO_LOCK_SSL_CTX 12 196109998Smarkm#define CRYPTO_LOCK_SSL_CERT 13 197109998Smarkm#define CRYPTO_LOCK_SSL_SESSION 14 198109998Smarkm#define CRYPTO_LOCK_SSL_SESS_CERT 15 199109998Smarkm#define CRYPTO_LOCK_SSL 16 200109998Smarkm#define CRYPTO_LOCK_SSL_METHOD 17 201109998Smarkm#define CRYPTO_LOCK_RAND 18 202109998Smarkm#define CRYPTO_LOCK_RAND2 19 203109998Smarkm#define CRYPTO_LOCK_MALLOC 20 204109998Smarkm#define CRYPTO_LOCK_BIO 21 205109998Smarkm#define CRYPTO_LOCK_GETHOSTBYNAME 22 206109998Smarkm#define CRYPTO_LOCK_GETSERVBYNAME 23 207109998Smarkm#define CRYPTO_LOCK_READDIR 24 208109998Smarkm#define CRYPTO_LOCK_RSA_BLINDING 25 209109998Smarkm#define CRYPTO_LOCK_DH 26 210109998Smarkm#define CRYPTO_LOCK_MALLOC2 27 211109998Smarkm#define CRYPTO_LOCK_DSO 28 212109998Smarkm#define CRYPTO_LOCK_DYNLOCK 29 213109998Smarkm#define CRYPTO_LOCK_ENGINE 30 214109998Smarkm#define CRYPTO_LOCK_UI 31 215160814Ssimon#define CRYPTO_LOCK_ECDSA 32 216160814Ssimon#define CRYPTO_LOCK_EC 33 217160814Ssimon#define CRYPTO_LOCK_ECDH 34 218160814Ssimon#define CRYPTO_LOCK_BN 35 219160814Ssimon#define CRYPTO_LOCK_EC_PRE_COMP 36 220160814Ssimon#define CRYPTO_LOCK_STORE 37 221160814Ssimon#define CRYPTO_LOCK_COMP 38 222194206Ssimon#ifndef OPENSSL_FIPS 223160814Ssimon#define CRYPTO_NUM_LOCKS 39 224194206Ssimon#else 225194206Ssimon#define CRYPTO_LOCK_FIPS 39 226194206Ssimon#define CRYPTO_LOCK_FIPS2 40 227194206Ssimon#define CRYPTO_NUM_LOCKS 41 228194206Ssimon#endif 22955714Skris 23055714Skris#define CRYPTO_LOCK 1 23155714Skris#define CRYPTO_UNLOCK 2 23255714Skris#define CRYPTO_READ 4 23355714Skris#define CRYPTO_WRITE 8 23455714Skris 235109998Smarkm#ifndef OPENSSL_NO_LOCKING 23655714Skris#ifndef CRYPTO_w_lock 23755714Skris#define CRYPTO_w_lock(type) \ 23855714Skris CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) 23955714Skris#define CRYPTO_w_unlock(type) \ 24055714Skris CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) 24155714Skris#define CRYPTO_r_lock(type) \ 24255714Skris CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__) 24355714Skris#define CRYPTO_r_unlock(type) \ 24455714Skris CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__) 24555714Skris#define CRYPTO_add(addr,amount,type) \ 24655714Skris CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__) 24755714Skris#endif 24855714Skris#else 24955714Skris#define CRYPTO_w_lock(a) 250109998Smarkm#define CRYPTO_w_unlock(a) 25155714Skris#define CRYPTO_r_lock(a) 25255714Skris#define CRYPTO_r_unlock(a) 25355714Skris#define CRYPTO_add(a,b,c) ((*(a))+=(b)) 25455714Skris#endif 25555714Skris 25668651Skris/* Some applications as well as some parts of OpenSSL need to allocate 25768651Skris and deallocate locks in a dynamic fashion. The following typedef 25868651Skris makes this possible in a type-safe manner. */ 25968651Skris/* struct CRYPTO_dynlock_value has to be defined by the application. */ 26068651Skristypedef struct 26168651Skris { 26268651Skris int references; 26368651Skris struct CRYPTO_dynlock_value *data; 26468651Skris } CRYPTO_dynlock; 26568651Skris 26668651Skris 26755714Skris/* The following can be used to detect memory leaks in the SSLeay library. 26855714Skris * It used, it turns on malloc checking */ 26955714Skris 27055714Skris#define CRYPTO_MEM_CHECK_OFF 0x0 /* an enume */ 27155714Skris#define CRYPTO_MEM_CHECK_ON 0x1 /* a bit */ 27255714Skris#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */ 27355714Skris#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */ 27455714Skris 27559191Skris/* The following are bit values to turn on or off options connected to the 27659191Skris * malloc checking functionality */ 27755714Skris 27859191Skris/* Adds time to the memory checking information */ 27959191Skris#define V_CRYPTO_MDEBUG_TIME 0x1 /* a bit */ 28059191Skris/* Adds thread number to the memory checking information */ 28159191Skris#define V_CRYPTO_MDEBUG_THREAD 0x2 /* a bit */ 28259191Skris 28359191Skris#define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD) 28459191Skris 28559191Skris 28655714Skris/* predec of the BIO type */ 28755714Skristypedef struct bio_st BIO_dummy; 28855714Skris 289160814Ssimonstruct crypto_ex_data_st 29055714Skris { 29155714Skris STACK *sk; 29255714Skris int dummy; /* gcc is screwing up this data structure :-( */ 293160814Ssimon }; 29455714Skris 29555714Skris/* This stuff is basically class callback functions 29659191Skris * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */ 29759191Skris 29855714Skristypedef struct crypto_ex_data_func_st 29955714Skris { 30055714Skris long argl; /* Arbitary long */ 30159191Skris void *argp; /* Arbitary void * */ 30259191Skris CRYPTO_EX_new *new_func; 30359191Skris CRYPTO_EX_free *free_func; 30459191Skris CRYPTO_EX_dup *dup_func; 30555714Skris } CRYPTO_EX_DATA_FUNCS; 30655714Skris 30759191SkrisDECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS) 30859191Skris 30955714Skris/* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA 31055714Skris * entry. 31155714Skris */ 31255714Skris 31355714Skris#define CRYPTO_EX_INDEX_BIO 0 31455714Skris#define CRYPTO_EX_INDEX_SSL 1 31555714Skris#define CRYPTO_EX_INDEX_SSL_CTX 2 31655714Skris#define CRYPTO_EX_INDEX_SSL_SESSION 3 31755714Skris#define CRYPTO_EX_INDEX_X509_STORE 4 31855714Skris#define CRYPTO_EX_INDEX_X509_STORE_CTX 5 319109998Smarkm#define CRYPTO_EX_INDEX_RSA 6 320109998Smarkm#define CRYPTO_EX_INDEX_DSA 7 321109998Smarkm#define CRYPTO_EX_INDEX_DH 8 322109998Smarkm#define CRYPTO_EX_INDEX_ENGINE 9 323109998Smarkm#define CRYPTO_EX_INDEX_X509 10 324109998Smarkm#define CRYPTO_EX_INDEX_UI 11 325160814Ssimon#define CRYPTO_EX_INDEX_ECDSA 12 326160814Ssimon#define CRYPTO_EX_INDEX_ECDH 13 327160814Ssimon#define CRYPTO_EX_INDEX_COMP 14 328160814Ssimon#define CRYPTO_EX_INDEX_STORE 15 32955714Skris 330109998Smarkm/* Dynamically assigned indexes start from this value (don't use directly, use 331109998Smarkm * via CRYPTO_ex_data_new_class). */ 332109998Smarkm#define CRYPTO_EX_INDEX_USER 100 33359191Skris 334109998Smarkm 33559191Skris/* This is the default callbacks, but we can have others as well: 33659191Skris * this is needed in Win32 where the application malloc and the 33759191Skris * library malloc may not be the same. 33859191Skris */ 33955714Skris#define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\ 34059191Skris malloc, realloc, free) 34155714Skris 34259191Skris#if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD 34355714Skris# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */ 34455714Skris# define CRYPTO_MDEBUG 34555714Skris# endif 34655714Skris#endif 34755714Skris 34859191Skris/* Set standard debugging functions (not done by default 34959191Skris * unless CRYPTO_MDEBUG is defined) */ 350194206Ssimonvoid CRYPTO_malloc_debug_init(void); 35159191Skris 35259191Skrisint CRYPTO_mem_ctrl(int mode); 35359191Skrisint CRYPTO_is_mem_check_on(void); 35459191Skris 35559191Skris/* for applications */ 35655714Skris#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON) 35755714Skris#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF) 35859191Skris 35959191Skris/* for library-internal use */ 36055714Skris#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE) 36155714Skris#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE) 36259191Skris#define is_MemCheck_on() CRYPTO_is_mem_check_on() 36359191Skris 36468651Skris#define OPENSSL_malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__) 365194206Ssimon#define OPENSSL_strdup(str) CRYPTO_strdup((str),__FILE__,__LINE__) 36668651Skris#define OPENSSL_realloc(addr,num) \ 36759191Skris CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__) 368109998Smarkm#define OPENSSL_realloc_clean(addr,old_num,num) \ 369109998Smarkm CRYPTO_realloc_clean(addr,old_num,num,__FILE__,__LINE__) 37068651Skris#define OPENSSL_remalloc(addr,num) \ 37159191Skris CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__) 37268651Skris#define OPENSSL_freeFunc CRYPTO_free 37368651Skris#define OPENSSL_free(addr) CRYPTO_free(addr) 37459191Skris 37568651Skris#define OPENSSL_malloc_locked(num) \ 37668651Skris CRYPTO_malloc_locked((int)num,__FILE__,__LINE__) 37768651Skris#define OPENSSL_free_locked(addr) CRYPTO_free_locked(addr) 37855714Skris 37959191Skris 38055714Skrisconst char *SSLeay_version(int type); 38155714Skrisunsigned long SSLeay(void); 38255714Skris 38376866Skrisint OPENSSL_issetugid(void); 38476866Skris 385109998Smarkm/* An opaque type representing an implementation of "ex_data" support */ 386109998Smarkmtypedef struct st_CRYPTO_EX_DATA_IMPL CRYPTO_EX_DATA_IMPL; 387109998Smarkm/* Return an opaque pointer to the current "ex_data" implementation */ 388109998Smarkmconst CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void); 389109998Smarkm/* Sets the "ex_data" implementation to be used (if it's not too late) */ 390109998Smarkmint CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i); 391109998Smarkm/* Get a new "ex_data" class, and return the corresponding "class_index" */ 392109998Smarkmint CRYPTO_ex_data_new_class(void); 393109998Smarkm/* Within a given class, get/register a new index */ 394109998Smarkmint CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, 395109998Smarkm CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, 396109998Smarkm CRYPTO_EX_free *free_func); 397109998Smarkm/* Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a given 398109998Smarkm * class (invokes whatever per-class callbacks are applicable) */ 399109998Smarkmint CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); 400109998Smarkmint CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, 401109998Smarkm CRYPTO_EX_DATA *from); 402109998Smarkmvoid CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); 403109998Smarkm/* Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular index 404109998Smarkm * (relative to the class type involved) */ 40559191Skrisint CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val); 406109998Smarkmvoid *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad,int idx); 407109998Smarkm/* This function cleans up all "ex_data" state. It mustn't be called under 408109998Smarkm * potential race-conditions. */ 409109998Smarkmvoid CRYPTO_cleanup_all_ex_data(void); 41055714Skris 41155714Skrisint CRYPTO_get_new_lockid(char *name); 41255714Skris 41355714Skrisint CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */ 41455714Skrisvoid CRYPTO_lock(int mode, int type,const char *file,int line); 41555714Skrisvoid CRYPTO_set_locking_callback(void (*func)(int mode,int type, 41655714Skris const char *file,int line)); 41755714Skrisvoid (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file, 41855714Skris int line); 41955714Skrisvoid CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type, 42055714Skris const char *file, int line)); 42155714Skrisint (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type, 42255714Skris const char *file,int line); 42355714Skrisvoid CRYPTO_set_id_callback(unsigned long (*func)(void)); 42455714Skrisunsigned long (*CRYPTO_get_id_callback(void))(void); 42555714Skrisunsigned long CRYPTO_thread_id(void); 42655714Skrisconst char *CRYPTO_get_lock_name(int type); 42755714Skrisint CRYPTO_add_lock(int *pointer,int amount,int type, const char *file, 42855714Skris int line); 42955714Skris 430194206Ssimonvoid int_CRYPTO_set_do_dynlock_callback( 431194206Ssimon void (*do_dynlock_cb)(int mode, int type, const char *file, int line)); 432194206Ssimon 43368651Skrisint CRYPTO_get_new_dynlockid(void); 43468651Skrisvoid CRYPTO_destroy_dynlockid(int i); 43568651Skrisstruct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i); 43668651Skrisvoid CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*dyn_create_function)(const char *file, int line)); 43768651Skrisvoid CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line)); 43868651Skrisvoid CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)(struct CRYPTO_dynlock_value *l, const char *file, int line)); 43968651Skrisstruct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))(const char *file,int line); 44068651Skrisvoid (*CRYPTO_get_dynlock_lock_callback(void))(int mode, struct CRYPTO_dynlock_value *l, const char *file,int line); 44168651Skrisvoid (*CRYPTO_get_dynlock_destroy_callback(void))(struct CRYPTO_dynlock_value *l, const char *file,int line); 44268651Skris 44359191Skris/* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions -- 44459191Skris * call the latter last if you need different functions */ 44559191Skrisint CRYPTO_set_mem_functions(void *(*m)(size_t),void *(*r)(void *,size_t), void (*f)(void *)); 44659191Skrisint CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*free_func)(void *)); 447109998Smarkmint CRYPTO_set_mem_ex_functions(void *(*m)(size_t,const char *,int), 448109998Smarkm void *(*r)(void *,size_t,const char *,int), 449109998Smarkm void (*f)(void *)); 450109998Smarkmint CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t,const char *,int), 451109998Smarkm void (*free_func)(void *)); 45268651Skrisint CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int), 45368651Skris void (*r)(void *,void *,int,const char *,int,int), 45468651Skris void (*f)(void *,int), 45568651Skris void (*so)(long), 45668651Skris long (*go)(void)); 457194206Ssimonvoid CRYPTO_set_mem_info_functions( 458194206Ssimon int (*push_info_fn)(const char *info, const char *file, int line), 459194206Ssimon int (*pop_info_fn)(void), 460194206Ssimon int (*remove_all_info_fn)(void)); 46159191Skrisvoid CRYPTO_get_mem_functions(void *(**m)(size_t),void *(**r)(void *, size_t), void (**f)(void *)); 46259191Skrisvoid CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *)); 463109998Smarkmvoid CRYPTO_get_mem_ex_functions(void *(**m)(size_t,const char *,int), 464109998Smarkm void *(**r)(void *, size_t,const char *,int), 465109998Smarkm void (**f)(void *)); 466109998Smarkmvoid CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t,const char *,int), 467109998Smarkm void (**f)(void *)); 46868651Skrisvoid CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int), 46968651Skris void (**r)(void *,void *,int,const char *,int,int), 47068651Skris void (**f)(void *,int), 47168651Skris void (**so)(long), 47268651Skris long (**go)(void)); 47355714Skris 47459191Skrisvoid *CRYPTO_malloc_locked(int num, const char *file, int line); 47555714Skrisvoid CRYPTO_free_locked(void *); 47659191Skrisvoid *CRYPTO_malloc(int num, const char *file, int line); 477194206Ssimonchar *CRYPTO_strdup(const char *str, const char *file, int line); 47855714Skrisvoid CRYPTO_free(void *); 47959191Skrisvoid *CRYPTO_realloc(void *addr,int num, const char *file, int line); 480109998Smarkmvoid *CRYPTO_realloc_clean(void *addr,int old_num,int num,const char *file, 481109998Smarkm int line); 48259191Skrisvoid *CRYPTO_remalloc(void *addr,int num, const char *file, int line); 48355714Skris 484109998Smarkmvoid OPENSSL_cleanse(void *ptr, size_t len); 485109998Smarkm 48659191Skrisvoid CRYPTO_set_mem_debug_options(long bits); 48759191Skrislong CRYPTO_get_mem_debug_options(void); 48859191Skris 48959191Skris#define CRYPTO_push_info(info) \ 49059191Skris CRYPTO_push_info_(info, __FILE__, __LINE__); 49159191Skrisint CRYPTO_push_info_(const char *info, const char *file, int line); 49259191Skrisint CRYPTO_pop_info(void); 49359191Skrisint CRYPTO_remove_all_info(void); 49459191Skris 49589837Skris 49689837Skris/* Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro; 49789837Skris * used as default in CRYPTO_MDEBUG compilations): */ 49859191Skris/* The last argument has the following significance: 49959191Skris * 50059191Skris * 0: called before the actual memory allocation has taken place 50159191Skris * 1: called after the actual memory allocation has taken place 50259191Skris */ 50359191Skrisvoid CRYPTO_dbg_malloc(void *addr,int num,const char *file,int line,int before_p); 50459191Skrisvoid CRYPTO_dbg_realloc(void *addr1,void *addr2,int num,const char *file,int line,int before_p); 50559191Skrisvoid CRYPTO_dbg_free(void *addr,int before_p); 50659191Skris/* Tell the debugging code about options. By default, the following values 50759191Skris * apply: 50859191Skris * 50989837Skris * 0: Clear all options. 51089837Skris * V_CRYPTO_MDEBUG_TIME (1): Set the "Show Time" option. 51189837Skris * V_CRYPTO_MDEBUG_THREAD (2): Set the "Show Thread Number" option. 51289837Skris * V_CRYPTO_MDEBUG_ALL (3): 1 + 2 51359191Skris */ 51459191Skrisvoid CRYPTO_dbg_set_options(long bits); 51559191Skrislong CRYPTO_dbg_get_options(void); 51659191Skris 517194206Ssimonint CRYPTO_dbg_push_info(const char *info, const char *file, int line); 518194206Ssimonint CRYPTO_dbg_pop_info(void); 519194206Ssimonint CRYPTO_dbg_remove_all_info(void); 52089837Skris 521109998Smarkm#ifndef OPENSSL_NO_FP_API 52255714Skrisvoid CRYPTO_mem_leaks_fp(FILE *); 52355714Skris#endif 52455714Skrisvoid CRYPTO_mem_leaks(struct bio_st *bio); 52555714Skris/* unsigned long order, char *file, int line, int num_bytes, char *addr */ 526109998Smarkmtypedef void *CRYPTO_MEM_LEAK_CB(unsigned long, const char *, int, int, void *); 527109998Smarkmvoid CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb); 52855714Skris 529109998Smarkm/* die if we have to */ 530109998Smarkmvoid OpenSSLDie(const char *file,int line,const char *assertion); 531160814Ssimon#define OPENSSL_assert(e) (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1)) 532109998Smarkm 533160814Ssimonunsigned long *OPENSSL_ia32cap_loc(void); 534160814Ssimon#define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc())) 535194206Ssimonint OPENSSL_isservice(void); 536142425Snectar 537194206Ssimon#ifdef OPENSSL_FIPS 538194206Ssimon#define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \ 539194206Ssimon alg " previous FIPS forbidden algorithm error ignored"); 540194206Ssimon 541194206Ssimon#define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \ 542194206Ssimon #alg " Algorithm forbidden in FIPS mode"); 543194206Ssimon 544194206Ssimon#ifdef OPENSSL_FIPS_STRICT 545194206Ssimon#define FIPS_BAD_ALGORITHM(alg) FIPS_BAD_ABORT(alg) 546194206Ssimon#else 547194206Ssimon#define FIPS_BAD_ALGORITHM(alg) \ 548194206Ssimon { \ 549194206Ssimon FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD); \ 550194206Ssimon ERR_add_error_data(2, "Algorithm=", #alg); \ 551194206Ssimon return 0; \ 552194206Ssimon } 553194206Ssimon#endif 554194206Ssimon 555194206Ssimon/* Low level digest API blocking macro */ 556194206Ssimon 557194206Ssimon#define FIPS_NON_FIPS_MD_Init(alg) \ 558194206Ssimon int alg##_Init(alg##_CTX *c) \ 559194206Ssimon { \ 560194206Ssimon if (FIPS_mode()) \ 561194206Ssimon FIPS_BAD_ALGORITHM(alg) \ 562194206Ssimon return private_##alg##_Init(c); \ 563194206Ssimon } \ 564194206Ssimon int private_##alg##_Init(alg##_CTX *c) 565194206Ssimon 566194206Ssimon/* For ciphers the API often varies from cipher to cipher and each needs to 567194206Ssimon * be treated as a special case. Variable key length ciphers (Blowfish, RC4, 568194206Ssimon * CAST) however are very similar and can use a blocking macro. 569194206Ssimon */ 570194206Ssimon 571194206Ssimon#define FIPS_NON_FIPS_VCIPHER_Init(alg) \ 572194206Ssimon void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) \ 573194206Ssimon { \ 574194206Ssimon if (FIPS_mode()) \ 575194206Ssimon FIPS_BAD_ABORT(alg) \ 576194206Ssimon private_##alg##_set_key(key, len, data); \ 577194206Ssimon } \ 578194206Ssimon void private_##alg##_set_key(alg##_KEY *key, int len, \ 579194206Ssimon const unsigned char *data) 580194206Ssimon 581194206Ssimon#else 582194206Ssimon 583194206Ssimon#define FIPS_NON_FIPS_VCIPHER_Init(alg) \ 584194206Ssimon void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) 585194206Ssimon 586194206Ssimon#define FIPS_NON_FIPS_MD_Init(alg) \ 587194206Ssimon int alg##_Init(alg##_CTX *c) 588194206Ssimon 589194206Ssimon#endif /* def OPENSSL_FIPS */ 590194206Ssimon 591237998Sjkim#define OPENSSL_HAVE_INIT 1 592237998Sjkimvoid OPENSSL_init(void); 593237998Sjkim 594248272Sdelphij/* CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal. It 595248272Sdelphij * takes an amount of time dependent on |len|, but independent of the contents 596248272Sdelphij * of |a| and |b|. Unlike memcmp, it cannot be used to put elements into a 597248272Sdelphij * defined order as the return value when a != b is undefined, other than to be 598248272Sdelphij * non-zero. */ 599248272Sdelphijint CRYPTO_memcmp(const void *a, const void *b, size_t len); 600248272Sdelphij 60155714Skris/* BEGIN ERROR CODES */ 60255714Skris/* The following lines are auto generated by the script mkerr.pl. Any changes 60355714Skris * made after this point may be overwritten when the script is next run. 60455714Skris */ 60589837Skrisvoid ERR_load_CRYPTO_strings(void); 60655714Skris 60755714Skris/* Error codes for the CRYPTO functions. */ 60855714Skris 60955714Skris/* Function codes. */ 61055714Skris#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100 61168651Skris#define CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID 103 61255714Skris#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101 61355714Skris#define CRYPTO_F_CRYPTO_SET_EX_DATA 102 614109998Smarkm#define CRYPTO_F_DEF_ADD_INDEX 104 615109998Smarkm#define CRYPTO_F_DEF_GET_CLASS 105 616109998Smarkm#define CRYPTO_F_INT_DUP_EX_DATA 106 617109998Smarkm#define CRYPTO_F_INT_FREE_EX_DATA 107 618109998Smarkm#define CRYPTO_F_INT_NEW_EX_DATA 108 61955714Skris 62055714Skris/* Reason codes. */ 62168651Skris#define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK 100 62255714Skris 62355714Skris#ifdef __cplusplus 62455714Skris} 62555714Skris#endif 62655714Skris#endif 627