By adding a BN_CTX parameter to the 'rsa_mod_exp' callback, private key
[openssl.git] / engines / e_cswift.c
index 2ed9357f136b6599dba198bbb4592f0718c627da..cc39cd4947395f55f748bb15ff8f83afdf59ea68 100644 (file)
@@ -57,6 +57,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <openssl/crypto.h>
 #include <openssl/buffer.h>
 #include <openssl/dso.h>
@@ -91,7 +92,7 @@
 static int cswift_destroy(ENGINE *e);
 static int cswift_init(ENGINE *e);
 static int cswift_finish(ENGINE *e);
-static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
+static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
 
 /* BIGNUM stuff */
 static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -102,7 +103,7 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 
 #ifndef OPENSSL_NO_RSA
 /* RSA stuff */
-static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
+static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
 #endif
 /* This function is aliased to mod_exp (with the mont stuff dropped). */
 static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -153,6 +154,7 @@ static RSA_METHOD cswift_rsa =
        0,
        NULL,
        NULL,
+       NULL,
        NULL
        };
 #endif
@@ -170,7 +172,9 @@ static DSA_METHOD cswift_dsa =
        NULL, /* init */
        NULL, /* finish */
        0, /* flags */
-       NULL /* app_data */
+       NULL, /* app_data */
+       NULL, /* dsa_paramgen */
+       NULL /* dsa_keygen */
        };
 #endif
 
@@ -185,6 +189,7 @@ static DH_METHOD cswift_dh =
        NULL,
        NULL,
        0,
+       NULL,
        NULL
        };
 #endif
@@ -261,6 +266,7 @@ static int bind_helper(ENGINE *e)
        return 1;
        }
 
+#ifdef OPENSSL_NO_DYNAMIC_ENGINE
 static ENGINE *engine_cswift(void)
        {
        ENGINE *ret = ENGINE_new();
@@ -283,6 +289,7 @@ void ENGINE_load_cswift(void)
        ENGINE_free(toadd);
        ERR_clear_error();
        }
+#endif
 
 /* This is a process-global DSO handle used for loading and unloading
  * the CryptoSwift library. NB: This is only set (or unset) during an
@@ -432,7 +439,7 @@ static int cswift_finish(ENGINE *e)
        return 1;
        }
 
-static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
+static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
        {
        int initialised = ((cswift_dso == NULL) ? 0 : 1);
        switch(cmd)
@@ -661,13 +668,10 @@ err:
        }
  
 #ifndef OPENSSL_NO_RSA
-static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
+static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
        {
-       BN_CTX *ctx;
        int to_return = 0;
 
-       if((ctx = BN_CTX_new()) == NULL)
-               goto err;
        if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
                {
                CSWIFTerr(CSWIFT_F_CSWIFT_RSA_MOD_EXP,CSWIFT_R_MISSING_KEY_COMPONENTS);
@@ -676,8 +680,6 @@ static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
        to_return = cswift_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
                rsa->dmq1, rsa->iqmp, ctx);
 err:
-       if(ctx)
-               BN_CTX_free(ctx);
        return to_return;
        }
 #endif