~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to crypto/cryptlib.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Martin
  • Date: 2004-12-16 18:41:29 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041216184129-z7xjkul57mh1jiha
Tags: upstream-0.9.7e
ImportĀ upstreamĀ versionĀ 0.9.7e

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
        "engine",
106
106
        "ui",
107
107
        "hwcrhk",               /* This is a HACK which will disappear in 0.9.8 */
108
 
#if CRYPTO_NUM_LOCKS != 33
 
108
        "fips",
 
109
        "fips2",
 
110
#if CRYPTO_NUM_LOCKS != 35
109
111
# error "Inconsistency between crypto.h and cryptlib.c"
110
112
#endif
111
113
        };
512
514
                file,line,assertion);
513
515
        abort();
514
516
        }
 
517
 
 
518
#ifdef OPENSSL_FIPS
 
519
static int fips_started = 0;
 
520
static int fips_mode = 0;
 
521
static void *fips_rand_check = 0;
 
522
static unsigned long fips_thread = 0;
 
523
 
 
524
void fips_set_started(void)
 
525
        {
 
526
        fips_started = 1;
 
527
        }
 
528
 
 
529
int fips_is_started(void)
 
530
        {
 
531
        return fips_started;
 
532
        }
 
533
 
 
534
int fips_is_owning_thread(void)
 
535
        {
 
536
        int ret = 0;
 
537
 
 
538
        if (fips_is_started())
 
539
                {
 
540
                CRYPTO_r_lock(CRYPTO_LOCK_FIPS2);
 
541
                if (fips_thread != 0 && fips_thread == CRYPTO_thread_id())
 
542
                        ret = 1;
 
543
                CRYPTO_r_unlock(CRYPTO_LOCK_FIPS2);
 
544
                }
 
545
        return ret;
 
546
        }
 
547
 
 
548
int fips_set_owning_thread(void)
 
549
        {
 
550
        int ret = 0;
 
551
 
 
552
        if (fips_is_started())
 
553
                {
 
554
                CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
 
555
                if (fips_thread == 0)
 
556
                        {
 
557
                        fips_thread = CRYPTO_thread_id();
 
558
                        ret = 1;
 
559
                        }
 
560
                CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
 
561
                }
 
562
        return ret;
 
563
        }
 
564
 
 
565
int fips_clear_owning_thread(void)
 
566
        {
 
567
        int ret = 0;
 
568
 
 
569
        if (fips_is_started())
 
570
                {
 
571
                CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
 
572
                if (fips_thread == CRYPTO_thread_id())
 
573
                        {
 
574
                        fips_thread = 0;
 
575
                        ret = 1;
 
576
                        }
 
577
                CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
 
578
                }
 
579
        return ret;
 
580
        }
 
581
 
 
582
void fips_set_mode(int onoff)
 
583
        {
 
584
        int owning_thread = fips_is_owning_thread();
 
585
 
 
586
        if (fips_is_started())
 
587
                {
 
588
                if (!owning_thread) CRYPTO_w_lock(CRYPTO_LOCK_FIPS);
 
589
                fips_mode = onoff;
 
590
                if (!owning_thread) CRYPTO_w_unlock(CRYPTO_LOCK_FIPS);
 
591
                }
 
592
        }
 
593
 
 
594
void fips_set_rand_check(void *rand_check)
 
595
        {
 
596
        int owning_thread = fips_is_owning_thread();
 
597
 
 
598
        if (fips_is_started())
 
599
                {
 
600
                if (!owning_thread) CRYPTO_w_lock(CRYPTO_LOCK_FIPS);
 
601
                fips_rand_check = rand_check;
 
602
                if (!owning_thread) CRYPTO_w_unlock(CRYPTO_LOCK_FIPS);
 
603
                }
 
604
        }
 
605
 
 
606
int FIPS_mode(void)
 
607
        {
 
608
        int ret = 0;
 
609
        int owning_thread = fips_is_owning_thread();
 
610
 
 
611
        if (fips_is_started())
 
612
                {
 
613
                if (!owning_thread) CRYPTO_r_lock(CRYPTO_LOCK_FIPS);
 
614
                ret = fips_mode;
 
615
                if (!owning_thread) CRYPTO_r_unlock(CRYPTO_LOCK_FIPS);
 
616
                }
 
617
        return ret;
 
618
        }
 
619
 
 
620
void *FIPS_rand_check(void)
 
621
        {
 
622
        void *ret = 0;
 
623
        int owning_thread = fips_is_owning_thread();
 
624
 
 
625
        if (fips_is_started())
 
626
                {
 
627
                if (!owning_thread) CRYPTO_r_lock(CRYPTO_LOCK_FIPS);
 
628
                ret = fips_rand_check;
 
629
                if (!owning_thread) CRYPTO_r_unlock(CRYPTO_LOCK_FIPS);
 
630
                }
 
631
        return ret;
 
632
        }
 
633
 
 
634
#endif /* OPENSSL_FIPS */
 
635