[331] | 1 | /*
|
---|
| 2 | * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
|
---|
| 3 | *
|
---|
| 4 | * Licensed under the OpenSSL license (the "License"). You may not use
|
---|
| 5 | * this file except in compliance with the License. You can obtain a copy
|
---|
| 6 | * in the file LICENSE in the source distribution or at
|
---|
| 7 | * https://www.openssl.org/source/license.html
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | /* ====================================================================
|
---|
| 11 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
---|
| 12 | * ECDH support in OpenSSL originally developed by
|
---|
| 13 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
|
---|
| 14 | */
|
---|
| 15 |
|
---|
| 16 | #ifndef HEADER_ENGINE_INT_H
|
---|
| 17 | # define HEADER_ENGINE_INT_H
|
---|
| 18 |
|
---|
| 19 | # include "internal/cryptlib.h"
|
---|
| 20 | # include <internal/engine.h>
|
---|
| 21 | # include <internal/thread_once.h>
|
---|
| 22 |
|
---|
| 23 | #ifdef __cplusplus
|
---|
| 24 | extern "C" {
|
---|
| 25 | #endif
|
---|
| 26 |
|
---|
| 27 | extern CRYPTO_RWLOCK *global_engine_lock;
|
---|
| 28 |
|
---|
| 29 | /*
|
---|
| 30 | * If we compile with this symbol defined, then both reference counts in the
|
---|
| 31 | * ENGINE structure will be monitored with a line of output on stderr for
|
---|
| 32 | * each change. This prints the engine's pointer address (truncated to
|
---|
| 33 | * unsigned int), "struct" or "funct" to indicate the reference type, the
|
---|
| 34 | * before and after reference count, and the file:line-number pair. The
|
---|
| 35 | * "engine_ref_debug" statements must come *after* the change.
|
---|
| 36 | */
|
---|
| 37 | # ifdef ENGINE_REF_COUNT_DEBUG
|
---|
| 38 |
|
---|
| 39 | # define engine_ref_debug(e, isfunct, diff) \
|
---|
| 40 | fprintf(stderr, "engine: %08x %s from %d to %d (%s:%d)\n", \
|
---|
| 41 | (unsigned int)(e), (isfunct ? "funct" : "struct"), \
|
---|
| 42 | ((isfunct) ? ((e)->funct_ref - (diff)) : ((e)->struct_ref - (diff))), \
|
---|
| 43 | ((isfunct) ? (e)->funct_ref : (e)->struct_ref), \
|
---|
| 44 | (OPENSSL_FILE), (OPENSSL_LINE))
|
---|
| 45 |
|
---|
| 46 | # else
|
---|
| 47 |
|
---|
| 48 | # define engine_ref_debug(e, isfunct, diff)
|
---|
| 49 |
|
---|
| 50 | # endif
|
---|
| 51 |
|
---|
| 52 | /*
|
---|
| 53 | * Any code that will need cleanup operations should use these functions to
|
---|
| 54 | * register callbacks. engine_cleanup_int() will call all registered
|
---|
| 55 | * callbacks in order. NB: both the "add" functions assume the engine lock to
|
---|
| 56 | * already be held (in "write" mode).
|
---|
| 57 | */
|
---|
| 58 | typedef void (ENGINE_CLEANUP_CB) (void);
|
---|
| 59 | typedef struct st_engine_cleanup_item {
|
---|
| 60 | ENGINE_CLEANUP_CB *cb;
|
---|
| 61 | } ENGINE_CLEANUP_ITEM;
|
---|
| 62 | DEFINE_STACK_OF(ENGINE_CLEANUP_ITEM)
|
---|
| 63 | void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb);
|
---|
| 64 | void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb);
|
---|
| 65 |
|
---|
| 66 | /* We need stacks of ENGINEs for use in eng_table.c */
|
---|
| 67 | DEFINE_STACK_OF(ENGINE)
|
---|
| 68 |
|
---|
| 69 | /*
|
---|
| 70 | * If this symbol is defined then engine_table_select(), the function that is
|
---|
| 71 | * used by RSA, DSA (etc) code to select registered ENGINEs, cache defaults
|
---|
| 72 | * and functional references (etc), will display debugging summaries to
|
---|
| 73 | * stderr.
|
---|
| 74 | */
|
---|
| 75 | /* #define ENGINE_TABLE_DEBUG */
|
---|
| 76 |
|
---|
| 77 | /*
|
---|
| 78 | * This represents an implementation table. Dependent code should instantiate
|
---|
| 79 | * it as a (ENGINE_TABLE *) pointer value set initially to NULL.
|
---|
| 80 | */
|
---|
| 81 | typedef struct st_engine_table ENGINE_TABLE;
|
---|
| 82 | int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
|
---|
| 83 | ENGINE *e, const int *nids, int num_nids,
|
---|
| 84 | int setdefault);
|
---|
| 85 | void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e);
|
---|
| 86 | void engine_table_cleanup(ENGINE_TABLE **table);
|
---|
| 87 | # ifndef ENGINE_TABLE_DEBUG
|
---|
| 88 | ENGINE *engine_table_select(ENGINE_TABLE **table, int nid);
|
---|
| 89 | # else
|
---|
| 90 | ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,
|
---|
| 91 | int l);
|
---|
| 92 | # define engine_table_select(t,n) engine_table_select_tmp(t,n,OPENSSL_FILE,OPENSSL_LINE)
|
---|
| 93 | # endif
|
---|
| 94 | typedef void (engine_table_doall_cb) (int nid, STACK_OF(ENGINE) *sk,
|
---|
| 95 | ENGINE *def, void *arg);
|
---|
| 96 | void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb,
|
---|
| 97 | void *arg);
|
---|
| 98 |
|
---|
| 99 | /*
|
---|
| 100 | * Internal versions of API functions that have control over locking. These
|
---|
| 101 | * are used between C files when functionality needs to be shared but the
|
---|
| 102 | * caller may already be controlling of the engine lock.
|
---|
| 103 | */
|
---|
| 104 | int engine_unlocked_init(ENGINE *e);
|
---|
| 105 | int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers);
|
---|
| 106 | int engine_free_util(ENGINE *e, int locked);
|
---|
| 107 |
|
---|
| 108 | /*
|
---|
| 109 | * This function will reset all "set"able values in an ENGINE to NULL. This
|
---|
| 110 | * won't touch reference counts or ex_data, but is equivalent to calling all
|
---|
| 111 | * the ENGINE_set_***() functions with a NULL value.
|
---|
| 112 | */
|
---|
| 113 | void engine_set_all_null(ENGINE *e);
|
---|
| 114 |
|
---|
| 115 | /*
|
---|
| 116 | * NB: Bitwise OR-able values for the "flags" variable in ENGINE are now
|
---|
| 117 | * exposed in engine.h.
|
---|
| 118 | */
|
---|
| 119 |
|
---|
| 120 | /* Free up dynamically allocated public key methods associated with ENGINE */
|
---|
| 121 |
|
---|
| 122 | void engine_pkey_meths_free(ENGINE *e);
|
---|
| 123 | void engine_pkey_asn1_meths_free(ENGINE *e);
|
---|
| 124 |
|
---|
| 125 | /* Once initialisation function */
|
---|
| 126 | extern CRYPTO_ONCE engine_lock_init;
|
---|
| 127 | DECLARE_RUN_ONCE(do_engine_lock_init)
|
---|
| 128 |
|
---|
| 129 | /*
|
---|
| 130 | * This is a structure for storing implementations of various crypto
|
---|
| 131 | * algorithms and functions.
|
---|
| 132 | */
|
---|
| 133 | struct engine_st {
|
---|
| 134 | const char *id;
|
---|
| 135 | const char *name;
|
---|
| 136 | const RSA_METHOD *rsa_meth;
|
---|
| 137 | const DSA_METHOD *dsa_meth;
|
---|
| 138 | const DH_METHOD *dh_meth;
|
---|
| 139 | const EC_KEY_METHOD *ec_meth;
|
---|
| 140 | const RAND_METHOD *rand_meth;
|
---|
| 141 | /* Cipher handling is via this callback */
|
---|
| 142 | ENGINE_CIPHERS_PTR ciphers;
|
---|
| 143 | /* Digest handling is via this callback */
|
---|
| 144 | ENGINE_DIGESTS_PTR digests;
|
---|
| 145 | /* Public key handling via this callback */
|
---|
| 146 | ENGINE_PKEY_METHS_PTR pkey_meths;
|
---|
| 147 | /* ASN1 public key handling via this callback */
|
---|
| 148 | ENGINE_PKEY_ASN1_METHS_PTR pkey_asn1_meths;
|
---|
| 149 | ENGINE_GEN_INT_FUNC_PTR destroy;
|
---|
| 150 | ENGINE_GEN_INT_FUNC_PTR init;
|
---|
| 151 | ENGINE_GEN_INT_FUNC_PTR finish;
|
---|
| 152 | ENGINE_CTRL_FUNC_PTR ctrl;
|
---|
| 153 | ENGINE_LOAD_KEY_PTR load_privkey;
|
---|
| 154 | ENGINE_LOAD_KEY_PTR load_pubkey;
|
---|
| 155 | ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert;
|
---|
| 156 | const ENGINE_CMD_DEFN *cmd_defns;
|
---|
| 157 | int flags;
|
---|
| 158 | /* reference count on the structure itself */
|
---|
| 159 | int struct_ref;
|
---|
| 160 | /*
|
---|
| 161 | * reference count on usability of the engine type. NB: This controls the
|
---|
| 162 | * loading and initialisation of any functionality required by this
|
---|
| 163 | * engine, whereas the previous count is simply to cope with
|
---|
| 164 | * (de)allocation of this structure. Hence, running_ref <= struct_ref at
|
---|
| 165 | * all times.
|
---|
| 166 | */
|
---|
| 167 | int funct_ref;
|
---|
| 168 | /* A place to store per-ENGINE data */
|
---|
| 169 | CRYPTO_EX_DATA ex_data;
|
---|
| 170 | /* Used to maintain the linked-list of engines. */
|
---|
| 171 | struct engine_st *prev;
|
---|
| 172 | struct engine_st *next;
|
---|
| 173 | };
|
---|
| 174 |
|
---|
| 175 | typedef struct st_engine_pile ENGINE_PILE;
|
---|
| 176 |
|
---|
| 177 | DEFINE_LHASH_OF(ENGINE_PILE);
|
---|
| 178 |
|
---|
| 179 | #ifdef __cplusplus
|
---|
| 180 | }
|
---|
| 181 | #endif
|
---|
| 182 |
|
---|
| 183 | #endif /* HEADER_ENGINE_INT_H */
|
---|