From 7d711cbc335206327d1dbb0389d9ab83b461d4de Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Wed, 28 Oct 2015 12:29:43 +0000 Subject: Engine EC_KEY_METHOD functionality. Rename ENGINE _EC_KEY functions to _EC. Add support for EC_KEY_METHOD in ENGINE_set_default et al. Copy ec_meth. Reviewed-by: Richard Levitte --- crypto/ec/ec_kmeth.c | 4 ++-- crypto/engine/eng_fat.c | 5 +++++ crypto/engine/eng_int.h | 2 +- crypto/engine/eng_list.c | 2 +- crypto/engine/tb_eckey.c | 30 +++++++++++++++--------------- include/openssl/engine.h | 19 +++++++++---------- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/crypto/ec/ec_kmeth.c b/crypto/ec/ec_kmeth.c index 172aaddd20..a329e7adcb 100644 --- a/crypto/ec/ec_kmeth.c +++ b/crypto/ec/ec_kmeth.c @@ -109,9 +109,9 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine) } ret->engine = engine; } else - ret->engine = ENGINE_get_default_EC_KEY(); + ret->engine = ENGINE_get_default_EC(); if (ret->engine) { - ret->meth = ENGINE_get_EC_KEY(ret->engine); + ret->meth = ENGINE_get_EC(ret->engine); if (!ret->meth) { ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB); ENGINE_finish(ret->engine); diff --git a/crypto/engine/eng_fat.c b/crypto/engine/eng_fat.c index 7984a5bf21..79d30bc8f5 100644 --- a/crypto/engine/eng_fat.c +++ b/crypto/engine/eng_fat.c @@ -80,6 +80,8 @@ int ENGINE_set_default(ENGINE *e, unsigned int flags) return 0; #endif #ifndef OPENSSL_NO_EC + if ((flags & ENGINE_METHOD_EC) && !ENGINE_set_default_EC(e)) + return 0; #endif if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) return 0; @@ -107,6 +109,8 @@ static int int_def_cb(const char *alg, int len, void *arg) *pflags |= ENGINE_METHOD_DSA; else if (strncmp(alg, "DH", len) == 0) *pflags |= ENGINE_METHOD_DH; + else if (strncmp(alg, "EC", len) == 0) + *pflags |= ENGINE_METHOD_EC; else if (strncmp(alg, "RAND", len) == 0) *pflags |= ENGINE_METHOD_RAND; else if (strncmp(alg, "CIPHERS", len) == 0) @@ -150,6 +154,7 @@ int ENGINE_register_complete(ENGINE *e) ENGINE_register_DH(e); #endif #ifndef OPENSSL_NO_EC + ENGINE_register_EC(e); #endif ENGINE_register_RAND(e); ENGINE_register_pkey_meths(e); diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h index eea5e3d298..2a0a9d452f 100644 --- a/crypto/engine/eng_int.h +++ b/crypto/engine/eng_int.h @@ -179,7 +179,7 @@ struct engine_st { const RSA_METHOD *rsa_meth; const DSA_METHOD *dsa_meth; const DH_METHOD *dh_meth; - const EC_KEY_METHOD *ec_key_meth; + const EC_KEY_METHOD *ec_meth; const RAND_METHOD *rand_meth; const STORE_METHOD *store_meth; /* Cipher handling is via this callback */ diff --git a/crypto/engine/eng_list.c b/crypto/engine/eng_list.c index 72d3a17f19..f7739bae5e 100644 --- a/crypto/engine/eng_list.c +++ b/crypto/engine/eng_list.c @@ -302,7 +302,7 @@ static void engine_cpy(ENGINE *dest, const ENGINE *src) dest->dh_meth = src->dh_meth; #endif #ifndef OPENSSL_NO_EC - + dest->ec_meth = src->ec_meth; #endif dest->rand_meth = src->rand_meth; dest->store_meth = src->store_meth; diff --git a/crypto/engine/tb_eckey.c b/crypto/engine/tb_eckey.c index a3a4a23f81..a1cffe8159 100644 --- a/crypto/engine/tb_eckey.c +++ b/crypto/engine/tb_eckey.c @@ -64,38 +64,38 @@ static ENGINE_TABLE *dh_table = NULL; static const int dummy_nid = 1; -void ENGINE_unregister_EC_KEY(ENGINE *e) +void ENGINE_unregister_EC(ENGINE *e) { engine_table_unregister(&dh_table, e); } -static void engine_unregister_all_EC_KEY(void) +static void engine_unregister_all_EC(void) { engine_table_cleanup(&dh_table); } -int ENGINE_register_EC_KEY(ENGINE *e) +int ENGINE_register_EC(ENGINE *e) { - if (e->ec_key_meth) + if (e->ec_meth) return engine_table_register(&dh_table, - engine_unregister_all_EC_KEY, e, &dummy_nid, + engine_unregister_all_EC, e, &dummy_nid, 1, 0); return 1; } -void ENGINE_register_all_EC_KEY() +void ENGINE_register_all_EC() { ENGINE *e; for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) - ENGINE_register_EC_KEY(e); + ENGINE_register_EC(e); } -int ENGINE_set_default_EC_KEY(ENGINE *e) +int ENGINE_set_default_EC(ENGINE *e) { - if (e->ec_key_meth) + if (e->ec_meth) return engine_table_register(&dh_table, - engine_unregister_all_EC_KEY, e, &dummy_nid, + engine_unregister_all_EC, e, &dummy_nid, 1, 1); return 1; } @@ -105,20 +105,20 @@ int ENGINE_set_default_EC_KEY(ENGINE *e) * table (ie. try to get a functional reference from the tabled structural * references). */ -ENGINE *ENGINE_get_default_EC_KEY(void) +ENGINE *ENGINE_get_default_EC(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) +const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e) { - return e->ec_key_meth; + return e->ec_meth; } /* Sets an EC_KEY implementation in an ENGINE structure */ -int ENGINE_set_EC_KEY(ENGINE *e, const EC_KEY_METHOD *ec_key_meth) +int ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ec_meth) { - e->ec_key_meth = ec_key_meth; + e->ec_meth = ec_meth; return 1; } diff --git a/include/openssl/engine.h b/include/openssl/engine.h index 92a9753fe7..0ab687cc00 100644 --- a/include/openssl/engine.h +++ b/include/openssl/engine.h @@ -83,8 +83,7 @@ # include # endif # ifndef OPENSSL_NO_EC -# include -# include +# include # endif # include # include @@ -113,7 +112,7 @@ extern "C" { # define ENGINE_METHOD_STORE (unsigned int)0x0100 # define ENGINE_METHOD_PKEY_METHS (unsigned int)0x0200 # define ENGINE_METHOD_PKEY_ASN1_METHS (unsigned int)0x0400 -# define ENGINE_METHOD_EC_KEY (unsigned int)0x0800 +# define ENGINE_METHOD_EC (unsigned int)0x0800 /* Obvious all-or-nothing cases. */ # define ENGINE_METHOD_ALL (unsigned int)0xFFFF # define ENGINE_METHOD_NONE (unsigned int)0x0000 @@ -438,9 +437,9 @@ int ENGINE_register_DSA(ENGINE *e); void ENGINE_unregister_DSA(ENGINE *e); void ENGINE_register_all_DSA(void); -int ENGINE_register_EC_KEY(ENGINE *e); -void ENGINE_unregister_EC_KEY(ENGINE *e); -void ENGINE_register_all_EC_KEY(void); +int ENGINE_register_EC(ENGINE *e); +void ENGINE_unregister_EC(ENGINE *e); +void ENGINE_register_all_EC(void); int ENGINE_register_DH(ENGINE *e); void ENGINE_unregister_DH(ENGINE *e); @@ -548,7 +547,7 @@ int ENGINE_set_id(ENGINE *e, const char *id); int ENGINE_set_name(ENGINE *e, const char *name); int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); -int ENGINE_set_EC_KEY(ENGINE *e, const EC_KEY_METHOD *ecdsa_meth); +int ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ecdsa_meth); int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth); @@ -592,7 +591,7 @@ const char *ENGINE_get_id(const ENGINE *e); const char *ENGINE_get_name(const ENGINE *e); const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); -const EC_KEY_METHOD *ENGINE_get_EC_KEY(const ENGINE *e); +const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e); const DH_METHOD *ENGINE_get_DH(const ENGINE *e); const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e); @@ -670,7 +669,7 @@ int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, ENGINE *ENGINE_get_default_RSA(void); /* Same for the other "methods" */ ENGINE *ENGINE_get_default_DSA(void); -ENGINE *ENGINE_get_default_EC_KEY(void); +ENGINE *ENGINE_get_default_EC(void); ENGINE *ENGINE_get_default_DH(void); ENGINE *ENGINE_get_default_RAND(void); /* @@ -692,7 +691,7 @@ int ENGINE_set_default_RSA(ENGINE *e); int ENGINE_set_default_string(ENGINE *e, const char *def_list); /* Same for the other "methods" */ int ENGINE_set_default_DSA(ENGINE *e); -int ENGINE_set_default_EC_KEY(ENGINE *e); +int ENGINE_set_default_EC(ENGINE *e); int ENGINE_set_default_DH(ENGINE *e); int ENGINE_set_default_RAND(ENGINE *e); int ENGINE_set_default_ciphers(ENGINE *e); -- cgit v1.2.3