blib/lib/Net/SSH/Perl/Cipher/DES3.pm

filter: Statementstmt 65.0% 39 / 60 Branchbran 42.8% 6 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.8% 11 / 19 Podpod 50.0% 3 / 6 totaltotal 58.6% 61 / 104 SCAR 29.0
CC
11
Cov
61%
init
7.3
new
6.0
init
6.0
CRAP 18.2
« blib/lib/Net/SSH/Perl/Auth/Rhosts.pm ↑ Summary blib/lib/Net/SSH/Perl/Util/Term.pm »
1 package Net::SSH::Perl::Cipher::DES3;
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 Net::SSH::Perl::Cipher::CBC;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Crypt::Cipher::DES;
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
BranchTrueFalseTotal
if @_ 6 0 6
16 6 $ciph;
17 }
18  
19 0 ▶sub keysize { 24 }
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=6 SCAR=19.9
Pod undocumented
24 6 my($key, $iv, $is_ssh2) = @_;
25 6 ▶ $ciph->{is_ssh2} = defined $is_ssh2 ? $is_ssh2 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $is_ssh2 ? : 0 6 6
26  
27 6 ▶ if ($is_ssh2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ssh2) { } 0 6 6
28 0 my $ede3 = Net::SSH::Perl::Cipher::DES3::EDE3->new($key);
29 0 $ciph->{cbc} = Net::SSH::Perl::Cipher::CBC->new($ede3,
30 substr($iv, 0, 8));
31 }
32 else {
33 6 for my $i (1..3) {
34 18 ▶ my $this_key = $i == 3 && length($key) <= 16 ?
Branch: 1 branch
BranchTrueFalseTotal
$i == 3 && length $key <= 16 ? : 0 18 18
Condition66%2/3
$i == 3 and length $key <= 16
!ll&&!rl&&r
1260
MC/DC0%0/2
$i == 3 and length $key <= 16
$i == 3 length $key <= 16
Truth table66%2/3
A and B
A= $i == 3B= length $key <= 16
ABresult
0X0
100
111
35 substr $key, 0, 8 :
36 substr $key, 8*($i-1), 8;
37 18 $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 ▶ my($ciph, $text) = @_;
Subroutine encrypt: called CC=2 SCAR=7.6
Pod documented
46 3 ▶ if ($ciph->{is_ssh2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ciph->{'is_ssh2'}) { } 0 3 3
47 0 return $ciph->{cbc}->encrypt($text);
48 }
49 else {
50 return $ciph->{cbc3}->encrypt(
51 $ciph->{cbc2}->decrypt(
52 3 $ciph->{cbc1}->encrypt($text)
53 )
54 );
55 }
56 }
57  
58 sub decrypt {
59 3 ▶ my($ciph, $text) = @_;
Subroutine decrypt: called CC=2 SCAR=7.6
Pod documented
60 3 ▶ if ($ciph->{is_ssh2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ciph->{'is_ssh2'}) { } 0 3 3
61 0 return $ciph->{cbc}->decrypt($text);
62 }
63 else {
64 return $ciph->{cbc1}->decrypt(
65 $ciph->{cbc2}->encrypt(
66 3 $ciph->{cbc3}->decrypt($text)
67 )
68 );
69 }
70 }
71  
72 package Net::SSH::Perl::Cipher::DES3::EDE3;
73 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 sub new {
76 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
77 0 my $ede3 = bless {}, $class;
78 0 ▶ $ede3->init(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
79 0 $ede3;
80 }
81  
82 0 ▶sub keysize { 24 }
Subroutine keysize: not called CC=1 SCAR=6.9
83 0 ▶sub blocksize { 8 }
Subroutine blocksize: not called CC=1 SCAR=6.9
84  
85 sub init {
86 0 ▶ my $ede3 = shift;
Subroutine init: not called CC=2 SCAR=17.9
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 ▶ my($ede3, $block) = @_;
Subroutine encrypt: not called CC=1 SCAR=6.9
96 $ede3->{des3}->encrypt(
97 $ede3->{des2}->decrypt(
98 0 $ede3->{des1}->encrypt($block)
99 )
100 );
101 }
102  
103 sub decrypt {
104 0 ▶ my($ede3, $block) = @_;
Subroutine decrypt: not called CC=1 SCAR=6.9
105 $ede3->{des1}->decrypt(
106 $ede3->{des2}->encrypt(
107 0 $ede3->{des3}->decrypt($block)
108 )
109 );
110 }
111  
112 1 1;
113 __END__
« blib/lib/Net/SSH/Perl/Auth/Rhosts.pm ↑ Summary blib/lib/Net/SSH/Perl/Util/Term.pm »