Add AES SPARC T4 module from master.
[oweals/openssl.git] / crypto / engine / tb_pkmeth.c
index dfc7d0fab1225632684467254f2fb5c10ff1cd95..1cdb967f25366300aedd438fee629ef5351aa3ab 100644 (file)
@@ -53,6 +53,7 @@
  */
 
 #include "eng_int.h"
+#include <openssl/evp.h>
 
 /* If this symbol is defined then ENGINE_get_pkey_meth_engine(), the function
  * that is used by EVP to hook in pkey_meth code and cache defaults (etc), will
@@ -118,12 +119,12 @@ ENGINE *ENGINE_get_pkey_meth_engine(int nid)
 /* Obtains a pkey_meth implementation from an ENGINE functional reference */
 const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid)
        {
-       const EVP_PKEY_METHOD *ret;
+       EVP_PKEY_METHOD *ret;
        ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e);
        if(!fn || !fn(e, &ret, NULL, nid))
                {
-               ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER,
-                               ENGINE_R_UNIMPLEMENTED_CIPHER);
+               ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH,
+                               ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
                return NULL;
                }
        return ret;
@@ -141,3 +142,26 @@ int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f)
        e->pkey_meths = f;
        return 1;
        }
+
+/* Internal function to free up EVP_PKEY_METHOD structures before an
+ * ENGINE is destroyed
+ */
+
+void engine_pkey_meths_free(ENGINE *e)
+       {
+       int i;
+       EVP_PKEY_METHOD *pkm;
+       if (e->pkey_meths)
+               {
+               const int *pknids;
+               int npknids;
+               npknids = e->pkey_meths(e, NULL, &pknids, 0);
+               for (i = 0; i < npknids; i++)
+                       {
+                       if (e->pkey_meths(e, &pkm, NULL, pknids[i]))
+                               {
+                               EVP_PKEY_meth_free(pkm);
+                               }
+                       }
+               }
+       }