crypto.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /* crypto/crypto.h */
  2. /* ====================================================================
  3. * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. *
  17. * 3. All advertising materials mentioning features or use of this
  18. * software must display the following acknowledgment:
  19. * "This product includes software developed by the OpenSSL Project
  20. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  21. *
  22. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  23. * endorse or promote products derived from this software without
  24. * prior written permission. For written permission, please contact
  25. * openssl-core@openssl.org.
  26. *
  27. * 5. Products derived from this software may not be called "OpenSSL"
  28. * nor may "OpenSSL" appear in their names without prior written
  29. * permission of the OpenSSL Project.
  30. *
  31. * 6. Redistributions of any form whatsoever must retain the following
  32. * acknowledgment:
  33. * "This product includes software developed by the OpenSSL Project
  34. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  37. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  42. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  45. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  46. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  47. * OF THE POSSIBILITY OF SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This product includes cryptographic software written by Eric Young
  51. * (eay@cryptsoft.com). This product includes software written by Tim
  52. * Hudson (tjh@cryptsoft.com).
  53. *
  54. */
  55. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  56. * All rights reserved.
  57. *
  58. * This package is an SSL implementation written
  59. * by Eric Young (eay@cryptsoft.com).
  60. * The implementation was written so as to conform with Netscapes SSL.
  61. *
  62. * This library is free for commercial and non-commercial use as long as
  63. * the following conditions are aheared to. The following conditions
  64. * apply to all code found in this distribution, be it the RC4, RSA,
  65. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  66. * included with this distribution is covered by the same copyright terms
  67. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  68. *
  69. * Copyright remains Eric Young's, and as such any Copyright notices in
  70. * the code are not to be removed.
  71. * If this package is used in a product, Eric Young should be given attribution
  72. * as the author of the parts of the library used.
  73. * This can be in the form of a textual message at program startup or
  74. * in documentation (online or textual) provided with the package.
  75. *
  76. * Redistribution and use in source and binary forms, with or without
  77. * modification, are permitted provided that the following conditions
  78. * are met:
  79. * 1. Redistributions of source code must retain the copyright
  80. * notice, this list of conditions and the following disclaimer.
  81. * 2. Redistributions in binary form must reproduce the above copyright
  82. * notice, this list of conditions and the following disclaimer in the
  83. * documentation and/or other materials provided with the distribution.
  84. * 3. All advertising materials mentioning features or use of this software
  85. * must display the following acknowledgement:
  86. * "This product includes cryptographic software written by
  87. * Eric Young (eay@cryptsoft.com)"
  88. * The word 'cryptographic' can be left out if the rouines from the library
  89. * being used are not cryptographic related :-).
  90. * 4. If you include any Windows specific code (or a derivative thereof) from
  91. * the apps directory (application code) you must include an acknowledgement:
  92. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  93. *
  94. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  95. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  96. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  97. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  98. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  99. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  100. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  101. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  102. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  103. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  104. * SUCH DAMAGE.
  105. *
  106. * The licence and distribution terms for any publically available version or
  107. * derivative of this code cannot be changed. i.e. this code cannot simply be
  108. * copied and put under another distribution licence
  109. * [including the GNU Public Licence.]
  110. */
  111. /* ====================================================================
  112. * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  113. * ECDH support in OpenSSL originally developed by
  114. * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
  115. */
  116. #ifndef HEADER_CRYPTO_H
  117. # define HEADER_CRYPTO_H
  118. # include <stdlib.h>
  119. # include <openssl/e_os2.h>
  120. # ifndef OPENSSL_NO_FP_API
  121. # include <stdio.h>
  122. # endif
  123. # include <openssl/stack.h>
  124. # include <openssl/safestack.h>
  125. # include <openssl/opensslv.h>
  126. # include <openssl/ossl_typ.h>
  127. # ifdef CHARSET_EBCDIC
  128. # include <openssl/ebcdic.h>
  129. # endif
  130. /*
  131. * Resolve problems on some operating systems with symbol names that clash
  132. * one way or another
  133. */
  134. # include <openssl/symhacks.h>
  135. #ifdef __cplusplus
  136. extern "C" {
  137. #endif
  138. /* Backward compatibility to SSLeay */
  139. /*
  140. * This is more to be used to check the correct DLL is being used in the MS
  141. * world.
  142. */
  143. # define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
  144. # define SSLEAY_VERSION 0
  145. /* #define SSLEAY_OPTIONS 1 no longer supported */
  146. # define SSLEAY_CFLAGS 2
  147. # define SSLEAY_BUILT_ON 3
  148. # define SSLEAY_PLATFORM 4
  149. # define SSLEAY_DIR 5
  150. /* Already declared in ossl_typ.h */
  151. # if 0
  152. typedef struct crypto_ex_data_st CRYPTO_EX_DATA;
  153. /* Called when a new object is created */
  154. typedef int CRYPTO_EX_new (void *parent, void *ptr, CRYPTO_EX_DATA *ad,
  155. int idx, long argl, void *argp);
  156. /* Called when an object is free()ed */
  157. typedef void CRYPTO_EX_free (void *parent, void *ptr, CRYPTO_EX_DATA *ad,
  158. int idx, long argl, void *argp);
  159. /* Called when we need to dup an object */
  160. typedef int CRYPTO_EX_dup (CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from,
  161. void *from_d, int idx, long argl, void *argp);
  162. # endif
  163. /* A generic structure to pass assorted data in a expandable way */
  164. typedef struct openssl_item_st {
  165. int code;
  166. void *value; /* Not used for flag attributes */
  167. size_t value_size; /* Max size of value for output, length for
  168. * input */
  169. size_t *value_length; /* Returned length of value for output */
  170. } OPENSSL_ITEM;
  171. /*
  172. * When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock
  173. * names in cryptlib.c
  174. */
  175. # define CRYPTO_LOCK_ERR 1
  176. # define CRYPTO_LOCK_EX_DATA 2
  177. # define CRYPTO_LOCK_X509 3
  178. # define CRYPTO_LOCK_X509_INFO 4
  179. # define CRYPTO_LOCK_X509_PKEY 5
  180. # define CRYPTO_LOCK_X509_CRL 6
  181. # define CRYPTO_LOCK_X509_REQ 7
  182. # define CRYPTO_LOCK_DSA 8
  183. # define CRYPTO_LOCK_RSA 9
  184. # define CRYPTO_LOCK_EVP_PKEY 10
  185. # define CRYPTO_LOCK_X509_STORE 11
  186. # define CRYPTO_LOCK_SSL_CTX 12
  187. # define CRYPTO_LOCK_SSL_CERT 13
  188. # define CRYPTO_LOCK_SSL_SESSION 14
  189. # define CRYPTO_LOCK_SSL_SESS_CERT 15
  190. # define CRYPTO_LOCK_SSL 16
  191. # define CRYPTO_LOCK_SSL_METHOD 17
  192. # define CRYPTO_LOCK_RAND 18
  193. # define CRYPTO_LOCK_RAND2 19
  194. # define CRYPTO_LOCK_MALLOC 20
  195. # define CRYPTO_LOCK_BIO 21
  196. # define CRYPTO_LOCK_GETHOSTBYNAME 22
  197. # define CRYPTO_LOCK_GETSERVBYNAME 23
  198. # define CRYPTO_LOCK_READDIR 24
  199. # define CRYPTO_LOCK_RSA_BLINDING 25
  200. # define CRYPTO_LOCK_DH 26
  201. # define CRYPTO_LOCK_MALLOC2 27
  202. # define CRYPTO_LOCK_DSO 28
  203. # define CRYPTO_LOCK_DYNLOCK 29
  204. # define CRYPTO_LOCK_ENGINE 30
  205. # define CRYPTO_LOCK_UI 31
  206. # define CRYPTO_LOCK_ECDSA 32
  207. # define CRYPTO_LOCK_EC 33
  208. # define CRYPTO_LOCK_ECDH 34
  209. # define CRYPTO_LOCK_BN 35
  210. # define CRYPTO_LOCK_EC_PRE_COMP 36
  211. # define CRYPTO_LOCK_STORE 37
  212. # define CRYPTO_LOCK_COMP 38
  213. # ifndef OPENSSL_FIPS
  214. # define CRYPTO_NUM_LOCKS 39
  215. # else
  216. # define CRYPTO_LOCK_FIPS 39
  217. # define CRYPTO_LOCK_FIPS2 40
  218. # define CRYPTO_NUM_LOCKS 41
  219. # endif
  220. # define CRYPTO_LOCK 1
  221. # define CRYPTO_UNLOCK 2
  222. # define CRYPTO_READ 4
  223. # define CRYPTO_WRITE 8
  224. # ifndef OPENSSL_NO_LOCKING
  225. # ifndef CRYPTO_w_lock
  226. # define CRYPTO_w_lock(type) \
  227. CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
  228. # define CRYPTO_w_unlock(type) \
  229. CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
  230. # define CRYPTO_r_lock(type) \
  231. CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__)
  232. # define CRYPTO_r_unlock(type) \
  233. CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
  234. # define CRYPTO_add(addr,amount,type) \
  235. CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
  236. # endif
  237. # else
  238. # define CRYPTO_w_lock(a)
  239. # define CRYPTO_w_unlock(a)
  240. # define CRYPTO_r_lock(a)
  241. # define CRYPTO_r_unlock(a)
  242. # define CRYPTO_add(a,b,c) ((*(a))+=(b))
  243. # endif
  244. /*
  245. * Some applications as well as some parts of OpenSSL need to allocate and
  246. * deallocate locks in a dynamic fashion. The following typedef makes this
  247. * possible in a type-safe manner.
  248. */
  249. /* struct CRYPTO_dynlock_value has to be defined by the application. */
  250. typedef struct {
  251. int references;
  252. struct CRYPTO_dynlock_value *data;
  253. } CRYPTO_dynlock;
  254. /*
  255. * The following can be used to detect memory leaks in the SSLeay library. It
  256. * used, it turns on malloc checking
  257. */
  258. # define CRYPTO_MEM_CHECK_OFF 0x0/* an enume */
  259. # define CRYPTO_MEM_CHECK_ON 0x1/* a bit */
  260. # define CRYPTO_MEM_CHECK_ENABLE 0x2/* a bit */
  261. # define CRYPTO_MEM_CHECK_DISABLE 0x3/* an enume */
  262. /*
  263. * The following are bit values to turn on or off options connected to the
  264. * malloc checking functionality
  265. */
  266. /* Adds time to the memory checking information */
  267. # define V_CRYPTO_MDEBUG_TIME 0x1/* a bit */
  268. /* Adds thread number to the memory checking information */
  269. # define V_CRYPTO_MDEBUG_THREAD 0x2/* a bit */
  270. # define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD)
  271. /* predec of the BIO type */
  272. typedef struct bio_st BIO_dummy;
  273. struct crypto_ex_data_st {
  274. STACK *sk;
  275. /* gcc is screwing up this data structure :-( */
  276. int dummy;
  277. };
  278. /*
  279. * This stuff is basically class callback functions The current classes are
  280. * SSL_CTX, SSL, SSL_SESSION, and a few more
  281. */
  282. typedef struct crypto_ex_data_func_st {
  283. long argl; /* Arbitary long */
  284. void *argp; /* Arbitary void * */
  285. CRYPTO_EX_new *new_func;
  286. CRYPTO_EX_free *free_func;
  287. CRYPTO_EX_dup *dup_func;
  288. } CRYPTO_EX_DATA_FUNCS;
  289. DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
  290. /*
  291. * Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA
  292. * entry.
  293. */
  294. # define CRYPTO_EX_INDEX_BIO 0
  295. # define CRYPTO_EX_INDEX_SSL 1
  296. # define CRYPTO_EX_INDEX_SSL_CTX 2
  297. # define CRYPTO_EX_INDEX_SSL_SESSION 3
  298. # define CRYPTO_EX_INDEX_X509_STORE 4
  299. # define CRYPTO_EX_INDEX_X509_STORE_CTX 5
  300. # define CRYPTO_EX_INDEX_RSA 6
  301. # define CRYPTO_EX_INDEX_DSA 7
  302. # define CRYPTO_EX_INDEX_DH 8
  303. # define CRYPTO_EX_INDEX_ENGINE 9
  304. # define CRYPTO_EX_INDEX_X509 10
  305. # define CRYPTO_EX_INDEX_UI 11
  306. # define CRYPTO_EX_INDEX_ECDSA 12
  307. # define CRYPTO_EX_INDEX_ECDH 13
  308. # define CRYPTO_EX_INDEX_COMP 14
  309. # define CRYPTO_EX_INDEX_STORE 15
  310. /*
  311. * Dynamically assigned indexes start from this value (don't use directly,
  312. * use via CRYPTO_ex_data_new_class).
  313. */
  314. # define CRYPTO_EX_INDEX_USER 100
  315. /*
  316. * This is the default callbacks, but we can have others as well: this is
  317. * needed in Win32 where the application malloc and the library malloc may
  318. * not be the same.
  319. */
  320. # define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\
  321. malloc, realloc, free)
  322. # if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
  323. # ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
  324. # define CRYPTO_MDEBUG
  325. # endif
  326. # endif
  327. /*
  328. * Set standard debugging functions (not done by default unless CRYPTO_MDEBUG
  329. * is defined)
  330. */
  331. void CRYPTO_malloc_debug_init(void);
  332. int CRYPTO_mem_ctrl(int mode);
  333. int CRYPTO_is_mem_check_on(void);
  334. /* for applications */
  335. # define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
  336. # define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
  337. /* for library-internal use */
  338. # define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
  339. # define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
  340. # define is_MemCheck_on() CRYPTO_is_mem_check_on()
  341. # define OPENSSL_malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__)
  342. # define OPENSSL_strdup(str) CRYPTO_strdup((str),__FILE__,__LINE__)
  343. # define OPENSSL_realloc(addr,num) \
  344. CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__)
  345. # define OPENSSL_realloc_clean(addr,old_num,num) \
  346. CRYPTO_realloc_clean(addr,old_num,num,__FILE__,__LINE__)
  347. # define OPENSSL_remalloc(addr,num) \
  348. CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
  349. # define OPENSSL_freeFunc CRYPTO_free
  350. # define OPENSSL_free(addr) CRYPTO_free(addr)
  351. # define OPENSSL_malloc_locked(num) \
  352. CRYPTO_malloc_locked((int)num,__FILE__,__LINE__)
  353. # define OPENSSL_free_locked(addr) CRYPTO_free_locked(addr)
  354. const char *SSLeay_version(int type);
  355. unsigned long SSLeay(void);
  356. int OPENSSL_issetugid(void);
  357. /* An opaque type representing an implementation of "ex_data" support */
  358. typedef struct st_CRYPTO_EX_DATA_IMPL CRYPTO_EX_DATA_IMPL;
  359. /* Return an opaque pointer to the current "ex_data" implementation */
  360. const CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void);
  361. /* Sets the "ex_data" implementation to be used (if it's not too late) */
  362. int CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i);
  363. /* Get a new "ex_data" class, and return the corresponding "class_index" */
  364. int CRYPTO_ex_data_new_class(void);
  365. /* Within a given class, get/register a new index */
  366. int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp,
  367. CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
  368. CRYPTO_EX_free *free_func);
  369. /*
  370. * Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a
  371. * given class (invokes whatever per-class callbacks are applicable)
  372. */
  373. int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
  374. int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
  375. CRYPTO_EX_DATA *from);
  376. void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad);
  377. /*
  378. * Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular
  379. * index (relative to the class type involved)
  380. */
  381. int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val);
  382. void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx);
  383. /*
  384. * This function cleans up all "ex_data" state. It mustn't be called under
  385. * potential race-conditions.
  386. */
  387. void CRYPTO_cleanup_all_ex_data(void);
  388. int CRYPTO_get_new_lockid(char *name);
  389. int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */
  390. void CRYPTO_lock(int mode, int type, const char *file, int line);
  391. void CRYPTO_set_locking_callback(void (*func) (int mode, int type,
  392. const char *file, int line));
  393. void (*CRYPTO_get_locking_callback(void)) (int mode, int type,
  394. const char *file, int line);
  395. void CRYPTO_set_add_lock_callback(int (*func)
  396. (int *num, int mount, int type,
  397. const char *file, int line));
  398. int (*CRYPTO_get_add_lock_callback(void)) (int *num, int mount, int type,
  399. const char *file, int line);
  400. void CRYPTO_set_id_callback(unsigned long (*func) (void));
  401. unsigned long (*CRYPTO_get_id_callback(void)) (void);
  402. unsigned long CRYPTO_thread_id(void);
  403. const char *CRYPTO_get_lock_name(int type);
  404. int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
  405. int line);
  406. void int_CRYPTO_set_do_dynlock_callback(void (*do_dynlock_cb)
  407. (int mode, int type,
  408. const char *file, int line));
  409. int CRYPTO_get_new_dynlockid(void);
  410. void CRYPTO_destroy_dynlockid(int i);
  411. struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i);
  412. void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value
  413. *(*dyn_create_function) (const char
  414. *file,
  415. int line));
  416. void CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)
  417. (int mode,
  418. struct CRYPTO_dynlock_value *l,
  419. const char *file, int line));
  420. void CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)
  421. (struct CRYPTO_dynlock_value *l,
  422. const char *file, int line));
  423. struct CRYPTO_dynlock_value
  424. *(*CRYPTO_get_dynlock_create_callback(void)) (const char *file, int line);
  425. void (*CRYPTO_get_dynlock_lock_callback(void)) (int mode,
  426. struct CRYPTO_dynlock_value
  427. *l, const char *file,
  428. int line);
  429. void (*CRYPTO_get_dynlock_destroy_callback(void)) (struct CRYPTO_dynlock_value
  430. *l, const char *file,
  431. int line);
  432. /*
  433. * CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions -- call
  434. * the latter last if you need different functions
  435. */
  436. int CRYPTO_set_mem_functions(void *(*m) (size_t), void *(*r) (void *, size_t),
  437. void (*f) (void *));
  438. int CRYPTO_set_locked_mem_functions(void *(*m) (size_t),
  439. void (*free_func) (void *));
  440. int CRYPTO_set_mem_ex_functions(void *(*m) (size_t, const char *, int),
  441. void *(*r) (void *, size_t, const char *,
  442. int), void (*f) (void *));
  443. int CRYPTO_set_locked_mem_ex_functions(void *(*m) (size_t, const char *, int),
  444. void (*free_func) (void *));
  445. int CRYPTO_set_mem_debug_functions(void (*m)
  446. (void *, int, const char *, int, int),
  447. void (*r) (void *, void *, int,
  448. const char *, int, int),
  449. void (*f) (void *, int), void (*so) (long),
  450. long (*go) (void));
  451. void CRYPTO_set_mem_info_functions(int (*push_info_fn)
  452. (const char *info, const char *file,
  453. int line), int (*pop_info_fn) (void),
  454. int (*remove_all_info_fn) (void));
  455. void CRYPTO_get_mem_functions(void *(**m) (size_t),
  456. void *(**r) (void *, size_t),
  457. void (**f) (void *));
  458. void CRYPTO_get_locked_mem_functions(void *(**m) (size_t),
  459. void (**f) (void *));
  460. void CRYPTO_get_mem_ex_functions(void *(**m) (size_t, const char *, int),
  461. void *(**r) (void *, size_t, const char *,
  462. int), void (**f) (void *));
  463. void CRYPTO_get_locked_mem_ex_functions(void
  464. *(**m) (size_t, const char *, int),
  465. void (**f) (void *));
  466. void CRYPTO_get_mem_debug_functions(void (**m)
  467. (void *, int, const char *, int, int),
  468. void (**r) (void *, void *, int,
  469. const char *, int, int),
  470. void (**f) (void *, int),
  471. void (**so) (long), long (**go) (void));
  472. void *CRYPTO_malloc_locked(int num, const char *file, int line);
  473. void CRYPTO_free_locked(void *);
  474. void *CRYPTO_malloc(int num, const char *file, int line);
  475. char *CRYPTO_strdup(const char *str, const char *file, int line);
  476. void CRYPTO_free(void *);
  477. void *CRYPTO_realloc(void *addr, int num, const char *file, int line);
  478. void *CRYPTO_realloc_clean(void *addr, int old_num, int num, const char *file,
  479. int line);
  480. void *CRYPTO_remalloc(void *addr, int num, const char *file, int line);
  481. void OPENSSL_cleanse(void *ptr, size_t len);
  482. void CRYPTO_set_mem_debug_options(long bits);
  483. long CRYPTO_get_mem_debug_options(void);
  484. # define CRYPTO_push_info(info) \
  485. CRYPTO_push_info_(info, __FILE__, __LINE__);
  486. int CRYPTO_push_info_(const char *info, const char *file, int line);
  487. int CRYPTO_pop_info(void);
  488. int CRYPTO_remove_all_info(void);
  489. /*
  490. * Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro;
  491. * used as default in CRYPTO_MDEBUG compilations):
  492. */
  493. /*-
  494. * The last argument has the following significance:
  495. *
  496. * 0: called before the actual memory allocation has taken place
  497. * 1: called after the actual memory allocation has taken place
  498. */
  499. void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line,
  500. int before_p);
  501. void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num, const char *file,
  502. int line, int before_p);
  503. void CRYPTO_dbg_free(void *addr, int before_p);
  504. /*-
  505. * Tell the debugging code about options. By default, the following values
  506. * apply:
  507. *
  508. * 0: Clear all options.
  509. * V_CRYPTO_MDEBUG_TIME (1): Set the "Show Time" option.
  510. * V_CRYPTO_MDEBUG_THREAD (2): Set the "Show Thread Number" option.
  511. * V_CRYPTO_MDEBUG_ALL (3): 1 + 2
  512. */
  513. void CRYPTO_dbg_set_options(long bits);
  514. long CRYPTO_dbg_get_options(void);
  515. int CRYPTO_dbg_push_info(const char *info, const char *file, int line);
  516. int CRYPTO_dbg_pop_info(void);
  517. int CRYPTO_dbg_remove_all_info(void);
  518. # ifndef OPENSSL_NO_FP_API
  519. void CRYPTO_mem_leaks_fp(FILE *);
  520. # endif
  521. void CRYPTO_mem_leaks(struct bio_st *bio);
  522. /* unsigned long order, char *file, int line, int num_bytes, char *addr */
  523. typedef void *CRYPTO_MEM_LEAK_CB (unsigned long, const char *, int, int,
  524. void *);
  525. void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb);
  526. /* die if we have to */
  527. void OpenSSLDie(const char *file, int line, const char *assertion);
  528. # define OPENSSL_assert(e) (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1))
  529. unsigned long *OPENSSL_ia32cap_loc(void);
  530. # define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc()))
  531. int OPENSSL_isservice(void);
  532. # ifdef OPENSSL_FIPS
  533. # define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \
  534. alg " previous FIPS forbidden algorithm error ignored");
  535. # define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \
  536. #alg " Algorithm forbidden in FIPS mode");
  537. # ifdef OPENSSL_FIPS_STRICT
  538. # define FIPS_BAD_ALGORITHM(alg) FIPS_BAD_ABORT(alg)
  539. # else
  540. # define FIPS_BAD_ALGORITHM(alg) \
  541. { \
  542. FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD); \
  543. ERR_add_error_data(2, "Algorithm=", #alg); \
  544. return 0; \
  545. }
  546. # endif
  547. /* Low level digest API blocking macro */
  548. # define FIPS_NON_FIPS_MD_Init(alg) \
  549. int alg##_Init(alg##_CTX *c) \
  550. { \
  551. if (FIPS_mode()) \
  552. FIPS_BAD_ALGORITHM(alg) \
  553. return private_##alg##_Init(c); \
  554. } \
  555. int private_##alg##_Init(alg##_CTX *c)
  556. /*
  557. * For ciphers the API often varies from cipher to cipher and each needs to
  558. * be treated as a special case. Variable key length ciphers (Blowfish, RC4,
  559. * CAST) however are very similar and can use a blocking macro.
  560. */
  561. # define FIPS_NON_FIPS_VCIPHER_Init(alg) \
  562. void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) \
  563. { \
  564. if (FIPS_mode()) \
  565. FIPS_BAD_ABORT(alg) \
  566. private_##alg##_set_key(key, len, data); \
  567. } \
  568. void private_##alg##_set_key(alg##_KEY *key, int len, \
  569. const unsigned char *data)
  570. # else
  571. # define FIPS_NON_FIPS_VCIPHER_Init(alg) \
  572. void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data)
  573. # define FIPS_NON_FIPS_MD_Init(alg) \
  574. int alg##_Init(alg##_CTX *c)
  575. # endif /* def OPENSSL_FIPS */
  576. # define OPENSSL_HAVE_INIT 1
  577. void OPENSSL_init(void);
  578. /*
  579. * CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal.
  580. * It takes an amount of time dependent on |len|, but independent of the
  581. * contents of |a| and |b|. Unlike memcmp, it cannot be used to put elements
  582. * into a defined order as the return value when a != b is undefined, other
  583. * than to be non-zero.
  584. */
  585. int CRYPTO_memcmp(const void *a, const void *b, size_t len);
  586. /* BEGIN ERROR CODES */
  587. /*
  588. * The following lines are auto generated by the script mkerr.pl. Any changes
  589. * made after this point may be overwritten when the script is next run.
  590. */
  591. void ERR_load_CRYPTO_strings(void);
  592. /* Error codes for the CRYPTO functions. */
  593. /* Function codes. */
  594. # define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100
  595. # define CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID 103
  596. # define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101
  597. # define CRYPTO_F_CRYPTO_SET_EX_DATA 102
  598. # define CRYPTO_F_DEF_ADD_INDEX 104
  599. # define CRYPTO_F_DEF_GET_CLASS 105
  600. # define CRYPTO_F_INT_DUP_EX_DATA 106
  601. # define CRYPTO_F_INT_FREE_EX_DATA 107
  602. # define CRYPTO_F_INT_NEW_EX_DATA 108
  603. /* Reason codes. */
  604. # define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK 100
  605. #ifdef __cplusplus
  606. }
  607. #endif
  608. #endif