line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Blowfish.pm,v 1.14 2001/05/08 02:55:40 btrott Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher::Blowfish; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use Net::SSH::Perl::Cipher; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
9
|
1
|
|
|
1
|
|
8
|
use base qw( Net::SSH::Perl::Cipher ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
85
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
372
|
use Crypt::Cipher::Blowfish; |
|
1
|
|
|
|
|
385
|
|
|
1
|
|
|
|
|
32
|
|
12
|
1
|
|
|
1
|
|
7
|
use Net::SSH::Perl::Cipher::CBC; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
426
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
6
|
|
|
6
|
1
|
16
|
my $class = shift; |
16
|
6
|
|
|
|
|
18
|
my $ciph = bless { }, $class; |
17
|
6
|
50
|
|
|
|
28
|
$ciph->init(@_) if @_; |
18
|
6
|
|
|
|
|
18
|
$ciph; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
0
|
0
|
sub keysize { 16 } |
22
|
0
|
|
|
0
|
0
|
0
|
sub blocksize { 8 } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub init { |
25
|
6
|
|
|
6
|
0
|
13
|
my $ciph = shift; |
26
|
6
|
|
|
|
|
17
|
my($key, $iv, $is_ssh2) = @_; |
27
|
6
|
|
|
|
|
17
|
$key = substr($key, 0, 16); |
28
|
6
|
|
|
|
|
34
|
my $blow = Crypt::Cipher::Blowfish->new($key); |
29
|
6
|
50
|
|
|
|
569
|
$ciph->{cbc} = Net::SSH::Perl::Cipher::CBC->new($blow, |
30
|
|
|
|
|
|
|
$iv ? substr($iv, 0, 8) : undef); |
31
|
6
|
50
|
|
|
|
89
|
$ciph->{is_ssh2} = defined $is_ssh2 ? $is_ssh2 : 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub encrypt { |
35
|
3
|
|
|
3
|
1
|
3066
|
my($ciph, $text) = @_; |
36
|
|
|
|
|
|
|
$ciph->{is_ssh2} ? |
37
|
|
|
|
|
|
|
$ciph->{cbc}->encrypt($text) : |
38
|
3
|
50
|
|
|
|
16
|
_swap_bytes($ciph->{cbc}->encrypt(_swap_bytes($text))); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub decrypt { |
42
|
3
|
|
|
3
|
1
|
17
|
my($ciph, $text) = @_; |
43
|
|
|
|
|
|
|
$ciph->{is_ssh2} ? |
44
|
|
|
|
|
|
|
$ciph->{cbc}->decrypt($text) : |
45
|
3
|
50
|
|
|
|
13
|
_swap_bytes($ciph->{cbc}->decrypt(_swap_bytes($text))); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _swap_bytes { |
49
|
12
|
|
|
12
|
|
26
|
my $str = $_[0]; |
50
|
12
|
|
|
|
|
59
|
$str =~ s/(.{4})/reverse $1/sge; |
|
24
|
|
|
|
|
153
|
|
51
|
12
|
|
|
|
|
48
|
$str; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
__END__ |