line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Digest::HMAC; |
2
|
|
|
|
|
|
|
our $VERSION = '1.03_01'; # TRIAL VERSION |
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
417
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# OO interface |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new |
10
|
|
|
|
|
|
|
{ |
11
|
14
|
|
|
14
|
0
|
29
|
my($class, $key, $hasher, $block_size) = @_; |
12
|
14
|
|
50
|
|
|
28
|
$block_size ||= 64; |
13
|
14
|
100
|
|
|
|
35
|
$key = $hasher->new->add($key)->digest if length($key) > $block_size; |
14
|
|
|
|
|
|
|
|
15
|
14
|
|
|
|
|
51
|
my $self = bless {}, $class; |
16
|
14
|
|
|
|
|
46
|
$self->{k_ipad} = $key ^ (chr(0x36) x $block_size); |
17
|
14
|
|
|
|
|
27
|
$self->{k_opad} = $key ^ (chr(0x5c) x $block_size); |
18
|
14
|
|
|
|
|
45
|
$self->{hasher} = $hasher->new->add($self->{k_ipad}); |
19
|
14
|
|
|
|
|
122
|
$self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub reset |
23
|
|
|
|
|
|
|
{ |
24
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
25
|
0
|
|
|
|
|
0
|
$self->{hasher}->reset->add($self->{k_ipad}); |
26
|
0
|
|
|
|
|
0
|
$self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
14
|
|
|
14
|
0
|
45
|
sub add { my $self = shift; $self->{hasher}->add(@_); $self; } |
|
14
|
|
|
|
|
39
|
|
|
14
|
|
|
|
|
29
|
|
30
|
0
|
|
|
0
|
0
|
0
|
sub addfile { my $self = shift; $self->{hasher}->addfile(@_); $self; } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _digest |
33
|
|
|
|
|
|
|
{ |
34
|
14
|
|
|
14
|
|
16
|
my $self = shift; |
35
|
14
|
|
|
|
|
44
|
my $inner_digest = $self->{hasher}->digest; |
36
|
14
|
|
|
|
|
52
|
$self->{hasher}->reset->add($self->{k_opad}, $inner_digest); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
14
|
|
|
14
|
0
|
51
|
sub digest { shift->_digest->digest; } |
40
|
0
|
|
|
0
|
0
|
0
|
sub hexdigest { shift->_digest->hexdigest; } |
41
|
0
|
|
|
0
|
0
|
0
|
sub b64digest { shift->_digest->b64digest; } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Functional interface |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
require Exporter; |
47
|
|
|
|
|
|
|
*import = \&Exporter::import; |
48
|
1
|
|
|
1
|
|
8
|
use vars qw(@EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
195
|
|
49
|
|
|
|
|
|
|
@EXPORT_OK = qw(hmac hmac_hex); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub hmac |
52
|
|
|
|
|
|
|
{ |
53
|
14
|
|
|
14
|
0
|
27
|
my($data, $key, $hash_func, $block_size) = @_; |
54
|
14
|
|
50
|
|
|
26
|
$block_size ||= 64; |
55
|
14
|
100
|
|
|
|
33
|
$key = &$hash_func($key) if length($key) > $block_size; |
56
|
|
|
|
|
|
|
|
57
|
14
|
|
|
|
|
31
|
my $k_ipad = $key ^ (chr(0x36) x $block_size); |
58
|
14
|
|
|
|
|
24
|
my $k_opad = $key ^ (chr(0x5c) x $block_size); |
59
|
|
|
|
|
|
|
|
60
|
14
|
|
|
|
|
75
|
&$hash_func($k_opad, &$hash_func($k_ipad, $data)); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
0
|
0
|
|
sub hmac_hex { unpack("H*", &hmac); } |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |