KDF2Generator.pm

filter: Statementstmt 60.0% 27 / 45 Branchbran 31.8% 7 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 4 / 4 totaltotal 54.4% 43 / 79 CC 12 SCAR 28.0
CC
12
Cov
51%
init
42.0
new
7.6
kdf2_generate
2.0
CRAP 16.5
« KDF1Generator.pm ↑ Summary _base.pm »
1 package Crypt::KDF::KDF2Generator;
2
3 BEGIN
4 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶ use vars qw($VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use Crypt::KDF::BaseKDFGenerator;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 1 ($VERSION) = sprintf '%i.%03i', split(/\./,('$Revision: 0.1 $' =~ /Revision: (\S+)\s/)[0]); # $Date: $
10
11 1 require Exporter;
12 1 @EXPORT_OK = qw(kdf2_generate);
13
14 1 @ISA=qw{ Crypt::KDF::BaseKDFGenerator };
15
16 }
17
18 =head1 NAME
19
20 Crypt::KDF::KDF2Generator - KDF2 generator for derived keys and ivs as defined by IEEE P1363a/ISO 18033.
21
22 =head1 SYNOPSIS
23
24 =head1 DESCRIPTION
25
26 This implementation is based on ISO 18033/P1363a.
27
28 =head1 FUNCTIONS
29
30 =head2 $derivedKey = kdf2_generate( $digest, $seed, $len )
31
32 Quick functional interface to use KDF2.
33
34 =cut
35
36 sub kdf2_generate
37 0 ▶{
Subroutine kdf2_generate: not called CC=1 SCAR=6.9
Pod documented
38 0 my ($digest, $seed, $len) = @_;
39 0 my $kdf = Crypt::KDF::KDF2Generator->new(-digest => $digest, -seed => $seed);
40 0 return $kdf->kdf($len);
41 }
42
43 =head1 METHODS
44
45 =head2 $kdf = Crypt::KDF::KDF2Generator->new( [options] )
46
47 Construct a KDF2 generator.
48
49 -digest the digest to be used as the source of derived keys.
50 -digestparam optional parameters for the digest used to derive keys.
51 -seed the seed to be used to derive keys.
52 -iv optional iv to be used to derive keys.
53
54 =cut
55
56 sub new
57 4 ▶{
Subroutine new: called CC=7 SCAR=20.3
Pod documented
58 4 my $class = shift @_;
59 4 my $self = {};
60 4 ▶ bless($self, (ref($class) ? ref($class) : $class));
Branch: 1 branch
BranchTrueFalseTotal
ref $class ? : 0 4 4
61 4 my %opts = @_;
62 4 ▶ if(exists $opts{-digest})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"-digest"}) 4 0 4
63 {
64 4 ▶ $self->{-digest} = (ref($opts{-digest}) ? ref($opts{-digest}) : $opts{-digest});
Branch: 1 branch
BranchTrueFalseTotal
ref $opts{'-digest'} ? : 0 4 4
65 }
66 4 ▶ if(exists $opts{-digestparam})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"-digestparam"}) 0 4 4
67 {
68 0 $self->{-digestparam} = $opts{-digestparam};
69 }
70 4 ▶ if(exists $opts{-seed})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"-seed"}) 4 0 4
71 {
72 4 $self->{-seed} = $opts{-seed};
73 }
74 4 ▶ if(exists $opts{-iv})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"-iv"}) 2 2 4
75 {
76 2 $self->{-iv} = $opts{-iv};
77 }
78 4 $self->{-counter} = 1;
79 4 return $self;
80 }
81
82 =head2 $kdf->init( [options] )
83
84 Initialize the KDF2 generator.
85
86 -digest the digest to be used as the source of derived keys.
87 -digestparam optional parameters for the digest used to derive keys.
88 -seed the seed to be used to derive keys.
89 -iv optional iv to be used to derive keys.
90
91 =cut
92
93 sub init
94 0 ▶{
Subroutine init: not called CC=6 SCAR=37.4
Pod documented
95 0 my $self = shift @_;
96 0 my %opts = @_;
97 0 ▶ if(exists $opts{-digest})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"-digest"}) 0 0 0
98 {
99 0 ▶ $self->{-digest} = (ref($opts{-digest}) ? ref($opts{-digest}) : $opts{-digest});
Branch: 1 branch
BranchTrueFalseTotal
ref $opts{'-digest'} ? : 0 0 0
100 }
101 0 ▶ if(exists $opts{-digestparam})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"-digestparam"}) 0 0 0
102 {
103 0 $self->{-digestparam} = $opts{-digestparam};
104 }
105 0 ▶ if(exists $opts{-seed})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"-seed"}) 0 0 0
106 {
107 0 $self->{-seed} = $opts{-seed};
108 }
109 0 ▶ if(exists $opts{-iv})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"-iv"}) 0 0 0
110 {
111 0 $self->{-iv} = $opts{-iv};
112 }
113 0 $self->{-counter} = 1;
114 0 return $self;
115 }
116
117 sub counter
118 0 ▶{
Subroutine counter: not called CC=1 SCAR=6.9
Pod documented
119 0 my $self = shift @_;
120 0 return $self->{-counter};
121 }
122
123 1 1;
124
125 __END__
« KDF1Generator.pm ↑ Summary _base.pm »