line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Crypt::HCE_MD5 |
3
|
|
|
|
|
|
|
# implements one way hash chaining encryption using MD5 |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: HCE_MD5.pm,v 1.3 1999/08/17 13:35:06 eric Exp $ |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Crypt::HCE_MD5; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
17850
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
110
|
|
11
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
190
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
24
|
use Digest::MD5; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
102
|
|
14
|
2
|
|
|
2
|
|
13964
|
use MIME::Base64; |
|
2
|
|
|
|
|
2058
|
|
|
2
|
|
|
|
|
120
|
|
15
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1680
|
|
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
|
6010061
|
my $class = shift; |
31
|
4
|
|
|
|
|
24
|
my $self = {}; |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
32
|
bless $self, $class; |
34
|
|
|
|
|
|
|
|
35
|
4
|
0
|
50
|
|
|
23
|
if ((scalar(@_) != 2) && (scalar(@_ != 3))) { |
36
|
0
|
|
|
|
|
0
|
croak "Error: must be invoked HCE_MD5->new(key, random_thing) or HCE_MD5->new(KEYBUG, key, random_thing)"; |
37
|
|
|
|
|
|
|
} |
38
|
4
|
50
|
|
|
|
20
|
if ($_[0] eq "KEYBUG") { |
39
|
0
|
|
|
|
|
0
|
$self->{HAVE_KEYBUG} = shift(@_); |
40
|
|
|
|
|
|
|
} else { |
41
|
4
|
|
|
|
|
31
|
delete $self->{HAVE_KEYBUG}; |
42
|
|
|
|
|
|
|
} |
43
|
4
|
|
|
|
|
26
|
$self->{SKEY} = shift(@_); |
44
|
4
|
|
|
|
|
21
|
$self->{RKEY} = shift(@_); |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
32
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _new_key { |
50
|
108
|
|
|
108
|
|
163
|
my $self = shift; |
51
|
108
|
|
|
|
|
150
|
my ($rnd) = @_; |
52
|
|
|
|
|
|
|
|
53
|
108
|
|
|
|
|
1462
|
my $context = new Digest::MD5; |
54
|
108
|
|
|
|
|
675
|
$context->add($self->{SKEY}, $rnd); |
55
|
108
|
|
|
|
|
430
|
my $digest = $context->digest(); |
56
|
108
|
|
|
|
|
727
|
my @e_block = unpack('C*', $digest); |
57
|
108
|
|
|
|
|
1230
|
return @e_block; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub hce_block_encrypt { |
61
|
8
|
|
|
8
|
0
|
28
|
my $self = shift; |
62
|
8
|
|
|
|
|
13
|
my ($data) = @_; |
63
|
8
|
|
|
|
|
14
|
my ($i, $key, $data_size, $ans, $mod, @e_block, @data, @key, @ans); |
64
|
|
|
|
|
|
|
|
65
|
8
|
|
|
|
|
85
|
@key = unpack ('C*', $self->{SKEY}); |
66
|
8
|
|
|
|
|
166
|
@data = unpack ('C*', $data); |
67
|
|
|
|
|
|
|
|
68
|
8
|
|
|
|
|
46
|
undef @ans; |
69
|
8
|
|
|
|
|
29
|
@e_block = $self->_new_key($self->{RKEY}); |
70
|
8
|
|
|
|
|
27
|
$data_size = scalar(@data); |
71
|
8
|
|
|
|
|
32
|
for($i=0; $i < $data_size; $i++) { |
72
|
798
|
|
|
|
|
1132
|
$mod = $i % 16; |
73
|
798
|
100
|
100
|
|
|
2986
|
if (($mod == 0) && ($i > 15)) { |
74
|
46
|
50
|
|
|
|
131
|
if (defined($self->{HAVE_KEYBUG})) { |
75
|
0
|
|
|
|
|
0
|
@e_block = $self->_new_key((@ans)[($i-16)..($i-1)]); |
76
|
|
|
|
|
|
|
} else { |
77
|
46
|
|
|
|
|
580
|
@e_block = $self->_new_key(pack 'C*', (@ans)[($i-16)..($i-1)]); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
798
|
|
|
|
|
2778
|
$ans[$i] = $e_block[$mod] ^ $data[$i]; |
81
|
|
|
|
|
|
|
} |
82
|
8
|
|
|
|
|
57
|
$ans = pack 'C*', @ans; |
83
|
8
|
|
|
|
|
65
|
return $ans; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub hce_block_decrypt { |
87
|
8
|
|
|
8
|
0
|
27
|
my $self = shift; |
88
|
8
|
|
|
|
|
23
|
my ($data) = @_; |
89
|
8
|
|
|
|
|
14
|
my ($i, $key, $data_size, $ans, $mod, @e_block, @data, @key, @ans); |
90
|
|
|
|
|
|
|
|
91
|
8
|
|
|
|
|
43
|
@key = unpack ('C*', $self->{SKEY}); |
92
|
8
|
|
|
|
|
153
|
@data = unpack ('C*', $data); |
93
|
|
|
|
|
|
|
|
94
|
8
|
|
|
|
|
42
|
undef @ans; |
95
|
8
|
|
|
|
|
26
|
@e_block = $self->_new_key($self->{RKEY}); |
96
|
8
|
|
|
|
|
17
|
$data_size = scalar(@data); |
97
|
8
|
|
|
|
|
31
|
for($i=0; $i < $data_size; $i++) { |
98
|
798
|
|
|
|
|
959
|
$mod = $i % 16; |
99
|
798
|
100
|
100
|
|
|
3880
|
if (($mod == 0) && ($i > 15)) { |
100
|
46
|
50
|
|
|
|
183
|
if (defined($self->{HAVE_KEYBUG})) { |
101
|
0
|
|
|
|
|
0
|
@e_block = $self->_new_key((@data)[($i-16)..($i-1)]); |
102
|
|
|
|
|
|
|
} else { |
103
|
46
|
|
|
|
|
406
|
@e_block = $self->_new_key(pack 'C*', (@data)[($i-16)..($i-1)]); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
798
|
|
|
|
|
3016
|
$ans[$i] = $e_block[$mod] ^ $data[$i]; |
107
|
|
|
|
|
|
|
} |
108
|
8
|
|
|
|
|
64
|
$ans = pack 'C*', @ans; |
109
|
8
|
|
|
|
|
77
|
return $ans; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub hce_block_encode_mime { |
113
|
6
|
|
|
6
|
0
|
3293
|
my $self = shift; |
114
|
6
|
|
|
|
|
99
|
my ($data) = @_; |
115
|
|
|
|
|
|
|
|
116
|
6
|
|
|
|
|
23
|
my $new_data = $self->hce_block_encrypt($data); |
117
|
6
|
|
|
|
|
70
|
my $encode = encode_base64($new_data, ""); |
118
|
6
|
|
|
|
|
30
|
return $encode; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub hce_block_decode_mime { |
122
|
6
|
|
|
6
|
0
|
13149
|
my $self = shift; |
123
|
6
|
|
|
|
|
740
|
my ($data) = @_; |
124
|
|
|
|
|
|
|
|
125
|
6
|
|
|
|
|
37
|
my $decode = decode_base64($data); |
126
|
6
|
|
|
|
|
41
|
my $new_data = $self->hce_block_decrypt($decode); |
127
|
6
|
|
|
|
|
23
|
return $new_data; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
__END__ |