X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=engines%2Fe_aep.c;h=742b4f9b186dea01a64567568781fa4dec93aecb;hp=3bb979a5f1560fbc4a6da803026445a38e0ca720;hb=6b3bf0edf3b22e0f8f4de2f831cc4ed89b503e7c;hpb=4ebb5293fc7ae1fbb7c5cd8bbe114049bcd8685e diff --git a/engines/e_aep.c b/engines/e_aep.c index 3bb979a5f1..742b4f9b18 100644 --- a/engines/e_aep.c +++ b/engines/e_aep.c @@ -1,6 +1,3 @@ -/* crypto/engine/hw_aep.c */ -/* - */ /* ==================================================================== * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * @@ -60,7 +57,7 @@ #include #include -#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__) +#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__) || defined(__MINGW32__) #include #include #else @@ -68,10 +65,25 @@ typedef int pid_t; #endif +#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) +#define getpid GetThreadID +extern int GetThreadID(void); +#endif + #include #include #include #include +#ifndef OPENSSL_NO_RSA +#include +#endif +#ifndef OPENSSL_NO_DSA +#include +#endif +#ifndef OPENSSL_NO_DH +#include +#endif +#include #ifndef OPENSSL_NO_HW #ifndef OPENSSL_NO_HW_AEP @@ -88,7 +100,7 @@ typedef int pid_t; static int aep_init(ENGINE *e); static int aep_finish(ENGINE *e); -static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); +static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); static int aep_destroy(ENGINE *e); static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR hConnection); @@ -97,21 +109,25 @@ static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection); static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use); /* BIGNUM stuff */ +#ifndef OPENSSL_NO_RSA static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx); static AEP_RV aep_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); +#endif /* RSA stuff */ #ifndef OPENSSL_NO_RSA -static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); +static int aep_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). */ +#ifndef OPENSSL_NO_RSA static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +#endif /* DSA stuff */ #ifndef OPENSSL_NO_DSA @@ -190,7 +206,9 @@ static DSA_METHOD aep_dsa = NULL, /* init */ NULL, /* finish */ 0, /* flags */ - NULL /* app_data */ + NULL, /* app_data */ + NULL, /* dsa_paramgen */ + NULL /* dsa_keygen */ }; #endif @@ -205,6 +223,7 @@ static DH_METHOD aep_dh = NULL, NULL, 0, + NULL, NULL }; #endif @@ -475,6 +494,7 @@ static int aep_init(ENGINE *e) if(aep_dso) DSO_free(aep_dso); + aep_dso = NULL; p_AEP_OpenConnection = NULL; p_AEP_ModExp = NULL; @@ -551,7 +571,7 @@ static int aep_finish(ENGINE *e) return to_return; } -static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) +static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) { int initialised = ((aep_dso == NULL) ? 0 : 1); switch(cmd) @@ -616,7 +636,7 @@ static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, rv = aep_return_connection(hConnection); if (rv != AEP_R_OK) { - AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED); + AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_RETURN_CONNECTION_FAILED); goto err; } @@ -625,6 +645,7 @@ static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, return to_return; } +#ifndef OPENSSL_NO_RSA static AEP_RV aep_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) @@ -654,13 +675,14 @@ static AEP_RV aep_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, rv = aep_return_connection(hConnection); if (rv != AEP_R_OK) { - AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED); + AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_RETURN_CONNECTION_FAILED); goto err; } err: return rv; } +#endif #ifdef AEPRAND @@ -742,15 +764,11 @@ static int aep_rand_status(void) #endif #ifndef OPENSSL_NO_RSA -static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) +static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) { - BN_CTX *ctx = NULL; int to_return = 0; AEP_RV rv = AEP_R_OK; - if ((ctx = BN_CTX_new()) == NULL) - goto err; - if (!aep_dso) { AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_NOT_LOADED); @@ -764,7 +782,7 @@ static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) if (rv == FAIL_TO_SW){ const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); - to_return = (*meth->rsa_mod_exp)(r0, I, rsa); + to_return = (*meth->rsa_mod_exp)(r0, I, rsa, ctx); goto err; } else if (rv != AEP_R_OK) @@ -787,8 +805,6 @@ static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) to_return = 1; err: - if(ctx) - BN_CTX_free(ctx); return to_return; } #endif @@ -822,12 +838,14 @@ static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, } #endif +#ifndef OPENSSL_NO_RSA /* This function is aliased to mod_exp (with the mont stuff dropped). */ static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) { return aep_mod_exp(r, a, p, m, ctx); } +#endif #ifndef OPENSSL_NO_DH /* This function is aliased to mod_exp (with the dh and mont dropped). */ @@ -849,7 +867,13 @@ static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection) CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); +#ifdef NETWARE_CLIB + curr_pid = GetThreadID(); +#elif defined(_WIN32) + curr_pid = _getpid(); +#else curr_pid = getpid(); +#endif /*Check if this is the first time this is being called from the current process*/