]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/evp/evp_rand.c
evp: support modified gettable/settable ctx calls for RNGs
[thirdparty/openssl.git] / crypto / evp / evp_rand.c
1 /*
2 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include <openssl/evp.h>
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <openssl/engine.h>
15 #include <openssl/evp.h>
16 #include <openssl/x509v3.h>
17 #include <openssl/rand.h>
18 #include <openssl/core.h>
19 #include <openssl/core_names.h>
20 #include <openssl/crypto.h>
21 #include "crypto/asn1.h"
22 #include "crypto/evp.h"
23 #include "internal/cryptlib.h"
24 #include "internal/numbers.h"
25 #include "internal/provider.h"
26 #include "evp_local.h"
27
28 struct evp_rand_st {
29 OSSL_PROVIDER *prov;
30 int name_id;
31 CRYPTO_REF_COUNT refcnt;
32 CRYPTO_RWLOCK *refcnt_lock;
33
34 const OSSL_DISPATCH *dispatch;
35 OSSL_FUNC_rand_newctx_fn *newctx;
36 OSSL_FUNC_rand_freectx_fn *freectx;
37 OSSL_FUNC_rand_instantiate_fn *instantiate;
38 OSSL_FUNC_rand_uninstantiate_fn *uninstantiate;
39 OSSL_FUNC_rand_generate_fn *generate;
40 OSSL_FUNC_rand_reseed_fn *reseed;
41 OSSL_FUNC_rand_nonce_fn *nonce;
42 OSSL_FUNC_rand_enable_locking_fn *enable_locking;
43 OSSL_FUNC_rand_lock_fn *lock;
44 OSSL_FUNC_rand_unlock_fn *unlock;
45 OSSL_FUNC_rand_gettable_params_fn *gettable_params;
46 OSSL_FUNC_rand_gettable_ctx_params_fn *gettable_ctx_params;
47 OSSL_FUNC_rand_settable_ctx_params_fn *settable_ctx_params;
48 OSSL_FUNC_rand_get_params_fn *get_params;
49 OSSL_FUNC_rand_get_ctx_params_fn *get_ctx_params;
50 OSSL_FUNC_rand_set_ctx_params_fn *set_ctx_params;
51 OSSL_FUNC_rand_verify_zeroization_fn *verify_zeroization;
52 } /* EVP_RAND */ ;
53
54 static int evp_rand_up_ref(void *vrand)
55 {
56 EVP_RAND *rand = (EVP_RAND *)vrand;
57 int ref = 0;
58
59 if (rand != NULL)
60 return CRYPTO_UP_REF(&rand->refcnt, &ref, rand->refcnt_lock);
61 return 1;
62 }
63
64 static void evp_rand_free(void *vrand){
65 EVP_RAND *rand = (EVP_RAND *)vrand;
66 int ref = 0;
67
68 if (rand != NULL) {
69 CRYPTO_DOWN_REF(&rand->refcnt, &ref, rand->refcnt_lock);
70 if (ref <= 0) {
71 ossl_provider_free(rand->prov);
72 CRYPTO_THREAD_lock_free(rand->refcnt_lock);
73 OPENSSL_free(rand);
74 }
75 }
76 }
77
78 static void *evp_rand_new(void)
79 {
80 EVP_RAND *rand = OPENSSL_zalloc(sizeof(*rand));
81
82 if (rand == NULL
83 || (rand->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL) {
84 OPENSSL_free(rand);
85 return NULL;
86 }
87 rand->refcnt = 1;
88 return rand;
89 }
90
91 /* Enable locking of the underlying DRBG/RAND if available */
92 int EVP_RAND_enable_locking(EVP_RAND_CTX *rand)
93 {
94 if (rand->meth->enable_locking != NULL)
95 return rand->meth->enable_locking(rand->data);
96 ERR_raise(ERR_LIB_EVP, EVP_R_LOCKING_NOT_SUPPORTED);
97 return 0;
98 }
99
100 /* Lock the underlying DRBG/RAND if available */
101 static int evp_rand_lock(EVP_RAND_CTX *rand)
102 {
103 if (rand->meth->lock != NULL)
104 return rand->meth->lock(rand->data);
105 return 1;
106 }
107
108 /* Unlock the underlying DRBG/RAND if available */
109 static void evp_rand_unlock(EVP_RAND_CTX *rand)
110 {
111 if (rand->meth->unlock != NULL)
112 rand->meth->unlock(rand->data);
113 }
114
115 static void *evp_rand_from_dispatch(int name_id,
116 const OSSL_DISPATCH *fns,
117 OSSL_PROVIDER *prov)
118 {
119 EVP_RAND *rand = NULL;
120 int fnrandcnt = 0, fnctxcnt = 0, fnlockcnt = 0, fnenablelockcnt = 0;
121 #ifdef FIPS_MODULE
122 int fnzeroizecnt = 0;
123 #endif
124
125 if ((rand = evp_rand_new()) == NULL) {
126 ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
127 return NULL;
128 }
129 rand->name_id = name_id;
130 rand->dispatch = fns;
131 for (; fns->function_id != 0; fns++) {
132 switch (fns->function_id) {
133 case OSSL_FUNC_RAND_NEWCTX:
134 if (rand->newctx != NULL)
135 break;
136 rand->newctx = OSSL_FUNC_rand_newctx(fns);
137 fnctxcnt++;
138 break;
139 case OSSL_FUNC_RAND_FREECTX:
140 if (rand->freectx != NULL)
141 break;
142 rand->freectx = OSSL_FUNC_rand_freectx(fns);
143 fnctxcnt++;
144 break;
145 case OSSL_FUNC_RAND_INSTANTIATE:
146 if (rand->instantiate != NULL)
147 break;
148 rand->instantiate = OSSL_FUNC_rand_instantiate(fns);
149 fnrandcnt++;
150 break;
151 case OSSL_FUNC_RAND_UNINSTANTIATE:
152 if (rand->uninstantiate != NULL)
153 break;
154 rand->uninstantiate = OSSL_FUNC_rand_uninstantiate(fns);
155 fnrandcnt++;
156 break;
157 case OSSL_FUNC_RAND_GENERATE:
158 if (rand->generate != NULL)
159 break;
160 rand->generate = OSSL_FUNC_rand_generate(fns);
161 fnrandcnt++;
162 break;
163 case OSSL_FUNC_RAND_RESEED:
164 if (rand->reseed != NULL)
165 break;
166 rand->reseed = OSSL_FUNC_rand_reseed(fns);
167 break;
168 case OSSL_FUNC_RAND_NONCE:
169 if (rand->nonce != NULL)
170 break;
171 rand->nonce = OSSL_FUNC_rand_nonce(fns);
172 break;
173 case OSSL_FUNC_RAND_ENABLE_LOCKING:
174 if (rand->enable_locking != NULL)
175 break;
176 rand->enable_locking = OSSL_FUNC_rand_enable_locking(fns);
177 fnenablelockcnt++;
178 break;
179 case OSSL_FUNC_RAND_LOCK:
180 if (rand->lock != NULL)
181 break;
182 rand->lock = OSSL_FUNC_rand_lock(fns);
183 fnlockcnt++;
184 break;
185 case OSSL_FUNC_RAND_UNLOCK:
186 if (rand->unlock != NULL)
187 break;
188 rand->unlock = OSSL_FUNC_rand_unlock(fns);
189 fnlockcnt++;
190 break;
191 case OSSL_FUNC_RAND_GETTABLE_PARAMS:
192 if (rand->gettable_params != NULL)
193 break;
194 rand->gettable_params =
195 OSSL_FUNC_rand_gettable_params(fns);
196 break;
197 case OSSL_FUNC_RAND_GETTABLE_CTX_PARAMS:
198 if (rand->gettable_ctx_params != NULL)
199 break;
200 rand->gettable_ctx_params =
201 OSSL_FUNC_rand_gettable_ctx_params(fns);
202 break;
203 case OSSL_FUNC_RAND_SETTABLE_CTX_PARAMS:
204 if (rand->settable_ctx_params != NULL)
205 break;
206 rand->settable_ctx_params =
207 OSSL_FUNC_rand_settable_ctx_params(fns);
208 break;
209 case OSSL_FUNC_RAND_GET_PARAMS:
210 if (rand->get_params != NULL)
211 break;
212 rand->get_params = OSSL_FUNC_rand_get_params(fns);
213 break;
214 case OSSL_FUNC_RAND_GET_CTX_PARAMS:
215 if (rand->get_ctx_params != NULL)
216 break;
217 rand->get_ctx_params = OSSL_FUNC_rand_get_ctx_params(fns);
218 fnctxcnt++;
219 break;
220 case OSSL_FUNC_RAND_SET_CTX_PARAMS:
221 if (rand->set_ctx_params != NULL)
222 break;
223 rand->set_ctx_params = OSSL_FUNC_rand_set_ctx_params(fns);
224 break;
225 case OSSL_FUNC_RAND_VERIFY_ZEROIZATION:
226 if (rand->verify_zeroization != NULL)
227 break;
228 rand->verify_zeroization = OSSL_FUNC_rand_verify_zeroization(fns);
229 #ifdef FIPS_MODULE
230 fnzeroizecnt++;
231 #endif
232 break;
233 }
234 }
235 /*
236 * In order to be a consistent set of functions we must have at least
237 * a complete set of "rand" functions and a complete set of context
238 * management functions. In FIPS mode, we also require the zeroization
239 * verification function.
240 *
241 * In addition, if locking can be enabled, we need a complete set of
242 * locking functions.
243 */
244 if (fnrandcnt != 3
245 || fnctxcnt != 3
246 || (fnenablelockcnt != 0 && fnenablelockcnt != 1)
247 || (fnlockcnt != 0 && fnlockcnt != 2)
248 #ifdef FIPS_MODULE
249 || fnzeroizecnt != 1
250 #endif
251 ) {
252 evp_rand_free(rand);
253 ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS);
254 return NULL;
255 }
256
257 if (prov != NULL && !ossl_provider_up_ref(prov)) {
258 evp_rand_free(rand);
259 ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
260 return NULL;
261 }
262 rand->prov = prov;
263
264 return rand;
265 }
266
267 EVP_RAND *EVP_RAND_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
268 const char *properties)
269 {
270 return evp_generic_fetch(libctx, OSSL_OP_RAND, algorithm, properties,
271 evp_rand_from_dispatch, evp_rand_up_ref,
272 evp_rand_free);
273 }
274
275 int EVP_RAND_up_ref(EVP_RAND *rand)
276 {
277 return evp_rand_up_ref(rand);
278 }
279
280 void EVP_RAND_free(EVP_RAND *rand)
281 {
282 evp_rand_free(rand);
283 }
284
285 int EVP_RAND_number(const EVP_RAND *rand)
286 {
287 return rand->name_id;
288 }
289
290 const char *EVP_RAND_name(const EVP_RAND *rand)
291 {
292 return evp_first_name(rand->prov, rand->name_id);
293 }
294
295 int EVP_RAND_is_a(const EVP_RAND *rand, const char *name)
296 {
297 return evp_is_a(rand->prov, rand->name_id, NULL, name);
298 }
299
300 const OSSL_PROVIDER *EVP_RAND_provider(const EVP_RAND *rand)
301 {
302 return rand->prov;
303 }
304
305 int EVP_RAND_get_params(EVP_RAND *rand, OSSL_PARAM params[])
306 {
307 if (rand->get_params != NULL)
308 return rand->get_params(params);
309 return 1;
310 }
311
312 static int evp_rand_ctx_up_ref(EVP_RAND_CTX *ctx)
313 {
314 int ref = 0;
315
316 return CRYPTO_UP_REF(&ctx->refcnt, &ref, ctx->refcnt_lock);
317 }
318
319 EVP_RAND_CTX *EVP_RAND_CTX_new(EVP_RAND *rand, EVP_RAND_CTX *parent)
320 {
321 EVP_RAND_CTX *ctx;
322 void *parent_ctx = NULL;
323 const OSSL_DISPATCH *parent_dispatch = NULL;
324
325 if (rand == NULL) {
326 ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_NULL_ALGORITHM);
327 return NULL;
328 }
329
330 ctx = OPENSSL_zalloc(sizeof(*ctx));
331 if (ctx == NULL || (ctx->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL) {
332 OPENSSL_free(ctx);
333 ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
334 return NULL;
335 }
336 if (parent != NULL) {
337 if (!evp_rand_ctx_up_ref(parent)) {
338 ERR_raise(ERR_LIB_EVP, ERR_R_INTERNAL_ERROR);
339 CRYPTO_THREAD_lock_free(ctx->refcnt_lock);
340 OPENSSL_free(ctx);
341 return NULL;
342 }
343 parent_ctx = parent->data;
344 parent_dispatch = parent->meth->dispatch;
345 }
346 if ((ctx->data = rand->newctx(ossl_provider_ctx(rand->prov), parent_ctx,
347 parent_dispatch)) == NULL
348 || !EVP_RAND_up_ref(rand)) {
349 ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
350 rand->freectx(ctx->data);
351 CRYPTO_THREAD_lock_free(ctx->refcnt_lock);
352 OPENSSL_free(ctx);
353 EVP_RAND_CTX_free(parent);
354 return NULL;
355 }
356 ctx->meth = rand;
357 ctx->parent = parent;
358 ctx->refcnt = 1;
359 return ctx;
360 }
361
362 void EVP_RAND_CTX_free(EVP_RAND_CTX *ctx)
363 {
364 if (ctx != NULL) {
365 int ref = 0;
366
367 CRYPTO_DOWN_REF(&ctx->refcnt, &ref, ctx->refcnt_lock);
368 if (ref <= 0) {
369 EVP_RAND_CTX *parent = ctx->parent;
370
371 ctx->meth->freectx(ctx->data);
372 ctx->data = NULL;
373 EVP_RAND_free(ctx->meth);
374 CRYPTO_THREAD_lock_free(ctx->refcnt_lock);
375 OPENSSL_free(ctx);
376 EVP_RAND_CTX_free(parent);
377 }
378 }
379 }
380
381 EVP_RAND *EVP_RAND_CTX_rand(EVP_RAND_CTX *ctx)
382 {
383 return ctx->meth;
384 }
385
386 static int evp_rand_get_ctx_params_locked(EVP_RAND_CTX *ctx,
387 OSSL_PARAM params[])
388 {
389 return ctx->meth->get_ctx_params(ctx->data, params);
390 }
391
392 int EVP_RAND_get_ctx_params(EVP_RAND_CTX *ctx, OSSL_PARAM params[])
393 {
394 int res;
395
396 if (!evp_rand_lock(ctx))
397 return 0;
398 res = evp_rand_get_ctx_params_locked(ctx, params);
399 evp_rand_unlock(ctx);
400 return res;
401 }
402
403 static int evp_rand_set_ctx_params_locked(EVP_RAND_CTX *ctx,
404 const OSSL_PARAM params[])
405 {
406 if (ctx->meth->set_ctx_params != NULL)
407 return ctx->meth->set_ctx_params(ctx->data, params);
408 return 1;
409 }
410
411 int EVP_RAND_set_ctx_params(EVP_RAND_CTX *ctx, const OSSL_PARAM params[])
412 {
413 int res;
414
415 if (!evp_rand_lock(ctx))
416 return 0;
417 res = evp_rand_set_ctx_params_locked(ctx, params);
418 evp_rand_unlock(ctx);
419 return res;
420 }
421
422 const OSSL_PARAM *EVP_RAND_gettable_params(const EVP_RAND *rand)
423 {
424 if (rand->gettable_params == NULL)
425 return NULL;
426 return rand->gettable_params(ossl_provider_ctx(EVP_RAND_provider(rand)));
427 }
428
429 const OSSL_PARAM *EVP_RAND_gettable_ctx_params(const EVP_RAND *rand)
430 {
431 void *provctx;
432
433 if (rand->gettable_ctx_params == NULL)
434 return NULL;
435 provctx = ossl_provider_ctx(EVP_RAND_provider(rand));
436 return rand->gettable_ctx_params(NULL, provctx);
437 }
438
439 const OSSL_PARAM *EVP_RAND_settable_ctx_params(const EVP_RAND *rand)
440 {
441 void *provctx;
442
443 if (rand->settable_ctx_params == NULL)
444 return NULL;
445 provctx = ossl_provider_ctx(EVP_RAND_provider(rand));
446 return rand->settable_ctx_params(NULL, provctx);
447 }
448
449 const OSSL_PARAM *EVP_RAND_CTX_gettable_params(EVP_RAND_CTX *ctx)
450 {
451 void *provctx;
452
453 if (ctx->meth->gettable_ctx_params == NULL)
454 return NULL;
455 provctx = ossl_provider_ctx(EVP_RAND_provider(ctx->meth));
456 return ctx->meth->gettable_ctx_params(ctx->data, provctx);
457 }
458
459 const OSSL_PARAM *EVP_RAND_CTX_settable_params(EVP_RAND_CTX *ctx)
460 {
461 void *provctx;
462
463 if (ctx->meth->settable_ctx_params == NULL)
464 return NULL;
465 provctx = ossl_provider_ctx(EVP_RAND_provider(ctx->meth));
466 return ctx->meth->settable_ctx_params(ctx->data, provctx);
467 }
468
469 void EVP_RAND_do_all_provided(OSSL_LIB_CTX *libctx,
470 void (*fn)(EVP_RAND *rand, void *arg),
471 void *arg)
472 {
473 evp_generic_do_all(libctx, OSSL_OP_RAND,
474 (void (*)(void *, void *))fn, arg,
475 evp_rand_from_dispatch, evp_rand_free);
476 }
477
478 int EVP_RAND_names_do_all(const EVP_RAND *rand,
479 void (*fn)(const char *name, void *data),
480 void *data)
481 {
482 if (rand->prov != NULL)
483 return evp_names_do_all(rand->prov, rand->name_id, fn, data);
484
485 return 1;
486 }
487
488 static int evp_rand_instantiate_locked
489 (EVP_RAND_CTX *ctx, unsigned int strength, int prediction_resistance,
490 const unsigned char *pstr, size_t pstr_len)
491 {
492 return ctx->meth->instantiate(ctx->data, strength, prediction_resistance,
493 pstr, pstr_len);
494 }
495
496 int EVP_RAND_instantiate(EVP_RAND_CTX *ctx, unsigned int strength,
497 int prediction_resistance,
498 const unsigned char *pstr, size_t pstr_len)
499 {
500 int res;
501
502 if (!evp_rand_lock(ctx))
503 return 0;
504 res = evp_rand_instantiate_locked(ctx, strength, prediction_resistance,
505 pstr, pstr_len);
506 evp_rand_unlock(ctx);
507 return res;
508 }
509
510 static int evp_rand_uninstantiate_locked(EVP_RAND_CTX *ctx)
511 {
512 return ctx->meth->uninstantiate(ctx->data);
513 }
514
515 int EVP_RAND_uninstantiate(EVP_RAND_CTX *ctx)
516 {
517 int res;
518
519 if (!evp_rand_lock(ctx))
520 return 0;
521 res = evp_rand_uninstantiate_locked(ctx);
522 evp_rand_unlock(ctx);
523 return res;
524 }
525
526 static int evp_rand_generate_locked(EVP_RAND_CTX *ctx, unsigned char *out,
527 size_t outlen, unsigned int strength,
528 int prediction_resistance,
529 const unsigned char *addin,
530 size_t addin_len)
531 {
532 size_t chunk, max_request = 0;
533 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
534
535 params[0] = OSSL_PARAM_construct_size_t(OSSL_RAND_PARAM_MAX_REQUEST,
536 &max_request);
537 if (!evp_rand_get_ctx_params_locked(ctx, params)
538 || max_request == 0) {
539 ERR_raise(ERR_LIB_EVP, EVP_R_UNABLE_TO_GET_MAXIMUM_REQUEST_SIZE);
540 return 0;
541 }
542 for (; outlen > 0; outlen -= chunk, out += chunk) {
543 chunk = outlen > max_request ? max_request : outlen;
544 if (!ctx->meth->generate(ctx->data, out, chunk, strength,
545 prediction_resistance, addin, addin_len)) {
546 ERR_raise(ERR_LIB_EVP, EVP_R_GENERATE_ERROR);
547 return 0;
548 }
549 /*
550 * Prediction resistance is only relevant the first time around,
551 * subsequently, the DRBG has already been properly reseeded.
552 */
553 prediction_resistance = 0;
554 }
555 return 1;
556 }
557
558 int EVP_RAND_generate(EVP_RAND_CTX *ctx, unsigned char *out, size_t outlen,
559 unsigned int strength, int prediction_resistance,
560 const unsigned char *addin, size_t addin_len)
561 {
562 int res;
563
564 if (!evp_rand_lock(ctx))
565 return 0;
566 res = evp_rand_generate_locked(ctx, out, outlen, strength,
567 prediction_resistance, addin, addin_len);
568 evp_rand_unlock(ctx);
569 return res;
570 }
571
572 static int evp_rand_reseed_locked(EVP_RAND_CTX *ctx, int prediction_resistance,
573 const unsigned char *ent, size_t ent_len,
574 const unsigned char *addin, size_t addin_len)
575 {
576 if (ctx->meth->reseed != NULL)
577 return ctx->meth->reseed(ctx->data, prediction_resistance,
578 ent, ent_len, addin, addin_len);
579 return 1;
580 }
581
582 int EVP_RAND_reseed(EVP_RAND_CTX *ctx, int prediction_resistance,
583 const unsigned char *ent, size_t ent_len,
584 const unsigned char *addin, size_t addin_len)
585 {
586 int res;
587
588 if (!evp_rand_lock(ctx))
589 return 0;
590 res = evp_rand_reseed_locked(ctx, prediction_resistance,
591 ent, ent_len, addin, addin_len);
592 evp_rand_unlock(ctx);
593 return res;
594 }
595
596 static unsigned int evp_rand_strength_locked(EVP_RAND_CTX *ctx)
597 {
598 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
599 unsigned int strength = 0;
600
601 params[0] = OSSL_PARAM_construct_uint(OSSL_RAND_PARAM_STRENGTH, &strength);
602 if (!evp_rand_get_ctx_params_locked(ctx, params))
603 return 0;
604 return strength;
605 }
606
607 unsigned int EVP_RAND_strength(EVP_RAND_CTX *ctx)
608 {
609 unsigned int res;
610
611 if (!evp_rand_lock(ctx))
612 return 0;
613 res = evp_rand_strength_locked(ctx);
614 evp_rand_unlock(ctx);
615 return res;
616 }
617
618 static int evp_rand_nonce_locked(EVP_RAND_CTX *ctx, unsigned char *out,
619 size_t outlen)
620 {
621 unsigned int str = evp_rand_strength_locked(ctx);
622
623 if (ctx->meth->nonce == NULL)
624 return 0;
625 if (ctx->meth->nonce(ctx->data, out, str, outlen, outlen))
626 return 1;
627 return evp_rand_generate_locked(ctx, out, outlen, str, 0, NULL, 0);
628 }
629
630 int EVP_RAND_nonce(EVP_RAND_CTX *ctx, unsigned char *out, size_t outlen)
631 {
632 int res;
633
634 if (!evp_rand_lock(ctx))
635 return 0;
636 res = evp_rand_nonce_locked(ctx, out, outlen);
637 evp_rand_unlock(ctx);
638 return res;
639 }
640
641 int EVP_RAND_state(EVP_RAND_CTX *ctx)
642 {
643 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
644 int state;
645
646 params[0] = OSSL_PARAM_construct_int(OSSL_RAND_PARAM_STATE, &state);
647 if (!EVP_RAND_get_ctx_params(ctx, params))
648 state = EVP_RAND_STATE_ERROR;
649 return state;
650 }
651
652 static int evp_rand_verify_zeroization_locked(EVP_RAND_CTX *ctx)
653 {
654 if (ctx->meth->verify_zeroization != NULL)
655 return ctx->meth->verify_zeroization(ctx->data);
656 return 0;
657 }
658
659 int EVP_RAND_verify_zeroization(EVP_RAND_CTX *ctx)
660 {
661 int res;
662
663 if (!evp_rand_lock(ctx))
664 return 0;
665 res = evp_rand_verify_zeroization_locked(ctx);
666 evp_rand_unlock(ctx);
667 return res;
668 }