2 * Copyright 1995-2017 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.
35 if (file == NULL || !RAND_load_file(file, -1)) {
36 if (RAND_status() == 0) {
38 BIO_printf(bio_err, "unable to load 'random state'\n");
40 "This means that the random number generator has not been seeded\n");
41 BIO_printf(bio_err, "with much random data.\n");
42 if (consider_randfile) { /* explanation does not apply when a
43 * file is explicitly named */
45 "Consider setting the RANDFILE environment variable to point at a file that\n");
47 "'random' data can be kept in (the file will be overwritten).\n");
57 long app_RAND_load_files(char *name)
62 #ifndef OPENSSL_NO_EGD
68 for (p = name; ((*p != '\0') && (*p != LIST_SEPARATOR_CHAR)); p++) ;
77 #ifndef OPENSSL_NO_EGD
83 tot += RAND_load_file(n, -1);
88 app_RAND_allow_write_file();
92 int app_RAND_write_file(const char *file)
96 if (egdsocket || !seeded)
98 * If we did not manage to read the seed file, we should not write a
99 * low-entropy seed file back -- it would suppress a crucial warning
100 * the next time we want to use it.
105 file = RAND_file_name(buffer, sizeof buffer);
106 if (file == NULL || !RAND_write_file(file)) {
107 BIO_printf(bio_err, "unable to write 'random state'\n");
113 void app_RAND_allow_write_file(void)