Add support for default public key digest type ctrl.
[openssl.git] / crypto / evp / p_lib.c
index f22a3fe..730520f 100644 (file)
@@ -74,6 +74,8 @@
 #include <openssl/dh.h>
 #endif
 
+#include "asn1_locl.h"
+
 static void EVP_PKEY_free_it(EVP_PKEY *x);
 
 int EVP_PKEY_bits(EVP_PKEY *pkey)
@@ -147,7 +149,7 @@ int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
                return -1;
        if (a->ameth && a->ameth->param_cmp)
                return a->ameth->param_cmp(a, b);
-       return -1;
+       return -2;
        }
 
 int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
@@ -183,13 +185,13 @@ EVP_PKEY *EVP_PKEY_new(void)
        return(ret);
        }
 
-int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
+int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key)
        {
        const EVP_PKEY_ASN1_METHOD *ameth;
        if (pkey == NULL) return(0);
        if (pkey->pkey.ptr != NULL)
                EVP_PKEY_free_it(pkey);
-       ameth = EVP_PKEY_ASN1_find(type);
+       ameth = EVP_PKEY_asn1_find(type);
        pkey->ameth = ameth;
        pkey->type = ameth->pkey_id;
        pkey->save_type=type;
@@ -197,6 +199,11 @@ int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
        return(key != NULL);
        }
 
+void *EVP_PKEY_get0(EVP_PKEY *pkey)
+       {
+       return pkey->pkey.ptr;
+       }
+
 #ifndef OPENSSL_NO_RSA
 int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
 {
@@ -284,7 +291,7 @@ DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
 int EVP_PKEY_type(int type)
        {
        const EVP_PKEY_ASN1_METHOD *ameth;
-       ameth = EVP_PKEY_ASN1_find(type);
+       ameth = EVP_PKEY_asn1_find(type);
        if (ameth)
                return ameth->pkey_id;
        return NID_undef;
@@ -320,3 +327,46 @@ static void EVP_PKEY_free_it(EVP_PKEY *x)
                x->ameth->pkey_free(x);
        }
 
+static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent,
+                               const char *kstr)
+       {
+       BIO_indent(out, indent, 128);
+       BIO_printf(out, "%s %s, algorithm, unsupported\n",
+                                               OBJ_nid2ln(pkey->type), kstr);
+       return 1;
+       }
+
+int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx)
+       {
+       if (pkey->ameth && pkey->ameth->pub_print)
+               return pkey->ameth->pub_print(out, pkey, indent, pctx);
+       
+       return unsup_alg(out, pkey, indent, "Public Key");
+       }
+
+int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx)
+       {
+       if (pkey->ameth && pkey->ameth->priv_print)
+               return pkey->ameth->priv_print(out, pkey, indent, pctx);
+       
+       return unsup_alg(out, pkey, indent, "Private Key");
+       }
+
+int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
+                               int indent, ASN1_PCTX *pctx)
+       {
+       if (pkey->ameth && pkey->ameth->param_print)
+               return pkey->ameth->param_print(out, pkey, indent, pctx);
+       return unsup_alg(out, pkey, indent, "Parameters");
+       }
+
+int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid)
+       {
+       if (!pkey->ameth || !pkey->ameth->pkey_ctrl)
+               return -2;
+       return pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID,
+                                               0, pnid);
+       }
+