line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Keyczar::Crypter; |
2
|
4
|
|
|
4
|
|
14365
|
use base 'Crypt::Keyczar::Encrypter'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
700
|
|
3
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
59
|
|
4
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
136
|
|
5
|
4
|
|
|
4
|
|
18
|
use Crypt::Keyczar qw(HEADER_SIZE KEY_HASH_SIZE FORMAT_VERSION); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
268
|
|
6
|
4
|
|
|
4
|
|
22
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
914
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub decrypt { |
10
|
4
|
|
|
4
|
0
|
15
|
my $self = shift; |
11
|
4
|
|
|
|
|
7
|
my $data = shift; |
12
|
|
|
|
|
|
|
|
13
|
4
|
50
|
|
|
|
13
|
if (length $data < HEADER_SIZE()) { |
14
|
0
|
|
|
|
|
0
|
croak "signature is short"; |
15
|
|
|
|
|
|
|
} |
16
|
4
|
|
|
|
|
8
|
my $hash_size = KEY_HASH_SIZE(); |
17
|
4
|
|
|
|
|
20
|
my ($v, $hash, $body) = unpack "C1 a$hash_size a*", $data; |
18
|
4
|
50
|
|
|
|
13
|
if ($v != FORMAT_VERSION()) { |
19
|
0
|
|
|
|
|
0
|
croak "bad format version: $v"; |
20
|
|
|
|
|
|
|
} |
21
|
4
|
|
|
|
|
21
|
my $key = $self->get_key($hash); |
22
|
4
|
50
|
|
|
|
12
|
if (!$key) { |
23
|
0
|
|
|
|
|
0
|
croak "key not found"; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
11
|
my $engine = $key->get_engine(); |
27
|
4
|
|
|
|
|
23
|
my $mac = $key->get_sign_engine(); |
28
|
4
|
|
|
|
|
20
|
my $cipher_body = substr $body, 0, $mac->digest_size()*-1; |
29
|
4
|
|
|
|
|
13
|
my $signature = substr $body, $mac->digest_size()*-1; |
30
|
4
|
|
|
|
|
17
|
my $iv = $engine->init($cipher_body); |
31
|
4
|
100
|
|
|
|
17
|
my $cipher_text = length $iv > 0 ? substr($cipher_body, length $iv) : $body; |
32
|
4
|
|
|
|
|
2438
|
my $plain_text = $engine->decrypt($cipher_text); |
33
|
4
|
|
|
|
|
62
|
my $signed_text = substr $data, 0, $mac->digest_size()*-1; |
34
|
4
|
|
|
|
|
14
|
$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__ |