+ if (rand_meth_lock == NULL)
+ goto err;
+
+ if (!rand_pool_init())
+ goto err;
+
+ rand_inited = 1;
+ return 1;
+
+ err:
+ CRYPTO_THREAD_lock_free(rand_meth_lock);
+ rand_meth_lock = NULL;
+# ifndef OPENSSL_NO_ENGINE
+ CRYPTO_THREAD_lock_free(rand_engine_lock);
+ rand_engine_lock = NULL;
+# endif
+ return 0;
+}
+
+void rand_cleanup_int(void)
+{
+ const RAND_METHOD *meth = default_RAND_meth;
+
+ if (!rand_inited)
+ return;
+
+ if (meth != NULL && meth->cleanup != NULL)
+ meth->cleanup();
+ RAND_set_rand_method(NULL);
+ rand_pool_cleanup();
+# ifndef OPENSSL_NO_ENGINE
+ CRYPTO_THREAD_lock_free(rand_engine_lock);
+ rand_engine_lock = NULL;
+# endif
+ CRYPTO_THREAD_lock_free(rand_meth_lock);
+ rand_meth_lock = NULL;
+ rand_inited = 0;
+}
+
+/*
+ * RAND_close_seed_files() ensures that any seed file descriptors are
+ * closed after use. This only applies to libcrypto/default provider,
+ * it does not apply to other providers.
+ */
+void RAND_keep_random_devices_open(int keep)
+{
+ if (RUN_ONCE(&rand_init, do_rand_init))
+ rand_pool_keep_random_devices_open(keep);
+}
+
+/*
+ * RAND_poll() reseeds the default RNG using random input
+ *
+ * The random input is obtained from polling various entropy
+ * sources which depend on the operating system and are
+ * configurable via the --with-rand-seed configure option.
+ */
+int RAND_poll(void)
+{
+ const RAND_METHOD *meth = RAND_get_rand_method();
+ int ret = meth == RAND_OpenSSL();
+ RAND_POOL *pool;
+
+ if (meth == NULL)
+ return 0;
+
+ if (!ret) {
+ /* fill random pool and seed the current legacy RNG */
+ pool = rand_pool_new(RAND_DRBG_STRENGTH, 1,
+ (RAND_DRBG_STRENGTH + 7) / 8,
+ RAND_POOL_MAX_LENGTH);
+ if (pool == NULL)
+ return 0;
+
+ if (prov_pool_acquire_entropy(pool) == 0)
+ goto err;
+
+ if (meth->add == NULL
+ || meth->add(rand_pool_buffer(pool),
+ rand_pool_length(pool),
+ (rand_pool_entropy(pool) / 8.0)) == 0)
+ goto err;
+
+ ret = 1;
+ err:
+ rand_pool_free(pool);
+ }