~ubuntu-branches/ubuntu/lucid/openssl/lucid-proposed

« back to all changes in this revision

Viewing changes to crypto/rand/rand_lib.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2009-06-13 18:15:46 UTC
  • mto: (11.1.5 squeeze)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20090613181546-vbfntai3b009dl1u
Tags: upstream-0.9.8k
ImportĀ upstreamĀ versionĀ 0.9.8k

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
#include <time.h>
61
61
#include "cryptlib.h"
62
62
#include <openssl/rand.h>
 
63
#include "rand_lcl.h"
 
64
#ifdef OPENSSL_FIPS
 
65
#include <openssl/fips.h>
 
66
#include <openssl/fips_rand.h>
 
67
#endif
 
68
 
63
69
#ifndef OPENSSL_NO_ENGINE
64
70
#include <openssl/engine.h>
65
71
#endif
66
72
 
 
73
static const RAND_METHOD *default_RAND_meth = NULL;
 
74
 
 
75
#ifdef OPENSSL_FIPS
 
76
 
 
77
static int fips_RAND_set_rand_method(const RAND_METHOD *meth,
 
78
                                        const RAND_METHOD **pmeth)
 
79
        {
 
80
        *pmeth = meth;
 
81
        return 1;
 
82
        }
 
83
 
 
84
static const RAND_METHOD *fips_RAND_get_rand_method(const RAND_METHOD **pmeth)
 
85
        {
 
86
        if (!*pmeth)
 
87
                {
 
88
                if(FIPS_mode())
 
89
                        *pmeth=FIPS_rand_method();
 
90
                else
 
91
                        *pmeth = RAND_SSLeay();
 
92
                }
 
93
 
 
94
        if(FIPS_mode()
 
95
                && *pmeth != FIPS_rand_check())
 
96
            {
 
97
            RANDerr(RAND_F_FIPS_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD);
 
98
            return 0;
 
99
            }
 
100
 
 
101
        return *pmeth;
 
102
        }
 
103
 
 
104
static int (*RAND_set_rand_method_func)(const RAND_METHOD *meth,
 
105
                                                const RAND_METHOD **pmeth)
 
106
        = fips_RAND_set_rand_method;
 
107
static const RAND_METHOD *(*RAND_get_rand_method_func)
 
108
                                                (const RAND_METHOD **pmeth)
 
109
        = fips_RAND_get_rand_method;
 
110
 
 
111
#ifndef OPENSSL_NO_ENGINE
 
112
void int_RAND_set_callbacks(
 
113
        int (*set_rand_func)(const RAND_METHOD *meth,
 
114
                                                const RAND_METHOD **pmeth),
 
115
        const RAND_METHOD *(*get_rand_func)
 
116
                                                (const RAND_METHOD **pmeth))
 
117
        {
 
118
        RAND_set_rand_method_func = set_rand_func;
 
119
        RAND_get_rand_method_func = get_rand_func;
 
120
        }
 
121
#endif
 
122
 
 
123
int RAND_set_rand_method(const RAND_METHOD *meth)
 
124
        {
 
125
        return RAND_set_rand_method_func(meth, &default_RAND_meth);
 
126
        }
 
127
 
 
128
const RAND_METHOD *RAND_get_rand_method(void)
 
129
        {
 
130
        return RAND_get_rand_method_func(&default_RAND_meth);
 
131
        }
 
132
 
 
133
#else
 
134
 
67
135
#ifndef OPENSSL_NO_ENGINE
68
136
/* non-NULL if default_RAND_meth is ENGINE-provided */
69
137
static ENGINE *funct_ref =NULL;
70
138
#endif
71
 
static const RAND_METHOD *default_RAND_meth = NULL;
72
139
 
73
140
int RAND_set_rand_method(const RAND_METHOD *meth)
74
141
        {
129
196
        }
130
197
#endif
131
198
 
 
199
#endif
 
200
 
132
201
void RAND_cleanup(void)
133
202
        {
134
203
        const RAND_METHOD *meth = RAND_get_rand_method();