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