1109998Smarkm/* crypto/engine/eng_int.h */ 2280304Sjkim/* 3280304Sjkim * Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL project 4280304Sjkim * 2000. 5109998Smarkm */ 6109998Smarkm/* ==================================================================== 7109998Smarkm * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 8109998Smarkm * 9109998Smarkm * Redistribution and use in source and binary forms, with or without 10109998Smarkm * modification, are permitted provided that the following conditions 11109998Smarkm * are met: 12109998Smarkm * 13109998Smarkm * 1. Redistributions of source code must retain the above copyright 14280304Sjkim * notice, this list of conditions and the following disclaimer. 15109998Smarkm * 16109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright 17109998Smarkm * notice, this list of conditions and the following disclaimer in 18109998Smarkm * the documentation and/or other materials provided with the 19109998Smarkm * distribution. 20109998Smarkm * 21109998Smarkm * 3. All advertising materials mentioning features or use of this 22109998Smarkm * software must display the following acknowledgment: 23109998Smarkm * "This product includes software developed by the OpenSSL Project 24109998Smarkm * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 25109998Smarkm * 26109998Smarkm * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27109998Smarkm * endorse or promote products derived from this software without 28109998Smarkm * prior written permission. For written permission, please contact 29109998Smarkm * licensing@OpenSSL.org. 30109998Smarkm * 31109998Smarkm * 5. Products derived from this software may not be called "OpenSSL" 32109998Smarkm * nor may "OpenSSL" appear in their names without prior written 33109998Smarkm * permission of the OpenSSL Project. 34109998Smarkm * 35109998Smarkm * 6. Redistributions of any form whatsoever must retain the following 36109998Smarkm * acknowledgment: 37109998Smarkm * "This product includes software developed by the OpenSSL Project 38109998Smarkm * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 39109998Smarkm * 40109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41109998Smarkm * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42109998Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43109998Smarkm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44109998Smarkm * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45109998Smarkm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46109998Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47109998Smarkm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48109998Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49109998Smarkm * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50109998Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51109998Smarkm * OF THE POSSIBILITY OF SUCH DAMAGE. 52109998Smarkm * ==================================================================== 53109998Smarkm * 54109998Smarkm * This product includes cryptographic software written by Eric Young 55109998Smarkm * (eay@cryptsoft.com). This product includes software written by Tim 56109998Smarkm * Hudson (tjh@cryptsoft.com). 57109998Smarkm * 58109998Smarkm */ 59160814Ssimon/* ==================================================================== 60160814Ssimon * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 61280304Sjkim * ECDH support in OpenSSL originally developed by 62160814Ssimon * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. 63160814Ssimon */ 64109998Smarkm 65109998Smarkm#ifndef HEADER_ENGINE_INT_H 66280304Sjkim# define HEADER_ENGINE_INT_H 67109998Smarkm 68280304Sjkim# include "cryptlib.h" 69109998Smarkm/* Take public definitions from engine.h */ 70280304Sjkim# include <openssl/engine.h> 71109998Smarkm 72109998Smarkm#ifdef __cplusplus 73109998Smarkmextern "C" { 74109998Smarkm#endif 75109998Smarkm 76280304Sjkim/* 77280304Sjkim * If we compile with this symbol defined, then both reference counts in the 78280304Sjkim * ENGINE structure will be monitored with a line of output on stderr for 79280304Sjkim * each change. This prints the engine's pointer address (truncated to 80280304Sjkim * unsigned int), "struct" or "funct" to indicate the reference type, the 81280304Sjkim * before and after reference count, and the file:line-number pair. The 82280304Sjkim * "engine_ref_debug" statements must come *after* the change. 83280304Sjkim */ 84280304Sjkim# ifdef ENGINE_REF_COUNT_DEBUG 85109998Smarkm 86280304Sjkim# define engine_ref_debug(e, isfunct, diff) \ 87280304Sjkim fprintf(stderr, "engine: %08x %s from %d to %d (%s:%d)\n", \ 88280304Sjkim (unsigned int)(e), (isfunct ? "funct" : "struct"), \ 89280304Sjkim ((isfunct) ? ((e)->funct_ref - (diff)) : ((e)->struct_ref - (diff))), \ 90280304Sjkim ((isfunct) ? (e)->funct_ref : (e)->struct_ref), \ 91280304Sjkim (__FILE__), (__LINE__)); 92109998Smarkm 93280304Sjkim# else 94109998Smarkm 95280304Sjkim# define engine_ref_debug(e, isfunct, diff) 96109998Smarkm 97280304Sjkim# endif 98109998Smarkm 99280304Sjkim/* 100280304Sjkim * Any code that will need cleanup operations should use these functions to 101109998Smarkm * register callbacks. ENGINE_cleanup() will call all registered callbacks in 102109998Smarkm * order. NB: both the "add" functions assume CRYPTO_LOCK_ENGINE to already be 103280304Sjkim * held (in "write" mode). 104280304Sjkim */ 105280304Sjkimtypedef void (ENGINE_CLEANUP_CB) (void); 106280304Sjkimtypedef struct st_engine_cleanup_item { 107280304Sjkim ENGINE_CLEANUP_CB *cb; 108280304Sjkim} ENGINE_CLEANUP_ITEM; 109109998SmarkmDECLARE_STACK_OF(ENGINE_CLEANUP_ITEM) 110109998Smarkmvoid engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb); 111109998Smarkmvoid engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb); 112109998Smarkm 113109998Smarkm/* We need stacks of ENGINEs for use in eng_table.c */ 114109998SmarkmDECLARE_STACK_OF(ENGINE) 115109998Smarkm 116280304Sjkim/* 117280304Sjkim * If this symbol is defined then engine_table_select(), the function that is 118280304Sjkim * used by RSA, DSA (etc) code to select registered ENGINEs, cache defaults 119280304Sjkim * and functional references (etc), will display debugging summaries to 120280304Sjkim * stderr. 121280304Sjkim */ 122109998Smarkm/* #define ENGINE_TABLE_DEBUG */ 123109998Smarkm 124280304Sjkim/* 125280304Sjkim * This represents an implementation table. Dependent code should instantiate 126280304Sjkim * it as a (ENGINE_TABLE *) pointer value set initially to NULL. 127280304Sjkim */ 128109998Smarkmtypedef struct st_engine_table ENGINE_TABLE; 129109998Smarkmint engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup, 130280304Sjkim ENGINE *e, const int *nids, int num_nids, 131280304Sjkim int setdefault); 132109998Smarkmvoid engine_table_unregister(ENGINE_TABLE **table, ENGINE *e); 133109998Smarkmvoid engine_table_cleanup(ENGINE_TABLE **table); 134280304Sjkim# ifndef ENGINE_TABLE_DEBUG 135109998SmarkmENGINE *engine_table_select(ENGINE_TABLE **table, int nid); 136280304Sjkim# else 137280304SjkimENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, 138280304Sjkim int l); 139280304Sjkim# define engine_table_select(t,n) engine_table_select_tmp(t,n,__FILE__,__LINE__) 140280304Sjkim# endif 141280304Sjkimtypedef void (engine_table_doall_cb) (int nid, STACK_OF(ENGINE) *sk, 142280304Sjkim ENGINE *def, void *arg); 143280304Sjkimvoid engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb, 144280304Sjkim void *arg); 145109998Smarkm 146280304Sjkim/* 147280304Sjkim * Internal versions of API functions that have control over locking. These 148280304Sjkim * are used between C files when functionality needs to be shared but the 149280304Sjkim * caller may already be controlling of the CRYPTO_LOCK_ENGINE lock. 150280304Sjkim */ 151109998Smarkmint engine_unlocked_init(ENGINE *e); 152109998Smarkmint engine_unlocked_finish(ENGINE *e, int unlock_for_handlers); 153109998Smarkmint engine_free_util(ENGINE *e, int locked); 154109998Smarkm 155280304Sjkim/* 156280304Sjkim * This function will reset all "set"able values in an ENGINE to NULL. This 157280304Sjkim * won't touch reference counts or ex_data, but is equivalent to calling all 158280304Sjkim * the ENGINE_set_***() functions with a NULL value. 159280304Sjkim */ 160109998Smarkmvoid engine_set_all_null(ENGINE *e); 161109998Smarkm 162280304Sjkim/* 163280304Sjkim * NB: Bitwise OR-able values for the "flags" variable in ENGINE are now 164280304Sjkim * exposed in engine.h. 165280304Sjkim */ 166109998Smarkm 167238405Sjkim/* Free up dynamically allocated public key methods associated with ENGINE */ 168238405Sjkim 169238405Sjkimvoid engine_pkey_meths_free(ENGINE *e); 170238405Sjkimvoid engine_pkey_asn1_meths_free(ENGINE *e); 171238405Sjkim 172280304Sjkim/* 173280304Sjkim * This is a structure for storing implementations of various crypto 174280304Sjkim * algorithms and functions. 175280304Sjkim */ 176280304Sjkimstruct engine_st { 177280304Sjkim const char *id; 178280304Sjkim const char *name; 179280304Sjkim const RSA_METHOD *rsa_meth; 180280304Sjkim const DSA_METHOD *dsa_meth; 181280304Sjkim const DH_METHOD *dh_meth; 182280304Sjkim const ECDH_METHOD *ecdh_meth; 183280304Sjkim const ECDSA_METHOD *ecdsa_meth; 184280304Sjkim const RAND_METHOD *rand_meth; 185280304Sjkim const STORE_METHOD *store_meth; 186280304Sjkim /* Cipher handling is via this callback */ 187280304Sjkim ENGINE_CIPHERS_PTR ciphers; 188280304Sjkim /* Digest handling is via this callback */ 189280304Sjkim ENGINE_DIGESTS_PTR digests; 190280304Sjkim /* Public key handling via this callback */ 191280304Sjkim ENGINE_PKEY_METHS_PTR pkey_meths; 192280304Sjkim /* ASN1 public key handling via this callback */ 193280304Sjkim ENGINE_PKEY_ASN1_METHS_PTR pkey_asn1_meths; 194280304Sjkim ENGINE_GEN_INT_FUNC_PTR destroy; 195280304Sjkim ENGINE_GEN_INT_FUNC_PTR init; 196280304Sjkim ENGINE_GEN_INT_FUNC_PTR finish; 197280304Sjkim ENGINE_CTRL_FUNC_PTR ctrl; 198280304Sjkim ENGINE_LOAD_KEY_PTR load_privkey; 199280304Sjkim ENGINE_LOAD_KEY_PTR load_pubkey; 200280304Sjkim ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert; 201280304Sjkim const ENGINE_CMD_DEFN *cmd_defns; 202280304Sjkim int flags; 203280304Sjkim /* reference count on the structure itself */ 204280304Sjkim int struct_ref; 205280304Sjkim /* 206280304Sjkim * reference count on usability of the engine type. NB: This controls the 207280304Sjkim * loading and initialisation of any functionlity required by this 208280304Sjkim * engine, whereas the previous count is simply to cope with 209280304Sjkim * (de)allocation of this structure. Hence, running_ref <= struct_ref at 210280304Sjkim * all times. 211280304Sjkim */ 212280304Sjkim int funct_ref; 213280304Sjkim /* A place to store per-ENGINE data */ 214280304Sjkim CRYPTO_EX_DATA ex_data; 215280304Sjkim /* Used to maintain the linked-list of engines. */ 216280304Sjkim struct engine_st *prev; 217280304Sjkim struct engine_st *next; 218280304Sjkim}; 219109998Smarkm 220109998Smarkm#ifdef __cplusplus 221109998Smarkm} 222109998Smarkm#endif 223109998Smarkm 224280304Sjkim#endif /* HEADER_ENGINE_INT_H */ 225