blib/lib/Acme/DRM.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 91.3% 42 / 46 CC 5 SCAR 8.6
CC
5
Cov
90%
secureXOR
3.1
doubleROT128
3.0
BEGIN
1.0
CRAP 2.4
↑ Summary
1 package Acme::DRM;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use vars qw(@ISA @EXPORT_OK $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 4 $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 4 require Exporter;
39 4 @ISA = qw(Exporter);
40  
41 =over 4
42  
43 =item B<secureXOR>
44  
45 =cut
46  
47 4 push( @EXPORT_OK, '&secureXOR' );
48  
49 =item B<doubleROT128>
50  
51 =cut
52  
53 4 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<Intellectual Property>. 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 2 ▶sub secureXOR {
Subroutine secureXOR: called CC=3 SCAR=11.2
Pod documented
67  
68 # Get the first argument
69 2 my $data = shift;
70  
71 # Make sure we really got something
72 2 ▶ unless ( defined($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 0 2 2
73 0 return;
74 }
75  
76 # Where we'll collect the output
77 2 my @output;
78  
79 # Break the data into individual bytes
80 2 my @data = unpack( 'C*', $data );
81  
82 # Iterate over each byte
83 2 for my $byte (@data) {
84  
85 # Protect each byte with the secure variable-key
86 # XOR algorithm
87 60 push( @output, $byte ^ $byte );
88 }
89  
90 # Re-encode the encrypted data and output it as a single stream
91 2 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<Intellectual Property> 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 2 ▶sub doubleROT128 {
Subroutine doubleROT128: called CC=3 SCAR=11.1
Pod documented
102  
103 # Get the first argument
104 2 my $data = shift;
105  
106 # Make sure we got something
107 2 ▶ unless ( defined($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 0 2 2
108 0 return;
109 }
110  
111 # Where to keep the output as individual bytes
112 2 my @output;
113  
114 # Break the input into individual bytes
115 2 my @data = unpack( 'C*', $data );
116  
117 # Protect each byte individually, and accumulate the results
118 2 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 $byte = $byte << 4;
124  
125 # Rotate the high 4 bits back around to make this an 8-bit value again
126 60 $byte = ( $byte / 2**8 ) + ( $byte % 2**8 );
127  
128 # Now rotate it again for twice the security
129 60 $byte = $byte << 4;
130 60 $byte = ( $byte / 2**8 ) + ( $byte % 2**8 );
131  
132 # And collect the output
133 60 push( @output, $byte );
134 }
135  
136 # Re-encode the encrypted stream and output it
137 2 return ( pack( 'C*', @output ) );
138 }
139  
140 =head1 AUTHOR
141  
142 Brett T. Warden, C<< <bwarden-cpan@wgz.org> >>
143  
144 =head1 BUGS
145  
146 Please report any bugs or feature requests to
147 C<bug-acme-drm@rt.cpan.org>, or through the web interface at
148 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-DRM>.
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 4 1; # End of Acme::DRM
↑ Summary