line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Protocol::TLS::Crypto::CryptX; |
2
|
2
|
|
|
2
|
|
1020
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
86
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
1230
|
use Crypt::PK::RSA; |
|
2
|
|
|
|
|
23398
|
|
|
2
|
|
|
|
|
81
|
|
5
|
2
|
|
|
2
|
|
1333
|
use Crypt::Mac::HMAC qw(hmac); |
|
2
|
|
|
|
|
2588
|
|
|
2
|
|
|
|
|
109
|
|
6
|
2
|
|
|
2
|
|
858
|
use Crypt::Digest::SHA256 qw(sha256); |
|
2
|
|
|
|
|
918
|
|
|
2
|
|
|
|
|
99
|
|
7
|
2
|
|
|
2
|
|
11
|
use Crypt::PRNG qw(random_bytes); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
65
|
|
8
|
2
|
|
|
2
|
|
10
|
use Crypt::Mode::CBC; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
29
|
|
9
|
2
|
|
|
2
|
|
1073
|
use Crypt::X509; |
|
2
|
|
|
|
|
76433
|
|
|
2
|
|
|
|
|
1202
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
4
|
|
|
4
|
0
|
19
|
bless {}, shift; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub PRF { |
16
|
11
|
|
|
11
|
0
|
497
|
my ( $self, $secret, $label, $seed, $len ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
11
|
|
|
|
|
19
|
$seed = $label . $seed; |
19
|
|
|
|
|
|
|
|
20
|
11
|
|
|
|
|
23
|
my $data = ''; |
21
|
11
|
|
|
|
|
16
|
my $a = $seed; |
22
|
11
|
|
|
|
|
46
|
while ( length($data) < $len ) { |
23
|
22
|
|
|
|
|
343
|
$a = hmac( 'SHA256', $secret, $a ); |
24
|
22
|
|
|
|
|
795
|
$data .= hmac( 'SHA256', $secret, $a . $seed ); |
25
|
|
|
|
|
|
|
} |
26
|
11
|
|
|
|
|
361
|
substr $data, 0, $len; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub PRF_hash { |
30
|
6
|
|
|
6
|
0
|
41
|
sha256( $_[1] ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub MAC { |
34
|
18
|
|
|
18
|
0
|
37
|
my ( $self, $type ) = splice @_, 0, 2; |
35
|
18
|
50
|
|
|
|
79
|
hmac( $type eq 'SHA' ? 'SHA1' : $type, @_ ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub CBC_encode { |
39
|
9
|
|
|
9
|
0
|
17
|
my ( $self, $type, $key, $iv, $plaintext ) = @_; |
40
|
9
|
0
|
|
|
|
45
|
$type = |
|
|
50
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$type =~ /AES/ ? 'AES' |
42
|
|
|
|
|
|
|
: $type =~ /DES/ ? 'DES_EDE' |
43
|
|
|
|
|
|
|
: die "unsupported CBC cipher $type\n"; |
44
|
9
|
|
|
|
|
68
|
my $m = Crypt::Mode::CBC->new( $type, 0 ); |
45
|
9
|
|
|
|
|
235
|
$m->encrypt( $plaintext, $key, $iv ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub CBC_decode { |
49
|
9
|
|
|
9
|
0
|
26
|
my ( $self, $type, $key, $iv, $ciphertext ) = @_; |
50
|
9
|
0
|
|
|
|
48
|
$type = |
|
|
50
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$type =~ /AES/ ? 'AES' |
52
|
|
|
|
|
|
|
: $type =~ /DES/ ? 'DES_EDE' |
53
|
|
|
|
|
|
|
: die "unsupported CBC cipher $type\n"; |
54
|
9
|
|
|
|
|
44
|
my $m = Crypt::Mode::CBC->new( $type, 0 ); |
55
|
9
|
|
|
|
|
259
|
$m->decrypt( $ciphertext, $key, $iv ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub random { |
59
|
16
|
|
|
16
|
0
|
69
|
random_bytes( $_[1] ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub rsa_encrypt { |
63
|
2
|
|
|
2
|
0
|
5
|
my ( $self, $der, $message ) = @_; |
64
|
2
|
|
|
|
|
42
|
my $pub = Crypt::PK::RSA->new( \$der ); |
65
|
2
|
|
|
|
|
412
|
$pub->encrypt( $message, 'v1.5' ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub rsa_decrypt { |
69
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $der, $message ) = @_; |
70
|
0
|
|
|
|
|
0
|
my $priv = Crypt::PK::RSA->new( \$der ); |
71
|
0
|
|
|
|
|
0
|
$priv->decrypt( $message, 'v1.5' ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub cert_pubkey { |
75
|
2
|
|
|
2
|
0
|
41
|
my $cert = Crypt::X509->new( cert => $_[1] ); |
76
|
2
|
50
|
|
|
|
85230
|
$cert ? $cert->pubkey : undef; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1 |