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

filter: Statementstmt 100% 22 / 22 Branchbran 75.0% 3 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 3 totaltotal 78.9% 30 / 38 SCAR 16.1
CC
5
Cov
90%
encrypt
4.0
new
2.3
BEGIN
1.0
CRAP 5.0
« blib/lib/Net/SSH/Perl/Util.pm ↑ Summary blib/lib/Net/SSH/Perl/Constants.pm »
1 package Net::SSH::Perl::Cipher::CTR;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 sub new {
5 6 ▶ my($class, $ciph, $iv) = @_;
Subroutine new: called CC=2 SCAR=8.1
Pod undocumented
6 6 ▶ bless {
Condition33%1/3
substr($iv, 0, $ciph->blocksize) || "\000" x $ciph->blocksize
l!l&&r!l&&!r
060
MC/DC0%0/2
substr($iv, 0, $ciph->blocksize) || "\000" x $ciph->blocksize
substr($iv, 0, $ciph->blocksize) "\000" x $ciph->blocksize
Truth table33%1/3
A || B
A= substr($iv, 0, $ciph->blocksize)B= "\000" x $ciph->blocksize
ABresult
1X1
011
000
7 cipher => $ciph,
8 iv => substr($iv,0,$ciph->blocksize) || "\0" x $ciph->blocksize,
9 }, $class;
10 }
11  
12 sub encrypt {
13 6 ▶ my $ctr = shift;
Subroutine encrypt: called CC=4 SCAR=13.9
Pod undocumented
14 6 my $data = shift;
15  
16 6 my $retval = '';
17 6 my $iv = $ctr->{iv};
18 6 my $size = $ctr->{cipher}->blocksize;
19  
20 6 ▶ while (length $data) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data) 6 6 12
21 6 my $in = substr($data, 0, $size, '');
22 6 $in ^= $ctr->{cipher}->encrypt($iv);
23 6 for my $i (1..$size) {
24 6 my $num = (unpack('C', substr($iv,-$i,1)) + 1) & 0xff;
25 6 substr($iv,-$i,1,pack('C',$num));
26 6 ▶ last if $num;
Branch: 1 branch
BranchTrueFalseTotal
if $num 6 0 6
27 }
28 6 $retval .= $in;
29 }
30 6 $ctr->{iv} = $iv;
31 6 $retval;
32 }
33  
34 3 ▶sub decrypt { shift->encrypt(@_) }
Subroutine decrypt: called CC=1 SCAR=0.0
Pod undocumented
35  
36 1 1;
37 __END__
« blib/lib/Net/SSH/Perl/Util.pm ↑ Summary blib/lib/Net/SSH/Perl/Constants.pm »