@@ -3,12 +3,12 @@ package Crypt::CBC;
33use strict;
44use Carp ' croak' ,' carp' ;
55use Crypt::CBC::PBKDF;
6+ use Crypt::URandom ();
67use bytes;
78use vars qw( $VERSION) ;
89no warnings ' uninitialized' ;
910$VERSION = ' 3.05' ;
1011
11- use constant RANDOM_DEVICE => ' /dev/urandom' ;
1212use constant DEFAULT_PBKDF => ' opensslv1' ;
1313use constant DEFAULT_ITER => 10_000; # same as OpenSSL default
1414
@@ -767,14 +767,7 @@ sub random_bytes {
767767sub _get_random_bytes {
768768 my $self = shift ;
769769 my $length = shift ;
770- my $result ;
771-
772- if (-r RANDOM_DEVICE && open (F,RANDOM_DEVICE)) {
773- read (F,$result ,$length );
774- close F;
775- } else {
776- $result = pack (" C*" ,map {rand (256)} 1..$length );
777- }
770+ my $result = Crypt::URandom::urandom($length );
778771 # Clear taint and check length
779772 $result =~ / ^(.+)$ /s ;
780773 length ($1 ) == $length or croak " Invalid length while gathering $length random bytes" ;
@@ -1430,10 +1423,9 @@ B<literal_key> is false.
14301423
14311424=head2 $data = random_bytes($numbytes)
14321425
1433- Return $numbytes worth of random data. On systems that support the
1434- "/dev/urandom" device file, this data will be read from the
1435- device. Otherwise, it will be generated by repeated calls to the Perl
1436- rand() function.
1426+ Return $numbytes worth of random data, using L<Crypt::URandom> , which
1427+ will read data from the system's source of random bytes, such as
1428+ F</dev/urandom> .
14371429
14381430=head2 cipher(), pbkdf(), padding(), keysize(), blocksize(), chain_mode()
14391431
0 commit comments