1Crypt::Random(3) User Contributed Perl Documentation Crypt::Random(3)
2
3
4
6 Crypt::Random - Cryptographically Secure, True Random Number Generator.
7
9 $Revision: 1.11 $
10 $Date: 2001/07/12 15:59:47 $
11
13 use Crypt::Random qw( makerandom );
14 my $r = makerandom ( Size => 512, Strength => 1 );
15
17 Crypt::Random is an interface module to the /dev/random device found on
18 most modern unix systems. It also interfaces with egd, a user space
19 entropy gathering daemon, available for systems where /dev/random (or
20 similar) devices are not available. When Math::Pari is installed,
21 Crypt::Random can generate random integers of arbritary size of a given
22 bitsize or in a specified interval.
23
25 The /dev/random driver maintains an estimate of true randomness in the
26 pool and decreases it every time random strings are requested for use.
27 When the estimate goes down to zero, the routine blocks and waits for
28 the occurrence of non-deterministic events to refresh the pool.
29
30 When the routine is blocked, Crypt::Random's read() will be blocked
31 till desired amount of random bytes have been read off of the device.
32 The /dev/random kernel module also provides another interface,
33 /dev/urandom, that does not wait for the entropy-pool to recharge and
34 returns as many bytes as requested. For applications that must not
35 block (for a potentially long time) should use /dev/urandom.
36 /dev/random should be reserved for instances where very high quality
37 randomness is desired.
38
40 If there's a hardware random number generator available, for instance
41 the Intel i8x0 random number generator, please use it instead of
42 /dev/random!. It'll be high quality, a lot faster and it won't block!
43 Usually your OS will provide access to the RNG as a device, eg
44 (/dev/intel_rng).
45
47 makerandom()
48 Generates a random number of requested bitsize in base 10.
49 Following arguments can be specified.
50
51 Size
52 Bitsize of the random number.
53
54 Strength 0 || 1
55 Value of 1 implies that /dev/random should be used for
56 requesting random bits while 0 implies /dev/urandom.
57
58 Device
59 Alternate device to request random bits from.
60
61 Uniform 0 || 1
62 Value of 0 (default) implies that the high bit of the generated
63 random number is always set, ensuring the bitsize of the
64 generated random will be exactly Size bits. For uniformally
65 distributed random numbers, Uniform should be set to 1.
66
67 makerandom_itv()
68 Generates a random number in the specified interval. In addition
69 to the arguments to makerandom() following attributes can be
70 specified.
71
72 Lower
73 Inclusive Lower limit.
74
75 Upper
76 Exclusive Upper limit.
77
78 makerandom_octet()
79 Generates a random octet string of specified length. In addition to
80 Strength, Device and Verbosity, following arguments can be
81 specified.
82
83 Length
84 Length of the desired octet string.
85
86 Skip
87 An octet string consisting of characters to be skipped while
88 reading from the random device.
89
91 Crypt::Random needs Math::Pari 2.001802 or higher. As of this writing,
92 the latest version of Math::Pari isn't available from CPAN. Fetch it
93 from ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl/modules/
94
96 1 random.c by Theodore Ts'o. Found in drivers/char directory of the
97 Linux kernel sources.
98 2 Handbook of Applied Cryptography by Menezes, Paul C. van Oorschot and
99 Scott Vanstone.
100
102 Vipul Ved Prakash, <mail@vipul.net>
103
104
105
106perl v5.12.0 2010-04-30 Crypt::Random(3)