Revert the size_t modifications from HEAD that had led to more
[openssl.git] / crypto / dsa / dsa_ameth.c
index d39833ca0d4b4cbdcb34ea288680da5e86985ed0..a588740cd80c327ed652bc9e27d3748f456560cc 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.
  */
 /* ====================================================================
 #include <openssl/x509.h>
 #include <openssl/asn1.h>
 #include <openssl/dsa.h>
+#include <openssl/bn.h>
+#ifndef OPENSSL_NO_CMS
+#include <openssl/cms.h>
+#endif
 #include "asn1_locl.h"
 
 static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
@@ -123,7 +127,7 @@ static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
        return 1;
 
        err:
-       if (pubkey)
+       if (public_key)
                ASN1_INTEGER_free(public_key);
        if (dsa)
                DSA_free(dsa);
@@ -537,14 +541,37 @@ static int dsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
                case ASN1_PKEY_CTRL_PKCS7_SIGN:
                if (arg1 == 0)
                        {
+                       int snid, hnid;
                        X509_ALGOR *alg1, *alg2;
                        PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2);
-                       X509_ALGOR_set0(alg1, OBJ_nid2obj(NID_sha1),
-                                                       V_ASN1_NULL, 0);
-                       X509_ALGOR_set0(alg2, OBJ_nid2obj(NID_dsaWithSHA1),
-                                                       V_ASN1_UNDEF, 0);
+                       if (alg1 == NULL || alg1->algorithm == NULL)
+                               return -1;
+                       hnid = OBJ_obj2nid(alg1->algorithm);
+                       if (hnid == NID_undef)
+                               return -1;
+                       if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
+                               return -1; 
+                       X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
                        }
                return 1;
+#ifndef OPENSSL_NO_CMS
+               case ASN1_PKEY_CTRL_CMS_SIGN:
+               if (arg1 == 0)
+                       {
+                       int snid, hnid;
+                       X509_ALGOR *alg1, *alg2;
+                       CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2);
+                       if (alg1 == NULL || alg1->algorithm == NULL)
+                               return -1;
+                       hnid = OBJ_obj2nid(alg1->algorithm);
+                       if (hnid == NID_undef)
+                               return -1;
+                       if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
+                               return -1; 
+                       X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
+                       }
+               return 1;
+#endif
 
                case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
                *(int *)arg2 = NID_sha1;