line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Digest::EMAC; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#use diagnostics; |
4
|
1
|
|
|
1
|
|
294465
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
#use warnings; |
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
72
|
|
7
|
1
|
|
|
1
|
|
14808
|
use Crypt::CBC; |
|
1
|
|
|
|
|
7196
|
|
|
1
|
|
|
|
|
57
|
|
8
|
1
|
|
|
1
|
|
1150
|
use MIME::Base64; |
|
1
|
|
|
|
|
877
|
|
|
1
|
|
|
|
|
81
|
|
9
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
10
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @EXPORT_OK @ISA); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
771
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.2'; |
12
|
|
|
|
|
|
|
@ISA = ('Exporter'); |
13
|
|
|
|
|
|
|
@EXPORT_OK = qw(emac hexdigest base64digest); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub createcipher |
16
|
|
|
|
|
|
|
{ |
17
|
0
|
|
|
0
|
0
|
|
my ($key, $iv, $cipher) = @_; |
18
|
0
|
|
|
|
|
|
my $cipher_obj = Crypt::CBC->new({'key' => $key, |
19
|
|
|
|
|
|
|
'cipher' => $cipher, |
20
|
|
|
|
|
|
|
'iv' => $iv, |
21
|
|
|
|
|
|
|
'regenerate_key' => 1, |
22
|
|
|
|
|
|
|
'padding' => 'standard', |
23
|
|
|
|
|
|
|
'prepend_iv' => 0}); |
24
|
0
|
|
|
|
|
|
return $cipher_obj; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub createsubkey |
28
|
|
|
|
|
|
|
{ |
29
|
0
|
|
|
0
|
0
|
|
my ($key, $iv, $cipher, $data) = @_; |
30
|
0
|
|
|
|
|
|
my $tempcipher = &createcipher($key, $iv, $cipher); |
31
|
0
|
|
|
|
|
|
return $tempcipher->encrypt($data); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub emac |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
0
|
0
|
|
my ($key, $cipher, $inputdata) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $DATASIZE = length $inputdata; |
39
|
0
|
|
|
|
|
|
my $data = pack "a$DATASIZE", $inputdata; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
$cipher = $cipher=~/^Crypt::/ ? $cipher : "Crypt::$cipher"; |
42
|
0
|
|
|
|
|
|
eval "require $cipher"; |
43
|
0
|
0
|
|
|
|
|
if ($@) { |
44
|
0
|
|
|
|
|
|
print "Can't load cipher $cipher.\n"; |
45
|
0
|
|
|
|
|
|
print "You must install $cipher first!\n"; |
46
|
0
|
|
|
|
|
|
exit 0; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
$cipher =~ s/^Crypt::// unless $cipher->can('blocksize'); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $BLOCKSIZE = eval {$cipher->blocksize}; |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $iv = pack "x$BLOCKSIZE", 0; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $subkey1 = &createsubkey($key, $iv, $cipher, 0); |
55
|
0
|
|
|
|
|
|
my $subkey2 = &createsubkey($key, $iv, $cipher, 1); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $cipher1 = &createcipher($subkey1, $iv, $cipher); |
58
|
0
|
|
|
|
|
|
my $ciphertext = $cipher1->encrypt($data); |
59
|
0
|
|
|
|
|
|
my $mac1 = substr $ciphertext, -$BLOCKSIZE; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $cipher2 = &createcipher($subkey2, $iv, $cipher); |
62
|
0
|
|
|
|
|
|
my $mac2 = $cipher2->encrypt($mac1); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $final_mac = substr $mac2, -$BLOCKSIZE; |
65
|
0
|
|
|
|
|
|
return $final_mac; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub hexdigest |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
0
|
0
|
|
my ($data) = @_; |
71
|
0
|
|
|
|
|
|
return unpack("H*", $data); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub base64digest |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
0
|
0
|
|
my ($data) = @_; |
77
|
0
|
|
|
|
|
|
return encode_base64($data, ""); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |