summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cryptlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/cryptlib.c')
-rw-r--r--src/lib/libcrypto/cryptlib.c130
1 files changed, 6 insertions, 124 deletions
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
index fef0afb29f..2924def2bb 100644
--- a/src/lib/libcrypto/cryptlib.c
+++ b/src/lib/libcrypto/cryptlib.c
@@ -105,9 +105,7 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] =
105 "engine", 105 "engine",
106 "ui", 106 "ui",
107 "hwcrhk", /* This is a HACK which will disappear in 0.9.8 */ 107 "hwcrhk", /* This is a HACK which will disappear in 0.9.8 */
108 "fips", 108#if CRYPTO_NUM_LOCKS != 33
109 "fips2",
110#if CRYPTO_NUM_LOCKS != 35
111# error "Inconsistency between crypto.h and cryptlib.c" 109# error "Inconsistency between crypto.h and cryptlib.c"
112#endif 110#endif
113 }; 111 };
@@ -480,12 +478,13 @@ const char *CRYPTO_get_lock_name(int type)
480 return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS)); 478 return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS));
481 } 479 }
482 480
483#if defined(_WIN32) && defined(_WINDLL) 481#ifdef _DLL
482#ifdef OPENSSL_SYS_WIN32
484 483
485/* All we really need to do is remove the 'error' state when a thread 484/* All we really need to do is remove the 'error' state when a thread
486 * detaches */ 485 * detaches */
487 486
488BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, 487BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason,
489 LPVOID lpvReserved) 488 LPVOID lpvReserved)
490 { 489 {
491 switch(fdwReason) 490 switch(fdwReason)
@@ -504,6 +503,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
504 } 503 }
505#endif 504#endif
506 505
506#endif
507
507void OpenSSLDie(const char *file,int line,const char *assertion) 508void OpenSSLDie(const char *file,int line,const char *assertion)
508 { 509 {
509 fprintf(stderr, 510 fprintf(stderr,
@@ -511,122 +512,3 @@ void OpenSSLDie(const char *file,int line,const char *assertion)
511 file,line,assertion); 512 file,line,assertion);
512 abort(); 513 abort();
513 } 514 }
514
515#ifdef OPENSSL_FIPS
516static int fips_started = 0;
517static int fips_mode = 0;
518static void *fips_rand_check = 0;
519static unsigned long fips_thread = 0;
520
521void fips_set_started(void)
522 {
523 fips_started = 1;
524 }
525
526int fips_is_started(void)
527 {
528 return fips_started;
529 }
530
531int fips_is_owning_thread(void)
532 {
533 int ret = 0;
534
535 if (fips_is_started())
536 {
537 CRYPTO_r_lock(CRYPTO_LOCK_FIPS2);
538 if (fips_thread != 0 && fips_thread == CRYPTO_thread_id())
539 ret = 1;
540 CRYPTO_r_unlock(CRYPTO_LOCK_FIPS2);
541 }
542 return ret;
543 }
544
545int fips_set_owning_thread(void)
546 {
547 int ret = 0;
548
549 if (fips_is_started())
550 {
551 CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
552 if (fips_thread == 0)
553 {
554 fips_thread = CRYPTO_thread_id();
555 ret = 1;
556 }
557 CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
558 }
559 return ret;
560 }
561
562int fips_clear_owning_thread(void)
563 {
564 int ret = 0;
565
566 if (fips_is_started())
567 {
568 CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
569 if (fips_thread == CRYPTO_thread_id())
570 {
571 fips_thread = 0;
572 ret = 1;
573 }
574 CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
575 }
576 return ret;
577 }
578
579void fips_set_mode(int onoff)
580 {
581 int owning_thread = fips_is_owning_thread();
582
583 if (fips_is_started())
584 {
585 if (!owning_thread) CRYPTO_w_lock(CRYPTO_LOCK_FIPS);
586 fips_mode = onoff;
587 if (!owning_thread) CRYPTO_w_unlock(CRYPTO_LOCK_FIPS);
588 }
589 }
590
591void fips_set_rand_check(void *rand_check)
592 {
593 int owning_thread = fips_is_owning_thread();
594
595 if (fips_is_started())
596 {
597 if (!owning_thread) CRYPTO_w_lock(CRYPTO_LOCK_FIPS);
598 fips_rand_check = rand_check;
599 if (!owning_thread) CRYPTO_w_unlock(CRYPTO_LOCK_FIPS);
600 }
601 }
602
603int FIPS_mode(void)
604 {
605 int ret = 0;
606 int owning_thread = fips_is_owning_thread();
607
608 if (fips_is_started())
609 {
610 if (!owning_thread) CRYPTO_r_lock(CRYPTO_LOCK_FIPS);
611 ret = fips_mode;
612 if (!owning_thread) CRYPTO_r_unlock(CRYPTO_LOCK_FIPS);
613 }
614 return ret;
615 }
616
617void *FIPS_rand_check(void)
618 {
619 void *ret = 0;
620 int owning_thread = fips_is_owning_thread();
621
622 if (fips_is_started())
623 {
624 if (!owning_thread) CRYPTO_r_lock(CRYPTO_LOCK_FIPS);
625 ret = fips_rand_check;
626 if (!owning_thread) CRYPTO_r_unlock(CRYPTO_LOCK_FIPS);
627 }
628 return ret;
629 }
630
631#endif /* OPENSSL_FIPS */
632