Reduce header interdependencies, initially in engine.h (the rest of the
[openssl.git] / engines / e_cswift.c
index 1b4e4e876ecac0253d85a74b3a839efe8a8bd1f1..b73126b0376bc928a7bf4b1109dd3f2c80370357 100644 (file)
  */
 
 #include <stdio.h>
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <openssl/crypto.h>
 #include <openssl/crypto.h>
-#include "cryptlib.h"
+#include <openssl/buffer.h>
 #include <openssl/dso.h>
 #include <openssl/engine.h>
 #include <openssl/dso.h>
 #include <openssl/engine.h>
+#include <openssl/rsa.h>
+#include <openssl/dsa.h>
+#include <openssl/dh.h>
+#include <openssl/rand.h>
 
 #ifndef OPENSSL_NO_HW
 #ifndef OPENSSL_NO_HW_CSWIFT
 
 #ifndef OPENSSL_NO_HW
 #ifndef OPENSSL_NO_HW_CSWIFT
 #endif
 
 #define CSWIFT_LIB_NAME "cswift engine"
 #endif
 
 #define CSWIFT_LIB_NAME "cswift engine"
-#include "hw_cswift_err.c"
+#include "e_cswift_err.c"
+
+#define DECIMAL_SIZE(type)     ((sizeof(type)*8+2)/3+1)
 
 static int cswift_destroy(ENGINE *e);
 static int cswift_init(ENGINE *e);
 static int cswift_finish(ENGINE *e);
 
 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,
 
 /* BIGNUM stuff */
 static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
@@ -100,7 +107,7 @@ static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
 
 #ifndef OPENSSL_NO_RSA
 /* RSA stuff */
 
 #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,
 #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,
@@ -151,6 +158,7 @@ static RSA_METHOD cswift_rsa =
        0,
        NULL,
        NULL,
        0,
        NULL,
        NULL,
+       NULL,
        NULL
        };
 #endif
        NULL
        };
 #endif
@@ -168,7 +176,9 @@ static DSA_METHOD cswift_dsa =
        NULL, /* init */
        NULL, /* finish */
        0, /* flags */
        NULL, /* init */
        NULL, /* finish */
        0, /* flags */
-       NULL /* app_data */
+       NULL, /* app_data */
+       NULL, /* dsa_paramgen */
+       NULL /* dsa_keygen */
        };
 #endif
 
        };
 #endif
 
@@ -183,6 +193,7 @@ static DH_METHOD cswift_dh =
        NULL,
        NULL,
        0,
        NULL,
        NULL,
        0,
+       NULL,
        NULL
        };
 #endif
        NULL
        };
 #endif
@@ -259,6 +270,7 @@ static int bind_helper(ENGINE *e)
        return 1;
        }
 
        return 1;
        }
 
+#ifdef OPENSSL_NO_DYNAMIC_ENGINE
 static ENGINE *engine_cswift(void)
        {
        ENGINE *ret = ENGINE_new();
 static ENGINE *engine_cswift(void)
        {
        ENGINE *ret = ENGINE_new();
@@ -281,6 +293,7 @@ void ENGINE_load_cswift(void)
        ENGINE_free(toadd);
        ERR_clear_error();
        }
        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
 
 /* This is a process-global DSO handle used for loading and unloading
  * the CryptoSwift library. NB: This is only set (or unset) during an
@@ -430,7 +443,7 @@ static int cswift_finish(ENGINE *e)
        return 1;
        }
 
        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)
        {
        int initialised = ((cswift_dso == NULL) ? 0 : 1);
        switch(cmd)
@@ -659,13 +672,10 @@ err:
        }
  
 #ifndef OPENSSL_NO_RSA
        }
  
 #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;
 
        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);
        if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
                {
                CSWIFTerr(CSWIFT_F_CSWIFT_RSA_MOD_EXP,CSWIFT_R_MISSING_KEY_COMPONENTS);
@@ -674,8 +684,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:
        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
        return to_return;
        }
 #endif
@@ -978,7 +986,7 @@ static int cswift_rand_status(void)
 
 /* This stuff is needed if this ENGINE is being compiled into a self-contained
  * shared-library. */
 
 /* This stuff is needed if this ENGINE is being compiled into a self-contained
  * shared-library. */
-#ifdef ENGINE_DYNAMIC_SUPPORT
+#ifndef OPENSSL_NO_DYNAMIC_ENGINE
 static int bind_fn(ENGINE *e, const char *id)
        {
        if(id && (strcmp(id, engine_cswift_id) != 0))
 static int bind_fn(ENGINE *e, const char *id)
        {
        if(id && (strcmp(id, engine_cswift_id) != 0))
@@ -989,7 +997,7 @@ static int bind_fn(ENGINE *e, const char *id)
        }       
 IMPLEMENT_DYNAMIC_CHECK_FN()
 IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
        }       
 IMPLEMENT_DYNAMIC_CHECK_FN()
 IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
-#endif /* ENGINE_DYNAMIC_SUPPORT */
+#endif /* OPENSSL_NO_DYNAMIC_ENGINE */
 
 #endif /* !OPENSSL_NO_HW_CSWIFT */
 #endif /* !OPENSSL_NO_HW */
 
 #endif /* !OPENSSL_NO_HW_CSWIFT */
 #endif /* !OPENSSL_NO_HW */