evp_rand.c 18 KB

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