From 68edd00d9258df93b1366c71ac124e0cadf7bc08 Mon Sep 17 00:00:00 2001 From: djm <> Date: Fri, 29 Apr 2005 05:39:33 +0000 Subject: resolve conflicts --- src/lib/libcrypto/cryptlib.c | 130 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 124 insertions(+), 6 deletions(-) (limited to 'src/lib/libcrypto/cryptlib.c') diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c index 2924def2bb..fef0afb29f 100644 --- a/src/lib/libcrypto/cryptlib.c +++ b/src/lib/libcrypto/cryptlib.c @@ -105,7 +105,9 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] = "engine", "ui", "hwcrhk", /* This is a HACK which will disappear in 0.9.8 */ -#if CRYPTO_NUM_LOCKS != 33 + "fips", + "fips2", +#if CRYPTO_NUM_LOCKS != 35 # error "Inconsistency between crypto.h and cryptlib.c" #endif }; @@ -478,13 +480,12 @@ const char *CRYPTO_get_lock_name(int type) return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS)); } -#ifdef _DLL -#ifdef OPENSSL_SYS_WIN32 +#if defined(_WIN32) && defined(_WINDLL) /* All we really need to do is remove the 'error' state when a thread * detaches */ -BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch(fdwReason) @@ -503,8 +504,6 @@ BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, } #endif -#endif - void OpenSSLDie(const char *file,int line,const char *assertion) { fprintf(stderr, @@ -512,3 +511,122 @@ void OpenSSLDie(const char *file,int line,const char *assertion) file,line,assertion); abort(); } + +#ifdef OPENSSL_FIPS +static int fips_started = 0; +static int fips_mode = 0; +static void *fips_rand_check = 0; +static unsigned long fips_thread = 0; + +void fips_set_started(void) + { + fips_started = 1; + } + +int fips_is_started(void) + { + return fips_started; + } + +int fips_is_owning_thread(void) + { + int ret = 0; + + if (fips_is_started()) + { + CRYPTO_r_lock(CRYPTO_LOCK_FIPS2); + if (fips_thread != 0 && fips_thread == CRYPTO_thread_id()) + ret = 1; + CRYPTO_r_unlock(CRYPTO_LOCK_FIPS2); + } + return ret; + } + +int fips_set_owning_thread(void) + { + int ret = 0; + + if (fips_is_started()) + { + CRYPTO_w_lock(CRYPTO_LOCK_FIPS2); + if (fips_thread == 0) + { + fips_thread = CRYPTO_thread_id(); + ret = 1; + } + CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2); + } + return ret; + } + +int fips_clear_owning_thread(void) + { + int ret = 0; + + if (fips_is_started()) + { + CRYPTO_w_lock(CRYPTO_LOCK_FIPS2); + if (fips_thread == CRYPTO_thread_id()) + { + fips_thread = 0; + ret = 1; + } + CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2); + } + return ret; + } + +void fips_set_mode(int onoff) + { + int owning_thread = fips_is_owning_thread(); + + if (fips_is_started()) + { + if (!owning_thread) CRYPTO_w_lock(CRYPTO_LOCK_FIPS); + fips_mode = onoff; + if (!owning_thread) CRYPTO_w_unlock(CRYPTO_LOCK_FIPS); + } + } + +void fips_set_rand_check(void *rand_check) + { + int owning_thread = fips_is_owning_thread(); + + if (fips_is_started()) + { + if (!owning_thread) CRYPTO_w_lock(CRYPTO_LOCK_FIPS); + fips_rand_check = rand_check; + if (!owning_thread) CRYPTO_w_unlock(CRYPTO_LOCK_FIPS); + } + } + +int FIPS_mode(void) + { + int ret = 0; + int owning_thread = fips_is_owning_thread(); + + if (fips_is_started()) + { + if (!owning_thread) CRYPTO_r_lock(CRYPTO_LOCK_FIPS); + ret = fips_mode; + if (!owning_thread) CRYPTO_r_unlock(CRYPTO_LOCK_FIPS); + } + return ret; + } + +void *FIPS_rand_check(void) + { + void *ret = 0; + int owning_thread = fips_is_owning_thread(); + + if (fips_is_started()) + { + if (!owning_thread) CRYPTO_r_lock(CRYPTO_LOCK_FIPS); + ret = fips_rand_check; + if (!owning_thread) CRYPTO_r_unlock(CRYPTO_LOCK_FIPS); + } + return ret; + } + +#endif /* OPENSSL_FIPS */ + -- cgit v1.2.3-55-g6feb