Merge from 1.0.0-stable branch.
[openssl.git] / crypto / evp / pmeth_lib.c
index 3fd11cbb5a1ab2f2da97f760ccaa3786d8848d9e..51f0b6ad63c9bad30ad8f455118fbf184a978d06 100644 (file)
@@ -1,5 +1,5 @@
 /* pmeth_lib.c */
-/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2006.
  */
 /* ====================================================================
@@ -80,12 +80,14 @@ static const EVP_PKEY_METHOD *standard_methods[] =
        &rsa_pkey_meth,
        &dh_pkey_meth,
        &dsa_pkey_meth,
+#ifndef OPENSSL_NO_EC
        &ec_pkey_meth,
+#endif
        &hmac_pkey_meth,
        };
 
-DECLARE_OBJ_BSEARCH_CMP_FN(EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
-                          pmeth_cmp);
+DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
+                          pmeth);
 
 static int pmeth_cmp(const EVP_PKEY_METHOD * const *a,
                     const EVP_PKEY_METHOD * const *b)
@@ -93,13 +95,13 @@ static int pmeth_cmp(const EVP_PKEY_METHOD * const *a,
         return ((*a)->pkey_id - (*b)->pkey_id);
        }
 
-IMPLEMENT_OBJ_BSEARCH_CMP_FN(EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
-                            pmeth_cmp);
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
+                            pmeth);
 
 const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
        {
-       EVP_PKEY_METHOD tmp, *t = &tmp;
-       const EVP_PKEY_METHOD **ret;
+       EVP_PKEY_METHOD tmp;
+       const EVP_PKEY_METHOD *t = &tmp, **ret;
        tmp.pkey_id = type;
        if (app_pkey_methods)
                {
@@ -108,10 +110,8 @@ const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
                if (idx >= 0)
                        return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
                }
-       ret = OBJ_bsearch(EVP_PKEY_METHOD *, &t,
-                         const EVP_PKEY_METHOD *, standard_methods,
-                         sizeof(standard_methods)/sizeof(EVP_PKEY_METHOD *),
-                         pmeth_cmp);
+       ret = OBJ_bsearch_pmeth(&t, standard_methods,
+                         sizeof(standard_methods)/sizeof(EVP_PKEY_METHOD *));
        if (!ret || !*ret)
                return NULL;
        return *ret;
@@ -127,6 +127,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
                        return NULL;
                id = pkey->ameth->pkey_id;
                }
+#ifndef OPENSSL_NO_ENGINE
        /* Try to find an ENGINE which implements this method */
        if (e)
                {
@@ -146,6 +147,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
        if (e)
                pmeth = ENGINE_get_pkey_meth(e, id);
        else
+#endif
                pmeth = EVP_PKEY_meth_find(id);
 
        if (pmeth == NULL)
@@ -157,8 +159,10 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
        ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
        if (!ret)
                {
+#ifndef OPENSSL_NO_ENGINE
                if (e)
                        ENGINE_finish(e);
+#endif
                EVPerr(EVP_F_INT_CTX_NEW,ERR_R_MALLOC_FAILURE);
                return NULL;
                }
@@ -494,11 +498,11 @@ void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth,
 
 void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth,
        int (*encrypt_init)(EVP_PKEY_CTX *ctx),
-       int (*encrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
+       int (*encryptfn)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
                                        const unsigned char *in, size_t inlen))
        {
        pmeth->encrypt_init = encrypt_init;
-       pmeth->encrypt = encrypt;
+       pmeth->encrypt = encryptfn;
        }
 
 void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth,