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   9 use strict;
  1         2  
  1         44  
6 1     1   7 use base 'Crypt::CBC::PBKDF';
  1         2  
  1         177  
7 1     1   7 use Digest::MD5 'md5';
  1         2  
  1         295  
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 8 my $class = shift;
16 3         11 my %options = @_;
17 3   50     16 $options{salt_len} ||= 8;
18 3   50     6 $options{key_len} ||= 32;
19 3   50     7 $options{iv_len} ||= 16;
20 3         27 return bless \%options,$class;
21             }
22              
23             sub generate_hash {
24 3     3 0 4 my $self = shift;
25 3         8 my ($salt,$passphrase) = @_;
26 3         8 my $desired_len = $self->{key_len};
27 3         14 my $material = md5($passphrase);
28 3         9 while (length($material) < $desired_len) {
29 9         31 $material .= md5($material);
30             }
31 3         8 substr($material,$desired_len) = '';
32 3         10 $material .= Crypt::CBC->_get_random_bytes($self->{iv_len});
33 3         12 return $material;
34             }
35              
36             1;