line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: CBC.pm,v 1.6 2008/09/24 19:21:21 turnstep Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This code is based in part on the Systemics Crypt::CBC. |
4
|
|
|
|
|
|
|
# Parts copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) |
5
|
|
|
|
|
|
|
# All rights reserved. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher::CBC; |
8
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
578
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
37
|
|
|
37
|
0
|
856
|
my($class, $ciph, $iv) = @_; |
12
|
37
|
|
66
|
|
|
164
|
bless { |
13
|
|
|
|
|
|
|
cipher => $ciph, |
14
|
|
|
|
|
|
|
iv => $iv || ("\0" x $ciph->blocksize), |
15
|
|
|
|
|
|
|
}, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub encrypt { |
19
|
18
|
|
|
18
|
0
|
43
|
my $cbc = shift; |
20
|
18
|
|
|
|
|
39
|
my $data = shift; |
21
|
|
|
|
|
|
|
|
22
|
18
|
|
|
|
|
38
|
my $retval = ""; |
23
|
18
|
|
|
|
|
42
|
my $iv = $cbc->{iv}; |
24
|
18
|
|
|
|
|
35
|
my $ciph = $cbc->{cipher}; |
25
|
18
|
|
|
|
|
71
|
my $size = $ciph->blocksize; |
26
|
|
|
|
|
|
|
|
27
|
18
|
|
|
|
|
223
|
while (length $data) { |
28
|
18
|
|
|
|
|
61
|
my $in = substr($data, 0, $size, '') ^ $iv; |
29
|
18
|
|
|
|
|
140
|
$iv = $ciph->encrypt($in); |
30
|
18
|
|
|
|
|
66
|
$retval .= $iv; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
18
|
|
|
|
|
42
|
$cbc->{iv} = $iv; |
34
|
18
|
|
|
|
|
73
|
$retval; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub decrypt { |
38
|
19
|
|
|
19
|
0
|
40
|
my $cbc = shift; |
39
|
19
|
|
|
|
|
41
|
my $data = shift; |
40
|
|
|
|
|
|
|
|
41
|
19
|
|
|
|
|
38
|
my $retval = ""; |
42
|
19
|
|
|
|
|
45
|
my $iv = $cbc->{iv}; |
43
|
19
|
|
|
|
|
38
|
my $ciph = $cbc->{cipher}; |
44
|
19
|
|
|
|
|
54
|
my $size = $ciph->blocksize; |
45
|
|
|
|
|
|
|
|
46
|
19
|
|
|
|
|
214
|
while (length $data) { |
47
|
29
|
|
|
|
|
81
|
my $in = substr($data, 0, $size, ''); |
48
|
29
|
|
|
|
|
152
|
$retval .= $ciph->decrypt($in) ^ $iv; |
49
|
29
|
|
|
|
|
98
|
$iv = $in; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
19
|
|
|
|
|
42
|
$cbc->{iv} = $iv; |
53
|
19
|
|
|
|
|
78
|
$retval; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
__END__ |