This moves string constants out of vendor headers and into C files.
[openssl.git] / crypto / engine / hw_atalla.c
index 30e5634c718d61667a0139350c23f454c966eafd..37066eb8083074590f63265681a6afeeb08c87c2 100644 (file)
@@ -63,8 +63,8 @@
 #include "engine_int.h"
 #include <openssl/engine.h>
 
-#ifndef NO_HW
-#ifndef NO_HW_ATALLA
+#ifndef OPENSSL_NO_HW
+#ifndef OPENSSL_NO_HW_ATALLA
 
 #ifdef FLAT_INC
 #include "atalla.h"
@@ -95,7 +95,8 @@ static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
 
 /* DH stuff */
 /* This function is alised to mod_exp (with the DH and mont dropped). */
-static int atalla_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r,
+               const BIGNUM *a, const BIGNUM *p,
                const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
 
 
@@ -170,9 +171,9 @@ static ENGINE engine_atalla =
  * (indeed - the lock will already be held by our caller!!!) */
 ENGINE *ENGINE_atalla()
        {
-       RSA_METHOD *meth1;
-       DSA_METHOD *meth2;
-       DH_METHOD *meth3;
+       const RSA_METHOD *meth1;
+       const DSA_METHOD *meth2;
+       const DH_METHOD *meth3;
 
        /* We know that the "PKCS1_SSLeay()" functions hook properly
         * to the atalla-specific mod_exp and mod_exp_crt so we use
@@ -214,8 +215,21 @@ static tfnASI_GetHardwareConfig *p_Atalla_GetHardwareConfig = NULL;
 static tfnASI_RSAPrivateKeyOpFn *p_Atalla_RSAPrivateKeyOpFn = NULL;
 static tfnASI_GetPerformanceStatistics *p_Atalla_GetPerformanceStatistics = NULL;
 
+/* These are the static string constants for the DSO file name and the function
+ * symbol names to bind to. Regrettably, the DSO name on *nix appears to be
+ * "atasi.so" rather than something more consistent like "libatasi.so". At the
+ * time of writing, I'm not sure what the file name on win32 is but clearly
+ * native name translation is not possible (eg libatasi.so on *nix, and
+ * atasi.dll on win32). For the purposes of testing, I have created a symbollic
+ * link called "libatasi.so" so that we can use native name-translation - a
+ * better solution will be needed. */
+static const char *ATALLA_LIBNAME = "atasi";
+static const char *ATALLA_F1 = "ASI_GetHardwareConfig";
+static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
+static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
+
 /* (de)initialisation functions. */
-static int atalla_init()
+static int atalla_init(void)
        {
        tfnASI_GetHardwareConfig *p1;
        tfnASI_RSAPrivateKeyOpFn *p2;
@@ -274,7 +288,7 @@ err:
        return 0;
        }
 
-static int atalla_finish()
+static int atalla_finish(void)
        {
        if(atalla_dso == NULL)
                {
@@ -317,11 +331,12 @@ static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                goto err;
        }
        /* Prepare the params */
+       BN_CTX_start(ctx);
        modulus = BN_CTX_get(ctx);
        exponent = BN_CTX_get(ctx);
        argument = BN_CTX_get(ctx);
        result = BN_CTX_get(ctx);
-       if(!modulus || !exponent || !argument || !result)
+       if (!result)
        {
                ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_BN_CTX_FULL);
                goto err;
@@ -359,10 +374,7 @@ static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
        BN_bin2bn((unsigned char *)result->d, numbytes, r);
        to_return = 1;
 err:
-       if(modulus) ctx->tos--;
-       if(exponent) ctx->tos--;
-       if(argument) ctx->tos--;
-       if(result) ctx->tos--;
+       BN_CTX_end(ctx);
        return to_return;
        }
 
@@ -433,11 +445,12 @@ static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
        }
 
 /* This function is aliased to mod_exp (with the dh and mont dropped). */
-static int atalla_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r,
+               const BIGNUM *a, const BIGNUM *p,
                const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
        {
        return atalla_mod_exp(r, a, p, m, ctx);
        }
 
-#endif /* !NO_HW_ATALLA */
-#endif /* !NO_HW */
+#endif /* !OPENSSL_NO_HW_ATALLA */
+#endif /* !OPENSSL_NO_HW */