#include "engine_int.h"
#include <openssl/engine.h>
-#ifndef NO_HW
-#ifndef NO_HW_CSWIFT
+#ifndef OPENSSL_NO_HW
+#ifndef OPENSSL_NO_HW_CSWIFT
/* Attribution notice: Rainbow have generously allowed me to reproduce
* the necessary definitions here from their API. This means the support
static int cswift_finish(void);
/* BIGNUM stuff */
-static int cswift_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx);
-static int cswift_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1,
const BIGNUM *iqmp, BN_CTX *ctx);
/* RSA stuff */
-static int cswift_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa);
+static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
/* This function is aliased to mod_exp (with the mont stuff dropped). */
-static int cswift_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
/* DSA stuff */
/* DH stuff */
/* This function is alised to mod_exp (with the DH and mont dropped). */
-static int cswift_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int cswift_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);
* (indeed - the lock will already be held by our caller!!!) */
ENGINE *ENGINE_cswift()
{
- RSA_METHOD *meth1;
- DH_METHOD *meth2;
+ const RSA_METHOD *meth1;
+ const DH_METHOD *meth2;
/* We know that the "PKCS1_SSLeay()" functions hook properly
* to the cswift-specific mod_exp and mod_exp_crt so we use
}
/* (de)initialisation functions. */
-static int cswift_init()
+static int cswift_init(void)
{
SW_CONTEXT_HANDLE hac;
t_swAcquireAccContext *p1;
return 0;
}
-static int cswift_finish()
+static int cswift_finish(void)
{
if(cswift_dso == NULL)
{
}
/* Un petit mod_exp */
-static int cswift_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx)
{
/* I need somewhere to store temporary serialised values for
}
acquired = 1;
/* 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_CSWIFT_MOD_EXP,ENGINE_R_BN_CTX_FULL);
goto err;
err:
if(acquired)
release_context(hac);
- if(modulus) ctx->tos--;
- if(exponent) ctx->tos--;
- if(argument) ctx->tos--;
- if(result) ctx->tos--;
+ BN_CTX_end(ctx);
return to_return;
}
/* Un petit mod_exp chinois */
-static int cswift_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *q, const BIGNUM *dmp1,
const BIGNUM *dmq1, const BIGNUM *iqmp, BN_CTX *ctx)
{
}
acquired = 1;
/* Prepare the params */
+ BN_CTX_start(ctx);
rsa_p = BN_CTX_get(ctx);
rsa_q = BN_CTX_get(ctx);
rsa_dmp1 = BN_CTX_get(ctx);
rsa_iqmp = BN_CTX_get(ctx);
argument = BN_CTX_get(ctx);
result = BN_CTX_get(ctx);
- if(!rsa_p || !rsa_q || !rsa_dmp1 || !rsa_dmq1 || !rsa_iqmp ||
- !argument || !result)
+ if(!result)
{
ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_BN_CTX_FULL);
goto err;
err:
if(acquired)
release_context(hac);
- if(rsa_p) ctx->tos--;
- if(rsa_q) ctx->tos--;
- if(rsa_dmp1) ctx->tos--;
- if(rsa_dmq1) ctx->tos--;
- if(rsa_iqmp) ctx->tos--;
- if(argument) ctx->tos--;
- if(result) ctx->tos--;
+ BN_CTX_end(ctx);
return to_return;
}
-static int cswift_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
+static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
{
BN_CTX *ctx;
int to_return = 0;
}
/* This function is aliased to mod_exp (with the mont stuff dropped). */
-static int cswift_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
{
return cswift_mod_exp(r, a, p, m, ctx);
}
acquired = 1;
/* Prepare the params */
+ BN_CTX_start(ctx);
dsa_p = BN_CTX_get(ctx);
dsa_q = BN_CTX_get(ctx);
dsa_g = BN_CTX_get(ctx);
dsa_key = BN_CTX_get(ctx);
result = BN_CTX_get(ctx);
- if(!dsa_p || !dsa_q || !dsa_g || !dsa_key || !result)
+ if(!result)
{
ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_BN_CTX_FULL);
goto err;
err:
if(acquired)
release_context(hac);
- if(dsa_p) ctx->tos--;
- if(dsa_q) ctx->tos--;
- if(dsa_g) ctx->tos--;
- if(dsa_key) ctx->tos--;
- if(result) ctx->tos--;
if(ctx)
+ {
+ BN_CTX_end(ctx);
BN_CTX_free(ctx);
+ }
return to_return;
}
}
acquired = 1;
/* Prepare the params */
+ BN_CTX_start(ctx);
dsa_p = BN_CTX_get(ctx);
dsa_q = BN_CTX_get(ctx);
dsa_g = BN_CTX_get(ctx);
dsa_key = BN_CTX_get(ctx);
argument = BN_CTX_get(ctx);
- if(!dsa_p || !dsa_q || !dsa_g || !dsa_key || !argument)
+ if(!argument)
{
ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_BN_CTX_FULL);
goto err;
err:
if(acquired)
release_context(hac);
- if(dsa_p) ctx->tos--;
- if(dsa_q) ctx->tos--;
- if(dsa_g) ctx->tos--;
- if(dsa_key) ctx->tos--;
- if(argument) ctx->tos--;
if(ctx)
+ {
+ BN_CTX_end(ctx);
BN_CTX_free(ctx);
+ }
return to_return;
}
/* This function is aliased to mod_exp (with the dh and mont dropped). */
-static int cswift_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
+static int cswift_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 cswift_mod_exp(r, a, p, m, ctx);
}
-#endif /* !NO_HW_CSWIFT */
-#endif /* !NO_HW */
+#endif /* !OPENSSL_NO_HW_CSWIFT */
+#endif /* !OPENSSL_NO_HW */