line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::DRM; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
68390
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
99
|
|
4
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
111
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
16
|
use vars qw(@ISA @EXPORT_OK $VERSION); |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
1061
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Acme::DRM - Library providing cryptographic capabilities especially suited for Digital Rights Management. Protects against Pirates. May increase global warming. Note: Not guaranteed to protect against Pirates or increase global warming. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.03 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$VERSION = '0.03'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Acme::DRM qw(secureXOR doubleROT128); |
23
|
|
|
|
|
|
|
my $intellectualProperty = 'One-hit Wonder Music'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Encrypt your IP to plug the digital hole |
26
|
|
|
|
|
|
|
my $encryptedContent = secureXOR($intellectualProperty); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Invoke the DMCA by encrypting your data, without invoking |
29
|
|
|
|
|
|
|
# additional overhead for decryption at runtime |
30
|
|
|
|
|
|
|
my $protectedContent = doubleROT128($intellectualProperty); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 EXPORT |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
require Exporter; |
39
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=over 4 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item B |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
push( @EXPORT_OK, '&secureXOR' ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item B |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
push( @EXPORT_OK, '&doubleROT128' ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=back |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 FUNCTIONS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 secureXOR |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
XOR is an extremely convenient method for encrypting a digital media stream. Given any two of the a) original data, b) encryption key, and c) encrypted data, you get the third item. Unfortunately, hackers have compromised the effectiveness of this computationally convenient method. The weakness is the reuse of a single key. |
62
|
|
|
|
|
|
|
The answer is to use a variable key, however, key distribution becomes a difficult proposition. If the key is distributed in the clear, pirates can simply decrypt the digital media stream, and steal your B. Our solution is to use the media itself as the key. This function conveniently takes only the media as a single argument, and automatically XORs the datastream with a copy of itself, rendering the stream almost completely unrecoverable without the key: the media itself. This is virtually hacker-proof, except for one exception: the encrypted datastream is exactly the same length as the original data, but this is almost never probably a weakness. This algorithm does guarantee that your original data will not be recoverable from the encrypted stream without the proper key. Additionally, use of an incorrect key will not provide hackers with any sort of clue that they have guessed an incorrect key. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub secureXOR { |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Get the first argument |
69
|
2
|
|
|
2
|
1
|
922
|
my $data = shift; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Make sure we really got something |
72
|
2
|
50
|
|
|
|
7
|
unless ( defined($data) ) { |
73
|
0
|
|
|
|
|
0
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Where we'll collect the output |
77
|
2
|
|
|
|
|
5
|
my @output; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Break the data into individual bytes |
80
|
2
|
|
|
|
|
17
|
my @data = unpack( 'C*', $data ); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Iterate over each byte |
83
|
2
|
|
|
|
|
7
|
for my $byte (@data) { |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Protect each byte with the secure variable-key |
86
|
|
|
|
|
|
|
# XOR algorithm |
87
|
60
|
|
|
|
|
87
|
push( @output, $byte ^ $byte ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Re-encode the encrypted data and output it as a single stream |
91
|
2
|
|
|
|
|
15
|
return ( pack( 'C*', @output ) ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 doubleROT128 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This function exists to provide a method by which you can protect your B under the DMCA, without imposing the difficulty of implementing a separate, potentially insecure decryption algorithm in your secure media playback application. |
97
|
|
|
|
|
|
|
Simply pass your digital media to this function, and it will output an encrypted stream, conveniently passed twice internally through a strong ROT-128 encryption algorithm. The resulting encrypted content cannot be legally decrypted by a hacker, since you encrypted it to protect it from hackers and pirates. Further, you can pass the content through this algorithm multiple times for enhanced protection. Decryption can be performed by either passing the encrypted datastream back through this algorithm, or in many cases, the encrypted stream itself can be used by the playback function. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub doubleROT128 { |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Get the first argument |
104
|
2
|
|
|
2
|
1
|
569
|
my $data = shift; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Make sure we got something |
107
|
2
|
50
|
|
|
|
7
|
unless ( defined($data) ) { |
108
|
0
|
|
|
|
|
0
|
return; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Where to keep the output as individual bytes |
112
|
2
|
|
|
|
|
4
|
my @output; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Break the input into individual bytes |
115
|
2
|
|
|
|
|
17
|
my @data = unpack( 'C*', $data ); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Protect each byte individually, and accumulate the results |
118
|
2
|
|
|
|
|
6
|
for my $byte (@data) { |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Marvel at the beauty of this algorithm |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Left shift 4 bits -- this makes the number 12 bits, lower 4 bits are all 0 |
123
|
60
|
|
|
|
|
57
|
$byte = $byte << 4; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Rotate the high 4 bits back around to make this an 8-bit value again |
126
|
60
|
|
|
|
|
77
|
$byte = ( $byte / 2**8 ) + ( $byte % 2**8 ); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Now rotate it again for twice the security |
129
|
60
|
|
|
|
|
60
|
$byte = $byte << 4; |
130
|
60
|
|
|
|
|
62
|
$byte = ( $byte / 2**8 ) + ( $byte % 2**8 ); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# And collect the output |
133
|
60
|
|
|
|
|
95
|
push( @output, $byte ); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Re-encode the encrypted stream and output it |
137
|
2
|
|
|
|
|
17
|
return ( pack( 'C*', @output ) ); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHOR |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Brett T. Warden, C<< >> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 BUGS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
147
|
|
|
|
|
|
|
C, or through the web interface at |
148
|
|
|
|
|
|
|
L. |
149
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
150
|
|
|
|
|
|
|
your bug as I make changes. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Thanks to the lobbyists behind the DMCA and the politicians who bought (or |
155
|
|
|
|
|
|
|
were bought) into the great idea of assigning corporate greed higher value |
156
|
|
|
|
|
|
|
than constitutionally-asserted citizen rights. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Copyright 2005-2007 Brett T. Warden, all rights reserved. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
163
|
|
|
|
|
|
|
under the same terms as Perl itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; # End of Acme::DRM |