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