line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Protocol::TLS::Crypto::CryptX; |
2
|
2
|
|
|
2
|
|
1577
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
4
|
2
|
|
|
2
|
|
2261
|
use Crypt::PK::RSA; |
|
2
|
|
|
|
|
38666
|
|
|
2
|
|
|
|
|
116
|
|
5
|
2
|
|
|
2
|
|
2277
|
use Crypt::Mac::HMAC qw(hmac); |
|
2
|
|
|
|
|
3414
|
|
|
2
|
|
|
|
|
134
|
|
6
|
2
|
|
|
2
|
|
2040
|
use Crypt::Digest::SHA256 qw(sha256); |
|
2
|
|
|
|
|
1384
|
|
|
2
|
|
|
|
|
174
|
|
7
|
2
|
|
|
2
|
|
15
|
use Crypt::PRNG qw(random_bytes); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
99
|
|
8
|
2
|
|
|
2
|
|
12
|
use Crypt::Mode::CBC; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
53
|
|
9
|
2
|
|
|
2
|
|
2150
|
use Crypt::X509; |
|
2
|
|
|
|
|
98839
|
|
|
2
|
|
|
|
|
1496
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
4
|
|
|
4
|
0
|
18
|
bless {}, shift; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub PRF { |
16
|
11
|
|
|
11
|
0
|
538
|
my ( $self, $secret, $label, $seed, $len ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
11
|
|
|
|
|
33
|
$seed = $label . $seed; |
19
|
|
|
|
|
|
|
|
20
|
11
|
|
|
|
|
22
|
my $data = ''; |
21
|
11
|
|
|
|
|
23
|
my $a = $seed; |
22
|
11
|
|
|
|
|
50
|
while ( length($data) < $len ) { |
23
|
22
|
|
|
|
|
496
|
$a = hmac( 'SHA256', $secret, $a ); |
24
|
22
|
|
|
|
|
1135
|
$data .= hmac( 'SHA256', $secret, $a . $seed ); |
25
|
|
|
|
|
|
|
} |
26
|
11
|
|
|
|
|
488
|
substr $data, 0, $len; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub PRF_hash { |
30
|
6
|
|
|
6
|
0
|
38
|
sha256( $_[1] ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub MAC { |
34
|
18
|
|
|
18
|
0
|
63
|
my ( $self, $type ) = splice @_, 0, 2; |
35
|
18
|
50
|
|
|
|
115
|
hmac( $type eq 'SHA' ? 'SHA1' : $type, @_ ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub CBC_encode { |
39
|
9
|
|
|
9
|
0
|
83
|
my ( $self, $type, $key, $iv, $plaintext ) = @_; |
40
|
9
|
0
|
|
|
|
53
|
$type = |
|
|
50
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$type =~ /AES/ ? 'AES' |
42
|
|
|
|
|
|
|
: $type =~ /DES/ ? 'DES_EDE' |
43
|
|
|
|
|
|
|
: die "unsupported CBC cipher $type\n"; |
44
|
9
|
|
|
|
|
99
|
my $m = Crypt::Mode::CBC->new( $type, 0 ); |
45
|
9
|
|
|
|
|
302
|
$m->encrypt( $plaintext, $key, $iv ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub CBC_decode { |
49
|
9
|
|
|
9
|
0
|
46
|
my ( $self, $type, $key, $iv, $ciphertext ) = @_; |
50
|
9
|
0
|
|
|
|
62
|
$type = |
|
|
50
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$type =~ /AES/ ? 'AES' |
52
|
|
|
|
|
|
|
: $type =~ /DES/ ? 'DES_EDE' |
53
|
|
|
|
|
|
|
: die "unsupported CBC cipher $type\n"; |
54
|
9
|
|
|
|
|
91
|
my $m = Crypt::Mode::CBC->new( $type, 0 ); |
55
|
9
|
|
|
|
|
381
|
$m->decrypt( $ciphertext, $key, $iv ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub random { |
59
|
16
|
|
|
16
|
0
|
93
|
random_bytes( $_[1] ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub rsa_encrypt { |
63
|
2
|
|
|
2
|
0
|
5
|
my ( $self, $der, $message ) = @_; |
64
|
2
|
|
|
|
|
34
|
my $pub = Crypt::PK::RSA->new( \$der ); |
65
|
2
|
|
|
|
|
737
|
$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 rsa_sign { |
75
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $der, $hash, $message ) = @_; |
76
|
0
|
|
|
|
|
0
|
my $priv = Crypt::PK::RSA->new( \$der ); |
77
|
0
|
|
|
|
|
0
|
$priv->sign_message( $message, $hash, 'v1.5' ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub cert_pubkey { |
81
|
2
|
|
|
2
|
0
|
53
|
my $cert = Crypt::X509->new( cert => $_[1] ); |
82
|
2
|
50
|
|
|
|
3035817
|
$cert ? $cert->pubkey : undef; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub cert_pubkeyalg { |
86
|
0
|
|
|
0
|
0
|
|
my $cert = Crypt::X509->new( cert => $_[1] ); |
87
|
0
|
0
|
|
|
|
|
$cert ? $cert->PubKeyAlg : undef; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1 |