2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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
11 #include <openssl/bio.h>
12 #include <openssl/rand.h>
14 static int seeded = 0;
15 static int egdsocket = 0;
17 int app_RAND_load_file(const char *file, int dont_warn)
19 int consider_randfile = (file == NULL);
23 file = RAND_file_name(buffer, sizeof buffer);
24 #ifndef OPENSSL_NO_EGD
25 else if (RAND_egd(file) > 0) {
27 * we try if the given filename is an EGD socket. if it is, we don't
28 * write anything back to the file.
34 if (file == NULL || !RAND_load_file(file, -1)) {
35 if (RAND_status() == 0) {
37 BIO_printf(bio_err, "unable to load 'random state'\n");
39 "This means that the random number generator has not been seeded\n");
40 BIO_printf(bio_err, "with much random data.\n");
41 if (consider_randfile) { /* explanation does not apply when a
42 * file is explicitly named */
44 "Consider setting the RANDFILE environment variable to point at a file that\n");
46 "'random' data can be kept in (the file will be overwritten).\n");
56 long app_RAND_load_files(char *name)
61 #ifndef OPENSSL_NO_EGD
67 for (p = name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++) ;
76 #ifndef OPENSSL_NO_EGD
82 tot += RAND_load_file(n, -1);
87 app_RAND_allow_write_file();
91 int app_RAND_write_file(const char *file)
95 if (egdsocket || !seeded)
97 * If we did not manage to read the seed file, we should not write a
98 * low-entropy seed file back -- it would suppress a crucial warning
99 * the next time we want to use it.
104 file = RAND_file_name(buffer, sizeof buffer);
105 if (file == NULL || !RAND_write_file(file)) {
106 BIO_printf(bio_err, "unable to write 'random state'\n");
112 void app_RAND_allow_write_file(void)