Skip to content

Commit 7c243eb

Browse files
committed
Fixed bug involving manually-specified IV not being used in some circumstances.
1 parent 651c104 commit 7c243eb

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
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.04 Mon 17 May 2021 10:58:37 AM EDT
3+
- Fixed bug involving manually-specified IV not being used in some circumstances.
4+
25
3.03 Sun 18 Apr 2021 10:54:19 PM EDT
36
- Fixed bug which caused an extraneous block of garbage data to be appended to encrypted
47
string when "nopadding" specified and plaintext is even multiple of blocksize.

lib/Crypt/CBC.pm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use Crypt::CBC::PBKDF;
66
use bytes;
77
use vars qw($VERSION);
88
no warnings 'uninitialized';
9-
$VERSION = '3.03';
9+
$VERSION = '3.04';
1010

1111
use constant RANDOM_DEVICE => '/dev/urandom';
1212
use constant DEFAULT_PBKDF => 'opensslv1';
@@ -97,6 +97,7 @@ sub new {
9797
'keysize' => $ks,
9898
'header_mode' => $header_mode,
9999
'literal_key' => $literal_key,
100+
'literal_iv' => defined $iv,
100101
'chain_mode' => $chain_mode,
101102
'make_random_salt' => $random_salt,
102103
'make_random_iv' => $random_iv,
@@ -143,7 +144,7 @@ sub encrypt_hex (\$$) {
143144

144145
sub decrypt_hex (\$$) {
145146
my ($self,$data) = @_;
146-
return $self->decrypt(pack'H*',$data);
147+
return $self->decrypt(pack 'H*',$data);
147148
}
148149

149150
# call to start a series of encryption/decryption operations
@@ -651,7 +652,9 @@ sub _read_key_and_iv {
651652
($self->{salt}) = $$input_stream =~ /^Salted__(.{8})/s;
652653
croak "Ciphertext does not begin with a valid header for 'salt' header mode" unless defined $self->{salt};
653654
substr($$input_stream,0,16) = '';
654-
($self->{key},$self->{iv}) = $self->pbkdf_obj->key_and_iv($self->{salt},$self->{passphrase});
655+
my ($k,$i) = $self->pbkdf_obj->key_and_iv($self->{salt},$self->{passphrase});
656+
$self->{key} = $k unless $self->{literal_key};
657+
$self->{iv} = $i unless $self->{literal_iv};
655658
}
656659

657660
elsif ($header_mode eq 'randomiv') {

t/parameters.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ test($old_salt ne $crypt->salt, "salt didn't change after an encrypt");
6262
test($old_key ne $crypt->key, "key didn't change after an encrypt");
6363

6464
test($plaintext eq $crypt->decrypt($ciphertext1),"decrypted text doesn't match original");
65-
test($old_iv eq $crypt->iv, "original IV wasn't restored after decryption");
66-
test($old_salt eq $crypt->salt, "original salt wasn't restored after decryption");
67-
test($old_key eq $crypt->key, "original key wasn't restored after decryption");
65+
test($old_iv eq $crypt->iv, "original IV wasn't restored after decryption");
66+
test($old_salt eq $crypt->salt, "original salt wasn't restored after decryption");
67+
test($old_key eq $crypt->key, "original key wasn't restored after decryption");
6868

6969
test($crypt->passphrase eq 'test key',"get passphrase()");
7070
$crypt->passphrase('new key');

0 commit comments

Comments
 (0)