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