File Coverage

lib/Crypt/CBC/PBKDF/randomiv.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition 3 6 50.0
subroutine 5 5 100.0
pod 0 2 0.0
total 32 37 86.4


line stmt bran cond sub pod time code
1             package Crypt::CBC::PBKDF::randomiv;
2              
3             # This is for compatibility with early (pre v1.0) versions of OpenSSL
4             # THE KEYS GENERATED BY THIS ALGORITHM ARE INSECURE!!!
5 1     1   8 use strict;
  1         10  
  1         42  
6 1     1   7 use base 'Crypt::CBC::PBKDF';
  1         2  
  1         237  
7 1     1   9 use Digest::MD5 'md5';
  1         2  
  1         288  
8              
9             # options:
10             # salt_len => 8 default
11             # key_len => 32 default
12             # iv_len => 16 default
13              
14             sub create {
15 3     3 0 7 my $class = shift;
16 3         13 my %options = @_;
17 3   50     20 $options{salt_len} ||= 8;
18 3   50     8 $options{key_len} ||= 32;
19 3   50     7 $options{iv_len} ||= 16;
20 3         24 return bless \%options,$class;
21             }
22              
23             sub generate_hash {
24 3     3 0 5 my $self = shift;
25 3         6 my ($salt,$passphrase) = @_;
26 3         8 my $desired_len = $self->{key_len};
27 3         14 my $material = md5($passphrase);
28 3         10 while (length($material) < $desired_len) {
29 9         30 $material .= md5($material);
30             }
31 3         7 substr($material,$desired_len) = '';
32 3         14 $material .= Crypt::CBC->_get_random_bytes($self->{iv_len});
33 3         12 return $material;
34             }
35              
36             1;