]>
git.ipfire.org Git - thirdparty/openssl.git/blob - apps/app_rand.c
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/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
);
31 if (save_rand_file
== NULL
)
32 save_rand_file
= OPENSSL_strdup(randfile
);
35 static int loadfiles(char *name
)
42 for (p
= name
; *p
!= '\0' && *p
!= LIST_SEPARATOR_CHAR
; p
++)
47 if (RAND_load_file(name
, -1) < 0) {
48 BIO_printf(bio_err
, "Can't load %s into RNG\n", name
);
49 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
);
69 OPENSSL_free(save_rand_file
);
70 save_rand_file
= NULL
;
75 * See comments in opt_verify for explanation of this.
77 enum r_range
{ OPT_R_ENUM
};
81 switch ((enum r_range
)opt
) {
86 return loadfiles(opt_arg());
89 OPENSSL_free(save_rand_file
);
90 save_rand_file
= OPENSSL_strdup(opt_arg());