Add lots of checks for memory allocation failure, error codes to indicate
[oweals/openssl.git] / crypto / rsa / rsa_sign.c
index 619755ce0bc41edf749e17b334980a3d941a2901..cee09eccb1f6246cfb4b159d63b890ee65b9c650 100644 (file)
@@ -62,9 +62,6 @@
 #include <openssl/rsa.h>
 #include <openssl/objects.h>
 #include <openssl/x509.h>
-#ifndef OPENSSL_NO_ENGINE
-#include <openssl/engine.h>
-#endif
 
 /* Size of an SSL signature: MD5+SHA1 */
 #define SSL_SIG_LENGTH 36
@@ -79,13 +76,8 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
        const unsigned char *s = NULL;
        X509_ALGOR algor;
        ASN1_OCTET_STRING digest;
-       if(rsa->flags & RSA_FLAG_SIGN_VER)
+       if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_sign)
                {
-#ifndef OPENSSL_NO_ENGINE
-               if(ENGINE_get_RSA(rsa->engine)->rsa_sign)
-                       return ENGINE_get_RSA(rsa->engine)->rsa_sign(type,
-                               m, m_len, sigret, siglen, rsa);
-#endif
                return rsa->meth->rsa_sign(type, m, m_len,
                        sigret, siglen, rsa);
                }
@@ -163,13 +155,8 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
                return(0);
                }
 
-       if(rsa->flags & RSA_FLAG_SIGN_VER)
+       if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_verify)
                {
-#ifndef OPENSSL_NO_ENGINE
-               if(ENGINE_get_RSA(rsa->engine)->rsa_verify)
-                       return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype,
-                               m, m_len, sigbuf, siglen, rsa);
-#endif
                return rsa->meth->rsa_verify(dtype, m, m_len,
                        sigbuf, siglen, rsa);
                }
@@ -182,7 +169,7 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
                }
        if((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {
                        RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);
-                       return(0);
+                       goto err;
        }
        i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
 
@@ -235,8 +222,11 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
        }
 err:
        if (sig != NULL) X509_SIG_free(sig);
-       OPENSSL_cleanse(s,(unsigned int)siglen);
-       OPENSSL_free(s);
+       if (s != NULL)
+               {
+               OPENSSL_cleanse(s,(unsigned int)siglen);
+               OPENSSL_free(s);
+               }
        return(ret);
        }