summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/engine')
-rw-r--r--src/lib/libcrypto/engine/eng_fat.c11
-rw-r--r--src/lib/libcrypto/engine/eng_int.h3
-rw-r--r--src/lib/libcrypto/engine/eng_list.c5
-rw-r--r--src/lib/libcrypto/engine/engine.h14
-rw-r--r--src/lib/libcrypto/engine/tb_eckey.c123
5 files changed, 152 insertions, 4 deletions
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c
index c97695a7d3..baf1a54883 100644
--- a/src/lib/libcrypto/engine/eng_fat.c
+++ b/src/lib/libcrypto/engine/eng_fat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_fat.c,v 1.16 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: eng_fat.c,v 1.17 2019/01/19 01:07:00 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -93,6 +93,10 @@ ENGINE_set_default(ENGINE *e, unsigned int flags)
93 if ((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e)) 93 if ((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e))
94 return 0; 94 return 0;
95#endif 95#endif
96#ifndef OPENSSL_NO_EC
97 if ((flags & ENGINE_METHOD_EC) && !ENGINE_set_default_EC(e))
98 return 0;
99#endif
96 if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) 100 if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
97 return 0; 101 return 0;
98 if ((flags & ENGINE_METHOD_PKEY_METHS) && 102 if ((flags & ENGINE_METHOD_PKEY_METHS) &&
@@ -123,6 +127,8 @@ int_def_cb(const char *alg, int len, void *arg)
123 *pflags |= ENGINE_METHOD_ECDSA; 127 *pflags |= ENGINE_METHOD_ECDSA;
124 else if (!strncmp(alg, "DH", len)) 128 else if (!strncmp(alg, "DH", len))
125 *pflags |= ENGINE_METHOD_DH; 129 *pflags |= ENGINE_METHOD_DH;
130 else if (strncmp(alg, "EC", len) == 0)
131 *pflags |= ENGINE_METHOD_EC;
126 else if (!strncmp(alg, "RAND", len)) 132 else if (!strncmp(alg, "RAND", len))
127 *pflags |= ENGINE_METHOD_RAND; 133 *pflags |= ENGINE_METHOD_RAND;
128 else if (!strncmp(alg, "CIPHERS", len)) 134 else if (!strncmp(alg, "CIPHERS", len))
@@ -174,6 +180,9 @@ ENGINE_register_complete(ENGINE *e)
174#ifndef OPENSSL_NO_ECDSA 180#ifndef OPENSSL_NO_ECDSA
175 ENGINE_register_ECDSA(e); 181 ENGINE_register_ECDSA(e);
176#endif 182#endif
183#ifndef OPENSSL_NO_EC
184 ENGINE_register_EC(e);
185#endif
177 ENGINE_register_RAND(e); 186 ENGINE_register_RAND(e);
178 ENGINE_register_pkey_meths(e); 187 ENGINE_register_pkey_meths(e);
179 return 1; 188 return 1;
diff --git a/src/lib/libcrypto/engine/eng_int.h b/src/lib/libcrypto/engine/eng_int.h
index dbb639949d..298c0e327f 100644
--- a/src/lib/libcrypto/engine/eng_int.h
+++ b/src/lib/libcrypto/engine/eng_int.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_int.h,v 1.9 2016/12/21 15:49:29 jsing Exp $ */ 1/* $OpenBSD: eng_int.h,v 1.10 2019/01/19 01:07:00 tb Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -159,6 +159,7 @@ struct engine_st {
159 const DH_METHOD *dh_meth; 159 const DH_METHOD *dh_meth;
160 const ECDH_METHOD *ecdh_meth; 160 const ECDH_METHOD *ecdh_meth;
161 const ECDSA_METHOD *ecdsa_meth; 161 const ECDSA_METHOD *ecdsa_meth;
162 const EC_KEY_METHOD *ec_meth;
162 const RAND_METHOD *rand_meth; 163 const RAND_METHOD *rand_meth;
163 const STORE_METHOD *store_meth; 164 const STORE_METHOD *store_meth;
164 /* Cipher handling is via this callback */ 165 /* Cipher handling is via this callback */
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c
index 134866d2c6..b29b4102e4 100644
--- a/src/lib/libcrypto/engine/eng_list.c
+++ b/src/lib/libcrypto/engine/eng_list.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_list.c,v 1.23 2018/08/24 19:25:31 tb Exp $ */ 1/* $OpenBSD: eng_list.c,v 1.24 2019/01/19 01:07:00 tb Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -316,6 +316,9 @@ engine_cpy(ENGINE *dest, const ENGINE *src)
316#ifndef OPENSSL_NO_ECDSA 316#ifndef OPENSSL_NO_ECDSA
317 dest->ecdsa_meth = src->ecdsa_meth; 317 dest->ecdsa_meth = src->ecdsa_meth;
318#endif 318#endif
319#ifndef OPENSSL_NO_EC
320 dest->ec_meth = src->ec_meth;
321#endif
319 dest->rand_meth = src->rand_meth; 322 dest->rand_meth = src->rand_meth;
320 dest->store_meth = src->store_meth; 323 dest->store_meth = src->store_meth;
321 dest->ciphers = src->ciphers; 324 dest->ciphers = src->ciphers;
diff --git a/src/lib/libcrypto/engine/engine.h b/src/lib/libcrypto/engine/engine.h
index 0f603feaaf..dc14be8e38 100644
--- a/src/lib/libcrypto/engine/engine.h
+++ b/src/lib/libcrypto/engine/engine.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: engine.h,v 1.32 2018/11/11 06:41:28 bcook Exp $ */ 1/* $OpenBSD: engine.h,v 1.33 2019/01/19 01:07:00 tb Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -87,6 +87,9 @@
87#ifndef OPENSSL_NO_ECDSA 87#ifndef OPENSSL_NO_ECDSA
88#include <openssl/ecdsa.h> 88#include <openssl/ecdsa.h>
89#endif 89#endif
90#ifndef OPENSSL_NO_EC
91#include <openssl/ec.h>
92#endif
90#include <openssl/ui.h> 93#include <openssl/ui.h>
91#include <openssl/err.h> 94#include <openssl/err.h>
92#endif 95#endif
@@ -112,6 +115,7 @@ extern "C" {
112#define ENGINE_METHOD_STORE (unsigned int)0x0100 115#define ENGINE_METHOD_STORE (unsigned int)0x0100
113#define ENGINE_METHOD_PKEY_METHS (unsigned int)0x0200 116#define ENGINE_METHOD_PKEY_METHS (unsigned int)0x0200
114#define ENGINE_METHOD_PKEY_ASN1_METHS (unsigned int)0x0400 117#define ENGINE_METHOD_PKEY_ASN1_METHS (unsigned int)0x0400
118#define ENGINE_METHOD_EC (unsigned int)0x0800
115/* Obvious all-or-nothing cases. */ 119/* Obvious all-or-nothing cases. */
116#define ENGINE_METHOD_ALL (unsigned int)0xFFFF 120#define ENGINE_METHOD_ALL (unsigned int)0xFFFF
117#define ENGINE_METHOD_NONE (unsigned int)0x0000 121#define ENGINE_METHOD_NONE (unsigned int)0x0000
@@ -353,6 +357,10 @@ int ENGINE_register_ECDSA(ENGINE *e);
353void ENGINE_unregister_ECDSA(ENGINE *e); 357void ENGINE_unregister_ECDSA(ENGINE *e);
354void ENGINE_register_all_ECDSA(void); 358void ENGINE_register_all_ECDSA(void);
355 359
360int ENGINE_register_EC(ENGINE *e);
361void ENGINE_unregister_EC(ENGINE *e);
362void ENGINE_register_all_EC(void);
363
356int ENGINE_register_DH(ENGINE *e); 364int ENGINE_register_DH(ENGINE *e);
357void ENGINE_unregister_DH(ENGINE *e); 365void ENGINE_unregister_DH(ENGINE *e);
358void ENGINE_register_all_DH(void); 366void ENGINE_register_all_DH(void);
@@ -447,6 +455,7 @@ int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
447int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); 455int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
448int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth); 456int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth);
449int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth); 457int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth);
458int ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ec_meth);
450int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); 459int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
451int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); 460int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
452int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth); 461int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth);
@@ -486,6 +495,7 @@ const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
486const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); 495const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
487const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e); 496const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);
488const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e); 497const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);
498const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e);
489const DH_METHOD *ENGINE_get_DH(const ENGINE *e); 499const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
490const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); 500const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
491const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e); 501const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e);
@@ -553,6 +563,7 @@ ENGINE *ENGINE_get_default_RSA(void);
553ENGINE *ENGINE_get_default_DSA(void); 563ENGINE *ENGINE_get_default_DSA(void);
554ENGINE *ENGINE_get_default_ECDH(void); 564ENGINE *ENGINE_get_default_ECDH(void);
555ENGINE *ENGINE_get_default_ECDSA(void); 565ENGINE *ENGINE_get_default_ECDSA(void);
566ENGINE *ENGINE_get_default_EC(void);
556ENGINE *ENGINE_get_default_DH(void); 567ENGINE *ENGINE_get_default_DH(void);
557ENGINE *ENGINE_get_default_RAND(void); 568ENGINE *ENGINE_get_default_RAND(void);
558/* These functions can be used to get a functional reference to perform 569/* These functions can be used to get a functional reference to perform
@@ -572,6 +583,7 @@ int ENGINE_set_default_string(ENGINE *e, const char *def_list);
572int ENGINE_set_default_DSA(ENGINE *e); 583int ENGINE_set_default_DSA(ENGINE *e);
573int ENGINE_set_default_ECDH(ENGINE *e); 584int ENGINE_set_default_ECDH(ENGINE *e);
574int ENGINE_set_default_ECDSA(ENGINE *e); 585int ENGINE_set_default_ECDSA(ENGINE *e);
586int ENGINE_set_default_EC(ENGINE *e);
575int ENGINE_set_default_DH(ENGINE *e); 587int ENGINE_set_default_DH(ENGINE *e);
576int ENGINE_set_default_RAND(ENGINE *e); 588int ENGINE_set_default_RAND(ENGINE *e);
577int ENGINE_set_default_ciphers(ENGINE *e); 589int ENGINE_set_default_ciphers(ENGINE *e);
diff --git a/src/lib/libcrypto/engine/tb_eckey.c b/src/lib/libcrypto/engine/tb_eckey.c
new file mode 100644
index 0000000000..dd30815788
--- /dev/null
+++ b/src/lib/libcrypto/engine/tb_eckey.c
@@ -0,0 +1,123 @@
1/* ====================================================================
2 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include "eng_int.h"
56
57static ENGINE_TABLE *ec_table = NULL;
58static const int dummy_nid = 1;
59
60void
61ENGINE_unregister_EC(ENGINE *e)
62{
63 engine_table_unregister(&ec_table, e);
64}
65
66static void
67engine_unregister_all_EC(void)
68{
69 engine_table_cleanup(&ec_table);
70}
71
72int
73ENGINE_register_EC(ENGINE *e)
74{
75 if (e->ec_meth)
76 return engine_table_register(&ec_table,
77 engine_unregister_all_EC, e, &dummy_nid, 1, 0);
78 return 1;
79}
80
81void
82ENGINE_register_all_EC(void)
83{
84 ENGINE *e;
85
86 for (e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e))
87 ENGINE_register_EC(e);
88}
89
90int
91ENGINE_set_default_EC(ENGINE *e)
92{
93 if (e->ec_meth != NULL)
94 return engine_table_register(&ec_table,
95 engine_unregister_all_EC, e, &dummy_nid, 1, 1);
96 return 1;
97}
98
99/*
100 * Exposed API function to get a functional reference from the implementation
101 * table (ie. try to get a functional reference from the tabled structural
102 * references).
103 */
104ENGINE *
105ENGINE_get_default_EC(void)
106{
107 return engine_table_select(&ec_table, dummy_nid);
108}
109
110/* Obtains an EC_KEY implementation from an ENGINE functional reference */
111const EC_KEY_METHOD *
112ENGINE_get_EC(const ENGINE *e)
113{
114 return e->ec_meth;
115}
116
117/* Sets an EC_KEY implementation in an ENGINE structure */
118int
119ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ec_meth)
120{
121 e->ec_meth = ec_meth;
122 return 1;
123}