1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1 christos RAND_load_file, RAND_write_file, RAND_file_name - PRNG seed file 6 1.1 christos 7 1.1 christos =head1 SYNOPSIS 8 1.1 christos 9 1.1 christos #include <openssl/rand.h> 10 1.1 christos 11 1.1 christos int RAND_load_file(const char *filename, long max_bytes); 12 1.1 christos 13 1.1 christos int RAND_write_file(const char *filename); 14 1.1 christos 15 1.1 christos const char *RAND_file_name(char *buf, size_t num); 16 1.1 christos 17 1.1 christos =head1 DESCRIPTION 18 1.1 christos 19 1.1 christos RAND_load_file() reads a number of bytes from file B<filename> and 20 1.1.1.2 christos adds them to the PRNG. If B<max_bytes> is nonnegative, 21 1.1 christos up to B<max_bytes> are read; 22 1.1 christos if B<max_bytes> is -1, the complete file is read. 23 1.1 christos Do not load the same file multiple times unless its contents have 24 1.1 christos been updated by RAND_write_file() between reads. 25 1.1 christos Also, note that B<filename> should be adequately protected so that an 26 1.1 christos attacker cannot replace or examine the contents. 27 1.1 christos If B<filename> is not a regular file, then user is considered to be 28 1.1 christos responsible for any side effects, e.g. non-anticipated blocking or 29 1.1 christos capture of controlling terminal. 30 1.1 christos 31 1.1 christos RAND_write_file() writes a number of random bytes (currently 128) to 32 1.1 christos file B<filename> which can be used to initialize the PRNG by calling 33 1.1 christos RAND_load_file() in a later session. 34 1.1 christos 35 1.1 christos RAND_file_name() generates a default path for the random seed 36 1.1 christos file. B<buf> points to a buffer of size B<num> in which to store the 37 1.1 christos filename. 38 1.1 christos 39 1.1 christos On all systems, if the environment variable B<RANDFILE> is set, its 40 1.1.1.2 christos value will be used as the seed filename. 41 1.1 christos Otherwise, the file is called C<.rnd>, found in platform dependent locations: 42 1.1 christos 43 1.1 christos =over 4 44 1.1 christos 45 1.1 christos =item On Windows (in order of preference) 46 1.1 christos 47 1.1 christos %HOME%, %USERPROFILE%, %SYSTEMROOT%, C:\ 48 1.1 christos 49 1.1 christos =item On VMS 50 1.1 christos 51 1.1 christos SYS$LOGIN: 52 1.1 christos 53 1.1 christos =item On all other systems 54 1.1 christos 55 1.1 christos $HOME 56 1.1 christos 57 1.1 christos =back 58 1.1 christos 59 1.1 christos If C<$HOME> (on non-Windows and non-VMS system) is not set either, or 60 1.1.1.2 christos B<num> is too small for the pathname, an error occurs. 61 1.1 christos 62 1.1 christos =head1 RETURN VALUES 63 1.1 christos 64 1.1 christos RAND_load_file() returns the number of bytes read or -1 on error. 65 1.1 christos 66 1.1 christos RAND_write_file() returns the number of bytes written, or -1 if the 67 1.1 christos bytes written were generated without appropriate seeding. 68 1.1 christos 69 1.1 christos RAND_file_name() returns a pointer to B<buf> on success, and NULL on 70 1.1 christos error. 71 1.1 christos 72 1.1 christos =head1 SEE ALSO 73 1.1 christos 74 1.1 christos L<RAND_add(3)>, 75 1.1 christos L<RAND_bytes(3)>, 76 1.1 christos L<RAND(7)> 77 1.1 christos 78 1.1 christos =head1 COPYRIGHT 79 1.1 christos 80 1.1.1.2 christos Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. 81 1.1 christos 82 1.1.1.3 christos Licensed under the Apache License 2.0 (the "License"). You may not use 83 1.1 christos this file except in compliance with the License. You can obtain a copy 84 1.1 christos in the file LICENSE in the source distribution or at 85 1.1 christos L<https://www.openssl.org/source/license.html>. 86 1.1 christos 87 1.1 christos =cut 88