Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rand/rand_lib.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | static ENGINE *funct_ref; | - | ||||||||||||
6 | static CRYPTO_RWLOCK *rand_engine_lock; | - | ||||||||||||
7 | - | |||||||||||||
8 | static CRYPTO_RWLOCK *rand_meth_lock; | - | ||||||||||||
9 | static const RAND_METHOD *default_RAND_meth; | - | ||||||||||||
10 | static CRYPTO_ONCE rand_init = | - | ||||||||||||
11 | 0 | - | ||||||||||||
12 | ; | - | ||||||||||||
13 | - | |||||||||||||
14 | int rand_fork_count; | - | ||||||||||||
15 | - | |||||||||||||
16 | static CRYPTO_RWLOCK *rand_nonce_lock; | - | ||||||||||||
17 | static int rand_nonce_count; | - | ||||||||||||
18 | - | |||||||||||||
19 | static int rand_cleaning_up = 0; | - | ||||||||||||
20 | size_t rand_drbg_get_entropy(RAND_DRBG *drbg, | - | ||||||||||||
21 | unsigned char **pout, | - | ||||||||||||
22 | int entropy, size_t min_len, size_t max_len, | - | ||||||||||||
23 | int prediction_resistance) | - | ||||||||||||
24 | { | - | ||||||||||||
25 | size_t ret = 0; | - | ||||||||||||
26 | size_t entropy_available = 0; | - | ||||||||||||
27 | RAND_POOL *pool; | - | ||||||||||||
28 | - | |||||||||||||
29 | if (drbg->parent
| 0-1057 | ||||||||||||
30 | - | |||||||||||||
31 | - | |||||||||||||
32 | - | |||||||||||||
33 | - | |||||||||||||
34 | ERR_put_error(36,(120),(131),__FILE__,145); | - | ||||||||||||
35 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
36 | } | - | ||||||||||||
37 | - | |||||||||||||
38 | pool = rand_pool_new(entropy, min_len, max_len); | - | ||||||||||||
39 | if (pool ==
| 0-1856 | ||||||||||||
40 | ((void *)0)
| 0-1856 | ||||||||||||
41 | ) | - | ||||||||||||
42 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
43 | - | |||||||||||||
44 | if (drbg->pool
| 19-1837 | ||||||||||||
45 | rand_pool_add(pool, | - | ||||||||||||
46 | rand_pool_buffer(drbg->pool), | - | ||||||||||||
47 | rand_pool_length(drbg->pool), | - | ||||||||||||
48 | rand_pool_entropy(drbg->pool)); | - | ||||||||||||
49 | rand_pool_free(drbg->pool); | - | ||||||||||||
50 | drbg->pool = | - | ||||||||||||
51 | ((void *)0) | - | ||||||||||||
52 | ; | - | ||||||||||||
53 | } executed 19 times by 1 test: end of block Executed by:
| 19 | ||||||||||||
54 | - | |||||||||||||
55 | if (drbg->parent
| 799-1057 | ||||||||||||
56 | size_t bytes_needed = rand_pool_bytes_needed(pool, 1 ); | - | ||||||||||||
57 | unsigned char *buffer = rand_pool_add_begin(pool, bytes_needed); | - | ||||||||||||
58 | - | |||||||||||||
59 | if (buffer !=
| 0-1057 | ||||||||||||
60 | ((void *)0)
| 0-1057 | ||||||||||||
61 | ) { | - | ||||||||||||
62 | size_t bytes = 0; | - | ||||||||||||
63 | - | |||||||||||||
64 | - | |||||||||||||
65 | - | |||||||||||||
66 | - | |||||||||||||
67 | - | |||||||||||||
68 | - | |||||||||||||
69 | - | |||||||||||||
70 | rand_drbg_lock(drbg->parent); | - | ||||||||||||
71 | if (RAND_DRBG_generate(drbg->parent,
| 2-1055 | ||||||||||||
72 | buffer, bytes_needed,
| 2-1055 | ||||||||||||
73 | prediction_resistance,
| 2-1055 | ||||||||||||
74 |
| 2-1055 | ||||||||||||
75 | ((void *)0)
| 2-1055 | ||||||||||||
76 | , 0) != 0
| 2-1055 | ||||||||||||
77 | bytes = bytes_needed; executed 1055 times by 2 tests: bytes = bytes_needed; Executed by:
| 1055 | ||||||||||||
78 | rand_drbg_unlock(drbg->parent); | - | ||||||||||||
79 | - | |||||||||||||
80 | rand_pool_add_end(pool, bytes, 8 * bytes); | - | ||||||||||||
81 | entropy_available = rand_pool_entropy_available(pool); | - | ||||||||||||
82 | } executed 1057 times by 2 tests: end of block Executed by:
| 1057 | ||||||||||||
83 | - | |||||||||||||
84 | } executed 1057 times by 2 tests: else {end of block Executed by:
| 1057 | ||||||||||||
85 | if (prediction_resistance
| 0-799 | ||||||||||||
86 | - | |||||||||||||
87 | - | |||||||||||||
88 | - | |||||||||||||
89 | - | |||||||||||||
90 | - | |||||||||||||
91 | ERR_put_error(36,(120),(133),__FILE__,195) | - | ||||||||||||
92 | ; | - | ||||||||||||
93 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
94 | } | - | ||||||||||||
95 | - | |||||||||||||
96 | - | |||||||||||||
97 | entropy_available = rand_pool_acquire_entropy(pool); | - | ||||||||||||
98 | } executed 799 times by 2 tests: end of block Executed by:
| 799 | ||||||||||||
99 | - | |||||||||||||
100 | if (entropy_available > 0
| 2-1854 | ||||||||||||
101 | ret = rand_pool_length(pool); | - | ||||||||||||
102 | *pout = rand_pool_detach(pool); | - | ||||||||||||
103 | } executed 1854 times by 2 tests: end of block Executed by:
| 1854 | ||||||||||||
104 | - | |||||||||||||
105 | err: code before this statement executed 1856 times by 2 tests: err: Executed by:
| 1856 | ||||||||||||
106 | rand_pool_free(pool); | - | ||||||||||||
107 | return executed 1856 times by 2 tests: ret;return ret; Executed by:
executed 1856 times by 2 tests: return ret; Executed by:
| 1856 | ||||||||||||
108 | } | - | ||||||||||||
109 | - | |||||||||||||
110 | - | |||||||||||||
111 | - | |||||||||||||
112 | - | |||||||||||||
113 | - | |||||||||||||
114 | void rand_drbg_cleanup_entropy(RAND_DRBG *drbg, | - | ||||||||||||
115 | unsigned char *out, size_t outlen) | - | ||||||||||||
116 | { | - | ||||||||||||
117 | CRYPTO_secure_clear_free(out, outlen, __FILE__, 220); | - | ||||||||||||
118 | } executed 1854 times by 2 tests: end of block Executed by:
| 1854 | ||||||||||||
119 | - | |||||||||||||
120 | - | |||||||||||||
121 | - | |||||||||||||
122 | - | |||||||||||||
123 | - | |||||||||||||
124 | - | |||||||||||||
125 | size_t rand_drbg_get_nonce(RAND_DRBG *drbg, | - | ||||||||||||
126 | unsigned char **pout, | - | ||||||||||||
127 | int entropy, size_t min_len, size_t max_len) | - | ||||||||||||
128 | { | - | ||||||||||||
129 | size_t ret = 0; | - | ||||||||||||
130 | RAND_POOL *pool; | - | ||||||||||||
131 | - | |||||||||||||
132 | struct { | - | ||||||||||||
133 | void * instance; | - | ||||||||||||
134 | int count; | - | ||||||||||||
135 | } data = { 0 }; | - | ||||||||||||
136 | - | |||||||||||||
137 | pool = rand_pool_new(0, min_len, max_len); | - | ||||||||||||
138 | if (pool ==
| 0-781 | ||||||||||||
139 | ((void *)0)
| 0-781 | ||||||||||||
140 | ) | - | ||||||||||||
141 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
142 | - | |||||||||||||
143 | if (rand_pool_add_nonce_data(pool) == 0
| 0-781 | ||||||||||||
144 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
145 | - | |||||||||||||
146 | data.instance = drbg; | - | ||||||||||||
147 | CRYPTO_atomic_add(&rand_nonce_count, 1, &data.count, rand_nonce_lock); | - | ||||||||||||
148 | - | |||||||||||||
149 | if (rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0) == 0
| 0-781 | ||||||||||||
150 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
151 | - | |||||||||||||
152 | ret = rand_pool_length(pool); | - | ||||||||||||
153 | *pout = rand_pool_detach(pool); | - | ||||||||||||
154 | - | |||||||||||||
155 | err: code before this statement executed 781 times by 2 tests: err: Executed by:
| 781 | ||||||||||||
156 | rand_pool_free(pool); | - | ||||||||||||
157 | - | |||||||||||||
158 | return executed 781 times by 2 tests: ret;return ret; Executed by:
executed 781 times by 2 tests: return ret; Executed by:
| 781 | ||||||||||||
159 | } | - | ||||||||||||
160 | - | |||||||||||||
161 | - | |||||||||||||
162 | - | |||||||||||||
163 | - | |||||||||||||
164 | - | |||||||||||||
165 | void rand_drbg_cleanup_nonce(RAND_DRBG *drbg, | - | ||||||||||||
166 | unsigned char *out, size_t outlen) | - | ||||||||||||
167 | { | - | ||||||||||||
168 | CRYPTO_secure_clear_free(out, outlen, __FILE__, 269); | - | ||||||||||||
169 | } executed 781 times by 2 tests: end of block Executed by:
| 781 | ||||||||||||
170 | size_t rand_drbg_get_additional_data(unsigned char **pout, size_t max_len) | - | ||||||||||||
171 | { | - | ||||||||||||
172 | size_t ret = 0; | - | ||||||||||||
173 | RAND_POOL *pool; | - | ||||||||||||
174 | - | |||||||||||||
175 | pool = rand_pool_new(0, 0, max_len); | - | ||||||||||||
176 | if (pool ==
| 0-1047778 | ||||||||||||
177 | ((void *)0)
| 0-1047778 | ||||||||||||
178 | ) | - | ||||||||||||
179 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
180 | - | |||||||||||||
181 | if (rand_pool_add_additional_data(pool) == 0
| 0-1050211 | ||||||||||||
182 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
183 | - | |||||||||||||
184 | ret = rand_pool_length(pool); | - | ||||||||||||
185 | *pout = rand_pool_detach(pool); | - | ||||||||||||
186 | - | |||||||||||||
187 | err: code before this statement executed 1048880 times by 2 tests: err: Executed by:
| 1048880 | ||||||||||||
188 | rand_pool_free(pool); | - | ||||||||||||
189 | - | |||||||||||||
190 | return executed 1042930 times by 2 tests: ret;return ret; Executed by:
executed 1042930 times by 2 tests: return ret; Executed by:
| 1042930 | ||||||||||||
191 | } | - | ||||||||||||
192 | - | |||||||||||||
193 | void rand_drbg_cleanup_additional_data(unsigned char *out, size_t outlen) | - | ||||||||||||
194 | { | - | ||||||||||||
195 | CRYPTO_secure_clear_free(out, outlen, __FILE__, 305); | - | ||||||||||||
196 | } never executed: end of block | 0 | ||||||||||||
197 | - | |||||||||||||
198 | void rand_fork(void) | - | ||||||||||||
199 | { | - | ||||||||||||
200 | rand_fork_count++; | - | ||||||||||||
201 | } never executed: end of block | 0 | ||||||||||||
202 | - | |||||||||||||
203 | static int do_rand_init(void); static int do_rand_init_ossl_ret_ = 0; static void do_rand_init_ossl_(void) { do_rand_init_ossl_ret_ = do_rand_init(); } executed 2076 times by 12 tests: static int do_rand_init(void)end of block Executed by:
| 2076 | ||||||||||||
204 | { | - | ||||||||||||
205 | - | |||||||||||||
206 | rand_engine_lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||
207 | if (rand_engine_lock ==
| 0-2076 | ||||||||||||
208 | ((void *)0)
| 0-2076 | ||||||||||||
209 | ) | - | ||||||||||||
210 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
211 | - | |||||||||||||
212 | - | |||||||||||||
213 | rand_meth_lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||
214 | if (rand_meth_lock ==
| 0-2076 | ||||||||||||
215 | ((void *)0)
| 0-2076 | ||||||||||||
216 | ) | - | ||||||||||||
217 | goto never executed: err1;goto err1; never executed: goto err1; | 0 | ||||||||||||
218 | - | |||||||||||||
219 | rand_nonce_lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||
220 | if (rand_nonce_lock ==
| 0-2076 | ||||||||||||
221 | ((void *)0)
| 0-2076 | ||||||||||||
222 | ) | - | ||||||||||||
223 | goto never executed: err2;goto err2; never executed: goto err2; | 0 | ||||||||||||
224 | - | |||||||||||||
225 | if (!rand_cleaning_up
| 0-1150 | ||||||||||||
226 | goto never executed: err3;goto err3; never executed: goto err3; | 0 | ||||||||||||
227 | - | |||||||||||||
228 | return executed 2076 times by 12 tests: 1;return 1; Executed by:
executed 2076 times by 12 tests: return 1; Executed by:
| 2076 | ||||||||||||
229 | - | |||||||||||||
230 | err3: | - | ||||||||||||
231 | rand_pool_cleanup(); | - | ||||||||||||
232 | err2: code before this statement never executed: err2: | 0 | ||||||||||||
233 | CRYPTO_THREAD_lock_free(rand_meth_lock); | - | ||||||||||||
234 | rand_meth_lock = | - | ||||||||||||
235 | ((void *)0) | - | ||||||||||||
236 | ; | - | ||||||||||||
237 | err1: code before this statement never executed: err1: | 0 | ||||||||||||
238 | - | |||||||||||||
239 | CRYPTO_THREAD_lock_free(rand_engine_lock); | - | ||||||||||||
240 | rand_engine_lock = | - | ||||||||||||
241 | ((void *)0) | - | ||||||||||||
242 | ; | - | ||||||||||||
243 | - | |||||||||||||
244 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
245 | } | - | ||||||||||||
246 | - | |||||||||||||
247 | void rand_cleanup_int(void) | - | ||||||||||||
248 | { | - | ||||||||||||
249 | const RAND_METHOD *meth = default_RAND_meth; | - | ||||||||||||
250 | - | |||||||||||||
251 | rand_cleaning_up = 1; | - | ||||||||||||
252 | - | |||||||||||||
253 | if (meth !=
| 926-1150 | ||||||||||||
254 | ((void *)0)
| 926-1150 | ||||||||||||
255 | && meth->cleanup !=
| 0-1150 | ||||||||||||
256 | ((void *)0)
| 0-1150 | ||||||||||||
257 | ) | - | ||||||||||||
258 | meth->cleanup(); never executed: meth->cleanup(); | 0 | ||||||||||||
259 | RAND_set_rand_method( | - | ||||||||||||
260 | ((void *)0) | - | ||||||||||||
261 | ); | - | ||||||||||||
262 | rand_pool_cleanup(); | - | ||||||||||||
263 | - | |||||||||||||
264 | CRYPTO_THREAD_lock_free(rand_engine_lock); | - | ||||||||||||
265 | rand_engine_lock = | - | ||||||||||||
266 | ((void *)0) | - | ||||||||||||
267 | ; | - | ||||||||||||
268 | - | |||||||||||||
269 | CRYPTO_THREAD_lock_free(rand_meth_lock); | - | ||||||||||||
270 | rand_meth_lock = | - | ||||||||||||
271 | ((void *)0) | - | ||||||||||||
272 | ; | - | ||||||||||||
273 | CRYPTO_THREAD_lock_free(rand_nonce_lock); | - | ||||||||||||
274 | rand_nonce_lock = | - | ||||||||||||
275 | ((void *)0) | - | ||||||||||||
276 | ; | - | ||||||||||||
277 | } executed 2076 times by 12 tests: end of block Executed by:
| 2076 | ||||||||||||
278 | - | |||||||||||||
279 | - | |||||||||||||
280 | - | |||||||||||||
281 | - | |||||||||||||
282 | - | |||||||||||||
283 | void RAND_keep_random_devices_open(int keep) | - | ||||||||||||
284 | { | - | ||||||||||||
285 | rand_pool_keep_random_devices_open(keep); | - | ||||||||||||
286 | } never executed: end of block | 0 | ||||||||||||
287 | int RAND_poll(void) | - | ||||||||||||
288 | { | - | ||||||||||||
289 | int ret = 0; | - | ||||||||||||
290 | - | |||||||||||||
291 | RAND_POOL *pool = | - | ||||||||||||
292 | ((void *)0) | - | ||||||||||||
293 | ; | - | ||||||||||||
294 | - | |||||||||||||
295 | const RAND_METHOD *meth = RAND_get_rand_method(); | - | ||||||||||||
296 | - | |||||||||||||
297 | if (meth == RAND_OpenSSL()
| 0 | ||||||||||||
298 | - | |||||||||||||
299 | RAND_DRBG *drbg = RAND_DRBG_get0_master(); | - | ||||||||||||
300 | - | |||||||||||||
301 | if (drbg ==
| 0 | ||||||||||||
302 | ((void *)0)
| 0 | ||||||||||||
303 | ) | - | ||||||||||||
304 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
305 | - | |||||||||||||
306 | rand_drbg_lock(drbg); | - | ||||||||||||
307 | ret = rand_drbg_restart(drbg, | - | ||||||||||||
308 | ((void *)0) | - | ||||||||||||
309 | , 0, 0); | - | ||||||||||||
310 | rand_drbg_unlock(drbg); | - | ||||||||||||
311 | - | |||||||||||||
312 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||
313 | - | |||||||||||||
314 | } else { | - | ||||||||||||
315 | - | |||||||||||||
316 | pool = rand_pool_new(256, | - | ||||||||||||
317 | 256 / 8, | - | ||||||||||||
318 | 128 * (256 / 8)); | - | ||||||||||||
319 | if (pool ==
| 0 | ||||||||||||
320 | ((void *)0)
| 0 | ||||||||||||
321 | ) | - | ||||||||||||
322 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
323 | - | |||||||||||||
324 | if (rand_pool_acquire_entropy(pool) == 0
| 0 | ||||||||||||
325 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
326 | - | |||||||||||||
327 | if (meth->add ==
| 0 | ||||||||||||
328 | ((void *)0)
| 0 | ||||||||||||
329 | - | |||||||||||||
330 | || meth->add(rand_pool_buffer(pool),
| 0 | ||||||||||||
331 | rand_pool_length(pool),
| 0 | ||||||||||||
332 | (rand_pool_entropy(pool) / 8.0)) == 0
| 0 | ||||||||||||
333 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
334 | - | |||||||||||||
335 | ret = 1; | - | ||||||||||||
336 | } never executed: end of block | 0 | ||||||||||||
337 | - | |||||||||||||
338 | err: code before this statement never executed: err: | 0 | ||||||||||||
339 | rand_pool_free(pool); | - | ||||||||||||
340 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||
341 | } | - | ||||||||||||
342 | - | |||||||||||||
343 | - | |||||||||||||
344 | - | |||||||||||||
345 | - | |||||||||||||
346 | - | |||||||||||||
347 | RAND_POOL *rand_pool_new(int entropy, size_t min_len, size_t max_len) | - | ||||||||||||
348 | { | - | ||||||||||||
349 | RAND_POOL *pool = CRYPTO_zalloc(sizeof(*pool), __FILE__, 435); | - | ||||||||||||
350 | - | |||||||||||||
351 | if (pool ==
| 0-1061406 | ||||||||||||
352 | ((void *)0)
| 0-1061406 | ||||||||||||
353 | ) { | - | ||||||||||||
354 | ERR_put_error(36,(116),((1|64)),__FILE__,438); | - | ||||||||||||
355 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
356 | } | - | ||||||||||||
357 | - | |||||||||||||
358 | pool->min_len = min_len; | - | ||||||||||||
359 | pool->max_len = max_len; | - | ||||||||||||
360 | - | |||||||||||||
361 | pool->buffer = CRYPTO_secure_zalloc(pool->max_len, __FILE__, 445); | - | ||||||||||||
362 | if (pool->buffer ==
| 0-1054013 | ||||||||||||
363 | ((void *)0)
| 0-1054013 | ||||||||||||
364 | ) { | - | ||||||||||||
365 | ERR_put_error(36,(116),((1|64)),__FILE__,447); | - | ||||||||||||
366 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
367 | } | - | ||||||||||||
368 | - | |||||||||||||
369 | pool->requested_entropy = entropy; | - | ||||||||||||
370 | - | |||||||||||||
371 | return executed 1052595 times by 2 tests: pool;return pool; Executed by:
executed 1052595 times by 2 tests: return pool; Executed by:
| 1052595 | ||||||||||||
372 | - | |||||||||||||
373 | err: | - | ||||||||||||
374 | CRYPTO_free(pool, __FILE__, 456); | - | ||||||||||||
375 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
376 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
377 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
378 | } | - | ||||||||||||
379 | - | |||||||||||||
380 | - | |||||||||||||
381 | - | |||||||||||||
382 | - | |||||||||||||
383 | void rand_pool_free(RAND_POOL *pool) | - | ||||||||||||
384 | { | - | ||||||||||||
385 | if (pool ==
| 0-1051506 | ||||||||||||
386 | ((void *)0)
| 0-1051506 | ||||||||||||
387 | ) | - | ||||||||||||
388 | return; never executed: return; | 0 | ||||||||||||
389 | - | |||||||||||||
390 | CRYPTO_secure_clear_free(pool->buffer, pool->max_len, __FILE__, 468); | - | ||||||||||||
391 | CRYPTO_free(pool, __FILE__, 469); | - | ||||||||||||
392 | } executed 1046152 times by 2 tests: end of block Executed by:
| 1046152 | ||||||||||||
393 | - | |||||||||||||
394 | - | |||||||||||||
395 | - | |||||||||||||
396 | - | |||||||||||||
397 | const unsigned char *rand_pool_buffer(RAND_POOL *pool) | - | ||||||||||||
398 | { | - | ||||||||||||
399 | return executed 19 times by 1 test: pool->buffer;return pool->buffer; Executed by:
executed 19 times by 1 test: return pool->buffer; Executed by:
| 19 | ||||||||||||
400 | } | - | ||||||||||||
401 | - | |||||||||||||
402 | - | |||||||||||||
403 | - | |||||||||||||
404 | - | |||||||||||||
405 | size_t rand_pool_entropy(RAND_POOL *pool) | - | ||||||||||||
406 | { | - | ||||||||||||
407 | return executed 19 times by 1 test: pool->entropy;return pool->entropy; Executed by:
executed 19 times by 1 test: return pool->entropy; Executed by:
| 19 | ||||||||||||
408 | } | - | ||||||||||||
409 | - | |||||||||||||
410 | - | |||||||||||||
411 | - | |||||||||||||
412 | - | |||||||||||||
413 | size_t rand_pool_length(RAND_POOL *pool) | - | ||||||||||||
414 | { | - | ||||||||||||
415 | return executed 1052292 times by 2 tests: pool->len;return pool->len; Executed by:
executed 1052292 times by 2 tests: return pool->len; Executed by:
| 1052292 | ||||||||||||
416 | } | - | ||||||||||||
417 | - | |||||||||||||
418 | - | |||||||||||||
419 | - | |||||||||||||
420 | - | |||||||||||||
421 | - | |||||||||||||
422 | - | |||||||||||||
423 | unsigned char *rand_pool_detach(RAND_POOL *pool) | - | ||||||||||||
424 | { | - | ||||||||||||
425 | unsigned char *ret = pool->buffer; | - | ||||||||||||
426 | pool->buffer = | - | ||||||||||||
427 | ((void *)0) | - | ||||||||||||
428 | ; | - | ||||||||||||
429 | return executed 1063882 times by 2 tests: ret;return ret; Executed by:
executed 1063882 times by 2 tests: return ret; Executed by:
| 1063882 | ||||||||||||
430 | } | - | ||||||||||||
431 | size_t rand_pool_entropy_available(RAND_POOL *pool) | - | ||||||||||||
432 | { | - | ||||||||||||
433 | if (pool->entropy < pool->requested_entropy
| 2-1854 | ||||||||||||
434 | return executed 2 times by 1 test: 0;return 0; Executed by:
executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||
435 | - | |||||||||||||
436 | if (pool->len < pool->min_len
| 0-1854 | ||||||||||||
437 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
438 | - | |||||||||||||
439 | return executed 1854 times by 2 tests: pool->entropy;return pool->entropy; Executed by:
executed 1854 times by 2 tests: return pool->entropy; Executed by:
| 1854 | ||||||||||||
440 | } | - | ||||||||||||
441 | - | |||||||||||||
442 | - | |||||||||||||
443 | - | |||||||||||||
444 | - | |||||||||||||
445 | - | |||||||||||||
446 | - | |||||||||||||
447 | size_t rand_pool_entropy_needed(RAND_POOL *pool) | - | ||||||||||||
448 | { | - | ||||||||||||
449 | if (pool->entropy < pool->requested_entropy
| 19-1837 | ||||||||||||
450 | return executed 1837 times by 2 tests: pool->requested_entropy - pool->entropy;return pool->requested_entropy - pool->entropy; Executed by:
executed 1837 times by 2 tests: return pool->requested_entropy - pool->entropy; Executed by:
| 1837 | ||||||||||||
451 | - | |||||||||||||
452 | return executed 19 times by 1 test: 0;return 0; Executed by:
executed 19 times by 1 test: return 0; Executed by:
| 19 | ||||||||||||
453 | } | - | ||||||||||||
454 | - | |||||||||||||
455 | - | |||||||||||||
456 | - | |||||||||||||
457 | - | |||||||||||||
458 | - | |||||||||||||
459 | - | |||||||||||||
460 | - | |||||||||||||
461 | size_t rand_pool_bytes_needed(RAND_POOL *pool, unsigned int entropy_factor) | - | ||||||||||||
462 | { | - | ||||||||||||
463 | size_t bytes_needed; | - | ||||||||||||
464 | size_t entropy_needed = rand_pool_entropy_needed(pool); | - | ||||||||||||
465 | - | |||||||||||||
466 | if (entropy_factor < 1
| 0-1856 | ||||||||||||
467 | ERR_put_error(36,(115),(105),__FILE__,561); | - | ||||||||||||
468 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
469 | } | - | ||||||||||||
470 | - | |||||||||||||
471 | bytes_needed = (((entropy_needed) * (entropy_factor) + 7) / 8); | - | ||||||||||||
472 | - | |||||||||||||
473 | if (bytes_needed > pool->max_len - pool->len
| 0-1856 | ||||||||||||
474 | - | |||||||||||||
475 | ERR_put_error(36,(115),(125),__FILE__,569); | - | ||||||||||||
476 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
477 | } | - | ||||||||||||
478 | - | |||||||||||||
479 | if (pool->len < pool->min_len
| 19-1837 | ||||||||||||
480 | bytes_needed < pool->min_len - pool->len
| 0-1837 | ||||||||||||
481 | - | |||||||||||||
482 | bytes_needed = pool->min_len - pool->len; never executed: bytes_needed = pool->min_len - pool->len; | 0 | ||||||||||||
483 | - | |||||||||||||
484 | return executed 1856 times by 2 tests: bytes_needed;return bytes_needed; Executed by:
executed 1856 times by 2 tests: return bytes_needed; Executed by:
| 1856 | ||||||||||||
485 | } | - | ||||||||||||
486 | - | |||||||||||||
487 | - | |||||||||||||
488 | size_t rand_pool_bytes_remaining(RAND_POOL *pool) | - | ||||||||||||
489 | { | - | ||||||||||||
490 | return never executed: pool->max_len - pool->len;return pool->max_len - pool->len; never executed: return pool->max_len - pool->len; | 0 | ||||||||||||
491 | } | - | ||||||||||||
492 | int rand_pool_add(RAND_POOL *pool, | - | ||||||||||||
493 | const unsigned char *buffer, size_t len, size_t entropy) | - | ||||||||||||
494 | { | - | ||||||||||||
495 | if (len > pool->max_len - pool->len
| 0-1049181 | ||||||||||||
496 | ERR_put_error(36,(103),(106),__FILE__,600); | - | ||||||||||||
497 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
498 | } | - | ||||||||||||
499 | - | |||||||||||||
500 | if (len > 0
| 0-1055166 | ||||||||||||
501 | memcpy(pool->buffer + pool->len, buffer, len); | - | ||||||||||||
502 | pool->len += len; | - | ||||||||||||
503 | pool->entropy += entropy; | - | ||||||||||||
504 | } executed 1053685 times by 2 tests: end of block Executed by:
| 1053685 | ||||||||||||
505 | - | |||||||||||||
506 | return executed 1056282 times by 2 tests: 1;return 1; Executed by:
executed 1056282 times by 2 tests: return 1; Executed by:
| 1056282 | ||||||||||||
507 | } | - | ||||||||||||
508 | unsigned char *rand_pool_add_begin(RAND_POOL *pool, size_t len) | - | ||||||||||||
509 | { | - | ||||||||||||
510 | if (len == 0
| 0-1837 | ||||||||||||
511 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
512 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
513 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
514 | - | |||||||||||||
515 | if (len > pool->max_len - pool->len
| 0-1837 | ||||||||||||
516 | ERR_put_error(36,(113),(125),__FILE__,631); | - | ||||||||||||
517 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
518 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
519 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
520 | } | - | ||||||||||||
521 | - | |||||||||||||
522 | return executed 1837 times by 2 tests: pool->buffer + pool->len;return pool->buffer + pool->len; Executed by:
executed 1837 times by 2 tests: return pool->buffer + pool->len; Executed by:
| 1837 | ||||||||||||
523 | } | - | ||||||||||||
524 | int rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy) | - | ||||||||||||
525 | { | - | ||||||||||||
526 | if (len > pool->max_len - pool->len
| 0-1837 | ||||||||||||
527 | ERR_put_error(36,(114),(125),__FILE__,650); | - | ||||||||||||
528 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
529 | } | - | ||||||||||||
530 | - | |||||||||||||
531 | if (len > 0
| 2-1835 | ||||||||||||
532 | pool->len += len; | - | ||||||||||||
533 | pool->entropy += entropy; | - | ||||||||||||
534 | } executed 1835 times by 2 tests: end of block Executed by:
| 1835 | ||||||||||||
535 | - | |||||||||||||
536 | return executed 1837 times by 2 tests: 1;return 1; Executed by:
executed 1837 times by 2 tests: return 1; Executed by:
| 1837 | ||||||||||||
537 | } | - | ||||||||||||
538 | - | |||||||||||||
539 | int RAND_set_rand_method(const RAND_METHOD *meth) | - | ||||||||||||
540 | { | - | ||||||||||||
541 | if (!(CRYPTO_THREAD_run_once(&rand_init, do_rand_init_ossl_)
| 0-2088 | ||||||||||||
542 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
543 | - | |||||||||||||
544 | CRYPTO_THREAD_write_lock(rand_meth_lock); | - | ||||||||||||
545 | - | |||||||||||||
546 | ENGINE_finish(funct_ref); | - | ||||||||||||
547 | funct_ref = | - | ||||||||||||
548 | ((void *)0) | - | ||||||||||||
549 | ; | - | ||||||||||||
550 | - | |||||||||||||
551 | default_RAND_meth = meth; | - | ||||||||||||
552 | CRYPTO_THREAD_unlock(rand_meth_lock); | - | ||||||||||||
553 | return executed 2088 times by 12 tests: 1;return 1; Executed by:
executed 2088 times by 12 tests: return 1; Executed by:
| 2088 | ||||||||||||
554 | } | - | ||||||||||||
555 | - | |||||||||||||
556 | const RAND_METHOD *RAND_get_rand_method(void) | - | ||||||||||||
557 | { | - | ||||||||||||
558 | const RAND_METHOD *tmp_meth = | - | ||||||||||||
559 | ((void *)0) | - | ||||||||||||
560 | ; | - | ||||||||||||
561 | - | |||||||||||||
562 | if (!(CRYPTO_THREAD_run_once(&rand_init, do_rand_init_ossl_)
| 0-1199521 | ||||||||||||
563 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
564 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
565 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
566 | - | |||||||||||||
567 | CRYPTO_THREAD_write_lock(rand_meth_lock); | - | ||||||||||||
568 | if (default_RAND_meth ==
| 1146-1212204 | ||||||||||||
569 | ((void *)0)
| 1146-1212204 | ||||||||||||
570 | ) { | - | ||||||||||||
571 | - | |||||||||||||
572 | ENGINE *e; | - | ||||||||||||
573 | - | |||||||||||||
574 | - | |||||||||||||
575 | if ((
| 367-779 | ||||||||||||
576 | ((void *)0)
| 367-779 | ||||||||||||
577 | - | |||||||||||||
578 | && (
| 0-367 | ||||||||||||
579 | ((void *)0)
| 0-367 | ||||||||||||
580 | ) { | - | ||||||||||||
581 | funct_ref = e; | - | ||||||||||||
582 | default_RAND_meth = tmp_meth; | - | ||||||||||||
583 | } executed 367 times by 1 test: else {end of block Executed by:
| 367 | ||||||||||||
584 | ENGINE_finish(e); | - | ||||||||||||
585 | default_RAND_meth = &rand_meth; | - | ||||||||||||
586 | } executed 779 times by 2 tests: end of block Executed by:
| 779 | ||||||||||||
587 | - | |||||||||||||
588 | - | |||||||||||||
589 | - | |||||||||||||
590 | } | - | ||||||||||||
591 | tmp_meth = default_RAND_meth; | - | ||||||||||||
592 | CRYPTO_THREAD_unlock(rand_meth_lock); | - | ||||||||||||
593 | return executed 1212036 times by 2 tests: tmp_meth;return tmp_meth; Executed by:
executed 1212036 times by 2 tests: return tmp_meth; Executed by:
| 1212036 | ||||||||||||
594 | } | - | ||||||||||||
595 | - | |||||||||||||
596 | - | |||||||||||||
597 | int RAND_set_rand_engine(ENGINE *engine) | - | ||||||||||||
598 | { | - | ||||||||||||
599 | const RAND_METHOD *tmp_meth = | - | ||||||||||||
600 | ((void *)0) | - | ||||||||||||
601 | ; | - | ||||||||||||
602 | - | |||||||||||||
603 | if (!(CRYPTO_THREAD_run_once(&rand_init, do_rand_init_ossl_)
| 0 | ||||||||||||
604 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
605 | - | |||||||||||||
606 | if (engine !=
| 0 | ||||||||||||
607 | ((void *)0)
| 0 | ||||||||||||
608 | ) { | - | ||||||||||||
609 | if (!ENGINE_init(engine)
| 0 | ||||||||||||
610 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
611 | tmp_meth = ENGINE_get_RAND(engine); | - | ||||||||||||
612 | if (tmp_meth ==
| 0 | ||||||||||||
613 | ((void *)0)
| 0 | ||||||||||||
614 | ) { | - | ||||||||||||
615 | ENGINE_finish(engine); | - | ||||||||||||
616 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
617 | } | - | ||||||||||||
618 | } never executed: end of block | 0 | ||||||||||||
619 | CRYPTO_THREAD_write_lock(rand_engine_lock); | - | ||||||||||||
620 | - | |||||||||||||
621 | RAND_set_rand_method(tmp_meth); | - | ||||||||||||
622 | funct_ref = engine; | - | ||||||||||||
623 | CRYPTO_THREAD_unlock(rand_engine_lock); | - | ||||||||||||
624 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||
625 | } | - | ||||||||||||
626 | - | |||||||||||||
627 | - | |||||||||||||
628 | void RAND_seed(const void *buf, int num) | - | ||||||||||||
629 | { | - | ||||||||||||
630 | const RAND_METHOD *meth = RAND_get_rand_method(); | - | ||||||||||||
631 | - | |||||||||||||
632 | if (meth->seed !=
| 0 | ||||||||||||
633 | ((void *)0)
| 0 | ||||||||||||
634 | ) | - | ||||||||||||
635 | meth->seed(buf, num); never executed: meth->seed(buf, num); | 0 | ||||||||||||
636 | } never executed: end of block | 0 | ||||||||||||
637 | - | |||||||||||||
638 | void RAND_add(const void *buf, int num, double randomness) | - | ||||||||||||
639 | { | - | ||||||||||||
640 | const RAND_METHOD *meth = RAND_get_rand_method(); | - | ||||||||||||
641 | - | |||||||||||||
642 | if (meth->add !=
| 0-21 | ||||||||||||
643 | ((void *)0)
| 0-21 | ||||||||||||
644 | ) | - | ||||||||||||
645 | meth->add(buf, num, randomness); executed 21 times by 1 test: meth->add(buf, num, randomness); Executed by:
| 21 | ||||||||||||
646 | } executed 21 times by 1 test: end of block Executed by:
| 21 | ||||||||||||
647 | - | |||||||||||||
648 | - | |||||||||||||
649 | - | |||||||||||||
650 | - | |||||||||||||
651 | - | |||||||||||||
652 | - | |||||||||||||
653 | int RAND_priv_bytes(unsigned char *buf, int num) | - | ||||||||||||
654 | { | - | ||||||||||||
655 | const RAND_METHOD *meth = RAND_get_rand_method(); | - | ||||||||||||
656 | RAND_DRBG *drbg; | - | ||||||||||||
657 | int ret; | - | ||||||||||||
658 | - | |||||||||||||
659 | if (meth != RAND_OpenSSL()
| 67542-498426 | ||||||||||||
660 | return executed 67542 times by 2 tests: RAND_bytes(buf, num);return RAND_bytes(buf, num); Executed by:
executed 67542 times by 2 tests: return RAND_bytes(buf, num); Executed by:
| 67542 | ||||||||||||
661 | - | |||||||||||||
662 | drbg = RAND_DRBG_get0_private(); | - | ||||||||||||
663 | if (drbg ==
| 0-498481 | ||||||||||||
664 | ((void *)0)
| 0-498481 | ||||||||||||
665 | ) | - | ||||||||||||
666 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
667 | - | |||||||||||||
668 | ret = RAND_DRBG_bytes(drbg, buf, num); | - | ||||||||||||
669 | return executed 497884 times by 2 tests: ret;return ret; Executed by:
executed 497884 times by 2 tests: return ret; Executed by:
| 497884 | ||||||||||||
670 | } | - | ||||||||||||
671 | - | |||||||||||||
672 | int RAND_bytes(unsigned char *buf, int num) | - | ||||||||||||
673 | { | - | ||||||||||||
674 | const RAND_METHOD *meth = RAND_get_rand_method(); | - | ||||||||||||
675 | - | |||||||||||||
676 | if (meth->bytes !=
| 0-646698 | ||||||||||||
677 | ((void *)0)
| 0-646698 | ||||||||||||
678 | ) | - | ||||||||||||
679 | return executed 646684 times by 2 tests: meth->bytes(buf, num);return meth->bytes(buf, num); Executed by:
executed 646684 times by 2 tests: return meth->bytes(buf, num); Executed by:
| 646684 | ||||||||||||
680 | ERR_put_error(36,(100),(101),__FILE__,777); | - | ||||||||||||
681 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
682 | } | - | ||||||||||||
683 | - | |||||||||||||
684 | - | |||||||||||||
685 | int RAND_pseudo_bytes(unsigned char *buf, int num) | - | ||||||||||||
686 | { | - | ||||||||||||
687 | const RAND_METHOD *meth = RAND_get_rand_method(); | - | ||||||||||||
688 | - | |||||||||||||
689 | if (meth->pseudorand !=
| 0 | ||||||||||||
690 | ((void *)0)
| 0 | ||||||||||||
691 | ) | - | ||||||||||||
692 | return never executed: meth->pseudorand(buf, num);return meth->pseudorand(buf, num); never executed: return meth->pseudorand(buf, num); | 0 | ||||||||||||
693 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
694 | } | - | ||||||||||||
695 | - | |||||||||||||
696 | - | |||||||||||||
697 | int RAND_status(void) | - | ||||||||||||
698 | { | - | ||||||||||||
699 | const RAND_METHOD *meth = RAND_get_rand_method(); | - | ||||||||||||
700 | - | |||||||||||||
701 | if (meth->status !=
| 0 | ||||||||||||
702 | ((void *)0)
| 0 | ||||||||||||
703 | ) | - | ||||||||||||
704 | return never executed: meth->status();return meth->status(); never executed: return meth->status(); | 0 | ||||||||||||
705 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
706 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |