line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::KDF::KDF1Generator;
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN
|
4
|
|
|
|
|
|
|
{
|
5
|
1
|
|
|
1
|
|
13097
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
6
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT_OK);
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
70
|
|
7
|
1
|
|
|
1
|
|
587
|
use Crypt::KDF::BaseKDFGenerator;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
287
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
10
|
($VERSION) = sprintf '%i.%03i', split(/\./,('$Revision: 0.1 $' =~ /Revision: (\S+)\s/)[0]); # $Date: $
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
6
|
require Exporter;
|
12
|
1
|
|
|
|
|
3
|
@EXPORT_OK = qw(kdf1_generate);
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
392
|
@ISA=qw{ Crypt::KDF::BaseKDFGenerator };
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
}
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Crypt::KDF::KDF1Generator - KDF1 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 = kdf1_generate( $digest, $seed, $len )
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Quick functional interface to use KDF1.
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub kdf1_generate
|
37
|
|
|
|
|
|
|
{
|
38
|
0
|
|
|
0
|
1
|
0
|
my ($digest, $seed, $len) = @_;
|
39
|
0
|
|
|
|
|
0
|
my $kdf = Crypt::KDF::KDF1Generator->new(-digest => $digest, -seed => $seed);
|
40
|
0
|
|
|
|
|
0
|
return $kdf->kdf($len);
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 $kdf = Crypt::KDF::KDF1Generator->new( [options] )
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Construct a KDF1 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
|
|
|
|
|
|
|
{
|
58
|
4
|
|
|
4
|
1
|
450
|
my $class = shift @_;
|
59
|
4
|
|
|
|
|
7
|
my $self = {};
|
60
|
4
|
50
|
|
|
|
13
|
bless($self, (ref($class) ? ref($class) : $class));
|
61
|
4
|
|
|
|
|
16
|
my %opts = @_;
|
62
|
4
|
50
|
|
|
|
11
|
if(exists $opts{-digest})
|
63
|
|
|
|
|
|
|
{
|
64
|
4
|
50
|
|
|
|
23
|
$self->{-digest} = (ref($opts{-digest}) ? ref($opts{-digest}) : $opts{-digest});
|
65
|
|
|
|
|
|
|
}
|
66
|
4
|
50
|
|
|
|
34
|
if(exists $opts{-digestparam})
|
67
|
|
|
|
|
|
|
{
|
68
|
0
|
|
|
|
|
0
|
$self->{-digestparam} = $opts{-digestparam};
|
69
|
|
|
|
|
|
|
}
|
70
|
4
|
50
|
|
|
|
11
|
if(exists $opts{-seed})
|
71
|
|
|
|
|
|
|
{
|
72
|
4
|
|
|
|
|
9
|
$self->{-seed} = $opts{-seed};
|
73
|
|
|
|
|
|
|
}
|
74
|
4
|
100
|
|
|
|
11
|
if(exists $opts{-iv})
|
75
|
|
|
|
|
|
|
{
|
76
|
2
|
|
|
|
|
6
|
$self->{-iv} = $opts{-iv};
|
77
|
|
|
|
|
|
|
}
|
78
|
4
|
|
|
|
|
5
|
$self->{-counter} = 0;
|
79
|
4
|
|
|
|
|
13
|
return $self;
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 $kdf->init( [options] )
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Initialize the KDF1 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
|
|
|
|
|
|
|
{
|
95
|
0
|
|
|
0
|
1
|
|
my $self = shift @_;
|
96
|
0
|
|
|
|
|
|
my %opts = @_;
|
97
|
0
|
0
|
|
|
|
|
if(exists $opts{-digest})
|
98
|
|
|
|
|
|
|
{
|
99
|
0
|
0
|
|
|
|
|
$self->{-digest} = (ref($opts{-digest}) ? ref($opts{-digest}) : $opts{-digest});
|
100
|
|
|
|
|
|
|
}
|
101
|
0
|
0
|
|
|
|
|
if(exists $opts{-digestparam})
|
102
|
|
|
|
|
|
|
{
|
103
|
0
|
|
|
|
|
|
$self->{-digestparam} = $opts{-digestparam};
|
104
|
|
|
|
|
|
|
}
|
105
|
0
|
0
|
|
|
|
|
if(exists $opts{-seed})
|
106
|
|
|
|
|
|
|
{
|
107
|
0
|
|
|
|
|
|
$self->{-seed} = $opts{-seed};
|
108
|
|
|
|
|
|
|
}
|
109
|
0
|
0
|
|
|
|
|
if(exists $opts{-iv})
|
110
|
|
|
|
|
|
|
{
|
111
|
0
|
|
|
|
|
|
$self->{-iv} = $opts{-iv};
|
112
|
|
|
|
|
|
|
}
|
113
|
0
|
|
|
|
|
|
$self->{-counter} = 0;
|
114
|
0
|
|
|
|
|
|
return $self;
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub counter
|
118
|
|
|
|
|
|
|
{
|
119
|
0
|
|
|
0
|
1
|
|
my $self = shift @_;
|
120
|
0
|
|
|
|
|
|
return $self->{-counter};
|
121
|
|
|
|
|
|
|
}
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1;
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__
|