Revert the size_t modifications from HEAD that had led to more
[openssl.git] / crypto / rsa / rsa_ameth.c
index 917b376caac0c356ad875a99340cb42c29957eae..8c3209885eab2f1bf3f4c18d3c5e06cf00cacfa2 100644 (file)
@@ -1,5 +1,5 @@
 /* crypto/rsa/rsa_ameth.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.
  */
 /* ====================================================================
 #include <openssl/asn1t.h>
 #include <openssl/x509.h>
 #include <openssl/rsa.h>
+#include <openssl/bn.h>
+#ifndef OPENSSL_NO_CMS
+#include <openssl/cms.h>
+#endif
 #include "asn1_locl.h"
 
 static int rsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
@@ -108,7 +112,7 @@ static int old_rsa_priv_decode(EVP_PKEY *pkey,
        RSA *rsa;
        if (!(rsa = d2i_RSAPrivateKey (NULL, pder, derlen)))
                {
-               RSAerr(RSA_F_RSA_PRIV_DECODE, ERR_R_RSA_LIB);
+               RSAerr(RSA_F_OLD_RSA_PRIV_DECODE, ERR_R_RSA_LIB);
                return 0;
                }
        EVP_PKEY_assign_RSA(pkey, rsa);
@@ -200,7 +204,7 @@ static int do_rsa_print(BIO *bp, const RSA *x, int off, int priv)
        m=(unsigned char *)OPENSSL_malloc(buf_len+10);
        if (m == NULL)
                {
-               RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
+               RSAerr(RSA_F_DO_RSA_PRINT,ERR_R_MALLOC_FAILURE);
                goto err;
                }
 
@@ -264,27 +268,33 @@ static int rsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,
 
 static int rsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
        {
+       X509_ALGOR *alg = NULL;
        switch (op)
                {
 
                case ASN1_PKEY_CTRL_PKCS7_SIGN:
                if (arg1 == 0)
-                       {
-                       X509_ALGOR *alg;
                        PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, NULL, &alg);
-                       X509_ALGOR_set0(alg, OBJ_nid2obj(NID_rsaEncryption),
-                                                       V_ASN1_NULL, 0);
-                       }
-               return 1;
+               break;
 
                case ASN1_PKEY_CTRL_PKCS7_ENCRYPT:
                if (arg1 == 0)
-                       {
-                       X509_ALGOR *alg;
                        PKCS7_RECIP_INFO_get0_alg(arg2, &alg);
-                       X509_ALGOR_set0(alg, OBJ_nid2obj(NID_rsaEncryption),
-                                                       V_ASN1_NULL, 0);
-                       }
+               break;
+#ifndef OPENSSL_NO_CMS
+               case ASN1_PKEY_CTRL_CMS_SIGN:
+               if (arg1 == 0)
+                       CMS_SignerInfo_get0_algs(arg2, NULL, NULL, NULL, &alg);
+               break;
+
+               case ASN1_PKEY_CTRL_CMS_ENVELOPE:
+               if (arg1 == 0)
+                       CMS_RecipientInfo_ktri_get0_algs(arg2, NULL, NULL, &alg);
+               break;
+#endif
+
+               case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+               *(int *)arg2 = NID_sha1;
                return 1;
 
                default:
@@ -292,6 +302,12 @@ static int rsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
 
                }
 
+       if (alg)
+               X509_ALGOR_set0(alg, OBJ_nid2obj(NID_rsaEncryption),
+                                                       V_ASN1_NULL, 0);
+
+       return 1;
+
        }