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>
13 #include <openssl/conf.h>
15 static const char *save_rand_file;
17 void app_RAND_load_conf(CONF *c, const char *section)
19 const char *randfile = NCONF_get_string(c, section, "RANDFILE");
21 if (randfile == NULL) {
25 if (RAND_load_file(randfile, -1) < 0) {
26 BIO_printf(bio_err, "Can't load %s into RNG\n", randfile);
27 ERR_print_errors(bio_err);
30 if (save_rand_file == NULL)
31 save_rand_file = randfile;
34 static int loadfiles(char *name)
41 for (p = name; *p != '\0' && *p != LIST_SEPARATOR_CHAR; p++)
46 if (RAND_load_file(name, -1) < 0) {
47 BIO_printf(bio_err, "Can't load %s into RNG\n", name);
48 ERR_print_errors(bio_err);
61 void app_RAND_write(void)
63 if (save_rand_file == NULL)
65 if (RAND_write_file(save_rand_file) == -1) {
66 BIO_printf(bio_err, "Cannot write random bytes:\n");
67 ERR_print_errors(bio_err);
73 * See comments in opt_verify for explanation of this.
75 enum r_range { OPT_R_ENUM };
79 switch ((enum r_range)opt) {
84 return loadfiles(opt_arg());
87 save_rand_file = opt_arg();