set engine to NULL after releasing it
[openssl.git] / crypto / evp / p_lib.c
index 939857fdb000b2b07694b1ddde47e3638a3d516d..1916c616991f9f36fcf6e2f366cc01ae0934690c 100644 (file)
@@ -161,11 +161,20 @@ int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
        if (a->type != b->type)
                return -1;
 
-       if (EVP_PKEY_cmp_parameters(a, b) == 0)
-               return 0;
-
-       if (a->ameth && a->ameth->pub_cmp)
-               return a->ameth->pub_cmp(a, b);
+       if (a->ameth)
+               {
+               int ret;
+               /* Compare parameters if the algorithm has them */
+               if (a->ameth->param_cmp)
+                       {
+                       ret = a->ameth->param_cmp(a, b);
+                       if (ret <= 0)
+                               return ret;
+                       }
+
+               if (a->ameth->pub_cmp)
+                       return a->ameth->pub_cmp(a, b);
+               }
 
        return -2;
        }
@@ -211,7 +220,10 @@ static int pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
 #ifndef OPENSSL_NO_ENGINE
                /* If we have an ENGINE release it */
                if (pkey->engine)
+                       {
                        ENGINE_finish(pkey->engine);
+                       pkey->engine = NULL;
+                       }
 #endif
                }
        if (str)