os/ossrv/ssl/libcrypto/src/crypto/engine/eng_int.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* crypto/engine/eng_int.h */
sl@0
     2
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
sl@0
     3
 * project 2000.
sl@0
     4
 */
sl@0
     5
/* ====================================================================
sl@0
     6
 * Copyright (c) 1999-2001 The OpenSSL Project.  All rights reserved.
sl@0
     7
 *
sl@0
     8
 * Redistribution and use in source and binary forms, with or without
sl@0
     9
 * modification, are permitted provided that the following conditions
sl@0
    10
 * are met:
sl@0
    11
 *
sl@0
    12
 * 1. Redistributions of source code must retain the above copyright
sl@0
    13
 *    notice, this list of conditions and the following disclaimer. 
sl@0
    14
 *
sl@0
    15
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    16
 *    notice, this list of conditions and the following disclaimer in
sl@0
    17
 *    the documentation and/or other materials provided with the
sl@0
    18
 *    distribution.
sl@0
    19
 *
sl@0
    20
 * 3. All advertising materials mentioning features or use of this
sl@0
    21
 *    software must display the following acknowledgment:
sl@0
    22
 *    "This product includes software developed by the OpenSSL Project
sl@0
    23
 *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
sl@0
    24
 *
sl@0
    25
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
sl@0
    26
 *    endorse or promote products derived from this software without
sl@0
    27
 *    prior written permission. For written permission, please contact
sl@0
    28
 *    licensing@OpenSSL.org.
sl@0
    29
 *
sl@0
    30
 * 5. Products derived from this software may not be called "OpenSSL"
sl@0
    31
 *    nor may "OpenSSL" appear in their names without prior written
sl@0
    32
 *    permission of the OpenSSL Project.
sl@0
    33
 *
sl@0
    34
 * 6. Redistributions of any form whatsoever must retain the following
sl@0
    35
 *    acknowledgment:
sl@0
    36
 *    "This product includes software developed by the OpenSSL Project
sl@0
    37
 *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
sl@0
    38
 *
sl@0
    39
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
sl@0
    40
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sl@0
    41
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
sl@0
    42
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
sl@0
    43
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
sl@0
    44
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
sl@0
    45
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
sl@0
    46
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    47
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
sl@0
    48
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
sl@0
    49
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
sl@0
    50
 * OF THE POSSIBILITY OF SUCH DAMAGE.
sl@0
    51
 * ====================================================================
sl@0
    52
 *
sl@0
    53
 * This product includes cryptographic software written by Eric Young
sl@0
    54
 * (eay@cryptsoft.com).  This product includes software written by Tim
sl@0
    55
 * Hudson (tjh@cryptsoft.com).
sl@0
    56
 *
sl@0
    57
 */
sl@0
    58
/* ====================================================================
sl@0
    59
 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
sl@0
    60
 * ECDH support in OpenSSL originally developed by 
sl@0
    61
 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
sl@0
    62
 */
sl@0
    63
sl@0
    64
#ifndef HEADER_ENGINE_INT_H
sl@0
    65
#define HEADER_ENGINE_INT_H
sl@0
    66
sl@0
    67
#include "cryptlib.h"
sl@0
    68
/* Take public definitions from engine.h */
sl@0
    69
#include <openssl/engine.h>
sl@0
    70
sl@0
    71
#ifdef  __cplusplus
sl@0
    72
extern "C" {
sl@0
    73
#endif
sl@0
    74
sl@0
    75
/* If we compile with this symbol defined, then both reference counts in the
sl@0
    76
 * ENGINE structure will be monitored with a line of output on stderr for each
sl@0
    77
 * change. This prints the engine's pointer address (truncated to unsigned int),
sl@0
    78
 * "struct" or "funct" to indicate the reference type, the before and after
sl@0
    79
 * reference count, and the file:line-number pair. The "engine_ref_debug"
sl@0
    80
 * statements must come *after* the change. */
sl@0
    81
#ifdef ENGINE_REF_COUNT_DEBUG
sl@0
    82
sl@0
    83
#define engine_ref_debug(e, isfunct, diff) \
sl@0
    84
	fprintf(stderr, "engine: %08x %s from %d to %d (%s:%d)\n", \
sl@0
    85
		(unsigned int)(e), (isfunct ? "funct" : "struct"), \
sl@0
    86
		((isfunct) ? ((e)->funct_ref - (diff)) : ((e)->struct_ref - (diff))), \
sl@0
    87
		((isfunct) ? (e)->funct_ref : (e)->struct_ref), \
sl@0
    88
		(__FILE__), (__LINE__));
sl@0
    89
sl@0
    90
#else
sl@0
    91
sl@0
    92
#define engine_ref_debug(e, isfunct, diff)
sl@0
    93
sl@0
    94
#endif
sl@0
    95
sl@0
    96
/* Any code that will need cleanup operations should use these functions to
sl@0
    97
 * register callbacks. ENGINE_cleanup() will call all registered callbacks in
sl@0
    98
 * order. NB: both the "add" functions assume CRYPTO_LOCK_ENGINE to already be
sl@0
    99
 * held (in "write" mode). */
sl@0
   100
typedef void (ENGINE_CLEANUP_CB)(void);
sl@0
   101
typedef struct st_engine_cleanup_item
sl@0
   102
	{
sl@0
   103
	ENGINE_CLEANUP_CB *cb;
sl@0
   104
	} ENGINE_CLEANUP_ITEM;
sl@0
   105
DECLARE_STACK_OF(ENGINE_CLEANUP_ITEM)
sl@0
   106
IMPORT_C void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb);
sl@0
   107
IMPORT_C void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb);
sl@0
   108
sl@0
   109
/* We need stacks of ENGINEs for use in eng_table.c */
sl@0
   110
DECLARE_STACK_OF(ENGINE)
sl@0
   111
sl@0
   112
/* If this symbol is defined then engine_table_select(), the function that is
sl@0
   113
 * used by RSA, DSA (etc) code to select registered ENGINEs, cache defaults and
sl@0
   114
 * functional references (etc), will display debugging summaries to stderr. */
sl@0
   115
/* #define ENGINE_TABLE_DEBUG */
sl@0
   116
sl@0
   117
/* This represents an implementation table. Dependent code should instantiate it
sl@0
   118
 * as a (ENGINE_TABLE *) pointer value set initially to NULL. */
sl@0
   119
typedef struct st_engine_table ENGINE_TABLE;
sl@0
   120
IMPORT_C int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
sl@0
   121
		ENGINE *e, const int *nids, int num_nids, int setdefault);
sl@0
   122
IMPORT_C void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e);
sl@0
   123
IMPORT_C void engine_table_cleanup(ENGINE_TABLE **table);
sl@0
   124
#ifndef ENGINE_TABLE_DEBUG
sl@0
   125
IMPORT_C ENGINE *engine_table_select(ENGINE_TABLE **table, int nid);
sl@0
   126
#else
sl@0
   127
ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l);
sl@0
   128
#define engine_table_select(t,n) engine_table_select_tmp(t,n,__FILE__,__LINE__)
sl@0
   129
#endif
sl@0
   130
sl@0
   131
/* Internal versions of API functions that have control over locking. These are
sl@0
   132
 * used between C files when functionality needs to be shared but the caller may
sl@0
   133
 * already be controlling of the CRYPTO_LOCK_ENGINE lock. */
sl@0
   134
IMPORT_C int engine_unlocked_init(ENGINE *e);
sl@0
   135
IMPORT_C int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers);
sl@0
   136
IMPORT_C int engine_free_util(ENGINE *e, int locked);
sl@0
   137
sl@0
   138
/* This function will reset all "set"able values in an ENGINE to NULL. This
sl@0
   139
 * won't touch reference counts or ex_data, but is equivalent to calling all the
sl@0
   140
 * ENGINE_set_***() functions with a NULL value. */
sl@0
   141
IMPORT_C void engine_set_all_null(ENGINE *e);
sl@0
   142
sl@0
   143
/* NB: Bitwise OR-able values for the "flags" variable in ENGINE are now exposed
sl@0
   144
 * in engine.h. */
sl@0
   145
sl@0
   146
/* This is a structure for storing implementations of various crypto
sl@0
   147
 * algorithms and functions. */
sl@0
   148
struct engine_st
sl@0
   149
	{
sl@0
   150
	const char *id;
sl@0
   151
	const char *name;
sl@0
   152
	const RSA_METHOD *rsa_meth;
sl@0
   153
	const DSA_METHOD *dsa_meth;
sl@0
   154
	const DH_METHOD *dh_meth;
sl@0
   155
	const ECDH_METHOD *ecdh_meth;
sl@0
   156
	const ECDSA_METHOD *ecdsa_meth;
sl@0
   157
	const RAND_METHOD *rand_meth;
sl@0
   158
	const STORE_METHOD *store_meth;
sl@0
   159
	/* Cipher handling is via this callback */
sl@0
   160
	ENGINE_CIPHERS_PTR ciphers;
sl@0
   161
	/* Digest handling is via this callback */
sl@0
   162
	ENGINE_DIGESTS_PTR digests;
sl@0
   163
sl@0
   164
sl@0
   165
	ENGINE_GEN_INT_FUNC_PTR	destroy;
sl@0
   166
sl@0
   167
	ENGINE_GEN_INT_FUNC_PTR init;
sl@0
   168
	ENGINE_GEN_INT_FUNC_PTR finish;
sl@0
   169
	ENGINE_CTRL_FUNC_PTR ctrl;
sl@0
   170
	ENGINE_LOAD_KEY_PTR load_privkey;
sl@0
   171
	ENGINE_LOAD_KEY_PTR load_pubkey;
sl@0
   172
sl@0
   173
	const ENGINE_CMD_DEFN *cmd_defns;
sl@0
   174
	int flags;
sl@0
   175
	/* reference count on the structure itself */
sl@0
   176
	int struct_ref;
sl@0
   177
	/* reference count on usability of the engine type. NB: This
sl@0
   178
	 * controls the loading and initialisation of any functionlity
sl@0
   179
	 * required by this engine, whereas the previous count is
sl@0
   180
	 * simply to cope with (de)allocation of this structure. Hence,
sl@0
   181
	 * running_ref <= struct_ref at all times. */
sl@0
   182
	int funct_ref;
sl@0
   183
	/* A place to store per-ENGINE data */
sl@0
   184
	CRYPTO_EX_DATA ex_data;
sl@0
   185
	/* Used to maintain the linked-list of engines. */
sl@0
   186
	struct engine_st *prev;
sl@0
   187
	struct engine_st *next;
sl@0
   188
	};
sl@0
   189
sl@0
   190
#ifdef  __cplusplus
sl@0
   191
}
sl@0
   192
#endif
sl@0
   193
sl@0
   194
#endif /* HEADER_ENGINE_INT_H */