1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1 christos RAND_add, RAND_poll, RAND_seed, RAND_status, RAND_event, RAND_screen, 6 1.1 christos RAND_keep_random_devices_open 7 1.1 christos - add randomness to the PRNG or get its status 8 1.1 christos 9 1.1 christos =head1 SYNOPSIS 10 1.1 christos 11 1.1 christos #include <openssl/rand.h> 12 1.1 christos 13 1.1 christos int RAND_status(void); 14 1.1 christos int RAND_poll(); 15 1.1 christos 16 1.1 christos void RAND_add(const void *buf, int num, double randomness); 17 1.1 christos void RAND_seed(const void *buf, int num); 18 1.1 christos 19 1.1 christos void RAND_keep_random_devices_open(int keep); 20 1.1 christos 21 1.1.1.4 christos The following functions have been deprecated since OpenSSL 1.1.0, and can be 22 1.1.1.4 christos hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 23 1.1.1.4 christos see L<openssl_user_macros(7)>: 24 1.1 christos 25 1.1 christos int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam); 26 1.1 christos void RAND_screen(void); 27 1.1 christos 28 1.1 christos =head1 DESCRIPTION 29 1.1 christos 30 1.1 christos These functions can be used to seed the random generator and to check its 31 1.1 christos seeded state. 32 1.1 christos In general, manual (re-)seeding of the default OpenSSL random generator 33 1.1 christos (L<RAND_OpenSSL(3)>) is not necessary (but allowed), since it does (re-)seed 34 1.1 christos itself automatically using trusted system entropy sources. 35 1.1 christos This holds unless the default RAND_METHOD has been replaced or OpenSSL was 36 1.1 christos built with automatic reseeding disabled, see L<RAND(7)> for more details. 37 1.1 christos 38 1.1 christos RAND_status() indicates whether or not the random generator has been sufficiently 39 1.1 christos seeded. If not, functions such as L<RAND_bytes(3)> will fail. 40 1.1 christos 41 1.1 christos RAND_poll() uses the system's capabilities to seed the random generator using 42 1.1 christos random input obtained from polling various trusted entropy sources. 43 1.1 christos The default choice of the entropy source can be modified at build time, 44 1.1 christos see L<RAND(7)> for more details. 45 1.1 christos 46 1.1 christos RAND_add() mixes the B<num> bytes at B<buf> into the internal state 47 1.1 christos of the random generator. 48 1.1 christos This function will not normally be needed, as mentioned above. 49 1.1 christos The B<randomness> argument is an estimate of how much randomness is 50 1.1 christos contained in 51 1.1 christos B<buf>, in bytes, and should be a number between zero and B<num>. 52 1.1 christos Details about sources of randomness and how to estimate their randomness 53 1.1 christos can be found in the literature; for example [NIST SP 800-90B]. 54 1.1 christos The content of B<buf> cannot be recovered from subsequent random generator output. 55 1.1 christos Applications that intend to save and restore random state in an external file 56 1.1 christos should consider using L<RAND_load_file(3)> instead. 57 1.1 christos 58 1.1.1.4 christos NOTE: In FIPS mode, random data provided by the application is not considered to 59 1.1.1.4 christos be a trusted entropy source. It is mixed into the internal state of the RNG as 60 1.1.1.4 christos additional data only and this does not count as a full reseed. 61 1.1.1.4 christos For more details, see L<EVP_RAND(7)>. 62 1.1.1.4 christos 63 1.1 christos RAND_seed() is equivalent to RAND_add() with B<randomness> set to B<num>. 64 1.1 christos 65 1.1 christos RAND_keep_random_devices_open() is used to control file descriptor 66 1.1 christos usage by the random seed sources. Some seed sources maintain open file 67 1.1 christos descriptors by default, which allows such sources to operate in a 68 1.1 christos chroot(2) jail without the associated device nodes being available. When 69 1.1 christos the B<keep> argument is zero, this call disables the retention of file 70 1.1.1.3 christos descriptors. Conversely, a nonzero argument enables the retention of 71 1.1 christos file descriptors. This function is usually called during initialization 72 1.1.1.4 christos and it takes effect immediately. This capability only applies to the default 73 1.1.1.4 christos provider. 74 1.1 christos 75 1.1 christos RAND_event() and RAND_screen() are equivalent to RAND_poll() and exist 76 1.1 christos for compatibility reasons only. See HISTORY section below. 77 1.1 christos 78 1.1 christos =head1 RETURN VALUES 79 1.1 christos 80 1.1 christos RAND_status() returns 1 if the random generator has been seeded 81 1.1 christos with enough data, 0 otherwise. 82 1.1 christos 83 1.1 christos RAND_poll() returns 1 if it generated seed data, 0 otherwise. 84 1.1 christos 85 1.1 christos RAND_event() returns RAND_status(). 86 1.1 christos 87 1.1 christos The other functions do not return values. 88 1.1 christos 89 1.1 christos =head1 SEE ALSO 90 1.1 christos 91 1.1 christos L<RAND_bytes(3)>, 92 1.1 christos L<RAND_egd(3)>, 93 1.1 christos L<RAND_load_file(3)>, 94 1.1 christos L<RAND(7)> 95 1.1.1.4 christos L<EVP_RAND(7)> 96 1.1 christos 97 1.1.1.2 christos =head1 HISTORY 98 1.1.1.2 christos 99 1.1.1.2 christos RAND_event() and RAND_screen() were deprecated in OpenSSL 1.1.0 and should 100 1.1.1.2 christos not be used. 101 1.1.1.2 christos 102 1.1 christos =head1 COPYRIGHT 103 1.1 christos 104 1.1.1.4 christos Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. 105 1.1 christos 106 1.1.1.4 christos Licensed under the Apache License 2.0 (the "License"). You may not use 107 1.1 christos this file except in compliance with the License. You can obtain a copy 108 1.1 christos in the file LICENSE in the source distribution or at 109 1.1 christos L<https://www.openssl.org/source/license.html>. 110 1.1 christos 111 1.1 christos =cut 112