line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Crypt::HCE_SHA |
3
|
|
|
|
|
|
|
# implements one way hash chaining encryption using SHA |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: HCE_SHA.pm,v 1.3 2000/02/19 03:47:11 eric Exp $ |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Crypt::HCE_SHA; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1400
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
80
|
|
11
|
2
|
|
|
2
|
|
10
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
150
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
2124
|
use Digest::SHA1; |
|
2
|
|
|
|
|
4576
|
|
|
2
|
|
|
|
|
120
|
|
14
|
2
|
|
|
2
|
|
1742
|
use MIME::Base64; |
|
2
|
|
|
|
|
2736
|
|
|
2
|
|
|
|
|
164
|
|
15
|
2
|
|
|
2
|
|
16
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1994
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
require Exporter; |
18
|
|
|
|
|
|
|
require AutoLoader; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
@ISA = qw(Exporter AutoLoader); |
21
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
22
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
23
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
24
|
|
|
|
|
|
|
@EXPORT = qw( |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
$VERSION = '0.70'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
4
|
|
|
4
|
0
|
6016682
|
my $class = shift; |
31
|
4
|
|
|
|
|
56
|
my $self = {}; |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
23
|
bless $self, $class; |
34
|
|
|
|
|
|
|
|
35
|
4
|
50
|
|
|
|
26
|
if (scalar(@_) != 2) { |
36
|
0
|
|
|
|
|
0
|
croak "Error: must be invoked HCE_SHA->new(key, random_thing)"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
44
|
$self->{SKEY} = shift(@_); |
40
|
4
|
|
|
|
|
21
|
$self->{RKEY} = shift(@_); |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
|
|
|
28
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _new_key { |
46
|
52
|
|
|
52
|
|
80
|
my $self = shift; |
47
|
52
|
|
|
|
|
95
|
my ($rnd) = @_; |
48
|
|
|
|
|
|
|
|
49
|
52
|
|
|
|
|
278
|
my $context = new Digest::SHA1; |
50
|
52
|
|
|
|
|
556
|
$context->add($self->{SKEY}, $rnd); |
51
|
52
|
|
|
|
|
620
|
my $digest = $context->digest(); |
52
|
52
|
|
|
|
|
245
|
my @e_block = unpack('C*', $digest); |
53
|
52
|
|
|
|
|
455
|
return @e_block; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub hce_block_encrypt { |
57
|
8
|
|
|
8
|
0
|
27
|
my $self = shift; |
58
|
8
|
|
|
|
|
15
|
my ($data) = @_; |
59
|
8
|
|
|
|
|
10
|
my ($i, $key, $data_size, $ans, $mod, @e_block, @data, @key, @ans); |
60
|
|
|
|
|
|
|
|
61
|
8
|
|
|
|
|
69
|
@key = unpack ('C*', $self->{SKEY}); |
62
|
8
|
|
|
|
|
538
|
@data = unpack ('C*', $data); |
63
|
|
|
|
|
|
|
|
64
|
8
|
|
|
|
|
32
|
undef @ans; |
65
|
8
|
|
|
|
|
29
|
@e_block = $self->_new_key($self->{RKEY}); |
66
|
8
|
|
|
|
|
18
|
$data_size = scalar(@data); |
67
|
8
|
|
|
|
|
29
|
for($i=0; $i < $data_size; $i++) { |
68
|
446
|
|
|
|
|
650
|
$mod = $i % 20; |
69
|
446
|
100
|
100
|
|
|
2048
|
if (($mod == 0) && ($i > 19)) { |
70
|
18
|
|
|
|
|
148
|
@e_block = $self->_new_key(pack 'C*', (@ans)[($i-20)..($i-1)]); |
71
|
|
|
|
|
|
|
} |
72
|
446
|
|
|
|
|
2070
|
$ans[$i] = $e_block[$mod] ^ $data[$i]; |
73
|
|
|
|
|
|
|
} |
74
|
8
|
|
|
|
|
29
|
$ans = pack 'C*', @ans; |
75
|
8
|
|
|
|
|
50
|
return $ans; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub hce_block_decrypt { |
79
|
8
|
|
|
8
|
0
|
35
|
my $self = shift; |
80
|
8
|
|
|
|
|
16
|
my ($data) = @_; |
81
|
8
|
|
|
|
|
20
|
my ($i, $key, $data_size, $ans, $mod, @e_block, @data, @key, @ans); |
82
|
|
|
|
|
|
|
|
83
|
8
|
|
|
|
|
45
|
@key = unpack ('C*', $self->{SKEY}); |
84
|
8
|
|
|
|
|
102
|
@data = unpack ('C*', $data); |
85
|
|
|
|
|
|
|
|
86
|
8
|
|
|
|
|
26
|
undef @ans; |
87
|
8
|
|
|
|
|
67
|
@e_block = $self->_new_key($self->{RKEY}); |
88
|
8
|
|
|
|
|
21
|
$data_size = scalar(@data); |
89
|
8
|
|
|
|
|
27
|
for($i=0; $i < $data_size; $i++) { |
90
|
446
|
|
|
|
|
466
|
$mod = $i % 20; |
91
|
446
|
100
|
100
|
|
|
1109
|
if (($mod == 0) && ($i > 19)) { |
92
|
18
|
|
|
|
|
128
|
@e_block = $self->_new_key(pack 'C*', (@data)[($i-20)..($i-1)]); |
93
|
|
|
|
|
|
|
} |
94
|
446
|
|
|
|
|
1497
|
$ans[$i] = $e_block[$mod] ^ $data[$i]; |
95
|
|
|
|
|
|
|
} |
96
|
8
|
|
|
|
|
42
|
$ans = pack 'C*', @ans; |
97
|
8
|
|
|
|
|
48
|
return $ans; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub hce_block_encode_mime { |
101
|
6
|
|
|
6
|
0
|
997
|
my $self = shift; |
102
|
6
|
|
|
|
|
21
|
my ($data) = @_; |
103
|
|
|
|
|
|
|
|
104
|
6
|
|
|
|
|
21
|
my $new_data = $self->hce_block_encrypt($data); |
105
|
6
|
|
|
|
|
55
|
my $encode = encode_base64($new_data, ""); |
106
|
6
|
|
|
|
|
24
|
return $encode; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub hce_block_decode_mime { |
110
|
6
|
|
|
6
|
0
|
8368
|
my $self = shift; |
111
|
6
|
|
|
|
|
26
|
my ($data) = @_; |
112
|
|
|
|
|
|
|
|
113
|
6
|
|
|
|
|
32
|
my $decode = decode_base64($data); |
114
|
6
|
|
|
|
|
35
|
my $new_data = $self->hce_block_decrypt($decode); |
115
|
6
|
|
|
|
|
42
|
return $new_data; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
__END__ |