Skip to content

Commit f3ad896

Browse files
authored
Merge pull request #10 from robrwo/rrwo/use-crypt-urandom-9
Fix CVE-2025-2814 by using Crypt::URandom to read random bytes
2 parents 97908cc + 784d599 commit f3ad896

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

Changes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Revision history for Perl extension Crypt::CBC.
2+
3+
- Fixed CVE-2025-2814 by using Crypt::URandom to read random bytes.
4+
25
3.05 Thu 20 May 2021 12:00:18 PM EDT
36
- Fixed bug involving manually-specified key not being used in some circumstances.
47

Makefile.PL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ WriteMakefile(
99
'Digest::SHA' => 0,
1010
'Crypt::PBKDF2' => 0,
1111
'Crypt::Cipher::AES' => 0,
12+
'Crypt::URandom' => 0,
1213
},
1314
'LIBS' => [''], # e.g., '-lm'
1415
'DEFINE' => '', # e.g., '-DHAVE_SOMETHING'

lib/Crypt/CBC.pm

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package Crypt::CBC;
33
use strict;
44
use Carp 'croak','carp';
55
use Crypt::CBC::PBKDF;
6+
use Crypt::URandom ();
67
use bytes;
78
use vars qw($VERSION);
89
no warnings 'uninitialized';
910
$VERSION = '3.05';
1011

11-
use constant RANDOM_DEVICE => '/dev/urandom';
1212
use constant DEFAULT_PBKDF => 'opensslv1';
1313
use constant DEFAULT_ITER => 10_000; # same as OpenSSL default
1414

@@ -767,14 +767,7 @@ sub random_bytes {
767767
sub _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

Comments
 (0)