| 1 | package Net::SSH::Perl::Cipher::Blowfish; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Net::SSH::Perl::Cipher; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use base qw( Net::SSH::Perl::Cipher ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Crypt::Cipher::Blowfish; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Net::SSH::Perl::Cipher::CBC; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | sub new { | ||||||||||
| 13 | 6 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 14 | 6 | my $ciph = bless { }, $class; | |||||||||
| 15 | 6 | ▶ | $ciph->init(@_) if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 6 | $ciph; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub keysize { 16 } | ||||||||
|
Subroutine
keysize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 20 | 0 | ▶ | sub blocksize { 8 } | ||||||||
|
Subroutine
blocksize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 21 | |||||||||||
| 22 | sub init { | ||||||||||
| 23 | 6 | ▶ | my $ciph = shift; | ||||||||
|
Subroutine
init: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||
| 24 | 6 | my($key, $iv, $is_ssh2) = @_; | |||||||||
| 25 | 6 | $key = substr($key, 0, 16); | |||||||||
| 26 | 6 | my $blow = Crypt::Cipher::Blowfish->new($key); | |||||||||
| 27 | 6 | ▶ | $ciph->{cbc} = Net::SSH::Perl::Cipher::CBC->new($blow, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | $iv ? substr($iv, 0, 8) : undef); | ||||||||||
| 29 | 6 | ▶ | $ciph->{is_ssh2} = defined $is_ssh2 ? $is_ssh2 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | sub encrypt { | ||||||||||
| 33 | 3 | ▶ | my($ciph, $text) = @_; | ||||||||
|
Subroutine
encrypt: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 34 | $ciph->{is_ssh2} ? | ||||||||||
| 35 | $ciph->{cbc}->encrypt($text) : | ||||||||||
| 36 | 3 | ▶ | _swap_bytes($ciph->{cbc}->encrypt(_swap_bytes($text))); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | sub decrypt { | ||||||||||
| 40 | 3 | ▶ | my($ciph, $text) = @_; | ||||||||
|
Subroutine
decrypt: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 41 | $ciph->{is_ssh2} ? | ||||||||||
| 42 | $ciph->{cbc}->decrypt($text) : | ||||||||||
| 43 | 3 | ▶ | _swap_bytes($ciph->{cbc}->decrypt(_swap_bytes($text))); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | sub _swap_bytes { | ||||||||||
| 47 | 12 | ▶ | my $str = $_[0]; | ||||||||
|
Subroutine
_swap_bytes: called CC=1 SCAR=0.0
| |||||||||||
| 48 | 12 | $str =~ s/(.{4})/reverse $1/sge; | |||||||||
| 49 | 12 | $str; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | 1; | |||||||||
| 53 | __END__ | ||||||||||