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