| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher::DES3; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Net::SSH::Perl::Cipher; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
64
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use base qw( Net::SSH::Perl::Cipher ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
118
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
8
|
use Net::SSH::Perl::Cipher::CBC; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
22
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use Crypt::Cipher::DES; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
490
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
6
|
|
|
6
|
1
|
14
|
my $class = shift; |
|
14
|
6
|
|
|
|
|
12
|
my $ciph = bless { }, $class; |
|
15
|
6
|
50
|
|
|
|
26
|
$ciph->init(@_) if @_; |
|
16
|
6
|
|
|
|
|
57
|
$ciph; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
|
|
0
|
0
|
0
|
sub keysize { 24 } |
|
20
|
0
|
|
|
0
|
0
|
0
|
sub blocksize { 8 } |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub init { |
|
23
|
6
|
|
|
6
|
0
|
12
|
my $ciph = shift; |
|
24
|
6
|
|
|
|
|
14
|
my($key, $iv, $is_ssh2) = @_; |
|
25
|
6
|
50
|
|
|
|
28
|
$ciph->{is_ssh2} = defined $is_ssh2 ? $is_ssh2 : 0; |
|
26
|
|
|
|
|
|
|
|
|
27
|
6
|
50
|
|
|
|
14
|
if ($is_ssh2) { |
|
28
|
0
|
|
|
|
|
0
|
my $ede3 = Net::SSH::Perl::Cipher::DES3::EDE3->new($key); |
|
29
|
0
|
|
|
|
|
0
|
$ciph->{cbc} = Net::SSH::Perl::Cipher::CBC->new($ede3, |
|
30
|
|
|
|
|
|
|
substr($iv, 0, 8)); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
else { |
|
33
|
6
|
|
|
|
|
21
|
for my $i (1..3) { |
|
34
|
18
|
50
|
66
|
|
|
115
|
my $this_key = $i == 3 && length($key) <= 16 ? |
|
35
|
|
|
|
|
|
|
substr $key, 0, 8 : |
|
36
|
|
|
|
|
|
|
substr $key, 8*($i-1), 8; |
|
37
|
18
|
|
|
|
|
476
|
$ciph->{"cbc$i"} = Net::SSH::Perl::Cipher::CBC->new( |
|
38
|
|
|
|
|
|
|
Crypt::Cipher::DES->new($this_key) |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub encrypt { |
|
45
|
3
|
|
|
3
|
1
|
2609
|
my($ciph, $text) = @_; |
|
46
|
3
|
50
|
|
|
|
13
|
if ($ciph->{is_ssh2}) { |
|
47
|
0
|
|
|
|
|
0
|
return $ciph->{cbc}->encrypt($text); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
else { |
|
50
|
|
|
|
|
|
|
return $ciph->{cbc3}->encrypt( |
|
51
|
|
|
|
|
|
|
$ciph->{cbc2}->decrypt( |
|
52
|
3
|
|
|
|
|
10
|
$ciph->{cbc1}->encrypt($text) |
|
53
|
|
|
|
|
|
|
) |
|
54
|
|
|
|
|
|
|
); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub decrypt { |
|
59
|
3
|
|
|
3
|
1
|
13
|
my($ciph, $text) = @_; |
|
60
|
3
|
50
|
|
|
|
9
|
if ($ciph->{is_ssh2}) { |
|
61
|
0
|
|
|
|
|
0
|
return $ciph->{cbc}->decrypt($text); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
else { |
|
64
|
|
|
|
|
|
|
return $ciph->{cbc1}->decrypt( |
|
65
|
|
|
|
|
|
|
$ciph->{cbc2}->encrypt( |
|
66
|
3
|
|
|
|
|
10
|
$ciph->{cbc3}->decrypt($text) |
|
67
|
|
|
|
|
|
|
) |
|
68
|
|
|
|
|
|
|
); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher::DES3::EDE3; |
|
73
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
301
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub new { |
|
76
|
0
|
|
|
0
|
|
|
my $class = shift; |
|
77
|
0
|
|
|
|
|
|
my $ede3 = bless {}, $class; |
|
78
|
0
|
0
|
|
|
|
|
$ede3->init(@_) if @_; |
|
79
|
0
|
|
|
|
|
|
$ede3; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
0
|
|
|
sub keysize { 24 } |
|
83
|
0
|
|
|
0
|
|
|
sub blocksize { 8 } |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub init { |
|
86
|
0
|
|
|
0
|
|
|
my $ede3 = shift; |
|
87
|
0
|
|
|
|
|
|
my($key) = @_; |
|
88
|
0
|
|
|
|
|
|
for my $i (1..3) { |
|
89
|
0
|
|
|
|
|
|
my $k = substr $key, 8*($i-1), 8; |
|
90
|
0
|
|
|
|
|
|
$ede3->{"des$i"} = Crypt::Cipher::DES->new($k); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub encrypt { |
|
95
|
0
|
|
|
0
|
|
|
my($ede3, $block) = @_; |
|
96
|
|
|
|
|
|
|
$ede3->{des3}->encrypt( |
|
97
|
|
|
|
|
|
|
$ede3->{des2}->decrypt( |
|
98
|
0
|
|
|
|
|
|
$ede3->{des1}->encrypt($block) |
|
99
|
|
|
|
|
|
|
) |
|
100
|
|
|
|
|
|
|
); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub decrypt { |
|
104
|
0
|
|
|
0
|
|
|
my($ede3, $block) = @_; |
|
105
|
|
|
|
|
|
|
$ede3->{des1}->decrypt( |
|
106
|
|
|
|
|
|
|
$ede3->{des2}->encrypt( |
|
107
|
0
|
|
|
|
|
|
$ede3->{des3}->decrypt($block) |
|
108
|
|
|
|
|
|
|
) |
|
109
|
|
|
|
|
|
|
); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
|
113
|
|
|
|
|
|
|
__END__ |