Skip to content

Commit 524db90

Browse files
committed
Fixed bug in which manually-specified key and -pkdf=>"none" was not having effect
1 parent 7c243eb commit 524db90

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-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.05 Thu 20 May 2021 12:00:18 PM EDT
3+
- Fixed bug involving manually-specified key not being used in some circumstances.
4+
25
3.04 Mon 17 May 2021 10:58:37 AM EDT
36
- Fixed bug involving manually-specified IV not being used in some circumstances.
47

lib/Crypt/CBC.pm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ sub new {
7272

7373
# HEADER consistency
7474
if ($header_mode eq 'salt') {
75-
croak "Cannot use salt-based key generation if literal key is specified"
75+
croak "Cannot use -header mode of 'salt' if a literal key is specified or key derivation function is none"
7676
if $literal_key;
7777
}
7878
elsif ($header_mode eq 'randomiv') {
79-
croak "Cannot encrypt using a non-8 byte blocksize cipher when using randomiv header mode"
79+
croak "Cannot use -header mode of 'randomiv' in conjunction with a cipher whose blocksize greater than 8"
8080
unless $bs == 8
8181
}
8282

@@ -618,16 +618,15 @@ sub pbkdf_obj {
618618
}
619619

620620
############################# generating key, iv and salt ########################
621-
# hopefully a replacement for mess below
622621
sub set_key_and_iv {
623622
my $self = shift;
624623

625-
if (!$self->{literal_key}) {
624+
if ($self->pbkdf eq 'none' || $self->{literal_key}) {
625+
$self->{iv} = $self->_get_random_bytes($self->blocksize) if $self->{make_random_iv};
626+
} else {
626627
my ($key,$iv) = $self->pbkdf_obj->key_and_iv($self->{salt},$self->{passphrase});
627628
$self->{key} = $key;
628629
$self->{iv} = $iv if $self->{make_random_iv};
629-
} else {
630-
$self->{iv} = $self->_get_random_bytes($self->blocksize) if $self->{make_random_iv};
631630
}
632631

633632
length $self->{salt} == 8 or croak "Salt must be exactly 8 bytes long";
@@ -929,6 +928,7 @@ Crypt::CBC - Encrypt Data with Cipher Block Chaining Mode
929928
$key = Crypt::CBC->random_bytes(8); # assuming a 8-byte block cipher
930929
$iv = Crypt::CBC->random_bytes(8);
931930
$cipher = Crypt::CBC->new(-pbkdf => 'none',
931+
-header => 'none',
932932
-key => $key,
933933
-iv => $iv);
934934

0 commit comments

Comments
 (0)