ea81492c2c55797e2549640cc26853863e1ab98d
[openssl.git] / doc / man3 / RAND_add.pod
1 =pod
2
3 =head1 NAME
4
5 RAND_add, RAND_poll, RAND_poll_ex, RAND_poll_cb,
6 RAND_seed, RAND_status, RAND_event, RAND_screen
7 - add randomness to the PRNG or get its status
8
9 =head1 SYNOPSIS
10
11  #include <openssl/rand.h>
12
13  int RAND_status(void);
14
15  typedef void (*RAND_poll_cb)(void *arg,
16                               const void *buf, int num, double randomness);
17  int RAND_poll_ex(RAND_poll_cb cb, void *arg);
18  int RAND_poll();
19
20  void RAND_add(const void *buf, int num, double randomness);
21  void RAND_seed(const void *buf, int num);
22
23 Deprecated:
24
25  #if OPENSSL_API_COMPAT < 0x10100000L
26  int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam);
27  void RAND_screen(void);
28  #endif
29
30 =head1 DESCRIPTION
31
32 Random numbers are a vital part of cryptography, including key generation,
33 creating salts, etc., and software-based
34 generators must be "seeded" with external randomness before they can be
35 used as a cryptographically-secure pseudo-random number generator (CSPRNG).
36 The availability of common hardware with special instructions and
37 modern operating systems, which may use items such as interrupt jitter
38 and network packet timings, can be reasonable sources of seeding material.
39
40 RAND_status() indicates whether or not the CSPRNG has been sufficiently
41 seeded. If not, functions such as RAND_bytes(3) will fail.
42
43 RAND_poll_ex() uses the system's capabilities to obtain a buffer
44 containing random bits which can then be used to seed a CSPRNG. The
45 exact features used depends on how OpenSSL was configured, and a summary
46 can be displayed with the OpenSSL L<version(1)> command.  This function
47 is normally called as needed by the CSPRNG.  The B<arg> parameter is an
48 arbitrary pointer which will be passed as an argument to the callback.
49 The B<cb> function is called each time there is data to add.
50
51 RAND_poll() invokes RAND_poll_ex() with B<cb> and B<arg> set so that it
52 will call RAND_add(), to add the randomness to the global CSPRNG.
53
54 RAND_add() mixes the B<num> bytes at B<buf> into the PRNG state.
55 The B<randomness> argument is an estimate of how much randomness is
56 contained in
57 B<buf>, in bytes, and should be a number between zero and B<num>.
58 Details about sources of randomness and how to estimate their randomness
59 can be found in the literature; for example NIST SP 800-90B.
60 The content of B<buf> cannot be recovered from subsequent CSPRNG output.
61 This function will not normally be needed, as RAND_poll() should have been
62 configured to do the appropriate seeding for the local platform.
63 Applications that need to keep random state in an external file should
64 use L<RAND_load_file(3)>.
65
66 RAND_seed() is equivalent to RAND_add() with B<randomness> set to B<num>.
67
68 RAND_event() and RAND_screen() are equivalent to RAND_poll().
69
70 =head1 RETURN VALUES
71
72 RAND_status() returns 1 if the CSPRNG has been seeded
73 with enough data, 0 otherwise.
74
75 RAND_poll() returns 1 if it generated seed data, 0 otherwise.
76
77 RAND_event() returns RAND_status().
78
79 The other functions do not return values.
80
81 =head1 HISTORY
82
83 RAND_event() and RAND_screen() were deprecated in OpenSSL 1.1.0 and should
84 not be used.
85
86 =head1 SEE ALSO
87
88 L<RAND_bytes(3)>, L<RAND_egd(3)>,
89 L<RAND_load_file(3)>
90
91 =head1 COPYRIGHT
92
93 Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
94
95 Licensed under the OpenSSL license (the "License").  You may not use
96 this file except in compliance with the License.  You can obtain a copy
97 in the file LICENSE in the source distribution or at
98 L<https://www.openssl.org/source/license.html>.
99
100 =cut