1#
2# Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/)
3# All rights reserved.
4#
5# Modifications are Copyright (c) 2000, W3Works, LLC
6# All Rights Reserved.
7
8package Crypt::DES;
9
10require Exporter;
11require DynaLoader;
12use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
13
14@ISA = qw(Exporter DynaLoader);
15
16# Items to export into callers namespace by default
17@EXPORT =	qw();
18
19# Other items we are prepared to export if requested
20@EXPORT_OK =	qw();
21
22$VERSION = '2.07';
23bootstrap Crypt::DES $VERSION;
24
25use strict;
26use Carp;
27
28sub usage
29{
30	my ($package, $filename, $line, $subr) = caller(1);
31	$Carp::CarpLevel = 2;
32	croak "Usage: $subr(@_)";
33}
34
35
36sub blocksize { 8; }
37sub keysize   { 8; }
38
39sub new
40{
41	usage("new DES key") unless @_ == 2;
42
43	my $type = shift;
44	my $self = {};
45	bless $self, $type;
46
47	$self->{'ks'} = Crypt::DES::expand_key(shift);
48
49	return $self;
50}
51
52sub encrypt
53{
54	usage("encrypt data[8 bytes]") unless @_ == 2;
55
56	my ($self,$data) = @_;
57	return Crypt::DES::crypt($data, $data, $self->{'ks'}, 1);
58}
59
60sub decrypt
61{
62	usage("decrypt data[8 bytes]") unless @_ == 2;
63
64	my ($self,$data) = @_;
65	return Crypt::DES::crypt($data, $data, $self->{'ks'}, 0);
66}
67
681;
69
70__END__
71
72=head1 NAME
73
74Crypt::DES - Perl DES encryption module
75
76=head1 SYNOPSIS
77
78    use Crypt::DES;
79
80
81=head1 DESCRIPTION
82
83The module implements the Crypt::CBC interface,
84which has the following methods
85
86=over 4
87
88=item blocksize
89=item keysize
90=item encrypt
91=item decrypt
92
93=back
94
95=head1 FUNCTIONS
96
97=over 4
98
99=item blocksize
100
101Returns the size (in bytes) of the block cipher.
102
103=item keysize
104
105Returns the size (in bytes) of the key. Optimal size is 8 bytes.
106
107=item new
108
109	my $cipher = new Crypt::DES $key;
110
111This creates a new Crypt::DES BlockCipher object, using $key,
112where $key is a key of C<keysize()> bytes.
113
114=item encrypt
115
116	my $cipher = new Crypt::DES $key;
117	my $ciphertext = $cipher->encrypt($plaintext);
118
119This function encrypts $plaintext and returns the $ciphertext
120where $plaintext and $ciphertext should be of C<blocksize()> bytes.
121
122=item decrypt
123
124	my $cipher = new Crypt::DES $key;
125	my $plaintext = $cipher->decrypt($ciphertext);
126
127This function decrypts $ciphertext and returns the $plaintext
128where $plaintext and $ciphertext should be of C<blocksize()> bytes.
129
130=back
131
132=head1 EXAMPLE
133
134	my $key = pack("H16", "0123456789ABCDEF");
135	my $cipher = new Crypt::DES $key;
136	my $ciphertext = $cipher->encrypt("plaintex");	# NB - 8 bytes
137	print unpack("H16", $ciphertext), "\n";
138
139=head1 NOTES
140
141Do note that DES only uses 8 byte keys and only works on 8 byte data
142blocks.  If you're intending to encrypt larger blocks or entire files,
143please use Crypt::CBC in conjunction with this module.  See the
144Crypt::CBC documentation for proper syntax and use.
145
146Also note that the DES algorithm is, by today's standard, weak
147encryption.  Crypt::Blowfish is highly recommended if you're
148interested in using strong encryption and a faster algorithm.
149
150=head1 SEE ALSO
151
152Crypt::Blowfish
153Crypt::IDEA
154
155Bruce Schneier, I<Applied Cryptography>, 1995, Second Edition,
156published by John Wiley & Sons, Inc.
157
158=head1 COPYRIGHT
159
160The implementation of the DES algorithm was developed by,
161and is copyright of, Eric Young (eay@mincom.oz.au).
162Other parts of the perl extension and module are
163copyright of Systemics Ltd ( http://www.systemics.com/ ).
164Cross-platform work and packaging for single algorithm
165distribution is copyright of W3Works, LLC.
166
167=head1 MAINTAINER
168
169This single-algorithm package and cross-platform code is
170maintained by Dave Paris <amused@pobox.com>.
171
172=cut
173