OLD | NEW |
1 /* crypto/rand/rand_lib.c */ | 1 /* crypto/rand/rand_lib.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 * The licence and distribution terms for any publically available version or | 53 * The licence and distribution terms for any publically available version or |
54 * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 * copied and put under another distribution licence | 55 * copied and put under another distribution licence |
56 * [including the GNU Public Licence.] | 56 * [including the GNU Public Licence.] |
57 */ | 57 */ |
58 | 58 |
59 #include <stdio.h> | 59 #include <stdio.h> |
60 #include <time.h> | 60 #include <time.h> |
61 #include "cryptlib.h" | 61 #include "cryptlib.h" |
62 #include <openssl/rand.h> | 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 | |
69 #ifndef OPENSSL_NO_ENGINE | 63 #ifndef OPENSSL_NO_ENGINE |
70 #include <openssl/engine.h> | 64 #include <openssl/engine.h> |
71 #endif | 65 #endif |
72 | 66 |
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 | |
135 #ifndef OPENSSL_NO_ENGINE | 67 #ifndef OPENSSL_NO_ENGINE |
136 /* non-NULL if default_RAND_meth is ENGINE-provided */ | 68 /* non-NULL if default_RAND_meth is ENGINE-provided */ |
137 static ENGINE *funct_ref =NULL; | 69 static ENGINE *funct_ref =NULL; |
138 #endif | 70 #endif |
| 71 static const RAND_METHOD *default_RAND_meth = NULL; |
139 | 72 |
140 int RAND_set_rand_method(const RAND_METHOD *meth) | 73 int RAND_set_rand_method(const RAND_METHOD *meth) |
141 { | 74 { |
142 #ifndef OPENSSL_NO_ENGINE | 75 #ifndef OPENSSL_NO_ENGINE |
143 if(funct_ref) | 76 if(funct_ref) |
144 { | 77 { |
145 ENGINE_finish(funct_ref); | 78 ENGINE_finish(funct_ref); |
146 funct_ref = NULL; | 79 funct_ref = NULL; |
147 } | 80 } |
148 #endif | 81 #endif |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return 0; | 122 return 0; |
190 } | 123 } |
191 } | 124 } |
192 /* This function releases any prior ENGINE so call it first */ | 125 /* This function releases any prior ENGINE so call it first */ |
193 RAND_set_rand_method(tmp_meth); | 126 RAND_set_rand_method(tmp_meth); |
194 funct_ref = engine; | 127 funct_ref = engine; |
195 return 1; | 128 return 1; |
196 } | 129 } |
197 #endif | 130 #endif |
198 | 131 |
199 #endif | |
200 | |
201 void RAND_cleanup(void) | 132 void RAND_cleanup(void) |
202 { | 133 { |
203 const RAND_METHOD *meth = RAND_get_rand_method(); | 134 const RAND_METHOD *meth = RAND_get_rand_method(); |
204 if (meth && meth->cleanup) | 135 if (meth && meth->cleanup) |
205 meth->cleanup(); | 136 meth->cleanup(); |
206 RAND_set_rand_method(NULL); | 137 RAND_set_rand_method(NULL); |
207 } | 138 } |
208 | 139 |
209 void RAND_seed(const void *buf, int num) | 140 void RAND_seed(const void *buf, int num) |
210 { | 141 { |
(...skipping 25 matching lines...) Expand all Loading... |
236 return(-1); | 167 return(-1); |
237 } | 168 } |
238 | 169 |
239 int RAND_status(void) | 170 int RAND_status(void) |
240 { | 171 { |
241 const RAND_METHOD *meth = RAND_get_rand_method(); | 172 const RAND_METHOD *meth = RAND_get_rand_method(); |
242 if (meth && meth->status) | 173 if (meth && meth->status) |
243 return meth->status(); | 174 return meth->status(); |
244 return 0; | 175 return 0; |
245 } | 176 } |
OLD | NEW |