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