Backport CMAC support from HEAD.
[openssl.git] / crypto / asn1 / ameth_lib.c
index fee7198b85ad6b836ba76f60c0ac6ecc851ca9bd..b5854f101a43f1aeccde0ce6f147501d21132e69 100644 (file)
@@ -1,4 +1,4 @@
-/* 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.
  */
 /* ====================================================================
@@ -69,6 +69,7 @@ extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[];
 extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
 extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
 extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
+extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
 
 /* Keep this sorted in type order !! */
 static const EVP_PKEY_ASN1_METHOD *standard_methods[] = 
@@ -90,7 +91,8 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] =
 #ifndef OPENSSL_NO_EC
        &eckey_asn1_meth,
 #endif
-       &hmac_asn1_meth
+       &hmac_asn1_meth,
+       &cmac_asn1_meth
        };
 
 typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
@@ -113,7 +115,7 @@ void main()
 #endif
 
 DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
-                          const EVP_PKEY_ASN1_METHOD *, ameth_cmp);
+                          const EVP_PKEY_ASN1_METHOD *, ameth);
 
 static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a,
                     const EVP_PKEY_ASN1_METHOD * const *b)
@@ -122,7 +124,7 @@ static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a,
        }
 
 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
-                            const EVP_PKEY_ASN1_METHOD *, ameth_cmp);
+                            const EVP_PKEY_ASN1_METHOD *, ameth);
 
 int EVP_PKEY_asn1_get_count(void)
        {
@@ -155,11 +157,9 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
                if (idx >= 0)
                        return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
                }
-       ret = OBJ_bsearch(const EVP_PKEY_ASN1_METHOD *, &t,
-                         const EVP_PKEY_ASN1_METHOD *, standard_methods,
+       ret = OBJ_bsearch_ameth(&t, standard_methods,
                          sizeof(standard_methods)
-                         /sizeof(EVP_PKEY_ASN1_METHOD *),
-                         ameth_cmp);
+                         /sizeof(EVP_PKEY_ASN1_METHOD *));
        if (!ret || !*ret)
                return NULL;
        return *ret;
@@ -174,7 +174,6 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)
        {
        const EVP_PKEY_ASN1_METHOD *t;
-       ENGINE *e;
 
        for (;;)
                {
@@ -186,6 +185,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)
        if (pe)
                {
 #ifndef OPENSSL_NO_ENGINE
+               ENGINE *e;
                /* type will contain the final unaliased type */
                e = ENGINE_get_pkey_asn1_meth_engine(type);
                if (e)
@@ -303,6 +303,8 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
                if (!ameth->info)
                        goto err;
                }
+       else
+               ameth->info = NULL;
 
        if (pem_str)
                {
@@ -310,6 +312,8 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
                if (!ameth->pem_str)
                        goto err;
                }
+       else
+               ameth->pem_str = NULL;
 
        ameth->pub_decode = 0;
        ameth->pub_encode = 0;