NativeCrypto: throw exception on RSA op failure

A -1 error code should have an error on the stack that explains what the
problem was, but if we call through to an ENGINE that fails we seem to
end up with no error on the stack. Ensure we throw BadPaddingException
in that case.

Bug: 19863798
Change-Id: Idecd9072c1e6636351bc90f16037852bdc55e4a0
diff --git a/src/main/native/org_conscrypt_NativeCrypto.cpp b/src/main/native/org_conscrypt_NativeCrypto.cpp
index f73c586..9876f8c 100644
--- a/src/main/native/org_conscrypt_NativeCrypto.cpp
+++ b/src/main/native/org_conscrypt_NativeCrypto.cpp
@@ -3117,9 +3117,9 @@
 typedef int RSACryptOperation(int flen, const unsigned char* from, unsigned char* to, RSA* rsa,
                               int padding);
 
-static jint RSA_crypt_operation(RSACryptOperation operation,
-        const char* caller __attribute__ ((unused)), JNIEnv* env, jint flen,
-        jbyteArray fromJavaBytes, jbyteArray toJavaBytes, jobject pkeyRef, jint padding) {
+static jint RSA_crypt_operation(RSACryptOperation operation, const char* caller, JNIEnv* env,
+                                jint flen, jbyteArray fromJavaBytes, jbyteArray toJavaBytes,
+                                jobject pkeyRef, jint padding) {
     EVP_PKEY* pkey = fromContextObject<EVP_PKEY>(env, pkeyRef);
     JNI_TRACE("%s(%d, %p, %p, %p)", caller, flen, fromJavaBytes, toJavaBytes, pkey);
 
@@ -3146,8 +3146,12 @@
             reinterpret_cast<const unsigned char*>(from.get()),
             reinterpret_cast<unsigned char*>(to.get()), rsa.get(), padding);
     if (resultSize == -1) {
-        JNI_TRACE("%s => failed", caller);
-        throwExceptionIfNecessary(env, "RSA_crypt_operation");
+        if (throwExceptionIfNecessary(env, caller)) {
+            JNI_TRACE("%s => threw error", caller);
+        } else {
+            throwBadPaddingException(env, caller);
+            JNI_TRACE("%s => threw padding exception", caller);
+        }
         return -1;
     }