2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include <openssl/bio.h>
12 #include <openssl/err.h>
13 #include <openssl/rand.h>
14 #include <openssl/conf.h>
16 static char *save_rand_file;
18 void app_RAND_load_conf(CONF *c, const char *section)
20 const char *randfile = NCONF_get_string(c, section, "RANDFILE");
22 if (randfile == NULL) {
26 if (RAND_load_file(randfile, -1) < 0) {
27 BIO_printf(bio_err, "Can't load %s into RNG\n", randfile);
28 ERR_print_errors(bio_err);
30 if (save_rand_file == NULL)
31 save_rand_file = OPENSSL_strdup(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);
60 void app_RAND_write(void)
62 if (save_rand_file == NULL)
64 if (RAND_write_file(save_rand_file) == -1) {
65 BIO_printf(bio_err, "Cannot write random bytes:\n");
66 ERR_print_errors(bio_err);
68 OPENSSL_free(save_rand_file);
69 save_rand_file = NULL;
74 * See comments in opt_verify for explanation of this.
76 enum r_range { OPT_R_ENUM };
80 switch ((enum r_range)opt) {
85 return loadfiles(opt_arg());
88 OPENSSL_free(save_rand_file);
89 save_rand_file = OPENSSL_strdup(opt_arg());