summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2014-06-10 14:56:02 +0000
committerjsing <>2014-06-10 14:56:02 +0000
commit3d34b57814cfdc90c98c015ae0dbd3c1862c83cd (patch)
treed8941695c82ed288c91b99b76a5a19ac06596dd7 /src
parent4ddb3c431a24f55e2e20d36bbcefaf3ab168082d (diff)
downloadopenbsd-3d34b57814cfdc90c98c015ae0dbd3c1862c83cd.tar.gz
openbsd-3d34b57814cfdc90c98c015ae0dbd3c1862c83cd.tar.bz2
openbsd-3d34b57814cfdc90c98c015ae0dbd3c1862c83cd.zip
KNF.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/engine/tb_asnmth.c167
-rw-r--r--src/lib/libcrypto/engine/tb_cipher.c97
-rw-r--r--src/lib/libcrypto/engine/tb_dh.c68
-rw-r--r--src/lib/libcrypto/engine/tb_digest.c97
-rw-r--r--src/lib/libcrypto/engine/tb_dsa.c68
-rw-r--r--src/lib/libcrypto/engine/tb_ecdh.c68
-rw-r--r--src/lib/libcrypto/engine/tb_ecdsa.c68
-rw-r--r--src/lib/libcrypto/engine/tb_pkmeth.c114
-rw-r--r--src/lib/libcrypto/engine/tb_rand.c68
-rw-r--r--src/lib/libcrypto/engine/tb_rsa.c68
-rw-r--r--src/lib/libcrypto/engine/tb_store.c68
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_asnmth.c167
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_cipher.c97
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_dh.c68
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_digest.c97
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_dsa.c68
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_ecdh.c68
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_ecdsa.c68
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_pkmeth.c114
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_rand.c68
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_rsa.c68
-rw-r--r--src/lib/libssl/src/crypto/engine/tb_store.c68
22 files changed, 1032 insertions, 870 deletions
diff --git a/src/lib/libcrypto/engine/tb_asnmth.c b/src/lib/libcrypto/engine/tb_asnmth.c
index 75090339f7..bd62f292c9 100644
--- a/src/lib/libcrypto/engine/tb_asnmth.c
+++ b/src/lib/libcrypto/engine/tb_asnmth.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -64,109 +64,115 @@
64 64
65static ENGINE_TABLE *pkey_asn1_meth_table = NULL; 65static ENGINE_TABLE *pkey_asn1_meth_table = NULL;
66 66
67void ENGINE_unregister_pkey_asn1_meths(ENGINE *e) 67void
68 { 68ENGINE_unregister_pkey_asn1_meths(ENGINE *e)
69{
69 engine_table_unregister(&pkey_asn1_meth_table, e); 70 engine_table_unregister(&pkey_asn1_meth_table, e);
70 } 71}
71 72
72static void engine_unregister_all_pkey_asn1_meths(void) 73static void
73 { 74engine_unregister_all_pkey_asn1_meths(void)
75{
74 engine_table_cleanup(&pkey_asn1_meth_table); 76 engine_table_cleanup(&pkey_asn1_meth_table);
75 } 77}
76 78
77int ENGINE_register_pkey_asn1_meths(ENGINE *e) 79int
78 { 80ENGINE_register_pkey_asn1_meths(ENGINE *e)
79 if(e->pkey_asn1_meths) 81{
80 { 82 if (e->pkey_asn1_meths) {
81 const int *nids; 83 const int *nids;
82 int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0); 84 int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0);
83 if(num_nids > 0) 85 if (num_nids > 0)
84 return engine_table_register(&pkey_asn1_meth_table, 86 return engine_table_register(&pkey_asn1_meth_table,
85 engine_unregister_all_pkey_asn1_meths, e, nids, 87 engine_unregister_all_pkey_asn1_meths, e, nids,
86 num_nids, 0); 88 num_nids, 0);
87 }
88 return 1;
89 } 89 }
90 return 1;
91}
90 92
91void ENGINE_register_all_pkey_asn1_meths(void) 93void
92 { 94ENGINE_register_all_pkey_asn1_meths(void)
95{
93 ENGINE *e; 96 ENGINE *e;
94 97
95 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 98 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
96 ENGINE_register_pkey_asn1_meths(e); 99 ENGINE_register_pkey_asn1_meths(e);
97 } 100}
98 101
99int ENGINE_set_default_pkey_asn1_meths(ENGINE *e) 102int
100 { 103ENGINE_set_default_pkey_asn1_meths(ENGINE *e)
101 if(e->pkey_asn1_meths) 104{
102 { 105 if (e->pkey_asn1_meths) {
103 const int *nids; 106 const int *nids;
104 int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0); 107 int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0);
105 if(num_nids > 0) 108 if (num_nids > 0)
106 return engine_table_register(&pkey_asn1_meth_table, 109 return engine_table_register(&pkey_asn1_meth_table,
107 engine_unregister_all_pkey_asn1_meths, e, nids, 110 engine_unregister_all_pkey_asn1_meths, e, nids,
108 num_nids, 1); 111 num_nids, 1);
109 }
110 return 1;
111 } 112 }
113 return 1;
114}
112 115
113/* Exposed API function to get a functional reference from the implementation 116/* Exposed API function to get a functional reference from the implementation
114 * table (ie. try to get a functional reference from the tabled structural 117 * table (ie. try to get a functional reference from the tabled structural
115 * references) for a given pkey_asn1_meth 'nid' */ 118 * references) for a given pkey_asn1_meth 'nid' */
116ENGINE *ENGINE_get_pkey_asn1_meth_engine(int nid) 119ENGINE *
117 { 120ENGINE_get_pkey_asn1_meth_engine(int nid)
121{
118 return engine_table_select(&pkey_asn1_meth_table, nid); 122 return engine_table_select(&pkey_asn1_meth_table, nid);
119 } 123}
120 124
121/* Obtains a pkey_asn1_meth implementation from an ENGINE functional reference */ 125/* Obtains a pkey_asn1_meth implementation from an ENGINE functional reference */
122const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid) 126const EVP_PKEY_ASN1_METHOD *
123 { 127ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid)
128{
124 EVP_PKEY_ASN1_METHOD *ret; 129 EVP_PKEY_ASN1_METHOD *ret;
125 ENGINE_PKEY_ASN1_METHS_PTR fn = ENGINE_get_pkey_asn1_meths(e); 130 ENGINE_PKEY_ASN1_METHS_PTR fn = ENGINE_get_pkey_asn1_meths(e);
126 if(!fn || !fn(e, &ret, NULL, nid)) 131
127 { 132 if (!fn || !fn(e, &ret, NULL, nid)) {
128 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH, 133 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH,
129 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD); 134 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
130 return NULL; 135 return NULL;
131 }
132 return ret;
133 } 136 }
137 return ret;
138}
134 139
135/* Gets the pkey_asn1_meth callback from an ENGINE structure */ 140/* Gets the pkey_asn1_meth callback from an ENGINE structure */
136ENGINE_PKEY_ASN1_METHS_PTR ENGINE_get_pkey_asn1_meths(const ENGINE *e) 141ENGINE_PKEY_ASN1_METHS_PTR
137 { 142ENGINE_get_pkey_asn1_meths(const ENGINE *e)
143{
138 return e->pkey_asn1_meths; 144 return e->pkey_asn1_meths;
139 } 145}
140 146
141/* Sets the pkey_asn1_meth callback in an ENGINE structure */ 147/* Sets the pkey_asn1_meth callback in an ENGINE structure */
142int ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f) 148int
143 { 149ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f)
150{
144 e->pkey_asn1_meths = f; 151 e->pkey_asn1_meths = f;
145 return 1; 152 return 1;
146 } 153}
147 154
148/* Internal function to free up EVP_PKEY_ASN1_METHOD structures before an 155/* Internal function to free up EVP_PKEY_ASN1_METHOD structures before an
149 * ENGINE is destroyed 156 * ENGINE is destroyed
150 */ 157 */
151 158
152void engine_pkey_asn1_meths_free(ENGINE *e) 159void
153 { 160engine_pkey_asn1_meths_free(ENGINE *e)
161{
154 int i; 162 int i;
155 EVP_PKEY_ASN1_METHOD *pkm; 163 EVP_PKEY_ASN1_METHOD *pkm;
156 if (e->pkey_asn1_meths) 164
157 { 165 if (e->pkey_asn1_meths) {
158 const int *pknids; 166 const int *pknids;
159 int npknids; 167 int npknids;
160 npknids = e->pkey_asn1_meths(e, NULL, &pknids, 0); 168 npknids = e->pkey_asn1_meths(e, NULL, &pknids, 0);
161 for (i = 0; i < npknids; i++) 169 for (i = 0; i < npknids; i++) {
162 { 170 if (e->pkey_asn1_meths(e, &pkm, NULL, pknids[i])) {
163 if (e->pkey_asn1_meths(e, &pkm, NULL, pknids[i]))
164 {
165 EVP_PKEY_asn1_free(pkm); 171 EVP_PKEY_asn1_free(pkm);
166 }
167 } 172 }
168 } 173 }
169 } 174 }
175}
170 176
171/* Find a method based on a string. This does a linear search through 177/* Find a method based on a string. This does a linear search through
172 * all implemented algorithms. This is OK in practice because only 178 * all implemented algorithms. This is OK in practice because only
@@ -174,60 +180,60 @@ void engine_pkey_asn1_meths_free(ENGINE *e)
174 * and it is not used for speed critical operations. 180 * and it is not used for speed critical operations.
175 */ 181 */
176 182
177const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth_str(ENGINE *e, 183const EVP_PKEY_ASN1_METHOD *
178 const char *str, int len) 184ENGINE_get_pkey_asn1_meth_str(ENGINE *e, const char *str, int len)
179 { 185{
180 int i, nidcount; 186 int i, nidcount;
181 const int *nids; 187 const int *nids;
182 EVP_PKEY_ASN1_METHOD *ameth; 188 EVP_PKEY_ASN1_METHOD *ameth;
189
183 if (!e->pkey_asn1_meths) 190 if (!e->pkey_asn1_meths)
184 return NULL; 191 return NULL;
185 if (len == -1) 192 if (len == -1)
186 len = strlen(str); 193 len = strlen(str);
187 nidcount = e->pkey_asn1_meths(e, NULL, &nids, 0); 194 nidcount = e->pkey_asn1_meths(e, NULL, &nids, 0);
188 for (i = 0; i < nidcount; i++) 195 for (i = 0; i < nidcount; i++) {
189 {
190 e->pkey_asn1_meths(e, &ameth, NULL, nids[i]); 196 e->pkey_asn1_meths(e, &ameth, NULL, nids[i]);
191 if (((int)strlen(ameth->pem_str) == len) && 197 if (((int)strlen(ameth->pem_str) == len) &&
192 !strncasecmp(ameth->pem_str, str, len)) 198 !strncasecmp(ameth->pem_str, str, len))
193 return ameth; 199 return ameth;
194 }
195 return NULL;
196 } 200 }
201 return NULL;
202}
197 203
198typedef struct 204typedef struct {
199 {
200 ENGINE *e; 205 ENGINE *e;
201 const EVP_PKEY_ASN1_METHOD *ameth; 206 const EVP_PKEY_ASN1_METHOD *ameth;
202 const char *str; 207 const char *str;
203 int len; 208 int len;
204 } ENGINE_FIND_STR; 209} ENGINE_FIND_STR;
205 210
206static void look_str_cb(int nid, STACK_OF(ENGINE) *sk, ENGINE *def, void *arg) 211static void
207 { 212look_str_cb(int nid, STACK_OF(ENGINE) *sk, ENGINE *def, void *arg)
213{
208 ENGINE_FIND_STR *lk = arg; 214 ENGINE_FIND_STR *lk = arg;
209 int i; 215 int i;
216
210 if (lk->ameth) 217 if (lk->ameth)
211 return; 218 return;
212 for (i = 0; i < sk_ENGINE_num(sk); i++) 219 for (i = 0; i < sk_ENGINE_num(sk); i++) {
213 {
214 ENGINE *e = sk_ENGINE_value(sk, i); 220 ENGINE *e = sk_ENGINE_value(sk, i);
215 EVP_PKEY_ASN1_METHOD *ameth; 221 EVP_PKEY_ASN1_METHOD *ameth;
216 e->pkey_asn1_meths(e, &ameth, NULL, nid); 222 e->pkey_asn1_meths(e, &ameth, NULL, nid);
217 if (((int)strlen(ameth->pem_str) == lk->len) && 223 if (((int)strlen(ameth->pem_str) == lk->len) &&
218 !strncasecmp(ameth->pem_str, lk->str, lk->len)) 224 !strncasecmp(ameth->pem_str, lk->str, lk->len)) {
219 {
220 lk->e = e; 225 lk->e = e;
221 lk->ameth = ameth; 226 lk->ameth = ameth;
222 return; 227 return;
223 }
224 } 228 }
225 } 229 }
230}
226 231
227const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe, 232const EVP_PKEY_ASN1_METHOD *
228 const char *str, int len) 233ENGINE_pkey_asn1_find_str(ENGINE **pe, const char *str, int len)
229 { 234{
230 ENGINE_FIND_STR fstr; 235 ENGINE_FIND_STR fstr;
236
231 fstr.e = NULL; 237 fstr.e = NULL;
232 fstr.ameth = NULL; 238 fstr.ameth = NULL;
233 fstr.str = str; 239 fstr.str = str;
@@ -235,12 +241,11 @@ const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe,
235 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 241 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
236 engine_table_doall(pkey_asn1_meth_table, look_str_cb, &fstr); 242 engine_table_doall(pkey_asn1_meth_table, look_str_cb, &fstr);
237 /* If found obtain a structural reference to engine */ 243 /* If found obtain a structural reference to engine */
238 if (fstr.e) 244 if (fstr.e) {
239 {
240 fstr.e->struct_ref++; 245 fstr.e->struct_ref++;
241 engine_ref_debug(fstr.e, 0, 1) 246 engine_ref_debug(fstr.e, 0, 1)
242 } 247 }
243 *pe = fstr.e; 248 *pe = fstr.e;
244 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 249 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
245 return fstr.ameth; 250 return fstr.ameth;
246 } 251}
diff --git a/src/lib/libcrypto/engine/tb_cipher.c b/src/lib/libcrypto/engine/tb_cipher.c
index 8d45a9a9cf..3218f5d86f 100644
--- a/src/lib/libcrypto/engine/tb_cipher.c
+++ b/src/lib/libcrypto/engine/tb_cipher.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -61,83 +61,90 @@
61 61
62static ENGINE_TABLE *cipher_table = NULL; 62static ENGINE_TABLE *cipher_table = NULL;
63 63
64void ENGINE_unregister_ciphers(ENGINE *e) 64void
65 { 65ENGINE_unregister_ciphers(ENGINE *e)
66{
66 engine_table_unregister(&cipher_table, e); 67 engine_table_unregister(&cipher_table, e);
67 } 68}
68 69
69static void engine_unregister_all_ciphers(void) 70static void
70 { 71engine_unregister_all_ciphers(void)
72{
71 engine_table_cleanup(&cipher_table); 73 engine_table_cleanup(&cipher_table);
72 } 74}
73 75
74int ENGINE_register_ciphers(ENGINE *e) 76int
75 { 77ENGINE_register_ciphers(ENGINE *e)
76 if(e->ciphers) 78{
77 { 79 if (e->ciphers) {
78 const int *nids; 80 const int *nids;
79 int num_nids = e->ciphers(e, NULL, &nids, 0); 81 int num_nids = e->ciphers(e, NULL, &nids, 0);
80 if(num_nids > 0) 82 if (num_nids > 0)
81 return engine_table_register(&cipher_table, 83 return engine_table_register(&cipher_table,
82 engine_unregister_all_ciphers, e, nids, 84 engine_unregister_all_ciphers, e, nids,
83 num_nids, 0); 85 num_nids, 0);
84 }
85 return 1;
86 } 86 }
87 return 1;
88}
87 89
88void ENGINE_register_all_ciphers(void) 90void
89 { 91ENGINE_register_all_ciphers(void)
92{
90 ENGINE *e; 93 ENGINE *e;
91 94
92 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 95 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
93 ENGINE_register_ciphers(e); 96 ENGINE_register_ciphers(e);
94 } 97}
95 98
96int ENGINE_set_default_ciphers(ENGINE *e) 99int
97 { 100ENGINE_set_default_ciphers(ENGINE *e)
98 if(e->ciphers) 101{
99 { 102 if (e->ciphers) {
100 const int *nids; 103 const int *nids;
101 int num_nids = e->ciphers(e, NULL, &nids, 0); 104 int num_nids = e->ciphers(e, NULL, &nids, 0);
102 if(num_nids > 0) 105 if (num_nids > 0)
103 return engine_table_register(&cipher_table, 106 return engine_table_register(&cipher_table,
104 engine_unregister_all_ciphers, e, nids, 107 engine_unregister_all_ciphers, e, nids,
105 num_nids, 1); 108 num_nids, 1);
106 }
107 return 1;
108 } 109 }
110 return 1;
111}
109 112
110/* Exposed API function to get a functional reference from the implementation 113/* Exposed API function to get a functional reference from the implementation
111 * table (ie. try to get a functional reference from the tabled structural 114 * table (ie. try to get a functional reference from the tabled structural
112 * references) for a given cipher 'nid' */ 115 * references) for a given cipher 'nid' */
113ENGINE *ENGINE_get_cipher_engine(int nid) 116ENGINE *
114 { 117ENGINE_get_cipher_engine(int nid)
118{
115 return engine_table_select(&cipher_table, nid); 119 return engine_table_select(&cipher_table, nid);
116 } 120}
117 121
118/* Obtains a cipher implementation from an ENGINE functional reference */ 122/* Obtains a cipher implementation from an ENGINE functional reference */
119const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid) 123const EVP_CIPHER *
120 { 124ENGINE_get_cipher(ENGINE *e, int nid)
125{
121 const EVP_CIPHER *ret; 126 const EVP_CIPHER *ret;
122 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e); 127 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e);
123 if(!fn || !fn(e, &ret, NULL, nid)) 128
124 { 129 if (!fn || !fn(e, &ret, NULL, nid)) {
125 ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER, 130 ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER,
126 ENGINE_R_UNIMPLEMENTED_CIPHER); 131 ENGINE_R_UNIMPLEMENTED_CIPHER);
127 return NULL; 132 return NULL;
128 }
129 return ret;
130 } 133 }
134 return ret;
135}
131 136
132/* Gets the cipher callback from an ENGINE structure */ 137/* Gets the cipher callback from an ENGINE structure */
133ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e) 138ENGINE_CIPHERS_PTR
134 { 139ENGINE_get_ciphers(const ENGINE *e)
140{
135 return e->ciphers; 141 return e->ciphers;
136 } 142}
137 143
138/* Sets the cipher callback in an ENGINE structure */ 144/* Sets the cipher callback in an ENGINE structure */
139int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f) 145int
140 { 146ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f)
147{
141 e->ciphers = f; 148 e->ciphers = f;
142 return 1; 149 return 1;
143 } 150}
diff --git a/src/lib/libcrypto/engine/tb_dh.c b/src/lib/libcrypto/engine/tb_dh.c
index 78515aeaa0..6e3ee6dd7c 100644
--- a/src/lib/libcrypto/engine/tb_dh.c
+++ b/src/lib/libcrypto/engine/tb_dh.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *dh_table = NULL; 62static ENGINE_TABLE *dh_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_DH(ENGINE *e) 65void
66 { 66ENGINE_unregister_DH(ENGINE *e)
67{
67 engine_table_unregister(&dh_table, e); 68 engine_table_unregister(&dh_table, e);
68 } 69}
69 70
70static void engine_unregister_all_DH(void) 71static void
71 { 72engine_unregister_all_DH(void)
73{
72 engine_table_cleanup(&dh_table); 74 engine_table_cleanup(&dh_table);
73 } 75}
74 76
75int ENGINE_register_DH(ENGINE *e) 77int
76 { 78ENGINE_register_DH(ENGINE *e)
77 if(e->dh_meth) 79{
80 if (e->dh_meth)
78 return engine_table_register(&dh_table, 81 return engine_table_register(&dh_table,
79 engine_unregister_all_DH, e, &dummy_nid, 1, 0); 82 engine_unregister_all_DH, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_DH(void) 86void
84 { 87ENGINE_register_all_DH(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_DH(e); 92 ENGINE_register_DH(e);
89 } 93}
90 94
91int ENGINE_set_default_DH(ENGINE *e) 95int
92 { 96ENGINE_set_default_DH(ENGINE *e)
93 if(e->dh_meth) 97{
98 if (e->dh_meth)
94 return engine_table_register(&dh_table, 99 return engine_table_register(&dh_table,
95 engine_unregister_all_DH, e, &dummy_nid, 1, 1); 100 engine_unregister_all_DH, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_DH(void) 107ENGINE *
103 { 108ENGINE_get_default_DH(void)
109{
104 return engine_table_select(&dh_table, dummy_nid); 110 return engine_table_select(&dh_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an DH implementation from an ENGINE functional reference */ 113/* Obtains an DH implementation from an ENGINE functional reference */
108const DH_METHOD *ENGINE_get_DH(const ENGINE *e) 114const DH_METHOD *
109 { 115ENGINE_get_DH(const ENGINE *e)
116{
110 return e->dh_meth; 117 return e->dh_meth;
111 } 118}
112 119
113/* Sets an DH implementation in an ENGINE structure */ 120/* Sets an DH implementation in an ENGINE structure */
114int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth) 121int
115 { 122ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth)
123{
116 e->dh_meth = dh_meth; 124 e->dh_meth = dh_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libcrypto/engine/tb_digest.c b/src/lib/libcrypto/engine/tb_digest.c
index d1bb90aedd..6a7167e071 100644
--- a/src/lib/libcrypto/engine/tb_digest.c
+++ b/src/lib/libcrypto/engine/tb_digest.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -61,83 +61,90 @@
61 61
62static ENGINE_TABLE *digest_table = NULL; 62static ENGINE_TABLE *digest_table = NULL;
63 63
64void ENGINE_unregister_digests(ENGINE *e) 64void
65 { 65ENGINE_unregister_digests(ENGINE *e)
66{
66 engine_table_unregister(&digest_table, e); 67 engine_table_unregister(&digest_table, e);
67 } 68}
68 69
69static void engine_unregister_all_digests(void) 70static void
70 { 71engine_unregister_all_digests(void)
72{
71 engine_table_cleanup(&digest_table); 73 engine_table_cleanup(&digest_table);
72 } 74}
73 75
74int ENGINE_register_digests(ENGINE *e) 76int
75 { 77ENGINE_register_digests(ENGINE *e)
76 if(e->digests) 78{
77 { 79 if (e->digests) {
78 const int *nids; 80 const int *nids;
79 int num_nids = e->digests(e, NULL, &nids, 0); 81 int num_nids = e->digests(e, NULL, &nids, 0);
80 if(num_nids > 0) 82 if (num_nids > 0)
81 return engine_table_register(&digest_table, 83 return engine_table_register(&digest_table,
82 engine_unregister_all_digests, e, nids, 84 engine_unregister_all_digests, e, nids,
83 num_nids, 0); 85 num_nids, 0);
84 }
85 return 1;
86 } 86 }
87 return 1;
88}
87 89
88void ENGINE_register_all_digests(void) 90void
89 { 91ENGINE_register_all_digests(void)
92{
90 ENGINE *e; 93 ENGINE *e;
91 94
92 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 95 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
93 ENGINE_register_digests(e); 96 ENGINE_register_digests(e);
94 } 97}
95 98
96int ENGINE_set_default_digests(ENGINE *e) 99int
97 { 100ENGINE_set_default_digests(ENGINE *e)
98 if(e->digests) 101{
99 { 102 if (e->digests) {
100 const int *nids; 103 const int *nids;
101 int num_nids = e->digests(e, NULL, &nids, 0); 104 int num_nids = e->digests(e, NULL, &nids, 0);
102 if(num_nids > 0) 105 if (num_nids > 0)
103 return engine_table_register(&digest_table, 106 return engine_table_register(&digest_table,
104 engine_unregister_all_digests, e, nids, 107 engine_unregister_all_digests, e, nids,
105 num_nids, 1); 108 num_nids, 1);
106 }
107 return 1;
108 } 109 }
110 return 1;
111}
109 112
110/* Exposed API function to get a functional reference from the implementation 113/* Exposed API function to get a functional reference from the implementation
111 * table (ie. try to get a functional reference from the tabled structural 114 * table (ie. try to get a functional reference from the tabled structural
112 * references) for a given digest 'nid' */ 115 * references) for a given digest 'nid' */
113ENGINE *ENGINE_get_digest_engine(int nid) 116ENGINE *
114 { 117ENGINE_get_digest_engine(int nid)
118{
115 return engine_table_select(&digest_table, nid); 119 return engine_table_select(&digest_table, nid);
116 } 120}
117 121
118/* Obtains a digest implementation from an ENGINE functional reference */ 122/* Obtains a digest implementation from an ENGINE functional reference */
119const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid) 123const EVP_MD *
120 { 124ENGINE_get_digest(ENGINE *e, int nid)
125{
121 const EVP_MD *ret; 126 const EVP_MD *ret;
122 ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e); 127 ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e);
123 if(!fn || !fn(e, &ret, NULL, nid)) 128
124 { 129 if (!fn || !fn(e, &ret, NULL, nid)) {
125 ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST, 130 ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST,
126 ENGINE_R_UNIMPLEMENTED_DIGEST); 131 ENGINE_R_UNIMPLEMENTED_DIGEST);
127 return NULL; 132 return NULL;
128 }
129 return ret;
130 } 133 }
134 return ret;
135}
131 136
132/* Gets the digest callback from an ENGINE structure */ 137/* Gets the digest callback from an ENGINE structure */
133ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e) 138ENGINE_DIGESTS_PTR
134 { 139ENGINE_get_digests(const ENGINE *e)
140{
135 return e->digests; 141 return e->digests;
136 } 142}
137 143
138/* Sets the digest callback in an ENGINE structure */ 144/* Sets the digest callback in an ENGINE structure */
139int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f) 145int
140 { 146ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f)
147{
141 e->digests = f; 148 e->digests = f;
142 return 1; 149 return 1;
143 } 150}
diff --git a/src/lib/libcrypto/engine/tb_dsa.c b/src/lib/libcrypto/engine/tb_dsa.c
index 6731aad1da..0abc4bc7fb 100644
--- a/src/lib/libcrypto/engine/tb_dsa.c
+++ b/src/lib/libcrypto/engine/tb_dsa.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *dsa_table = NULL; 62static ENGINE_TABLE *dsa_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_DSA(ENGINE *e) 65void
66 { 66ENGINE_unregister_DSA(ENGINE *e)
67{
67 engine_table_unregister(&dsa_table, e); 68 engine_table_unregister(&dsa_table, e);
68 } 69}
69 70
70static void engine_unregister_all_DSA(void) 71static void
71 { 72engine_unregister_all_DSA(void)
73{
72 engine_table_cleanup(&dsa_table); 74 engine_table_cleanup(&dsa_table);
73 } 75}
74 76
75int ENGINE_register_DSA(ENGINE *e) 77int
76 { 78ENGINE_register_DSA(ENGINE *e)
77 if(e->dsa_meth) 79{
80 if (e->dsa_meth)
78 return engine_table_register(&dsa_table, 81 return engine_table_register(&dsa_table,
79 engine_unregister_all_DSA, e, &dummy_nid, 1, 0); 82 engine_unregister_all_DSA, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_DSA(void) 86void
84 { 87ENGINE_register_all_DSA(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_DSA(e); 92 ENGINE_register_DSA(e);
89 } 93}
90 94
91int ENGINE_set_default_DSA(ENGINE *e) 95int
92 { 96ENGINE_set_default_DSA(ENGINE *e)
93 if(e->dsa_meth) 97{
98 if (e->dsa_meth)
94 return engine_table_register(&dsa_table, 99 return engine_table_register(&dsa_table,
95 engine_unregister_all_DSA, e, &dummy_nid, 1, 1); 100 engine_unregister_all_DSA, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_DSA(void) 107ENGINE *
103 { 108ENGINE_get_default_DSA(void)
109{
104 return engine_table_select(&dsa_table, dummy_nid); 110 return engine_table_select(&dsa_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an DSA implementation from an ENGINE functional reference */ 113/* Obtains an DSA implementation from an ENGINE functional reference */
108const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e) 114const DSA_METHOD *
109 { 115ENGINE_get_DSA(const ENGINE *e)
116{
110 return e->dsa_meth; 117 return e->dsa_meth;
111 } 118}
112 119
113/* Sets an DSA implementation in an ENGINE structure */ 120/* Sets an DSA implementation in an ENGINE structure */
114int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth) 121int
115 { 122ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth)
123{
116 e->dsa_meth = dsa_meth; 124 e->dsa_meth = dsa_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libcrypto/engine/tb_ecdh.c b/src/lib/libcrypto/engine/tb_ecdh.c
index 57354b8c11..0abeee163e 100644
--- a/src/lib/libcrypto/engine/tb_ecdh.c
+++ b/src/lib/libcrypto/engine/tb_ecdh.c
@@ -21,7 +21,7 @@
21 * are met: 21 * are met:
22 * 22 *
23 * 1. Redistributions of source code must retain the above copyright 23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer. 24 * notice, this list of conditions and the following disclaimer.
25 * 25 *
26 * 2. Redistributions in binary form must reproduce the above copyright 26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in 27 * notice, this list of conditions and the following disclaimer in
@@ -77,57 +77,65 @@
77static ENGINE_TABLE *ecdh_table = NULL; 77static ENGINE_TABLE *ecdh_table = NULL;
78static const int dummy_nid = 1; 78static const int dummy_nid = 1;
79 79
80void ENGINE_unregister_ECDH(ENGINE *e) 80void
81 { 81ENGINE_unregister_ECDH(ENGINE *e)
82{
82 engine_table_unregister(&ecdh_table, e); 83 engine_table_unregister(&ecdh_table, e);
83 } 84}
84 85
85static void engine_unregister_all_ECDH(void) 86static void
86 { 87engine_unregister_all_ECDH(void)
88{
87 engine_table_cleanup(&ecdh_table); 89 engine_table_cleanup(&ecdh_table);
88 } 90}
89 91
90int ENGINE_register_ECDH(ENGINE *e) 92int
91 { 93ENGINE_register_ECDH(ENGINE *e)
92 if(e->ecdh_meth) 94{
95 if (e->ecdh_meth)
93 return engine_table_register(&ecdh_table, 96 return engine_table_register(&ecdh_table,
94 engine_unregister_all_ECDH, e, &dummy_nid, 1, 0); 97 engine_unregister_all_ECDH, e, &dummy_nid, 1, 0);
95 return 1; 98 return 1;
96 } 99}
97 100
98void ENGINE_register_all_ECDH(void) 101void
99 { 102ENGINE_register_all_ECDH(void)
103{
100 ENGINE *e; 104 ENGINE *e;
101 105
102 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 106 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
103 ENGINE_register_ECDH(e); 107 ENGINE_register_ECDH(e);
104 } 108}
105 109
106int ENGINE_set_default_ECDH(ENGINE *e) 110int
107 { 111ENGINE_set_default_ECDH(ENGINE *e)
108 if(e->ecdh_meth) 112{
113 if (e->ecdh_meth)
109 return engine_table_register(&ecdh_table, 114 return engine_table_register(&ecdh_table,
110 engine_unregister_all_ECDH, e, &dummy_nid, 1, 1); 115 engine_unregister_all_ECDH, e, &dummy_nid, 1, 1);
111 return 1; 116 return 1;
112 } 117}
113 118
114/* Exposed API function to get a functional reference from the implementation 119/* Exposed API function to get a functional reference from the implementation
115 * table (ie. try to get a functional reference from the tabled structural 120 * table (ie. try to get a functional reference from the tabled structural
116 * references). */ 121 * references). */
117ENGINE *ENGINE_get_default_ECDH(void) 122ENGINE *
118 { 123ENGINE_get_default_ECDH(void)
124{
119 return engine_table_select(&ecdh_table, dummy_nid); 125 return engine_table_select(&ecdh_table, dummy_nid);
120 } 126}
121 127
122/* Obtains an ECDH implementation from an ENGINE functional reference */ 128/* Obtains an ECDH implementation from an ENGINE functional reference */
123const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e) 129const ECDH_METHOD *
124 { 130ENGINE_get_ECDH(const ENGINE *e)
131{
125 return e->ecdh_meth; 132 return e->ecdh_meth;
126 } 133}
127 134
128/* Sets an ECDH implementation in an ENGINE structure */ 135/* Sets an ECDH implementation in an ENGINE structure */
129int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth) 136int
130 { 137ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth)
138{
131 e->ecdh_meth = ecdh_meth; 139 e->ecdh_meth = ecdh_meth;
132 return 1; 140 return 1;
133 } 141}
diff --git a/src/lib/libcrypto/engine/tb_ecdsa.c b/src/lib/libcrypto/engine/tb_ecdsa.c
index 8f30e956e0..cae74317a4 100644
--- a/src/lib/libcrypto/engine/tb_ecdsa.c
+++ b/src/lib/libcrypto/engine/tb_ecdsa.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *ecdsa_table = NULL; 62static ENGINE_TABLE *ecdsa_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_ECDSA(ENGINE *e) 65void
66 { 66ENGINE_unregister_ECDSA(ENGINE *e)
67{
67 engine_table_unregister(&ecdsa_table, e); 68 engine_table_unregister(&ecdsa_table, e);
68 } 69}
69 70
70static void engine_unregister_all_ECDSA(void) 71static void
71 { 72engine_unregister_all_ECDSA(void)
73{
72 engine_table_cleanup(&ecdsa_table); 74 engine_table_cleanup(&ecdsa_table);
73 } 75}
74 76
75int ENGINE_register_ECDSA(ENGINE *e) 77int
76 { 78ENGINE_register_ECDSA(ENGINE *e)
77 if(e->ecdsa_meth) 79{
80 if (e->ecdsa_meth)
78 return engine_table_register(&ecdsa_table, 81 return engine_table_register(&ecdsa_table,
79 engine_unregister_all_ECDSA, e, &dummy_nid, 1, 0); 82 engine_unregister_all_ECDSA, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_ECDSA(void) 86void
84 { 87ENGINE_register_all_ECDSA(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_ECDSA(e); 92 ENGINE_register_ECDSA(e);
89 } 93}
90 94
91int ENGINE_set_default_ECDSA(ENGINE *e) 95int
92 { 96ENGINE_set_default_ECDSA(ENGINE *e)
93 if(e->ecdsa_meth) 97{
98 if (e->ecdsa_meth)
94 return engine_table_register(&ecdsa_table, 99 return engine_table_register(&ecdsa_table,
95 engine_unregister_all_ECDSA, e, &dummy_nid, 1, 1); 100 engine_unregister_all_ECDSA, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_ECDSA(void) 107ENGINE *
103 { 108ENGINE_get_default_ECDSA(void)
109{
104 return engine_table_select(&ecdsa_table, dummy_nid); 110 return engine_table_select(&ecdsa_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an ECDSA implementation from an ENGINE functional reference */ 113/* Obtains an ECDSA implementation from an ENGINE functional reference */
108const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e) 114const ECDSA_METHOD *
109 { 115ENGINE_get_ECDSA(const ENGINE *e)
116{
110 return e->ecdsa_meth; 117 return e->ecdsa_meth;
111 } 118}
112 119
113/* Sets an ECDSA implementation in an ENGINE structure */ 120/* Sets an ECDSA implementation in an ENGINE structure */
114int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth) 121int
115 { 122ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth)
123{
116 e->ecdsa_meth = ecdsa_meth; 124 e->ecdsa_meth = ecdsa_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libcrypto/engine/tb_pkmeth.c b/src/lib/libcrypto/engine/tb_pkmeth.c
index 7a59744102..7834a22599 100644
--- a/src/lib/libcrypto/engine/tb_pkmeth.c
+++ b/src/lib/libcrypto/engine/tb_pkmeth.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,106 +62,112 @@
62 62
63static ENGINE_TABLE *pkey_meth_table = NULL; 63static ENGINE_TABLE *pkey_meth_table = NULL;
64 64
65void ENGINE_unregister_pkey_meths(ENGINE *e) 65void
66 { 66ENGINE_unregister_pkey_meths(ENGINE *e)
67{
67 engine_table_unregister(&pkey_meth_table, e); 68 engine_table_unregister(&pkey_meth_table, e);
68 } 69}
69 70
70static void engine_unregister_all_pkey_meths(void) 71static void
71 { 72engine_unregister_all_pkey_meths(void)
73{
72 engine_table_cleanup(&pkey_meth_table); 74 engine_table_cleanup(&pkey_meth_table);
73 } 75}
74 76
75int ENGINE_register_pkey_meths(ENGINE *e) 77int
76 { 78ENGINE_register_pkey_meths(ENGINE *e)
77 if(e->pkey_meths) 79{
78 { 80 if (e->pkey_meths) {
79 const int *nids; 81 const int *nids;
80 int num_nids = e->pkey_meths(e, NULL, &nids, 0); 82 int num_nids = e->pkey_meths(e, NULL, &nids, 0);
81 if(num_nids > 0) 83 if (num_nids > 0)
82 return engine_table_register(&pkey_meth_table, 84 return engine_table_register(&pkey_meth_table,
83 engine_unregister_all_pkey_meths, e, nids, 85 engine_unregister_all_pkey_meths, e, nids,
84 num_nids, 0); 86 num_nids, 0);
85 }
86 return 1;
87 } 87 }
88 return 1;
89}
88 90
89void ENGINE_register_all_pkey_meths(void) 91void
90 { 92ENGINE_register_all_pkey_meths(void)
93{
91 ENGINE *e; 94 ENGINE *e;
92 95
93 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 96 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
94 ENGINE_register_pkey_meths(e); 97 ENGINE_register_pkey_meths(e);
95 } 98}
96 99
97int ENGINE_set_default_pkey_meths(ENGINE *e) 100int
98 { 101ENGINE_set_default_pkey_meths(ENGINE *e)
99 if(e->pkey_meths) 102{
100 { 103 if (e->pkey_meths) {
101 const int *nids; 104 const int *nids;
102 int num_nids = e->pkey_meths(e, NULL, &nids, 0); 105 int num_nids = e->pkey_meths(e, NULL, &nids, 0);
103 if(num_nids > 0) 106 if (num_nids > 0)
104 return engine_table_register(&pkey_meth_table, 107 return engine_table_register(&pkey_meth_table,
105 engine_unregister_all_pkey_meths, e, nids, 108 engine_unregister_all_pkey_meths, e, nids,
106 num_nids, 1); 109 num_nids, 1);
107 }
108 return 1;
109 } 110 }
111 return 1;
112}
110 113
111/* Exposed API function to get a functional reference from the implementation 114/* Exposed API function to get a functional reference from the implementation
112 * table (ie. try to get a functional reference from the tabled structural 115 * table (ie. try to get a functional reference from the tabled structural
113 * references) for a given pkey_meth 'nid' */ 116 * references) for a given pkey_meth 'nid' */
114ENGINE *ENGINE_get_pkey_meth_engine(int nid) 117ENGINE *
115 { 118ENGINE_get_pkey_meth_engine(int nid)
119{
116 return engine_table_select(&pkey_meth_table, nid); 120 return engine_table_select(&pkey_meth_table, nid);
117 } 121}
118 122
119/* Obtains a pkey_meth implementation from an ENGINE functional reference */ 123/* Obtains a pkey_meth implementation from an ENGINE functional reference */
120const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid) 124const EVP_PKEY_METHOD *
121 { 125ENGINE_get_pkey_meth(ENGINE *e, int nid)
126{
122 EVP_PKEY_METHOD *ret; 127 EVP_PKEY_METHOD *ret;
123 ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e); 128 ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e);
124 if(!fn || !fn(e, &ret, NULL, nid)) 129
125 { 130 if (!fn || !fn(e, &ret, NULL, nid)) {
126 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH, 131 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH,
127 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD); 132 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
128 return NULL; 133 return NULL;
129 }
130 return ret;
131 } 134 }
135 return ret;
136}
132 137
133/* Gets the pkey_meth callback from an ENGINE structure */ 138/* Gets the pkey_meth callback from an ENGINE structure */
134ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e) 139ENGINE_PKEY_METHS_PTR
135 { 140ENGINE_get_pkey_meths(const ENGINE *e)
141{
136 return e->pkey_meths; 142 return e->pkey_meths;
137 } 143}
138 144
139/* Sets the pkey_meth callback in an ENGINE structure */ 145/* Sets the pkey_meth callback in an ENGINE structure */
140int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f) 146int
141 { 147ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f)
148{
142 e->pkey_meths = f; 149 e->pkey_meths = f;
143 return 1; 150 return 1;
144 } 151}
145 152
146/* Internal function to free up EVP_PKEY_METHOD structures before an 153/* Internal function to free up EVP_PKEY_METHOD structures before an
147 * ENGINE is destroyed 154 * ENGINE is destroyed
148 */ 155 */
149 156
150void engine_pkey_meths_free(ENGINE *e) 157void
151 { 158engine_pkey_meths_free(ENGINE *e)
159{
152 int i; 160 int i;
153 EVP_PKEY_METHOD *pkm; 161 EVP_PKEY_METHOD *pkm;
154 if (e->pkey_meths) 162
155 { 163 if (e->pkey_meths) {
156 const int *pknids; 164 const int *pknids;
157 int npknids; 165 int npknids;
158 npknids = e->pkey_meths(e, NULL, &pknids, 0); 166 npknids = e->pkey_meths(e, NULL, &pknids, 0);
159 for (i = 0; i < npknids; i++) 167 for (i = 0; i < npknids; i++) {
160 { 168 if (e->pkey_meths(e, &pkm, NULL, pknids[i])) {
161 if (e->pkey_meths(e, &pkm, NULL, pknids[i]))
162 {
163 EVP_PKEY_meth_free(pkm); 169 EVP_PKEY_meth_free(pkm);
164 }
165 } 170 }
166 } 171 }
167 } 172 }
173}
diff --git a/src/lib/libcrypto/engine/tb_rand.c b/src/lib/libcrypto/engine/tb_rand.c
index 3745ae7abd..b99f3baba3 100644
--- a/src/lib/libcrypto/engine/tb_rand.c
+++ b/src/lib/libcrypto/engine/tb_rand.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *rand_table = NULL; 62static ENGINE_TABLE *rand_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_RAND(ENGINE *e) 65void
66 { 66ENGINE_unregister_RAND(ENGINE *e)
67{
67 engine_table_unregister(&rand_table, e); 68 engine_table_unregister(&rand_table, e);
68 } 69}
69 70
70static void engine_unregister_all_RAND(void) 71static void
71 { 72engine_unregister_all_RAND(void)
73{
72 engine_table_cleanup(&rand_table); 74 engine_table_cleanup(&rand_table);
73 } 75}
74 76
75int ENGINE_register_RAND(ENGINE *e) 77int
76 { 78ENGINE_register_RAND(ENGINE *e)
77 if(e->rand_meth) 79{
80 if (e->rand_meth)
78 return engine_table_register(&rand_table, 81 return engine_table_register(&rand_table,
79 engine_unregister_all_RAND, e, &dummy_nid, 1, 0); 82 engine_unregister_all_RAND, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_RAND(void) 86void
84 { 87ENGINE_register_all_RAND(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_RAND(e); 92 ENGINE_register_RAND(e);
89 } 93}
90 94
91int ENGINE_set_default_RAND(ENGINE *e) 95int
92 { 96ENGINE_set_default_RAND(ENGINE *e)
93 if(e->rand_meth) 97{
98 if (e->rand_meth)
94 return engine_table_register(&rand_table, 99 return engine_table_register(&rand_table,
95 engine_unregister_all_RAND, e, &dummy_nid, 1, 1); 100 engine_unregister_all_RAND, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_RAND(void) 107ENGINE *
103 { 108ENGINE_get_default_RAND(void)
109{
104 return engine_table_select(&rand_table, dummy_nid); 110 return engine_table_select(&rand_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an RAND implementation from an ENGINE functional reference */ 113/* Obtains an RAND implementation from an ENGINE functional reference */
108const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e) 114const RAND_METHOD *
109 { 115ENGINE_get_RAND(const ENGINE *e)
116{
110 return e->rand_meth; 117 return e->rand_meth;
111 } 118}
112 119
113/* Sets an RAND implementation in an ENGINE structure */ 120/* Sets an RAND implementation in an ENGINE structure */
114int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth) 121int
115 { 122ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth)
123{
116 e->rand_meth = rand_meth; 124 e->rand_meth = rand_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libcrypto/engine/tb_rsa.c b/src/lib/libcrypto/engine/tb_rsa.c
index 2f4928fd66..846c114435 100644
--- a/src/lib/libcrypto/engine/tb_rsa.c
+++ b/src/lib/libcrypto/engine/tb_rsa.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *rsa_table = NULL; 62static ENGINE_TABLE *rsa_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_RSA(ENGINE *e) 65void
66 { 66ENGINE_unregister_RSA(ENGINE *e)
67{
67 engine_table_unregister(&rsa_table, e); 68 engine_table_unregister(&rsa_table, e);
68 } 69}
69 70
70static void engine_unregister_all_RSA(void) 71static void
71 { 72engine_unregister_all_RSA(void)
73{
72 engine_table_cleanup(&rsa_table); 74 engine_table_cleanup(&rsa_table);
73 } 75}
74 76
75int ENGINE_register_RSA(ENGINE *e) 77int
76 { 78ENGINE_register_RSA(ENGINE *e)
77 if(e->rsa_meth) 79{
80 if (e->rsa_meth)
78 return engine_table_register(&rsa_table, 81 return engine_table_register(&rsa_table,
79 engine_unregister_all_RSA, e, &dummy_nid, 1, 0); 82 engine_unregister_all_RSA, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_RSA(void) 86void
84 { 87ENGINE_register_all_RSA(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_RSA(e); 92 ENGINE_register_RSA(e);
89 } 93}
90 94
91int ENGINE_set_default_RSA(ENGINE *e) 95int
92 { 96ENGINE_set_default_RSA(ENGINE *e)
93 if(e->rsa_meth) 97{
98 if (e->rsa_meth)
94 return engine_table_register(&rsa_table, 99 return engine_table_register(&rsa_table,
95 engine_unregister_all_RSA, e, &dummy_nid, 1, 1); 100 engine_unregister_all_RSA, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_RSA(void) 107ENGINE *
103 { 108ENGINE_get_default_RSA(void)
109{
104 return engine_table_select(&rsa_table, dummy_nid); 110 return engine_table_select(&rsa_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an RSA implementation from an ENGINE functional reference */ 113/* Obtains an RSA implementation from an ENGINE functional reference */
108const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e) 114const RSA_METHOD *
109 { 115ENGINE_get_RSA(const ENGINE *e)
116{
110 return e->rsa_meth; 117 return e->rsa_meth;
111 } 118}
112 119
113/* Sets an RSA implementation in an ENGINE structure */ 120/* Sets an RSA implementation in an ENGINE structure */
114int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth) 121int
115 { 122ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth)
123{
116 e->rsa_meth = rsa_meth; 124 e->rsa_meth = rsa_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libcrypto/engine/tb_store.c b/src/lib/libcrypto/engine/tb_store.c
index bd853733ea..81b3f7b27e 100644
--- a/src/lib/libcrypto/engine/tb_store.c
+++ b/src/lib/libcrypto/engine/tb_store.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,62 +62,70 @@
62static ENGINE_TABLE *store_table = NULL; 62static ENGINE_TABLE *store_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_STORE(ENGINE *e) 65void
66 { 66ENGINE_unregister_STORE(ENGINE *e)
67{
67 engine_table_unregister(&store_table, e); 68 engine_table_unregister(&store_table, e);
68 } 69}
69 70
70static void engine_unregister_all_STORE(void) 71static void
71 { 72engine_unregister_all_STORE(void)
73{
72 engine_table_cleanup(&store_table); 74 engine_table_cleanup(&store_table);
73 } 75}
74 76
75int ENGINE_register_STORE(ENGINE *e) 77int
76 { 78ENGINE_register_STORE(ENGINE *e)
77 if(e->store_meth) 79{
80 if (e->store_meth)
78 return engine_table_register(&store_table, 81 return engine_table_register(&store_table,
79 engine_unregister_all_STORE, e, &dummy_nid, 1, 0); 82 engine_unregister_all_STORE, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_STORE(void) 86void
84 { 87ENGINE_register_all_STORE(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_STORE(e); 92 ENGINE_register_STORE(e);
89 } 93}
90 94
91/* The following two functions are removed because they're useless. */ 95/* The following two functions are removed because they're useless. */
92#if 0 96#if 0
93int ENGINE_set_default_STORE(ENGINE *e) 97int
94 { 98ENGINE_set_default_STORE(ENGINE *e)
95 if(e->store_meth) 99{
100 if (e->store_meth)
96 return engine_table_register(&store_table, 101 return engine_table_register(&store_table,
97 engine_unregister_all_STORE, e, &dummy_nid, 1, 1); 102 engine_unregister_all_STORE, e, &dummy_nid, 1, 1);
98 return 1; 103 return 1;
99 } 104}
100#endif 105#endif
101 106
102#if 0 107#if 0
103/* Exposed API function to get a functional reference from the implementation 108/* Exposed API function to get a functional reference from the implementation
104 * table (ie. try to get a functional reference from the tabled structural 109 * table (ie. try to get a functional reference from the tabled structural
105 * references). */ 110 * references). */
106ENGINE *ENGINE_get_default_STORE(void) 111ENGINE *
107 { 112ENGINE_get_default_STORE(void)
113{
108 return engine_table_select(&store_table, dummy_nid); 114 return engine_table_select(&store_table, dummy_nid);
109 } 115}
110#endif 116#endif
111 117
112/* Obtains an STORE implementation from an ENGINE functional reference */ 118/* Obtains an STORE implementation from an ENGINE functional reference */
113const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e) 119const STORE_METHOD *
114 { 120ENGINE_get_STORE(const ENGINE *e)
121{
115 return e->store_meth; 122 return e->store_meth;
116 } 123}
117 124
118/* Sets an STORE implementation in an ENGINE structure */ 125/* Sets an STORE implementation in an ENGINE structure */
119int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth) 126int
120 { 127ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth)
128{
121 e->store_meth = store_meth; 129 e->store_meth = store_meth;
122 return 1; 130 return 1;
123 } 131}
diff --git a/src/lib/libssl/src/crypto/engine/tb_asnmth.c b/src/lib/libssl/src/crypto/engine/tb_asnmth.c
index 75090339f7..bd62f292c9 100644
--- a/src/lib/libssl/src/crypto/engine/tb_asnmth.c
+++ b/src/lib/libssl/src/crypto/engine/tb_asnmth.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -64,109 +64,115 @@
64 64
65static ENGINE_TABLE *pkey_asn1_meth_table = NULL; 65static ENGINE_TABLE *pkey_asn1_meth_table = NULL;
66 66
67void ENGINE_unregister_pkey_asn1_meths(ENGINE *e) 67void
68 { 68ENGINE_unregister_pkey_asn1_meths(ENGINE *e)
69{
69 engine_table_unregister(&pkey_asn1_meth_table, e); 70 engine_table_unregister(&pkey_asn1_meth_table, e);
70 } 71}
71 72
72static void engine_unregister_all_pkey_asn1_meths(void) 73static void
73 { 74engine_unregister_all_pkey_asn1_meths(void)
75{
74 engine_table_cleanup(&pkey_asn1_meth_table); 76 engine_table_cleanup(&pkey_asn1_meth_table);
75 } 77}
76 78
77int ENGINE_register_pkey_asn1_meths(ENGINE *e) 79int
78 { 80ENGINE_register_pkey_asn1_meths(ENGINE *e)
79 if(e->pkey_asn1_meths) 81{
80 { 82 if (e->pkey_asn1_meths) {
81 const int *nids; 83 const int *nids;
82 int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0); 84 int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0);
83 if(num_nids > 0) 85 if (num_nids > 0)
84 return engine_table_register(&pkey_asn1_meth_table, 86 return engine_table_register(&pkey_asn1_meth_table,
85 engine_unregister_all_pkey_asn1_meths, e, nids, 87 engine_unregister_all_pkey_asn1_meths, e, nids,
86 num_nids, 0); 88 num_nids, 0);
87 }
88 return 1;
89 } 89 }
90 return 1;
91}
90 92
91void ENGINE_register_all_pkey_asn1_meths(void) 93void
92 { 94ENGINE_register_all_pkey_asn1_meths(void)
95{
93 ENGINE *e; 96 ENGINE *e;
94 97
95 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 98 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
96 ENGINE_register_pkey_asn1_meths(e); 99 ENGINE_register_pkey_asn1_meths(e);
97 } 100}
98 101
99int ENGINE_set_default_pkey_asn1_meths(ENGINE *e) 102int
100 { 103ENGINE_set_default_pkey_asn1_meths(ENGINE *e)
101 if(e->pkey_asn1_meths) 104{
102 { 105 if (e->pkey_asn1_meths) {
103 const int *nids; 106 const int *nids;
104 int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0); 107 int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0);
105 if(num_nids > 0) 108 if (num_nids > 0)
106 return engine_table_register(&pkey_asn1_meth_table, 109 return engine_table_register(&pkey_asn1_meth_table,
107 engine_unregister_all_pkey_asn1_meths, e, nids, 110 engine_unregister_all_pkey_asn1_meths, e, nids,
108 num_nids, 1); 111 num_nids, 1);
109 }
110 return 1;
111 } 112 }
113 return 1;
114}
112 115
113/* Exposed API function to get a functional reference from the implementation 116/* Exposed API function to get a functional reference from the implementation
114 * table (ie. try to get a functional reference from the tabled structural 117 * table (ie. try to get a functional reference from the tabled structural
115 * references) for a given pkey_asn1_meth 'nid' */ 118 * references) for a given pkey_asn1_meth 'nid' */
116ENGINE *ENGINE_get_pkey_asn1_meth_engine(int nid) 119ENGINE *
117 { 120ENGINE_get_pkey_asn1_meth_engine(int nid)
121{
118 return engine_table_select(&pkey_asn1_meth_table, nid); 122 return engine_table_select(&pkey_asn1_meth_table, nid);
119 } 123}
120 124
121/* Obtains a pkey_asn1_meth implementation from an ENGINE functional reference */ 125/* Obtains a pkey_asn1_meth implementation from an ENGINE functional reference */
122const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid) 126const EVP_PKEY_ASN1_METHOD *
123 { 127ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid)
128{
124 EVP_PKEY_ASN1_METHOD *ret; 129 EVP_PKEY_ASN1_METHOD *ret;
125 ENGINE_PKEY_ASN1_METHS_PTR fn = ENGINE_get_pkey_asn1_meths(e); 130 ENGINE_PKEY_ASN1_METHS_PTR fn = ENGINE_get_pkey_asn1_meths(e);
126 if(!fn || !fn(e, &ret, NULL, nid)) 131
127 { 132 if (!fn || !fn(e, &ret, NULL, nid)) {
128 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH, 133 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH,
129 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD); 134 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
130 return NULL; 135 return NULL;
131 }
132 return ret;
133 } 136 }
137 return ret;
138}
134 139
135/* Gets the pkey_asn1_meth callback from an ENGINE structure */ 140/* Gets the pkey_asn1_meth callback from an ENGINE structure */
136ENGINE_PKEY_ASN1_METHS_PTR ENGINE_get_pkey_asn1_meths(const ENGINE *e) 141ENGINE_PKEY_ASN1_METHS_PTR
137 { 142ENGINE_get_pkey_asn1_meths(const ENGINE *e)
143{
138 return e->pkey_asn1_meths; 144 return e->pkey_asn1_meths;
139 } 145}
140 146
141/* Sets the pkey_asn1_meth callback in an ENGINE structure */ 147/* Sets the pkey_asn1_meth callback in an ENGINE structure */
142int ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f) 148int
143 { 149ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f)
150{
144 e->pkey_asn1_meths = f; 151 e->pkey_asn1_meths = f;
145 return 1; 152 return 1;
146 } 153}
147 154
148/* Internal function to free up EVP_PKEY_ASN1_METHOD structures before an 155/* Internal function to free up EVP_PKEY_ASN1_METHOD structures before an
149 * ENGINE is destroyed 156 * ENGINE is destroyed
150 */ 157 */
151 158
152void engine_pkey_asn1_meths_free(ENGINE *e) 159void
153 { 160engine_pkey_asn1_meths_free(ENGINE *e)
161{
154 int i; 162 int i;
155 EVP_PKEY_ASN1_METHOD *pkm; 163 EVP_PKEY_ASN1_METHOD *pkm;
156 if (e->pkey_asn1_meths) 164
157 { 165 if (e->pkey_asn1_meths) {
158 const int *pknids; 166 const int *pknids;
159 int npknids; 167 int npknids;
160 npknids = e->pkey_asn1_meths(e, NULL, &pknids, 0); 168 npknids = e->pkey_asn1_meths(e, NULL, &pknids, 0);
161 for (i = 0; i < npknids; i++) 169 for (i = 0; i < npknids; i++) {
162 { 170 if (e->pkey_asn1_meths(e, &pkm, NULL, pknids[i])) {
163 if (e->pkey_asn1_meths(e, &pkm, NULL, pknids[i]))
164 {
165 EVP_PKEY_asn1_free(pkm); 171 EVP_PKEY_asn1_free(pkm);
166 }
167 } 172 }
168 } 173 }
169 } 174 }
175}
170 176
171/* Find a method based on a string. This does a linear search through 177/* Find a method based on a string. This does a linear search through
172 * all implemented algorithms. This is OK in practice because only 178 * all implemented algorithms. This is OK in practice because only
@@ -174,60 +180,60 @@ void engine_pkey_asn1_meths_free(ENGINE *e)
174 * and it is not used for speed critical operations. 180 * and it is not used for speed critical operations.
175 */ 181 */
176 182
177const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth_str(ENGINE *e, 183const EVP_PKEY_ASN1_METHOD *
178 const char *str, int len) 184ENGINE_get_pkey_asn1_meth_str(ENGINE *e, const char *str, int len)
179 { 185{
180 int i, nidcount; 186 int i, nidcount;
181 const int *nids; 187 const int *nids;
182 EVP_PKEY_ASN1_METHOD *ameth; 188 EVP_PKEY_ASN1_METHOD *ameth;
189
183 if (!e->pkey_asn1_meths) 190 if (!e->pkey_asn1_meths)
184 return NULL; 191 return NULL;
185 if (len == -1) 192 if (len == -1)
186 len = strlen(str); 193 len = strlen(str);
187 nidcount = e->pkey_asn1_meths(e, NULL, &nids, 0); 194 nidcount = e->pkey_asn1_meths(e, NULL, &nids, 0);
188 for (i = 0; i < nidcount; i++) 195 for (i = 0; i < nidcount; i++) {
189 {
190 e->pkey_asn1_meths(e, &ameth, NULL, nids[i]); 196 e->pkey_asn1_meths(e, &ameth, NULL, nids[i]);
191 if (((int)strlen(ameth->pem_str) == len) && 197 if (((int)strlen(ameth->pem_str) == len) &&
192 !strncasecmp(ameth->pem_str, str, len)) 198 !strncasecmp(ameth->pem_str, str, len))
193 return ameth; 199 return ameth;
194 }
195 return NULL;
196 } 200 }
201 return NULL;
202}
197 203
198typedef struct 204typedef struct {
199 {
200 ENGINE *e; 205 ENGINE *e;
201 const EVP_PKEY_ASN1_METHOD *ameth; 206 const EVP_PKEY_ASN1_METHOD *ameth;
202 const char *str; 207 const char *str;
203 int len; 208 int len;
204 } ENGINE_FIND_STR; 209} ENGINE_FIND_STR;
205 210
206static void look_str_cb(int nid, STACK_OF(ENGINE) *sk, ENGINE *def, void *arg) 211static void
207 { 212look_str_cb(int nid, STACK_OF(ENGINE) *sk, ENGINE *def, void *arg)
213{
208 ENGINE_FIND_STR *lk = arg; 214 ENGINE_FIND_STR *lk = arg;
209 int i; 215 int i;
216
210 if (lk->ameth) 217 if (lk->ameth)
211 return; 218 return;
212 for (i = 0; i < sk_ENGINE_num(sk); i++) 219 for (i = 0; i < sk_ENGINE_num(sk); i++) {
213 {
214 ENGINE *e = sk_ENGINE_value(sk, i); 220 ENGINE *e = sk_ENGINE_value(sk, i);
215 EVP_PKEY_ASN1_METHOD *ameth; 221 EVP_PKEY_ASN1_METHOD *ameth;
216 e->pkey_asn1_meths(e, &ameth, NULL, nid); 222 e->pkey_asn1_meths(e, &ameth, NULL, nid);
217 if (((int)strlen(ameth->pem_str) == lk->len) && 223 if (((int)strlen(ameth->pem_str) == lk->len) &&
218 !strncasecmp(ameth->pem_str, lk->str, lk->len)) 224 !strncasecmp(ameth->pem_str, lk->str, lk->len)) {
219 {
220 lk->e = e; 225 lk->e = e;
221 lk->ameth = ameth; 226 lk->ameth = ameth;
222 return; 227 return;
223 }
224 } 228 }
225 } 229 }
230}
226 231
227const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe, 232const EVP_PKEY_ASN1_METHOD *
228 const char *str, int len) 233ENGINE_pkey_asn1_find_str(ENGINE **pe, const char *str, int len)
229 { 234{
230 ENGINE_FIND_STR fstr; 235 ENGINE_FIND_STR fstr;
236
231 fstr.e = NULL; 237 fstr.e = NULL;
232 fstr.ameth = NULL; 238 fstr.ameth = NULL;
233 fstr.str = str; 239 fstr.str = str;
@@ -235,12 +241,11 @@ const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe,
235 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 241 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
236 engine_table_doall(pkey_asn1_meth_table, look_str_cb, &fstr); 242 engine_table_doall(pkey_asn1_meth_table, look_str_cb, &fstr);
237 /* If found obtain a structural reference to engine */ 243 /* If found obtain a structural reference to engine */
238 if (fstr.e) 244 if (fstr.e) {
239 {
240 fstr.e->struct_ref++; 245 fstr.e->struct_ref++;
241 engine_ref_debug(fstr.e, 0, 1) 246 engine_ref_debug(fstr.e, 0, 1)
242 } 247 }
243 *pe = fstr.e; 248 *pe = fstr.e;
244 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 249 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
245 return fstr.ameth; 250 return fstr.ameth;
246 } 251}
diff --git a/src/lib/libssl/src/crypto/engine/tb_cipher.c b/src/lib/libssl/src/crypto/engine/tb_cipher.c
index 8d45a9a9cf..3218f5d86f 100644
--- a/src/lib/libssl/src/crypto/engine/tb_cipher.c
+++ b/src/lib/libssl/src/crypto/engine/tb_cipher.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -61,83 +61,90 @@
61 61
62static ENGINE_TABLE *cipher_table = NULL; 62static ENGINE_TABLE *cipher_table = NULL;
63 63
64void ENGINE_unregister_ciphers(ENGINE *e) 64void
65 { 65ENGINE_unregister_ciphers(ENGINE *e)
66{
66 engine_table_unregister(&cipher_table, e); 67 engine_table_unregister(&cipher_table, e);
67 } 68}
68 69
69static void engine_unregister_all_ciphers(void) 70static void
70 { 71engine_unregister_all_ciphers(void)
72{
71 engine_table_cleanup(&cipher_table); 73 engine_table_cleanup(&cipher_table);
72 } 74}
73 75
74int ENGINE_register_ciphers(ENGINE *e) 76int
75 { 77ENGINE_register_ciphers(ENGINE *e)
76 if(e->ciphers) 78{
77 { 79 if (e->ciphers) {
78 const int *nids; 80 const int *nids;
79 int num_nids = e->ciphers(e, NULL, &nids, 0); 81 int num_nids = e->ciphers(e, NULL, &nids, 0);
80 if(num_nids > 0) 82 if (num_nids > 0)
81 return engine_table_register(&cipher_table, 83 return engine_table_register(&cipher_table,
82 engine_unregister_all_ciphers, e, nids, 84 engine_unregister_all_ciphers, e, nids,
83 num_nids, 0); 85 num_nids, 0);
84 }
85 return 1;
86 } 86 }
87 return 1;
88}
87 89
88void ENGINE_register_all_ciphers(void) 90void
89 { 91ENGINE_register_all_ciphers(void)
92{
90 ENGINE *e; 93 ENGINE *e;
91 94
92 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 95 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
93 ENGINE_register_ciphers(e); 96 ENGINE_register_ciphers(e);
94 } 97}
95 98
96int ENGINE_set_default_ciphers(ENGINE *e) 99int
97 { 100ENGINE_set_default_ciphers(ENGINE *e)
98 if(e->ciphers) 101{
99 { 102 if (e->ciphers) {
100 const int *nids; 103 const int *nids;
101 int num_nids = e->ciphers(e, NULL, &nids, 0); 104 int num_nids = e->ciphers(e, NULL, &nids, 0);
102 if(num_nids > 0) 105 if (num_nids > 0)
103 return engine_table_register(&cipher_table, 106 return engine_table_register(&cipher_table,
104 engine_unregister_all_ciphers, e, nids, 107 engine_unregister_all_ciphers, e, nids,
105 num_nids, 1); 108 num_nids, 1);
106 }
107 return 1;
108 } 109 }
110 return 1;
111}
109 112
110/* Exposed API function to get a functional reference from the implementation 113/* Exposed API function to get a functional reference from the implementation
111 * table (ie. try to get a functional reference from the tabled structural 114 * table (ie. try to get a functional reference from the tabled structural
112 * references) for a given cipher 'nid' */ 115 * references) for a given cipher 'nid' */
113ENGINE *ENGINE_get_cipher_engine(int nid) 116ENGINE *
114 { 117ENGINE_get_cipher_engine(int nid)
118{
115 return engine_table_select(&cipher_table, nid); 119 return engine_table_select(&cipher_table, nid);
116 } 120}
117 121
118/* Obtains a cipher implementation from an ENGINE functional reference */ 122/* Obtains a cipher implementation from an ENGINE functional reference */
119const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid) 123const EVP_CIPHER *
120 { 124ENGINE_get_cipher(ENGINE *e, int nid)
125{
121 const EVP_CIPHER *ret; 126 const EVP_CIPHER *ret;
122 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e); 127 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e);
123 if(!fn || !fn(e, &ret, NULL, nid)) 128
124 { 129 if (!fn || !fn(e, &ret, NULL, nid)) {
125 ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER, 130 ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER,
126 ENGINE_R_UNIMPLEMENTED_CIPHER); 131 ENGINE_R_UNIMPLEMENTED_CIPHER);
127 return NULL; 132 return NULL;
128 }
129 return ret;
130 } 133 }
134 return ret;
135}
131 136
132/* Gets the cipher callback from an ENGINE structure */ 137/* Gets the cipher callback from an ENGINE structure */
133ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e) 138ENGINE_CIPHERS_PTR
134 { 139ENGINE_get_ciphers(const ENGINE *e)
140{
135 return e->ciphers; 141 return e->ciphers;
136 } 142}
137 143
138/* Sets the cipher callback in an ENGINE structure */ 144/* Sets the cipher callback in an ENGINE structure */
139int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f) 145int
140 { 146ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f)
147{
141 e->ciphers = f; 148 e->ciphers = f;
142 return 1; 149 return 1;
143 } 150}
diff --git a/src/lib/libssl/src/crypto/engine/tb_dh.c b/src/lib/libssl/src/crypto/engine/tb_dh.c
index 78515aeaa0..6e3ee6dd7c 100644
--- a/src/lib/libssl/src/crypto/engine/tb_dh.c
+++ b/src/lib/libssl/src/crypto/engine/tb_dh.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *dh_table = NULL; 62static ENGINE_TABLE *dh_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_DH(ENGINE *e) 65void
66 { 66ENGINE_unregister_DH(ENGINE *e)
67{
67 engine_table_unregister(&dh_table, e); 68 engine_table_unregister(&dh_table, e);
68 } 69}
69 70
70static void engine_unregister_all_DH(void) 71static void
71 { 72engine_unregister_all_DH(void)
73{
72 engine_table_cleanup(&dh_table); 74 engine_table_cleanup(&dh_table);
73 } 75}
74 76
75int ENGINE_register_DH(ENGINE *e) 77int
76 { 78ENGINE_register_DH(ENGINE *e)
77 if(e->dh_meth) 79{
80 if (e->dh_meth)
78 return engine_table_register(&dh_table, 81 return engine_table_register(&dh_table,
79 engine_unregister_all_DH, e, &dummy_nid, 1, 0); 82 engine_unregister_all_DH, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_DH(void) 86void
84 { 87ENGINE_register_all_DH(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_DH(e); 92 ENGINE_register_DH(e);
89 } 93}
90 94
91int ENGINE_set_default_DH(ENGINE *e) 95int
92 { 96ENGINE_set_default_DH(ENGINE *e)
93 if(e->dh_meth) 97{
98 if (e->dh_meth)
94 return engine_table_register(&dh_table, 99 return engine_table_register(&dh_table,
95 engine_unregister_all_DH, e, &dummy_nid, 1, 1); 100 engine_unregister_all_DH, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_DH(void) 107ENGINE *
103 { 108ENGINE_get_default_DH(void)
109{
104 return engine_table_select(&dh_table, dummy_nid); 110 return engine_table_select(&dh_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an DH implementation from an ENGINE functional reference */ 113/* Obtains an DH implementation from an ENGINE functional reference */
108const DH_METHOD *ENGINE_get_DH(const ENGINE *e) 114const DH_METHOD *
109 { 115ENGINE_get_DH(const ENGINE *e)
116{
110 return e->dh_meth; 117 return e->dh_meth;
111 } 118}
112 119
113/* Sets an DH implementation in an ENGINE structure */ 120/* Sets an DH implementation in an ENGINE structure */
114int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth) 121int
115 { 122ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth)
123{
116 e->dh_meth = dh_meth; 124 e->dh_meth = dh_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libssl/src/crypto/engine/tb_digest.c b/src/lib/libssl/src/crypto/engine/tb_digest.c
index d1bb90aedd..6a7167e071 100644
--- a/src/lib/libssl/src/crypto/engine/tb_digest.c
+++ b/src/lib/libssl/src/crypto/engine/tb_digest.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -61,83 +61,90 @@
61 61
62static ENGINE_TABLE *digest_table = NULL; 62static ENGINE_TABLE *digest_table = NULL;
63 63
64void ENGINE_unregister_digests(ENGINE *e) 64void
65 { 65ENGINE_unregister_digests(ENGINE *e)
66{
66 engine_table_unregister(&digest_table, e); 67 engine_table_unregister(&digest_table, e);
67 } 68}
68 69
69static void engine_unregister_all_digests(void) 70static void
70 { 71engine_unregister_all_digests(void)
72{
71 engine_table_cleanup(&digest_table); 73 engine_table_cleanup(&digest_table);
72 } 74}
73 75
74int ENGINE_register_digests(ENGINE *e) 76int
75 { 77ENGINE_register_digests(ENGINE *e)
76 if(e->digests) 78{
77 { 79 if (e->digests) {
78 const int *nids; 80 const int *nids;
79 int num_nids = e->digests(e, NULL, &nids, 0); 81 int num_nids = e->digests(e, NULL, &nids, 0);
80 if(num_nids > 0) 82 if (num_nids > 0)
81 return engine_table_register(&digest_table, 83 return engine_table_register(&digest_table,
82 engine_unregister_all_digests, e, nids, 84 engine_unregister_all_digests, e, nids,
83 num_nids, 0); 85 num_nids, 0);
84 }
85 return 1;
86 } 86 }
87 return 1;
88}
87 89
88void ENGINE_register_all_digests(void) 90void
89 { 91ENGINE_register_all_digests(void)
92{
90 ENGINE *e; 93 ENGINE *e;
91 94
92 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 95 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
93 ENGINE_register_digests(e); 96 ENGINE_register_digests(e);
94 } 97}
95 98
96int ENGINE_set_default_digests(ENGINE *e) 99int
97 { 100ENGINE_set_default_digests(ENGINE *e)
98 if(e->digests) 101{
99 { 102 if (e->digests) {
100 const int *nids; 103 const int *nids;
101 int num_nids = e->digests(e, NULL, &nids, 0); 104 int num_nids = e->digests(e, NULL, &nids, 0);
102 if(num_nids > 0) 105 if (num_nids > 0)
103 return engine_table_register(&digest_table, 106 return engine_table_register(&digest_table,
104 engine_unregister_all_digests, e, nids, 107 engine_unregister_all_digests, e, nids,
105 num_nids, 1); 108 num_nids, 1);
106 }
107 return 1;
108 } 109 }
110 return 1;
111}
109 112
110/* Exposed API function to get a functional reference from the implementation 113/* Exposed API function to get a functional reference from the implementation
111 * table (ie. try to get a functional reference from the tabled structural 114 * table (ie. try to get a functional reference from the tabled structural
112 * references) for a given digest 'nid' */ 115 * references) for a given digest 'nid' */
113ENGINE *ENGINE_get_digest_engine(int nid) 116ENGINE *
114 { 117ENGINE_get_digest_engine(int nid)
118{
115 return engine_table_select(&digest_table, nid); 119 return engine_table_select(&digest_table, nid);
116 } 120}
117 121
118/* Obtains a digest implementation from an ENGINE functional reference */ 122/* Obtains a digest implementation from an ENGINE functional reference */
119const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid) 123const EVP_MD *
120 { 124ENGINE_get_digest(ENGINE *e, int nid)
125{
121 const EVP_MD *ret; 126 const EVP_MD *ret;
122 ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e); 127 ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e);
123 if(!fn || !fn(e, &ret, NULL, nid)) 128
124 { 129 if (!fn || !fn(e, &ret, NULL, nid)) {
125 ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST, 130 ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST,
126 ENGINE_R_UNIMPLEMENTED_DIGEST); 131 ENGINE_R_UNIMPLEMENTED_DIGEST);
127 return NULL; 132 return NULL;
128 }
129 return ret;
130 } 133 }
134 return ret;
135}
131 136
132/* Gets the digest callback from an ENGINE structure */ 137/* Gets the digest callback from an ENGINE structure */
133ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e) 138ENGINE_DIGESTS_PTR
134 { 139ENGINE_get_digests(const ENGINE *e)
140{
135 return e->digests; 141 return e->digests;
136 } 142}
137 143
138/* Sets the digest callback in an ENGINE structure */ 144/* Sets the digest callback in an ENGINE structure */
139int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f) 145int
140 { 146ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f)
147{
141 e->digests = f; 148 e->digests = f;
142 return 1; 149 return 1;
143 } 150}
diff --git a/src/lib/libssl/src/crypto/engine/tb_dsa.c b/src/lib/libssl/src/crypto/engine/tb_dsa.c
index 6731aad1da..0abc4bc7fb 100644
--- a/src/lib/libssl/src/crypto/engine/tb_dsa.c
+++ b/src/lib/libssl/src/crypto/engine/tb_dsa.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *dsa_table = NULL; 62static ENGINE_TABLE *dsa_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_DSA(ENGINE *e) 65void
66 { 66ENGINE_unregister_DSA(ENGINE *e)
67{
67 engine_table_unregister(&dsa_table, e); 68 engine_table_unregister(&dsa_table, e);
68 } 69}
69 70
70static void engine_unregister_all_DSA(void) 71static void
71 { 72engine_unregister_all_DSA(void)
73{
72 engine_table_cleanup(&dsa_table); 74 engine_table_cleanup(&dsa_table);
73 } 75}
74 76
75int ENGINE_register_DSA(ENGINE *e) 77int
76 { 78ENGINE_register_DSA(ENGINE *e)
77 if(e->dsa_meth) 79{
80 if (e->dsa_meth)
78 return engine_table_register(&dsa_table, 81 return engine_table_register(&dsa_table,
79 engine_unregister_all_DSA, e, &dummy_nid, 1, 0); 82 engine_unregister_all_DSA, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_DSA(void) 86void
84 { 87ENGINE_register_all_DSA(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_DSA(e); 92 ENGINE_register_DSA(e);
89 } 93}
90 94
91int ENGINE_set_default_DSA(ENGINE *e) 95int
92 { 96ENGINE_set_default_DSA(ENGINE *e)
93 if(e->dsa_meth) 97{
98 if (e->dsa_meth)
94 return engine_table_register(&dsa_table, 99 return engine_table_register(&dsa_table,
95 engine_unregister_all_DSA, e, &dummy_nid, 1, 1); 100 engine_unregister_all_DSA, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_DSA(void) 107ENGINE *
103 { 108ENGINE_get_default_DSA(void)
109{
104 return engine_table_select(&dsa_table, dummy_nid); 110 return engine_table_select(&dsa_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an DSA implementation from an ENGINE functional reference */ 113/* Obtains an DSA implementation from an ENGINE functional reference */
108const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e) 114const DSA_METHOD *
109 { 115ENGINE_get_DSA(const ENGINE *e)
116{
110 return e->dsa_meth; 117 return e->dsa_meth;
111 } 118}
112 119
113/* Sets an DSA implementation in an ENGINE structure */ 120/* Sets an DSA implementation in an ENGINE structure */
114int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth) 121int
115 { 122ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth)
123{
116 e->dsa_meth = dsa_meth; 124 e->dsa_meth = dsa_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libssl/src/crypto/engine/tb_ecdh.c b/src/lib/libssl/src/crypto/engine/tb_ecdh.c
index 57354b8c11..0abeee163e 100644
--- a/src/lib/libssl/src/crypto/engine/tb_ecdh.c
+++ b/src/lib/libssl/src/crypto/engine/tb_ecdh.c
@@ -21,7 +21,7 @@
21 * are met: 21 * are met:
22 * 22 *
23 * 1. Redistributions of source code must retain the above copyright 23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer. 24 * notice, this list of conditions and the following disclaimer.
25 * 25 *
26 * 2. Redistributions in binary form must reproduce the above copyright 26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in 27 * notice, this list of conditions and the following disclaimer in
@@ -77,57 +77,65 @@
77static ENGINE_TABLE *ecdh_table = NULL; 77static ENGINE_TABLE *ecdh_table = NULL;
78static const int dummy_nid = 1; 78static const int dummy_nid = 1;
79 79
80void ENGINE_unregister_ECDH(ENGINE *e) 80void
81 { 81ENGINE_unregister_ECDH(ENGINE *e)
82{
82 engine_table_unregister(&ecdh_table, e); 83 engine_table_unregister(&ecdh_table, e);
83 } 84}
84 85
85static void engine_unregister_all_ECDH(void) 86static void
86 { 87engine_unregister_all_ECDH(void)
88{
87 engine_table_cleanup(&ecdh_table); 89 engine_table_cleanup(&ecdh_table);
88 } 90}
89 91
90int ENGINE_register_ECDH(ENGINE *e) 92int
91 { 93ENGINE_register_ECDH(ENGINE *e)
92 if(e->ecdh_meth) 94{
95 if (e->ecdh_meth)
93 return engine_table_register(&ecdh_table, 96 return engine_table_register(&ecdh_table,
94 engine_unregister_all_ECDH, e, &dummy_nid, 1, 0); 97 engine_unregister_all_ECDH, e, &dummy_nid, 1, 0);
95 return 1; 98 return 1;
96 } 99}
97 100
98void ENGINE_register_all_ECDH(void) 101void
99 { 102ENGINE_register_all_ECDH(void)
103{
100 ENGINE *e; 104 ENGINE *e;
101 105
102 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 106 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
103 ENGINE_register_ECDH(e); 107 ENGINE_register_ECDH(e);
104 } 108}
105 109
106int ENGINE_set_default_ECDH(ENGINE *e) 110int
107 { 111ENGINE_set_default_ECDH(ENGINE *e)
108 if(e->ecdh_meth) 112{
113 if (e->ecdh_meth)
109 return engine_table_register(&ecdh_table, 114 return engine_table_register(&ecdh_table,
110 engine_unregister_all_ECDH, e, &dummy_nid, 1, 1); 115 engine_unregister_all_ECDH, e, &dummy_nid, 1, 1);
111 return 1; 116 return 1;
112 } 117}
113 118
114/* Exposed API function to get a functional reference from the implementation 119/* Exposed API function to get a functional reference from the implementation
115 * table (ie. try to get a functional reference from the tabled structural 120 * table (ie. try to get a functional reference from the tabled structural
116 * references). */ 121 * references). */
117ENGINE *ENGINE_get_default_ECDH(void) 122ENGINE *
118 { 123ENGINE_get_default_ECDH(void)
124{
119 return engine_table_select(&ecdh_table, dummy_nid); 125 return engine_table_select(&ecdh_table, dummy_nid);
120 } 126}
121 127
122/* Obtains an ECDH implementation from an ENGINE functional reference */ 128/* Obtains an ECDH implementation from an ENGINE functional reference */
123const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e) 129const ECDH_METHOD *
124 { 130ENGINE_get_ECDH(const ENGINE *e)
131{
125 return e->ecdh_meth; 132 return e->ecdh_meth;
126 } 133}
127 134
128/* Sets an ECDH implementation in an ENGINE structure */ 135/* Sets an ECDH implementation in an ENGINE structure */
129int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth) 136int
130 { 137ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth)
138{
131 e->ecdh_meth = ecdh_meth; 139 e->ecdh_meth = ecdh_meth;
132 return 1; 140 return 1;
133 } 141}
diff --git a/src/lib/libssl/src/crypto/engine/tb_ecdsa.c b/src/lib/libssl/src/crypto/engine/tb_ecdsa.c
index 8f30e956e0..cae74317a4 100644
--- a/src/lib/libssl/src/crypto/engine/tb_ecdsa.c
+++ b/src/lib/libssl/src/crypto/engine/tb_ecdsa.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *ecdsa_table = NULL; 62static ENGINE_TABLE *ecdsa_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_ECDSA(ENGINE *e) 65void
66 { 66ENGINE_unregister_ECDSA(ENGINE *e)
67{
67 engine_table_unregister(&ecdsa_table, e); 68 engine_table_unregister(&ecdsa_table, e);
68 } 69}
69 70
70static void engine_unregister_all_ECDSA(void) 71static void
71 { 72engine_unregister_all_ECDSA(void)
73{
72 engine_table_cleanup(&ecdsa_table); 74 engine_table_cleanup(&ecdsa_table);
73 } 75}
74 76
75int ENGINE_register_ECDSA(ENGINE *e) 77int
76 { 78ENGINE_register_ECDSA(ENGINE *e)
77 if(e->ecdsa_meth) 79{
80 if (e->ecdsa_meth)
78 return engine_table_register(&ecdsa_table, 81 return engine_table_register(&ecdsa_table,
79 engine_unregister_all_ECDSA, e, &dummy_nid, 1, 0); 82 engine_unregister_all_ECDSA, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_ECDSA(void) 86void
84 { 87ENGINE_register_all_ECDSA(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_ECDSA(e); 92 ENGINE_register_ECDSA(e);
89 } 93}
90 94
91int ENGINE_set_default_ECDSA(ENGINE *e) 95int
92 { 96ENGINE_set_default_ECDSA(ENGINE *e)
93 if(e->ecdsa_meth) 97{
98 if (e->ecdsa_meth)
94 return engine_table_register(&ecdsa_table, 99 return engine_table_register(&ecdsa_table,
95 engine_unregister_all_ECDSA, e, &dummy_nid, 1, 1); 100 engine_unregister_all_ECDSA, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_ECDSA(void) 107ENGINE *
103 { 108ENGINE_get_default_ECDSA(void)
109{
104 return engine_table_select(&ecdsa_table, dummy_nid); 110 return engine_table_select(&ecdsa_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an ECDSA implementation from an ENGINE functional reference */ 113/* Obtains an ECDSA implementation from an ENGINE functional reference */
108const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e) 114const ECDSA_METHOD *
109 { 115ENGINE_get_ECDSA(const ENGINE *e)
116{
110 return e->ecdsa_meth; 117 return e->ecdsa_meth;
111 } 118}
112 119
113/* Sets an ECDSA implementation in an ENGINE structure */ 120/* Sets an ECDSA implementation in an ENGINE structure */
114int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth) 121int
115 { 122ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth)
123{
116 e->ecdsa_meth = ecdsa_meth; 124 e->ecdsa_meth = ecdsa_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libssl/src/crypto/engine/tb_pkmeth.c b/src/lib/libssl/src/crypto/engine/tb_pkmeth.c
index 7a59744102..7834a22599 100644
--- a/src/lib/libssl/src/crypto/engine/tb_pkmeth.c
+++ b/src/lib/libssl/src/crypto/engine/tb_pkmeth.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,106 +62,112 @@
62 62
63static ENGINE_TABLE *pkey_meth_table = NULL; 63static ENGINE_TABLE *pkey_meth_table = NULL;
64 64
65void ENGINE_unregister_pkey_meths(ENGINE *e) 65void
66 { 66ENGINE_unregister_pkey_meths(ENGINE *e)
67{
67 engine_table_unregister(&pkey_meth_table, e); 68 engine_table_unregister(&pkey_meth_table, e);
68 } 69}
69 70
70static void engine_unregister_all_pkey_meths(void) 71static void
71 { 72engine_unregister_all_pkey_meths(void)
73{
72 engine_table_cleanup(&pkey_meth_table); 74 engine_table_cleanup(&pkey_meth_table);
73 } 75}
74 76
75int ENGINE_register_pkey_meths(ENGINE *e) 77int
76 { 78ENGINE_register_pkey_meths(ENGINE *e)
77 if(e->pkey_meths) 79{
78 { 80 if (e->pkey_meths) {
79 const int *nids; 81 const int *nids;
80 int num_nids = e->pkey_meths(e, NULL, &nids, 0); 82 int num_nids = e->pkey_meths(e, NULL, &nids, 0);
81 if(num_nids > 0) 83 if (num_nids > 0)
82 return engine_table_register(&pkey_meth_table, 84 return engine_table_register(&pkey_meth_table,
83 engine_unregister_all_pkey_meths, e, nids, 85 engine_unregister_all_pkey_meths, e, nids,
84 num_nids, 0); 86 num_nids, 0);
85 }
86 return 1;
87 } 87 }
88 return 1;
89}
88 90
89void ENGINE_register_all_pkey_meths(void) 91void
90 { 92ENGINE_register_all_pkey_meths(void)
93{
91 ENGINE *e; 94 ENGINE *e;
92 95
93 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 96 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
94 ENGINE_register_pkey_meths(e); 97 ENGINE_register_pkey_meths(e);
95 } 98}
96 99
97int ENGINE_set_default_pkey_meths(ENGINE *e) 100int
98 { 101ENGINE_set_default_pkey_meths(ENGINE *e)
99 if(e->pkey_meths) 102{
100 { 103 if (e->pkey_meths) {
101 const int *nids; 104 const int *nids;
102 int num_nids = e->pkey_meths(e, NULL, &nids, 0); 105 int num_nids = e->pkey_meths(e, NULL, &nids, 0);
103 if(num_nids > 0) 106 if (num_nids > 0)
104 return engine_table_register(&pkey_meth_table, 107 return engine_table_register(&pkey_meth_table,
105 engine_unregister_all_pkey_meths, e, nids, 108 engine_unregister_all_pkey_meths, e, nids,
106 num_nids, 1); 109 num_nids, 1);
107 }
108 return 1;
109 } 110 }
111 return 1;
112}
110 113
111/* Exposed API function to get a functional reference from the implementation 114/* Exposed API function to get a functional reference from the implementation
112 * table (ie. try to get a functional reference from the tabled structural 115 * table (ie. try to get a functional reference from the tabled structural
113 * references) for a given pkey_meth 'nid' */ 116 * references) for a given pkey_meth 'nid' */
114ENGINE *ENGINE_get_pkey_meth_engine(int nid) 117ENGINE *
115 { 118ENGINE_get_pkey_meth_engine(int nid)
119{
116 return engine_table_select(&pkey_meth_table, nid); 120 return engine_table_select(&pkey_meth_table, nid);
117 } 121}
118 122
119/* Obtains a pkey_meth implementation from an ENGINE functional reference */ 123/* Obtains a pkey_meth implementation from an ENGINE functional reference */
120const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid) 124const EVP_PKEY_METHOD *
121 { 125ENGINE_get_pkey_meth(ENGINE *e, int nid)
126{
122 EVP_PKEY_METHOD *ret; 127 EVP_PKEY_METHOD *ret;
123 ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e); 128 ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e);
124 if(!fn || !fn(e, &ret, NULL, nid)) 129
125 { 130 if (!fn || !fn(e, &ret, NULL, nid)) {
126 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH, 131 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH,
127 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD); 132 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
128 return NULL; 133 return NULL;
129 }
130 return ret;
131 } 134 }
135 return ret;
136}
132 137
133/* Gets the pkey_meth callback from an ENGINE structure */ 138/* Gets the pkey_meth callback from an ENGINE structure */
134ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e) 139ENGINE_PKEY_METHS_PTR
135 { 140ENGINE_get_pkey_meths(const ENGINE *e)
141{
136 return e->pkey_meths; 142 return e->pkey_meths;
137 } 143}
138 144
139/* Sets the pkey_meth callback in an ENGINE structure */ 145/* Sets the pkey_meth callback in an ENGINE structure */
140int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f) 146int
141 { 147ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f)
148{
142 e->pkey_meths = f; 149 e->pkey_meths = f;
143 return 1; 150 return 1;
144 } 151}
145 152
146/* Internal function to free up EVP_PKEY_METHOD structures before an 153/* Internal function to free up EVP_PKEY_METHOD structures before an
147 * ENGINE is destroyed 154 * ENGINE is destroyed
148 */ 155 */
149 156
150void engine_pkey_meths_free(ENGINE *e) 157void
151 { 158engine_pkey_meths_free(ENGINE *e)
159{
152 int i; 160 int i;
153 EVP_PKEY_METHOD *pkm; 161 EVP_PKEY_METHOD *pkm;
154 if (e->pkey_meths) 162
155 { 163 if (e->pkey_meths) {
156 const int *pknids; 164 const int *pknids;
157 int npknids; 165 int npknids;
158 npknids = e->pkey_meths(e, NULL, &pknids, 0); 166 npknids = e->pkey_meths(e, NULL, &pknids, 0);
159 for (i = 0; i < npknids; i++) 167 for (i = 0; i < npknids; i++) {
160 { 168 if (e->pkey_meths(e, &pkm, NULL, pknids[i])) {
161 if (e->pkey_meths(e, &pkm, NULL, pknids[i]))
162 {
163 EVP_PKEY_meth_free(pkm); 169 EVP_PKEY_meth_free(pkm);
164 }
165 } 170 }
166 } 171 }
167 } 172 }
173}
diff --git a/src/lib/libssl/src/crypto/engine/tb_rand.c b/src/lib/libssl/src/crypto/engine/tb_rand.c
index 3745ae7abd..b99f3baba3 100644
--- a/src/lib/libssl/src/crypto/engine/tb_rand.c
+++ b/src/lib/libssl/src/crypto/engine/tb_rand.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *rand_table = NULL; 62static ENGINE_TABLE *rand_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_RAND(ENGINE *e) 65void
66 { 66ENGINE_unregister_RAND(ENGINE *e)
67{
67 engine_table_unregister(&rand_table, e); 68 engine_table_unregister(&rand_table, e);
68 } 69}
69 70
70static void engine_unregister_all_RAND(void) 71static void
71 { 72engine_unregister_all_RAND(void)
73{
72 engine_table_cleanup(&rand_table); 74 engine_table_cleanup(&rand_table);
73 } 75}
74 76
75int ENGINE_register_RAND(ENGINE *e) 77int
76 { 78ENGINE_register_RAND(ENGINE *e)
77 if(e->rand_meth) 79{
80 if (e->rand_meth)
78 return engine_table_register(&rand_table, 81 return engine_table_register(&rand_table,
79 engine_unregister_all_RAND, e, &dummy_nid, 1, 0); 82 engine_unregister_all_RAND, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_RAND(void) 86void
84 { 87ENGINE_register_all_RAND(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_RAND(e); 92 ENGINE_register_RAND(e);
89 } 93}
90 94
91int ENGINE_set_default_RAND(ENGINE *e) 95int
92 { 96ENGINE_set_default_RAND(ENGINE *e)
93 if(e->rand_meth) 97{
98 if (e->rand_meth)
94 return engine_table_register(&rand_table, 99 return engine_table_register(&rand_table,
95 engine_unregister_all_RAND, e, &dummy_nid, 1, 1); 100 engine_unregister_all_RAND, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_RAND(void) 107ENGINE *
103 { 108ENGINE_get_default_RAND(void)
109{
104 return engine_table_select(&rand_table, dummy_nid); 110 return engine_table_select(&rand_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an RAND implementation from an ENGINE functional reference */ 113/* Obtains an RAND implementation from an ENGINE functional reference */
108const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e) 114const RAND_METHOD *
109 { 115ENGINE_get_RAND(const ENGINE *e)
116{
110 return e->rand_meth; 117 return e->rand_meth;
111 } 118}
112 119
113/* Sets an RAND implementation in an ENGINE structure */ 120/* Sets an RAND implementation in an ENGINE structure */
114int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth) 121int
115 { 122ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth)
123{
116 e->rand_meth = rand_meth; 124 e->rand_meth = rand_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libssl/src/crypto/engine/tb_rsa.c b/src/lib/libssl/src/crypto/engine/tb_rsa.c
index 2f4928fd66..846c114435 100644
--- a/src/lib/libssl/src/crypto/engine/tb_rsa.c
+++ b/src/lib/libssl/src/crypto/engine/tb_rsa.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,57 +62,65 @@
62static ENGINE_TABLE *rsa_table = NULL; 62static ENGINE_TABLE *rsa_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_RSA(ENGINE *e) 65void
66 { 66ENGINE_unregister_RSA(ENGINE *e)
67{
67 engine_table_unregister(&rsa_table, e); 68 engine_table_unregister(&rsa_table, e);
68 } 69}
69 70
70static void engine_unregister_all_RSA(void) 71static void
71 { 72engine_unregister_all_RSA(void)
73{
72 engine_table_cleanup(&rsa_table); 74 engine_table_cleanup(&rsa_table);
73 } 75}
74 76
75int ENGINE_register_RSA(ENGINE *e) 77int
76 { 78ENGINE_register_RSA(ENGINE *e)
77 if(e->rsa_meth) 79{
80 if (e->rsa_meth)
78 return engine_table_register(&rsa_table, 81 return engine_table_register(&rsa_table,
79 engine_unregister_all_RSA, e, &dummy_nid, 1, 0); 82 engine_unregister_all_RSA, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_RSA(void) 86void
84 { 87ENGINE_register_all_RSA(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_RSA(e); 92 ENGINE_register_RSA(e);
89 } 93}
90 94
91int ENGINE_set_default_RSA(ENGINE *e) 95int
92 { 96ENGINE_set_default_RSA(ENGINE *e)
93 if(e->rsa_meth) 97{
98 if (e->rsa_meth)
94 return engine_table_register(&rsa_table, 99 return engine_table_register(&rsa_table,
95 engine_unregister_all_RSA, e, &dummy_nid, 1, 1); 100 engine_unregister_all_RSA, e, &dummy_nid, 1, 1);
96 return 1; 101 return 1;
97 } 102}
98 103
99/* Exposed API function to get a functional reference from the implementation 104/* Exposed API function to get a functional reference from the implementation
100 * table (ie. try to get a functional reference from the tabled structural 105 * table (ie. try to get a functional reference from the tabled structural
101 * references). */ 106 * references). */
102ENGINE *ENGINE_get_default_RSA(void) 107ENGINE *
103 { 108ENGINE_get_default_RSA(void)
109{
104 return engine_table_select(&rsa_table, dummy_nid); 110 return engine_table_select(&rsa_table, dummy_nid);
105 } 111}
106 112
107/* Obtains an RSA implementation from an ENGINE functional reference */ 113/* Obtains an RSA implementation from an ENGINE functional reference */
108const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e) 114const RSA_METHOD *
109 { 115ENGINE_get_RSA(const ENGINE *e)
116{
110 return e->rsa_meth; 117 return e->rsa_meth;
111 } 118}
112 119
113/* Sets an RSA implementation in an ENGINE structure */ 120/* Sets an RSA implementation in an ENGINE structure */
114int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth) 121int
115 { 122ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth)
123{
116 e->rsa_meth = rsa_meth; 124 e->rsa_meth = rsa_meth;
117 return 1; 125 return 1;
118 } 126}
diff --git a/src/lib/libssl/src/crypto/engine/tb_store.c b/src/lib/libssl/src/crypto/engine/tb_store.c
index bd853733ea..81b3f7b27e 100644
--- a/src/lib/libssl/src/crypto/engine/tb_store.c
+++ b/src/lib/libssl/src/crypto/engine/tb_store.c
@@ -6,7 +6,7 @@
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in 12 * notice, this list of conditions and the following disclaimer in
@@ -62,62 +62,70 @@
62static ENGINE_TABLE *store_table = NULL; 62static ENGINE_TABLE *store_table = NULL;
63static const int dummy_nid = 1; 63static const int dummy_nid = 1;
64 64
65void ENGINE_unregister_STORE(ENGINE *e) 65void
66 { 66ENGINE_unregister_STORE(ENGINE *e)
67{
67 engine_table_unregister(&store_table, e); 68 engine_table_unregister(&store_table, e);
68 } 69}
69 70
70static void engine_unregister_all_STORE(void) 71static void
71 { 72engine_unregister_all_STORE(void)
73{
72 engine_table_cleanup(&store_table); 74 engine_table_cleanup(&store_table);
73 } 75}
74 76
75int ENGINE_register_STORE(ENGINE *e) 77int
76 { 78ENGINE_register_STORE(ENGINE *e)
77 if(e->store_meth) 79{
80 if (e->store_meth)
78 return engine_table_register(&store_table, 81 return engine_table_register(&store_table,
79 engine_unregister_all_STORE, e, &dummy_nid, 1, 0); 82 engine_unregister_all_STORE, e, &dummy_nid, 1, 0);
80 return 1; 83 return 1;
81 } 84}
82 85
83void ENGINE_register_all_STORE(void) 86void
84 { 87ENGINE_register_all_STORE(void)
88{
85 ENGINE *e; 89 ENGINE *e;
86 90
87 for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 91 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
88 ENGINE_register_STORE(e); 92 ENGINE_register_STORE(e);
89 } 93}
90 94
91/* The following two functions are removed because they're useless. */ 95/* The following two functions are removed because they're useless. */
92#if 0 96#if 0
93int ENGINE_set_default_STORE(ENGINE *e) 97int
94 { 98ENGINE_set_default_STORE(ENGINE *e)
95 if(e->store_meth) 99{
100 if (e->store_meth)
96 return engine_table_register(&store_table, 101 return engine_table_register(&store_table,
97 engine_unregister_all_STORE, e, &dummy_nid, 1, 1); 102 engine_unregister_all_STORE, e, &dummy_nid, 1, 1);
98 return 1; 103 return 1;
99 } 104}
100#endif 105#endif
101 106
102#if 0 107#if 0
103/* Exposed API function to get a functional reference from the implementation 108/* Exposed API function to get a functional reference from the implementation
104 * table (ie. try to get a functional reference from the tabled structural 109 * table (ie. try to get a functional reference from the tabled structural
105 * references). */ 110 * references). */
106ENGINE *ENGINE_get_default_STORE(void) 111ENGINE *
107 { 112ENGINE_get_default_STORE(void)
113{
108 return engine_table_select(&store_table, dummy_nid); 114 return engine_table_select(&store_table, dummy_nid);
109 } 115}
110#endif 116#endif
111 117
112/* Obtains an STORE implementation from an ENGINE functional reference */ 118/* Obtains an STORE implementation from an ENGINE functional reference */
113const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e) 119const STORE_METHOD *
114 { 120ENGINE_get_STORE(const ENGINE *e)
121{
115 return e->store_meth; 122 return e->store_meth;
116 } 123}
117 124
118/* Sets an STORE implementation in an ENGINE structure */ 125/* Sets an STORE implementation in an ENGINE structure */
119int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth) 126int
120 { 127ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth)
128{
121 e->store_meth = store_meth; 129 e->store_meth = store_meth;
122 return 1; 130 return 1;
123 } 131}