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
|
|
750
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
48
|
|
11
|
2
|
|
|
2
|
|
6
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
102
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
8
|
use Digest::MD5; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
52
|
|
14
|
2
|
|
|
2
|
|
806
|
use MIME::Base64; |
|
2
|
|
|
|
|
928
|
|
|
2
|
|
|
|
|
94
|
|
15
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1174
|
|
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.75'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
4
|
|
|
4
|
0
|
6006643
|
my $class = shift; |
31
|
4
|
|
|
|
|
13
|
my $self = {}; |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
12
|
bless $self, $class; |
34
|
|
|
|
|
|
|
|
35
|
4
|
0
|
50
|
|
|
14
|
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
|
|
|
|
13
|
if ($_[0] eq "KEYBUG") { |
39
|
0
|
|
|
|
|
0
|
$self->{HAVE_KEYBUG} = shift(@_); |
40
|
|
|
|
|
|
|
} else { |
41
|
4
|
|
|
|
|
15
|
delete $self->{HAVE_KEYBUG}; |
42
|
|
|
|
|
|
|
} |
43
|
4
|
|
|
|
|
15
|
$self->{SKEY} = shift(@_); |
44
|
4
|
|
|
|
|
7
|
$self->{RKEY} = shift(@_); |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
10
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _new_key { |
50
|
108
|
|
|
108
|
|
85
|
my $self = shift; |
51
|
108
|
|
|
|
|
90
|
my ($rnd) = @_; |
52
|
|
|
|
|
|
|
|
53
|
108
|
|
|
|
|
228
|
my $context = new Digest::MD5; |
54
|
108
|
|
|
|
|
190
|
$context->add($self->{SKEY}, $rnd); |
55
|
108
|
|
|
|
|
197
|
my $digest = $context->digest(); |
56
|
108
|
|
|
|
|
217
|
my @e_block = unpack('C*', $digest); |
57
|
108
|
|
|
|
|
410
|
return @e_block; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub hce_block_encrypt { |
61
|
8
|
|
|
8
|
0
|
13
|
my $self = shift; |
62
|
8
|
|
|
|
|
12
|
my ($data) = @_; |
63
|
8
|
|
|
|
|
12
|
my ($i, $key, $data_size, $ans, $mod, @e_block, @data, @key, @ans); |
64
|
|
|
|
|
|
|
|
65
|
8
|
|
|
|
|
33
|
@key = unpack ('C*', $self->{SKEY}); |
66
|
8
|
|
|
|
|
74
|
@data = unpack ('C*', $data); |
67
|
|
|
|
|
|
|
|
68
|
8
|
|
|
|
|
24
|
undef @ans; |
69
|
8
|
|
|
|
|
34
|
@e_block = $self->_new_key($self->{RKEY}); |
70
|
8
|
|
|
|
|
10
|
$data_size = scalar(@data); |
71
|
8
|
|
|
|
|
21
|
for($i=0; $i < $data_size; $i++) { |
72
|
798
|
|
|
|
|
504
|
$mod = $i % 16; |
73
|
798
|
100
|
100
|
|
|
1059
|
if (($mod == 0) && ($i > 15)) { |
74
|
46
|
50
|
|
|
|
71
|
if (defined($self->{HAVE_KEYBUG})) { |
75
|
0
|
|
|
|
|
0
|
@e_block = $self->_new_key((@ans)[($i-16)..($i-1)]); |
76
|
|
|
|
|
|
|
} else { |
77
|
46
|
|
|
|
|
145
|
@e_block = $self->_new_key(pack 'C*', (@ans)[($i-16)..($i-1)]); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
798
|
|
|
|
|
1083
|
$ans[$i] = $e_block[$mod] ^ $data[$i]; |
81
|
|
|
|
|
|
|
} |
82
|
8
|
|
|
|
|
25
|
$ans = pack 'C*', @ans; |
83
|
8
|
|
|
|
|
39
|
return $ans; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub hce_block_decrypt { |
87
|
8
|
|
|
8
|
0
|
13
|
my $self = shift; |
88
|
8
|
|
|
|
|
8
|
my ($data) = @_; |
89
|
8
|
|
|
|
|
7
|
my ($i, $key, $data_size, $ans, $mod, @e_block, @data, @key, @ans); |
90
|
|
|
|
|
|
|
|
91
|
8
|
|
|
|
|
21
|
@key = unpack ('C*', $self->{SKEY}); |
92
|
8
|
|
|
|
|
64
|
@data = unpack ('C*', $data); |
93
|
|
|
|
|
|
|
|
94
|
8
|
|
|
|
|
17
|
undef @ans; |
95
|
8
|
|
|
|
|
15
|
@e_block = $self->_new_key($self->{RKEY}); |
96
|
8
|
|
|
|
|
9
|
$data_size = scalar(@data); |
97
|
8
|
|
|
|
|
28
|
for($i=0; $i < $data_size; $i++) { |
98
|
798
|
|
|
|
|
484
|
$mod = $i % 16; |
99
|
798
|
100
|
100
|
|
|
1017
|
if (($mod == 0) && ($i > 15)) { |
100
|
46
|
50
|
|
|
|
54
|
if (defined($self->{HAVE_KEYBUG})) { |
101
|
0
|
|
|
|
|
0
|
@e_block = $self->_new_key((@data)[($i-16)..($i-1)]); |
102
|
|
|
|
|
|
|
} else { |
103
|
46
|
|
|
|
|
136
|
@e_block = $self->_new_key(pack 'C*', (@data)[($i-16)..($i-1)]); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
798
|
|
|
|
|
1175
|
$ans[$i] = $e_block[$mod] ^ $data[$i]; |
107
|
|
|
|
|
|
|
} |
108
|
8
|
|
|
|
|
22
|
$ans = pack 'C*', @ans; |
109
|
8
|
|
|
|
|
36
|
return $ans; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub hce_block_encode_mime { |
113
|
6
|
|
|
6
|
0
|
233
|
my $self = shift; |
114
|
6
|
|
|
|
|
30
|
my ($data) = @_; |
115
|
|
|
|
|
|
|
|
116
|
6
|
|
|
|
|
15
|
my $new_data = $self->hce_block_encrypt($data); |
117
|
6
|
|
|
|
|
42
|
my $encode = encode_base64($new_data, ""); |
118
|
6
|
|
|
|
|
13
|
return $encode; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub hce_block_decode_mime { |
122
|
6
|
|
|
6
|
0
|
2421
|
my $self = shift; |
123
|
6
|
|
|
|
|
10
|
my ($data) = @_; |
124
|
|
|
|
|
|
|
|
125
|
6
|
|
|
|
|
18
|
my $decode = decode_base64($data); |
126
|
6
|
|
|
|
|
18
|
my $new_data = $self->hce_block_decrypt($decode); |
127
|
6
|
|
|
|
|
14
|
return $new_data; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
__END__ |