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