Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Crypt / Blowfish.pm
CommitLineData
86530b38
AT
1package Crypt::Blowfish;
2
3require Exporter;
4require DynaLoader;
5use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
6
7@ISA = qw(Exporter DynaLoader);
8# @ISA = qw(Exporter DynaLoader Crypt::BlockCipher);
9
10# Items to export into callers namespace by default
11@EXPORT = qw();
12
13# Other items we are prepared to export if requested
14@EXPORT_OK = qw(
15 blocksize keysize min_keysize max_keysize
16 new encrypt decrypt
17);
18
19$VERSION = '2.09';
20bootstrap Crypt::Blowfish $VERSION;
21
22use strict;
23use Carp;
24
25sub usage
26{
27 my ($package, $filename, $line, $subr) = caller(1);
28 $Carp::CarpLevel = 2;
29 croak "Usage: $subr(@_)";
30}
31
32
33sub blocksize { 8; } # /* byte my shiny metal.. */
34sub keysize { 0; } # /* we'll leave this at 8 .. for now. expect change. */
35sub min_keysize { 8; }
36sub max_keysize { 56; }
37
38sub new
39{
40 usage("new Blowfish key") unless @_ == 2;
41
42 my $type = shift; my $self = {}; bless $self, $type;
43
44 $self->{'ks'} = Crypt::Blowfish::init(shift);
45
46 $self;
47}
48
49sub encrypt
50{
51 usage("encrypt data[8 bytes]") unless @_ == 2;
52
53 my $self = shift;
54 my $data = shift;
55
56 Crypt::Blowfish::crypt($data, $data, $self->{'ks'}, 0);
57
58 $data;
59}
60
61sub decrypt
62{
63 usage("decrypt data[8 bytes]") unless @_ == 2;
64
65 my $self = shift;
66 my $data = shift;
67
68 Crypt::Blowfish::crypt($data, $data, $self->{'ks'}, 1);
69
70 $data;
71}
72
731;
74
75__END__
76#
77# Parts Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/)
78# New Parts Copyright (C) 2000, 2001 W3Works, LLC (http://www.w3works.com/)
79# All rights reserved.
80#
81
82=head1 NAME
83
84Crypt::Blowfish - Perl Blowfish encryption module
85
86=head1 SYNOPSIS
87
88 use Crypt::Blowfish;
89 my $cipher = new Crypt::Blowfish $key;
90 my $ciphertext = $cipher->encrypt($plaintext);
91 my $plaintext = $cipher->decrypt($ciphertext);
92
93=head1 DESCRIPTION
94
95Blowfish is capable of strong encryption and can use key sizes up
96to 56 bytes (a 448 bit key). You're encouraged to take advantage
97of the full key size to ensure the strongest encryption possible
98from this module.
99
100Crypt::Blowfish has the following methods:
101
102=over 4
103
104 blocksize()
105 keysize()
106 encrypt()
107 decrypt()
108
109=back
110
111=head1 FUNCTIONS
112
113=over 4
114
115=item blocksize
116
117Returns the size (in bytes) of the block cipher.
118
119Crypt::Blowfish doesn't return a key size due to its ability
120to use variable-length keys. (well, more accurately, it won't
121as of 2.09 .. for now, it does. expect that to change)
122
123=item new
124
125 my $cipher = new Crypt::Blowfish $key;
126
127This creates a new Crypt::Blowfish BlockCipher object, using $key,
128where $key is a key of C<keysize()> bytes (minimum of eight bytes).
129
130=item encrypt
131
132 my $cipher = new Crypt::Blowfish $key;
133 my $ciphertext = $cipher->encrypt($plaintext);
134
135This function encrypts $plaintext and returns the $ciphertext
136where $plaintext and $ciphertext must be of C<blocksize()> bytes.
137(hint: Blowfish is an 8 byte block cipher)
138
139=item decrypt
140
141 my $cipher = new Crypt::Blowfish $key;
142 my $plaintext = $cipher->decrypt($ciphertext);
143
144This function decrypts $ciphertext and returns the $plaintext
145where $plaintext and $ciphertext must be of C<blocksize()> bytes.
146(hint: see previous hint)
147
148=back
149
150=head1 EXAMPLE
151
152 my $key = pack("H16", "0123456789ABCDEF"); # min. 8 bytes
153 my $cipher = new Crypt::Blowfish $key;
154 my $ciphertext = $cipher->encrypt("plaintex"); # SEE NOTES
155 print unpack("H16", $ciphertext), "\n";
156
157=head1 PLATFORMS
158
159 Please see the README document for platforms and performance
160 tests.
161
162=head1 NOTES
163
164The module is capable of being used with Crypt::CBC. You're
165encouraged to read the perldoc for Crypt::CBC if you intend to
166use this module for Cipher Block Chaining modes. In fact, if
167you have any intentions of encrypting more than eight bytes of
168data with this, or any other block cipher, you're going to need
169B<some> type of block chaining help. Crypt::CBC tends to be
170very good at this. If you're not going to encrypt more than
171eight bytes, your data B<must> be B<exactly> eight bytes long.
172If need be, do your own padding. "\0" as a null byte is perfectly
173valid to use for this. Additionally, the current maintainer for
174Crypt::Blowfish may or may not release Crypt::CBC_R which
175replaces the default 'RandomIV' initialization vector in
176Crypt::CBC with a random initialization vector. (to the limits
177of /dev/urandom and associates) In either case, please email
178amused@pobox.com for Crypt::CBC_R.
179
180=head1 SEE ALSO
181
182Crypt::CBC,
183Crypt::DES,
184Crypt::IDEA
185
186Bruce Schneier, I<Applied Cryptography>, 1995, Second Edition,
187published by John Wiley & Sons, Inc.
188
189=head1 COPYRIGHT
190
191The implementation of the Blowfish algorithm was developed by,
192and is copyright of, A.M. Kuchling.
193
194Other parts of the perl extension and module are
195copyright of Systemics Ltd ( http://www.systemics.com/ ).
196
197Code revisions, updates, and standalone release are copyright
1981999-2001 W3Works, LLC.
199
200=head1 AUTHOR
201
202Original algorithm, Bruce Shneier. Original implementation, A.M.
203Kuchling. Original Perl implementation, Systemics Ltd. Current
204maintenance by W3Works, LLC.
205
206Current revision and maintainer: Dave Paris <amused@pobox.com>
207