line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher::CTR; |
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
300
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
sub new { |
5
|
6
|
|
|
6
|
0
|
23
|
my($class, $ciph, $iv) = @_; |
6
|
6
|
|
33
|
|
|
97
|
bless { |
7
|
|
|
|
|
|
|
cipher => $ciph, |
8
|
|
|
|
|
|
|
iv => substr($iv,0,$ciph->blocksize) || "\0" x $ciph->blocksize, |
9
|
|
|
|
|
|
|
}, $class; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub encrypt { |
13
|
6
|
|
|
6
|
0
|
16
|
my $ctr = shift; |
14
|
6
|
|
|
|
|
10
|
my $data = shift; |
15
|
|
|
|
|
|
|
|
16
|
6
|
|
|
|
|
12
|
my $retval = ''; |
17
|
6
|
|
|
|
|
17
|
my $iv = $ctr->{iv}; |
18
|
6
|
|
|
|
|
21
|
my $size = $ctr->{cipher}->blocksize; |
19
|
|
|
|
|
|
|
|
20
|
6
|
|
|
|
|
21
|
while (length $data) { |
21
|
6
|
|
|
|
|
23
|
my $in = substr($data, 0, $size, ''); |
22
|
6
|
|
|
|
|
49
|
$in ^= $ctr->{cipher}->encrypt($iv); |
23
|
6
|
|
|
|
|
18
|
for my $i (1..$size) { |
24
|
6
|
|
|
|
|
24
|
my $num = (unpack('C', substr($iv,-$i,1)) + 1) & 0xff; |
25
|
6
|
|
|
|
|
22
|
substr($iv,-$i,1,pack('C',$num)); |
26
|
6
|
50
|
|
|
|
16
|
last if $num; |
27
|
|
|
|
|
|
|
} |
28
|
6
|
|
|
|
|
18
|
$retval .= $in; |
29
|
|
|
|
|
|
|
} |
30
|
6
|
|
|
|
|
11
|
$ctr->{iv} = $iv; |
31
|
6
|
|
|
|
|
17
|
$retval; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
3
|
0
|
16
|
sub decrypt { shift->encrypt(@_) } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
__END__ |