Some more tweaks to ENGINE code.
[openssl.git] / crypto / engine / hw_ubsec.c
index 516855812108f2c6de81872ed755678e90afeb0c..a05211f27ab4dbf4a4398a43b48bc2ab211b6080 100644 (file)
@@ -62,7 +62,6 @@
 #include <openssl/crypto.h>
 #include "cryptlib.h"
 #include <openssl/dso.h>
-#include "engine_int.h"
 #include <openssl/engine.h>
 
 #ifndef OPENSSL_NO_HW
@@ -74,8 +73,8 @@
 #include "vendor_defns/hw_ubsec.h"
 #endif
 
-static int ubsec_init(void);
-static int ubsec_finish(void);
+static int ubsec_init(ENGINE *e);
+static int ubsec_finish(ENGINE *e);
 static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                const BIGNUM *m, BN_CTX *ctx);
 static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -153,26 +152,9 @@ static DH_METHOD ubsec_dh =
        NULL
        };
 
-/* Our ENGINE structure. */
-static ENGINE engine_ubsec =
-        {
-       "ubsec",
-       "UBSEC hardware engine support",
-       &ubsec_rsa,
-       &ubsec_dsa,
-       &ubsec_dh,
-       NULL,
-       ubsec_mod_exp,
-       ubsec_mod_exp_crt,
-       ubsec_init,
-       ubsec_finish,
-       NULL, /* no ctrl() */
-       NULL, /* no load_privkey() */
-       NULL, /* no load_pubkey() */
-       0, /* no flags */
-       0, 0, /* no references */
-       NULL, NULL /* unlinked */
-        };
+/* Constants used when creating the ENGINE */
+static const char *engine_ubsec_id = "ubsec";
+static const char *engine_ubsec_name = "UBSEC hardware engine support";
 
 /* As this is only ever called once, there's no need for locking
  * (indeed - the lock will already be held by our caller!!!) */
@@ -182,6 +164,22 @@ ENGINE *ENGINE_ubsec()
 #ifndef HAVE_UBSEC_DH
        const DH_METHOD *meth3;
 #endif /* HAVE_UBSEC_DH */
+       ENGINE *ret = ENGINE_new();
+       if(!ret)
+               return NULL;
+       if(!ENGINE_set_id(ret, engine_ubsec_id) ||
+                       !ENGINE_set_name(ret, engine_ubsec_name) ||
+                       !ENGINE_set_RSA(ret, &ubsec_rsa) ||
+                       !ENGINE_set_DSA(ret, &ubsec_dsa) ||
+                       !ENGINE_set_DH(ret, &ubsec_dh) ||
+                       !ENGINE_set_BN_mod_exp(ret, ubsec_mod_exp) ||
+                       !ENGINE_set_BN_mod_exp_crt(ret, ubsec_mod_exp_crt) ||
+                       !ENGINE_set_init_function(ret, ubsec_init) ||
+                       !ENGINE_set_finish_function(ret, ubsec_finish))
+               {
+               ENGINE_free(ret);
+               return NULL;
+               }
 
        /* We know that the "PKCS1_SSLeay()" functions hook properly
         * to the Broadcom-specific mod_exp and mod_exp_crt so we use
@@ -203,7 +201,7 @@ ENGINE *ENGINE_ubsec()
        ubsec_dh.compute_key = meth3->compute_key;
 #endif /* HAVE_UBSEC_DH */
 
-       return &engine_ubsec;
+       return ret;
        }
 
 /* This is a process-global DSO handle used for loading and unloading
@@ -231,8 +229,27 @@ static t_UBSEC_dsa_verify_ioctl *p_UBSEC_dsa_verify_ioctl = NULL;
 static t_UBSEC_math_accelerate_ioctl *p_UBSEC_math_accelerate_ioctl = NULL;
 static t_UBSEC_rng_ioctl *p_UBSEC_rng_ioctl = NULL;
 
+/* 
+ * These are the static string constants for the DSO file name and the function
+ * symbol names to bind to. 
+ */
+
+static const char *UBSEC_LIBNAME = "ubsec";
+static const char *UBSEC_F1 = "ubsec_bytes_to_bits";
+static const char *UBSEC_F2 = "ubsec_bits_to_bytes";
+static const char *UBSEC_F3 = "ubsec_open";
+static const char *UBSEC_F4 = "ubsec_close";
+static const char *UBSEC_F5 = "diffie_hellman_generate_ioctl";
+static const char *UBSEC_F6 = "diffie_hellman_agree_ioctl";
+static const char *UBSEC_F7 = "rsa_mod_exp_ioctl";
+static const char *UBSEC_F8 = "rsa_mod_exp_crt_ioctl";
+static const char *UBSEC_F9 = "dsa_sign_ioctl";
+static const char *UBSEC_F10 = "dsa_verify_ioctl";
+static const char *UBSEC_F11 = "math_accelerate_ioctl";
+static const char *UBSEC_F12 = "rng_ioctl";
+
 /* (de)initialisation functions. */
-static int ubsec_init()
+static int ubsec_init(ENGINE *e)
        {
        t_UBSEC_ubsec_bytes_to_bits *p1;
        t_UBSEC_ubsec_bits_to_bytes *p2;
@@ -328,7 +345,7 @@ err:
        return 0;
        }
 
-static int ubsec_finish()
+static int ubsec_finish(ENGINE *e)
        {
        if(ubsec_dso == NULL)
                {