The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Crypt::Random - Cryptographically Secure, True Random Number Generator.

SYNOPSIS

 use Crypt::Random qw( makerandom ); 
 my $r = makerandom ( Size => 512, Strength => 1 ); 

DESCRIPTION

Crypt::Random is an interface module to the /dev/random device found on most modern Unix systems. The /dev/random driver gathers environmental noise from various non-deterministic sources including, but not limited to, inter-keyboard timings and inter-interrupt timings that occur within the operating system environment. The noise data is sampled and combined with a CRC-like mixing function into a continuously updating "entropy-pool". Random bit strings are obtained by taking a MD5 hash of the contents of this pool. The one-way hash function distills the true random bits from pool data and hides the state of the pool from adversaries.

The /dev/random routine maintains an estimate of true randomness in the pool and decreases it every time random strings are requested for use. When the estimate goes down to zero, the routine locks and waits for the occurrence of non-deterministic events to refresh the pool.

The /dev/random kernel module also provides another interface, /dev/urandom, that does not wait for the entropy-pool to re-charge and returns as many bytes as requested. As a result /dev/urandom is considerably faster at generation compared to /dev/random which is used only when very high quality randomness is desired.

METHODS

makerandom()

Generates a random number of requested bitsize in base 10. Following arguments can be specified.

Size

Bitsize of the random number.

Strength 0 || 1

Value of 1 implies that /dev/random should be used for requesting random bits while 0 implies /dev/urandom.

Device

Alternate device to request random bits from.

makerandom_itv()

Generates a random number in the specified interval. In addition to the arguments to makerandom() following attributes can be specified.

Lower

Inclusive Lower limit.

Upper

Exclusive Upper limit.

BIBLIOGRAPHY

1 random.c by Theodore Ts'o. Found in drivers/char directory of the Linux kernel sources.
2 Handbook of Applied Cryptography by Menezes, Paul C. van Oorschot and Scott Vanstone.
3 RFC 1321, The MD5 Message Digest Algorithm by Ronald Rivest.

AUTHOR

Vipul Ved Prakash, mail@vipul.net

4 POD Errors

The following errors were encountered while parsing the POD:

Around line 115:

'=item' outside of any '=over'

Around line 156:

You forgot a '=back' before '=head1'

Around line 158:

'=item' outside of any '=over'

Around line 166:

You forgot a '=back' before '=head1'