Compile in gost engine.
[openssl.git] / crypto / engine / eng_lib.c
index d29258c04e88e133cb5e3447a761bdc151784c0d..18a66646458a9aa033abfdde32ce936229f75f57 100644 (file)
  *
  */
 
-#include <openssl/crypto.h>
-#include "cryptlib.h"
 #include "eng_int.h"
-#include <openssl/rand.h> /* FIXME: This shouldn't be needed */
-#include <openssl/engine.h>
+#include <openssl/rand.h>
 
 /* The "new"/"free" stuff first */
 
@@ -81,13 +78,37 @@ ENGINE *ENGINE_new(void)
        return ret;
        }
 
+/* Placed here (close proximity to ENGINE_new) so that modifications to the
+ * elements of the ENGINE structure are more likely to be caught and changed
+ * here. */
+void engine_set_all_null(ENGINE *e)
+       {
+       e->id = NULL;
+       e->name = NULL;
+       e->rsa_meth = NULL;
+       e->dsa_meth = NULL;
+       e->dh_meth = NULL;
+       e->rand_meth = NULL;
+       e->store_meth = NULL;
+       e->ciphers = NULL;
+       e->digests = NULL;
+       e->destroy = NULL;
+       e->init = NULL;
+       e->finish = NULL;
+       e->ctrl = NULL;
+       e->load_privkey = NULL;
+       e->load_pubkey = NULL;
+       e->cmd_defns = NULL;
+       e->flags = 0;
+       }
+
 int engine_free_util(ENGINE *e, int locked)
        {
        int i;
 
        if(e == NULL)
                {
-               ENGINEerr(ENGINE_F_ENGINE_FREE,
+               ENGINEerr(ENGINE_F_ENGINE_FREE_UTIL,
                        ERR_R_PASSED_NULL_PARAMETER);
                return 0;
                }
@@ -104,6 +125,9 @@ int engine_free_util(ENGINE *e, int locked)
                abort();
                }
 #endif
+       /* Free up any dynamically allocated public key methods */
+       engine_pkey_meths_free(e);
+       engine_pkey_asn1_meths_free(e);
        /* Give the ENGINE a chance to do any structural cleanup corresponding
         * to allocation it did in its constructor (eg. unload error strings) */
        if(e->destroy)
@@ -160,7 +184,7 @@ void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb)
 static void engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item)
        {
        (*(item->cb))();
-       OPENSSL_free(cb);
+       OPENSSL_free(item);
        }
 void ENGINE_cleanup(void)
        {
@@ -296,3 +320,13 @@ const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e)
        {
        return e->cmd_defns;
        }
+
+/* eng_lib.o is pretty much linked into anything that touches ENGINE already, so
+ * put the "static_state" hack here. */
+
+static int internal_static_hack = 0;
+
+void *ENGINE_get_static_state(void)
+       {
+       return &internal_static_hack;
+       }