line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Keyczar::Crypter; |
2
|
4
|
|
|
4
|
|
36493
|
use base 'Crypt::Keyczar::Encrypter'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1184
|
|
3
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
110
|
|
4
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
150
|
|
5
|
4
|
|
|
4
|
|
21
|
use Crypt::Keyczar qw(HEADER_SIZE KEY_HASH_SIZE FORMAT_VERSION); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
230
|
|
6
|
4
|
|
|
4
|
|
19
|
use Carp; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
1595
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub decrypt { |
10
|
4
|
|
|
4
|
0
|
13
|
my $self = shift; |
11
|
4
|
|
|
|
|
6
|
my $data = shift; |
12
|
|
|
|
|
|
|
|
13
|
4
|
50
|
|
|
|
15
|
if (length $data < HEADER_SIZE()) { |
14
|
0
|
|
|
|
|
0
|
croak "signature is short"; |
15
|
|
|
|
|
|
|
} |
16
|
4
|
|
|
|
|
6
|
my $hash_size = KEY_HASH_SIZE(); |
17
|
4
|
|
|
|
|
20
|
my ($v, $hash, $body) = unpack "C1 a$hash_size a*", $data; |
18
|
4
|
50
|
|
|
|
11
|
if ($v != FORMAT_VERSION()) { |
19
|
0
|
|
|
|
|
0
|
croak "bad format version: $v"; |
20
|
|
|
|
|
|
|
} |
21
|
4
|
|
|
|
|
22
|
my $key = $self->get_key($hash); |
22
|
4
|
50
|
|
|
|
11
|
if (!$key) { |
23
|
0
|
|
|
|
|
0
|
croak "key not found"; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
11
|
my $engine = $key->get_engine(); |
27
|
4
|
|
|
|
|
19
|
my $mac = $key->get_sign_engine(); |
28
|
4
|
|
|
|
|
27
|
my $cipher_body = substr $body, 0, $mac->digest_size()*-1; |
29
|
4
|
|
|
|
|
13
|
my $signature = substr $body, $mac->digest_size()*-1; |
30
|
4
|
|
|
|
|
14
|
my $iv = $engine->init($cipher_body); |
31
|
4
|
100
|
|
|
|
12
|
my $cipher_text = length $iv > 0 ? substr($cipher_body, length $iv) : $body; |
32
|
4
|
|
|
|
|
3699
|
my $plain_text = $engine->decrypt($cipher_text); |
33
|
4
|
|
|
|
|
122
|
my $signed_text = substr $data, 0, $mac->digest_size()*-1; |
34
|
4
|
|
|
|
|
15
|
$mac->update($signed_text); |
35
|
4
|
50
|
|
|
|
20
|
if (!$mac->verify($signature)) { |
36
|
0
|
|
|
|
|
0
|
croak "invalid signature"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
58
|
return $plain_text; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
__END__ |