1Random(3) User Contributed Perl Documentation Random(3)
2
3
4
6 Crypt::OpenSSL::Random - OpenSSL/LibreSSL pseudo-random number
7 generator access
8
10 use Crypt::OpenSSL::Random;
11
12 Crypt::OpenSSL::Random::random_seed($good_random_data);
13 Crypt::OpenSSL::Random::random_egd("/tmp/entropy");
14 Crypt::OpenSSL::Random::random_status() or
15 die "Unable to sufficiently seed the random number generator".
16
17 my $ten_good_random_bytes = Crypt::OpenSSL::Random::random_bytes(10);
18 my $ten_ok_random_bytes = Crypt::OpenSSL::Random::random_pseudo_bytes(10);
19
21 "Crypt::OpenSSL::Random" provides the ability to seed and query the
22 OpenSSL and LibreSSL library's pseudo-random number generators.
23
24 Note: On LibreSSL "random_egd()" is not defined.
25
26 EXPORT
27 None by default.
28
30 random_bytes (IV num_bytes)
31 This function, returns a specified number of cryptographically
32 strong pseudo-random bytes from the PRNG. If the PRNG has not been
33 seeded with enough randomness to ensure an unpredictable byte
34 sequence, then a false value is returned.
35
36 random_pseudo_bytes (IV num_bytes)
37 This function, is similar to "random_bytes", but the resulting
38 sequence of bytes are not necessarily unpredictable. They can be
39 used for non-cryptographic purposes and for certain purposes in
40 cryptographic protocols, but usually not for key generation etc.
41
42 random_seed (PV random_bytes_string)
43 This function seeds the PRNG with a supplied string of bytes. It
44 returns true if the PRNG has sufficient seeding. Note: calling
45 this function with non-random bytes is of limited value at best!
46
47 random_egd (PV egd_string)
48 This function seeds the PRNG with data from the specified entropy
49 gathering daemon. Returns the number of bytes read from the daemon
50 on success, or "-1" if not enough bytes were read, or if the
51 connection to the daemon failed.
52
53 "libressl" considers this function insecure, so with libressl this
54 function does not exist.
55
56 random_status ()
57 This function returns true if the PRNG has sufficient seeding.
58
60 Because of the internal workings of OpenSSL's random library, the
61 pseudo-random number generator (PRNG) accessed by
62 Crypt::OpenSSL::Random will be different than the one accessed by any
63 other perl module. Hence, to use a module such as
64 Crypt::OpenSSL::Random, you will need to seed the PRNG used there from
65 one used here. This class is still advantageous, however, as it
66 centralizes other methods, such as "random_egd", in one place.
67
69 Ian Robertson, "iroberts@cpan.com"
70
71 Now maintained by Reini Urban, "rurban@cpan.org"
72
74 This module is available under the same licences as perl, the Artistic
75 license and the GPL.
76
78 perl(1), rand(3), RAND_add(3), RAND_egd(3), RAND_bytes(3).
79
80
81
82perl v5.34.0 2021-07-22 Random(3)