Crypt-Twofish
view release on metacpan or search on metacpan
* Makefile.PL now tries to do the right thing on systems which don't
have <inttypes.h>.
* This release should work under Activeperl (thanks to Tony Cook).
2.02 2001-05-04
* The module is now distributed under the Artistic License.
2.00 2001-05-01 (By Abhijit Menon-Sen <ams@wiw.org>)
* Complete rewrite. The module is now Crypt::CBC compatible, has new
test cases, and a cleaner Twofish implementation.
1.00 1999-11-08 (By Nishant Kakani)
* original version; created by h2xs 1.16
$plaintext = $cipher->decrypt($ciphertext);
DESCRIPTION
Twofish is a 128-bit symmetric block cipher with a variable
length (128, 192, or 256-bit) key, developed by Counterpane
Labs. It is unpatented and free for all uses, as described at
<URL:http://www.counterpane.com/twofish.html>.
This module implements Twofish encryption. It supports the
Crypt::CBC interface, with the functions described below. It also
provides an interface that is call- compatible with Crypt::Twofish
1.0, but its use in new code is strongly discouraged.
Functions
blocksize
Returns the size (in bytes) of the block (16, in this case).
keysize
Returns the size (in bytes) of the key. Although the module
understands 128, 192, and 256-bit keys, it returns 16 for
compatibility with Crypt::CBC.
new($key)
This creates a new Crypt::Twofish object with the specified
key (which should be 16, 24, or 32 bytes long).
encrypt($data)
Encrypts blocksize() bytes of $data and returns the
corresponding ciphertext.
decrypt($data)
Decrypts blocksize() bytes of $data and returns the
corresponding plaintext.
SEE ALSO
Crypt::CBC, Crypt::Blowfish, Crypt::TEA
ACKNOWLEDGEMENTS
Nishant Kakani
For writing Crypt::Twofish 1.0 (this version is a complete
rewrite).
Tony Cook
For making the module work under Activeperl, testing on
several platforms, and suggesting that I probe for features
via %Config.
# the same way: they don't pad keys, and cannot decrypt ciphertext which
# was written by the old module.
#
# (This interface is deprecated. Please use the documented interface
# instead).
sub Encipher
{
my ($key, $keylength, $plaintext) = @_;
require Crypt::CBC;
my $cipher = Crypt::CBC->new($key, "Twofish");
return $cipher->encrypt($plaintext);
}
sub Decipher
{
my ($key, $keylength, $ciphertext, $cipherlength) = @_;
require Crypt::CBC;
my $cipher = Crypt::CBC->new($key, "Twofish");
return $cipher->decrypt($ciphertext);
}
sub LastError { ""; }
sub CheckTwofish { undef; }
1;
__END__
$plaintext = $cipher->decrypt($ciphertext);
=head1 DESCRIPTION
Twofish is a 128-bit symmetric block cipher with a variable length (128,
192, or 256-bit) key, developed by Counterpane Labs. It is unpatented
and free for all uses, as described at
<URL:http://www.counterpane.com/twofish.html>.
This module implements Twofish encryption. It supports the Crypt::CBC
interface, with the functions described below. It also provides an
interface that is call-compatible with Crypt::Twofish 1.0, but its use
in new code is strongly discouraged.
=head2 Functions
=over
=item blocksize
Returns the size (in bytes) of the block (16, in this case).
=item keysize
Returns the size (in bytes) of the key. Although the module understands
128, 192, and 256-bit keys, it returns 16 for compatibility with
Crypt::CBC.
=item new($key)
This creates a new Crypt::Twofish object with the specified key (which
should be 16, 24, or 32 bytes long).
=item encrypt($data)
Encrypts blocksize() bytes of $data and returns the corresponding
ciphertext.
=item decrypt($data)
Decrypts blocksize() bytes of $data and returns the corresponding
plaintext.
=back
=head1 SEE ALSO
Crypt::CBC, Crypt::Blowfish, Crypt::TEA
=head1 ACKNOWLEDGEMENTS
=over 4
=item Nishant Kakani
For writing Crypt::Twofish 1.0 (this version is a complete rewrite).
=item Tony Cook
elsif ($length == 32) { ok(unpack("H*", $text), "37fe26ff1cf66175f5ddf4c33b97a205"); }
for (1..49) {
$two = Crypt::Twofish->new(pop(@keys));
$text = $two->decrypt($text);
}
ok(unpack("H*", $text), "00"x16);
}
eval 'use Crypt::CBC';
if ($@) { print "skipping Crypt::CBC test\n"; }
else {
print "trying CBC... ";
my $c = Crypt::CBC->new($key, "Twofish") || die "$!\n";
my $t = $c->encrypt_hex($plaintext);
ok($plaintext, $c->decrypt_hex($t));
}
print "\nBenchmarks\n";
{
my $s = Benchmark->new;
for (my $i = 0; $i < 10000; $i++) {
my $in = pack "H*", "0123456789ABCDEFFEDCBA9876543210";
( run in 0.740 second using v1.01-cache-2.11-cpan-e1769b4cff6 )