diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2015-10-19 14:38:43 +0100 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2015-12-09 22:09:17 +0000 |
commit | 28572b577c9a8fa41d85e1d2dce8afb2892464cd (patch) | |
tree | e464aa284120d71e7528fe8f5a97ec5ee5e0c2fc /crypto/engine | |
parent | 28cbe2ab4a06058066f6328c6d8654954217c744 (diff) |
Support for EC_KEY_METHOD.
Add EC_KEY_METHOD. This is part of the EC revision and will make EC behave
more like other algorithms. Specifically:
EC_KEY_METHOD is part of EC_KEY.
It is part of ENGINE.
Default or key specific implementations can be provided to redirect some
or all operations.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/engine')
-rw-r--r-- | crypto/engine/Makefile | 4 | ||||
-rw-r--r-- | crypto/engine/eng_int.h | 1 | ||||
-rw-r--r-- | crypto/engine/tb_eckey.c | 124 |
3 files changed, 127 insertions, 2 deletions
diff --git a/crypto/engine/Makefile b/crypto/engine/Makefile index dae2926746..74ff4ff622 100644 --- a/crypto/engine/Makefile +++ b/crypto/engine/Makefile @@ -18,13 +18,13 @@ LIB=$(TOP)/libcrypto.a LIBSRC= eng_err.c eng_lib.c eng_list.c eng_init.c eng_ctrl.c \ eng_table.c eng_pkey.c eng_fat.c eng_all.c \ tb_rsa.c tb_dsa.c tb_ecdsa.c tb_dh.c tb_ecdh.c tb_rand.c tb_store.c \ - tb_cipher.c tb_digest.c tb_pkmeth.c tb_asnmth.c \ + tb_cipher.c tb_digest.c tb_pkmeth.c tb_asnmth.c tb_eckey.c \ eng_openssl.c eng_cnf.c eng_dyn.c eng_cryptodev.c \ eng_rdrand.c LIBOBJ= eng_err.o eng_lib.o eng_list.o eng_init.o eng_ctrl.o \ eng_table.o eng_pkey.o eng_fat.o eng_all.o \ tb_rsa.o tb_dsa.o tb_ecdsa.o tb_dh.o tb_ecdh.o tb_rand.o tb_store.o \ - tb_cipher.o tb_digest.o tb_pkmeth.o tb_asnmth.o \ + tb_cipher.o tb_digest.o tb_pkmeth.o tb_asnmth.o tb_eckey.o \ eng_openssl.o eng_cnf.o eng_dyn.o eng_cryptodev.o \ eng_rdrand.o diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h index 42674e14fa..91160ded48 100644 --- a/crypto/engine/eng_int.h +++ b/crypto/engine/eng_int.h @@ -181,6 +181,7 @@ struct engine_st { const DH_METHOD *dh_meth; const ECDH_METHOD *ecdh_meth; const ECDSA_METHOD *ecdsa_meth; + const EC_KEY_METHOD *ec_key_meth; const RAND_METHOD *rand_meth; const STORE_METHOD *store_meth; /* Cipher handling is via this callback */ diff --git a/crypto/engine/tb_eckey.c b/crypto/engine/tb_eckey.c new file mode 100644 index 0000000000..a3a4a23f81 --- /dev/null +++ b/crypto/engine/tb_eckey.c @@ -0,0 +1,124 @@ +/* ==================================================================== + * Copyright (c) 2000 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include "eng_int.h" + +/* + * If this symbol is defined then ENGINE_get_default_EC_KEY(), the function that + * is used by EC_KEY to hook in implementation code and cache defaults (etc), + * will display brief debugging summaries to stderr with the 'nid'. + */ +/* #define ENGINE_EC_KEY_DEBUG */ + +static ENGINE_TABLE *dh_table = NULL; +static const int dummy_nid = 1; + +void ENGINE_unregister_EC_KEY(ENGINE *e) +{ + engine_table_unregister(&dh_table, e); +} + +static void engine_unregister_all_EC_KEY(void) +{ + engine_table_cleanup(&dh_table); +} + +int ENGINE_register_EC_KEY(ENGINE *e) +{ + if (e->ec_key_meth) + return engine_table_register(&dh_table, + engine_unregister_all_EC_KEY, e, &dummy_nid, + 1, 0); + return 1; +} + +void ENGINE_register_all_EC_KEY() +{ + ENGINE *e; + + for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) + ENGINE_register_EC_KEY(e); +} + +int ENGINE_set_default_EC_KEY(ENGINE *e) +{ + if (e->ec_key_meth) + return engine_table_register(&dh_table, + engine_unregister_all_EC_KEY, e, &dummy_nid, + 1, 1); + return 1; +} + +/* + * Exposed API function to get a functional reference from the implementation + * table (ie. try to get a functional reference from the tabled structural + * references). + */ +ENGINE *ENGINE_get_default_EC_KEY(void) +{ + return engine_table_select(&dh_table, dummy_nid); +} + +/* Obtains an EC_KEY implementation from an ENGINE functional reference */ +const EC_KEY_METHOD *ENGINE_get_EC_KEY(const ENGINE *e) +{ + return e->ec_key_meth; +} + +/* Sets an EC_KEY implementation in an ENGINE structure */ +int ENGINE_set_EC_KEY(ENGINE *e, const EC_KEY_METHOD *ec_key_meth) +{ + e->ec_key_meth = ec_key_meth; + return 1; +} |