By adding a BN_CTX parameter to the 'rsa_mod_exp' callback, private key
[openssl.git] / engines / e_ncipher.c
index 44a522bc6780c0259957a58252063c7d73237c9d..e075d1b459abb870a8c10804b5268987aa3205ca 100644 (file)
@@ -88,7 +88,7 @@
 static int hwcrhk_destroy(ENGINE *e);
 static int hwcrhk_init(ENGINE *e);
 static int hwcrhk_finish(ENGINE *e);
-static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); 
+static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); 
 
 /* Functions to handle mutexes */
 static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*);
@@ -102,7 +102,7 @@ static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 
 #ifndef OPENSSL_NO_RSA
 /* RSA stuff */
-static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa);
+static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
 #endif
 /* This function is aliased to mod_exp (with the mont stuff dropped). */
 static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -185,6 +185,7 @@ static RSA_METHOD hwcrhk_rsa =
        0,
        NULL,
        NULL,
+       NULL,
        NULL
        };
 #endif
@@ -200,6 +201,7 @@ static DH_METHOD hwcrhk_dh =
        NULL,
        NULL,
        0,
+       NULL,
        NULL
        };
 #endif
@@ -559,15 +561,23 @@ static int hwcrhk_init(ENGINE *e)
 
        /* Check if the application decided to support dynamic locks,
           and if it does, use them. */
-       if (disable_mutex_callbacks == 0 &&
-               CRYPTO_get_dynlock_create_callback() != NULL &&
-               CRYPTO_get_dynlock_lock_callback() != NULL &&
-               CRYPTO_get_dynlock_destroy_callback() != NULL)
+       if (disable_mutex_callbacks == 0)
                {
-               hwcrhk_globals.mutex_init = hwcrhk_mutex_init;
-               hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock;
-               hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock;
-               hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy;
+               if (CRYPTO_get_dynlock_create_callback() != NULL &&
+                       CRYPTO_get_dynlock_lock_callback() != NULL &&
+                       CRYPTO_get_dynlock_destroy_callback() != NULL)
+                       {
+                       hwcrhk_globals.mutex_init = hwcrhk_mutex_init;
+                       hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock;
+                       hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock;
+                       hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy;
+                       }
+               else if (CRYPTO_get_locking_callback() != NULL)
+                       {
+                       HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_LOCKING_MISSING);
+                       ERR_add_error_data(1,"You HAVE to add dynamic locking callbacks via CRYPTO_set_dynlock_{create,lock,destroy}_callback()");
+                       goto err;
+                       }
                }
 
        /* Try and get a context - if not, we may have a DSO but no
@@ -638,7 +648,7 @@ static int hwcrhk_finish(ENGINE *e)
        return to_return;
        }
 
-static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
+static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
        {
        int to_return = 1;
 
@@ -936,7 +946,7 @@ err:
        }
 
 #ifndef OPENSSL_NO_RSA 
-static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa)
+static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
        {
        char tempbuf[1024];
        HWCryptoHook_ErrMsgBuf rmsg;