line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: CFB.pm,v 1.5 2001/04/03 19:44:47 btrott Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This code based in part on the Systemics Crypt::CFB. |
4
|
|
|
|
|
|
|
# Parts Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) |
5
|
|
|
|
|
|
|
# All rights reserved. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Net::SSH::Perl::Cipher::CFB; |
8
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
9
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
347
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
6
|
|
|
6
|
0
|
17
|
my($class, $ciph, $iv) = @_; |
13
|
6
|
|
33
|
|
|
302
|
bless { |
14
|
|
|
|
|
|
|
cipher => $ciph, |
15
|
|
|
|
|
|
|
iv => $iv || ("\0" x $ciph->blocksize), |
16
|
|
|
|
|
|
|
}, $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub encrypt { |
20
|
3
|
|
|
3
|
0
|
10
|
my $cfb = shift; |
21
|
3
|
|
|
|
|
8
|
my $data = shift; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
7
|
my $retval = ""; |
24
|
3
|
|
|
|
|
12
|
my $iv = $cfb->{iv}; |
25
|
3
|
|
|
|
|
267
|
my $size = $cfb->{cipher}->blocksize; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
28
|
while (length $data) { |
28
|
3
|
|
|
|
|
13
|
my $out = $cfb->{cipher}->encrypt($iv); |
29
|
3
|
|
|
|
|
54
|
$iv = substr($data, 0, $size, '') ^ substr($out, 0, $size, ''); |
30
|
3
|
|
|
|
|
13
|
$retval .= $iv; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
10
|
$cfb->{iv} = $iv; |
34
|
3
|
|
|
|
|
11
|
$retval; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub decrypt { |
38
|
3
|
|
|
3
|
0
|
9
|
my $cfb = shift; |
39
|
3
|
|
|
|
|
8
|
my $data = shift; |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
7
|
my $retval = ""; |
42
|
3
|
|
|
|
|
9
|
my $iv = $cfb->{iv}; |
43
|
3
|
|
|
|
|
10
|
my $size = $cfb->{cipher}->blocksize; |
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
17
|
while (length $data) { |
46
|
3
|
|
|
|
|
9
|
my $out = $cfb->{cipher}->encrypt($iv); |
47
|
3
|
|
|
|
|
37
|
$iv = substr($data, 0, $size, ''); |
48
|
3
|
|
|
|
|
15
|
$retval .= $iv ^ substr($out, 0, $size); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
3
|
|
|
|
|
7
|
$cfb->{iv} = $iv; |
52
|
3
|
|
|
|
|
14
|
$retval; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |