Crypt-Twofish_PP
view release on metacpan or search on metacpan
$cipher = Crypt::Twofish_PP->new ($key);
$ciphertext = $cipher->encrypt ($key);
$plaintext = $cipher->decrypt ($ciphertext);
$keysize = $cipher->keysize;
$blocksize = $cipher->blocksize;
$keysize = Crypt::Twofish_PP->keysize;
$blocksize = Crypt::Twofish_PP->blocksize;
use Crypt::CBC;
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP');
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP::Key24');
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP::Key16');
use Crypt::CBC;
use Crypt::Twofish_PP;
$Crypt::Twofish_PP::KEYSIZE = 24;
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP');
$Crypt::Twofish_PP::KEYSIZE = 32;
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP');
DESCRIPTION
Twofish is a 128-bit symmetric block cipher with a variable key length
(128, 192, or 256 bits) key, developed by Counterpane Labs. It is
unpatented and free for all uses, as described at
<http://www.counterpane.com/twofish.html>. It has been one of the five
finalists for AES.
This module is written in pure Perl, it should run everywhere where Perl
right-pad shorter blocks with null bytes.
blocksize
Returns the constant value 16.
keysize
Returns the length of the key in bytes. When called as a class
method, it returns the value $Crypt::Twofish_PP::KEYSIZE which is
initialized to 32.
CIPHER BLOCK CHAINING (CBC) MODE
When encrypting streams of data you will need an additional block
chaining mechanism like CBC as provided by Crypt::CBC(3). When used with
Crypt::CBC(3), Crypt::Twofish_PP(3) will usually work with a fixed key
length of 32 bytes, since Crypt::CBC(3) is not capable of handling
variable length keys.
If you need to use shorter keys with Crypt::CBC(3), you have two
choices: You can either overwrite the variable $Crypt::CBC::KEYSIZE with
the desired length (16 or 24) in bytes, or you can specify
'Twofish_PP::Key16' resp. 'Twofish_PP::Key24' as the cipher algorithm to
Crypt::CBC(3). The modules Crypt::Twofish_PP::Key32(3),
Crypt::Twofish_PP::Key24(3), and Crypt::Twofish_PP::Key16(3), inherit
all functionality from Crypt::Twofish_PP but overwrite the "keysize()"
method, such that another default key length is reported back to
Crypt::CBC(3).
UTF-8 NUISANCES
Beginning with Perl 5.6, Perl scalars might be internally flagged as
being UTF-8 strings, and are treated as character-oriented data, not as
byte-oriented data (one character may require one to six bytes for its
internal representation). In most cases you will gain nothing from the
introduction of that flag, and rather find yourself trying to get rid of
it. Crypt::Twofish_PP uses byte-oriented keys, and encrypts/decrypts
blocks of 16 bytes, and it is the callers responsability to clean input
data from that flag.
AUTHOR
Copyright (C) 2003, Guido Flohr <guido@imperia.net>, all rights
reserved. See the source code for details.
This software is contributed to the Perl community by Imperia
(<http://www.imperia.net/>).
SEE ALSO
Crypt::Twofish_PP::Key32(3), Crypt::Twofish_PP::Key24(3),
Crypt::Twofish_PP::Key16(3), Crypt::CBC(3), Crypt::Twofish2(3),
Crypt::Twofish(3), perl(1)
benchmark/README view on Meta::CPAN
In this directory you will find a benchmark script "benchmark.pl"
that will test the performance of all Crypt::CBC compatible
encryption modules available on CPAN at the time of this writing
(November 2003). Of course, it will only test those modules that
are installed on your system.
The results are writting into an HTML file "benchmark.html" (and
other files linked from there). The benchmarking is surely not
bullet-proof but the results should give you an idea of the
performance of the various modules on your(!) machine. Please
note, that the performance of all modules can vary a lot depending
on the operating system and hardware.
lib/Crypt/Twofish_PP.pm view on Meta::CPAN
$cipher = Crypt::Twofish_PP->new ($key);
$ciphertext = $cipher->encrypt ($key);
$plaintext = $cipher->decrypt ($ciphertext);
$keysize = $cipher->keysize;
$blocksize = $cipher->blocksize;
$keysize = Crypt::Twofish_PP->keysize;
$blocksize = Crypt::Twofish_PP->blocksize;
use Crypt::CBC;
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP');
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP::Key24');
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP::Key16');
use Crypt::CBC;
use Crypt::Twofish_PP;
$Crypt::Twofish_PP::KEYSIZE = 24;
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP');
$Crypt::Twofish_PP::KEYSIZE = 32;
$cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP');
=head1 DESCRIPTION
Twofish is a 128-bit symmetric block cipher with a variable key length
(128, 192, or 256 bits) key, developed by Counterpane Labs. It is unpatented
and free for all uses, as described at
L<http://www.counterpane.com/twofish.html>. It has been one of the
five finalists for AES.
lib/Crypt/Twofish_PP.pm view on Meta::CPAN
Returns the constant value 16.
=item B<keysize>
Returns the length of the key in bytes. When called as a class
method, it returns the value C<$Crypt::Twofish_PP::KEYSIZE> which
is initialized to 32.
=back
=head1 CIPHER BLOCK CHAINING (CBC) MODE
When encrypting streams of data you will need an additional block
chaining mechanism like CBC as provided by Crypt::CBC(3). When
used with Crypt::CBC(3), Crypt::Twofish_PP(3) will usually work
with a fixed key length of 32 bytes, since Crypt::CBC(3) is not
capable of handling variable length keys.
If you need to use shorter keys with Crypt::CBC(3), you have two
choices: You can either overwrite the variable C<$Crypt::CBC::KEYSIZE>
with the desired length (16 or 24) in bytes, or you can specify
'Twofish_PP::Key16' resp. 'Twofish_PP::Key24' as the cipher algorithm
to Crypt::CBC(3). The modules Crypt::Twofish_PP::Key32(3),
Crypt::Twofish_PP::Key24(3), and Crypt::Twofish_PP::Key16(3), inherit
all functionality from B<Crypt::Twofish_PP> but overwrite the
C<keysize()> method, such that another default key length is reported
back to Crypt::CBC(3).
=head1 UTF-8 NUISANCES
Beginning with Perl 5.6, Perl scalars might be internally flagged as
being UTF-8 strings, and are treated as character-oriented data, not
as byte-oriented data (one character may require one to six bytes
for its internal representation). In most cases you will gain nothing
from the introduction of that flag, and rather find yourself trying
to get rid of it. B<Crypt::Twofish_PP> uses byte-oriented keys, and
encrypts/decrypts blocks of 16 bytes, and it is the callers responsability
lib/Crypt/Twofish_PP.pm view on Meta::CPAN
Copyright (C) 2003, Guido Flohr E<lt>guido@imperia.netE<gt>, all
rights reserved. See the source code for details.
This software is contributed to the Perl community by Imperia
(L<http://www.imperia.net/>).
=head1 SEE ALSO
Crypt::Twofish_PP::Key32(3), Crypt::Twofish_PP::Key24(3),
Crypt::Twofish_PP::Key16(3), Crypt::CBC(3), Crypt::Twofish2(3),
Crypt::Twofish(3), perl(1)
=cut
Local Variables:
mode: perl
perl-indent-level: 4
perl-continued-statement-offset: 4
perl-continued-brace-offset: 0
perl-brace-offset: -4
perl-brace-imaginary-offset: 0
lib/Crypt/Twofish_PP/Key16.pm view on Meta::CPAN
1;
__END__
=head1 NAME
Crypt::Twofish_PP::Key16 - Twofish with 16 byte (128 bits) keysize
=head1 SYNOPSIS
use Crypt::CBC;
my $cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP::Key16');
=head1 DESCRIPTION
This module is only a helper module and you should never use it
directly. Use Crypt::Twofish_PP(3) instead and see there for more
documentation.
The standard module for Cipher Block Chaining (CBC) in Perl,
Crypt::CBC(3) cannot grok with variable key sizes. However, the
Twofish algorithm is defined for key sizes of 16, 24, and 32 bytes,
but there is no way to communicate that to Crypt::CBC.
If you want to use Crypt::Twofish_PP(3) in CBC mode with a keysize of
16, simply specify B<Crypt::Twofish_PP::Key16> as the algorithm. It
is eqeuivalent to Crypt::Twofish_PP(3) but it will report a default
keysize of 16 bytes back to Crypt::CBC(3).
Note that this is not necessarily the real keysize. The method
keysize() of Crypt::Twofish_PP(3) only exists to satisfy Crypt::CBC(3).
The module will derive the real keysize from the length of the key
you supply.
=head1 AUTHOR
Copyright (C) 2003, Guido Flohr E<lt>guido@imperia.netE<gt>, all
rights reserved. See the source code for details.
This software is contributed to the Perl community by Imperia
(L<http://www.imperia.net/>).
=head1 SEE ALSO
Crypt::CBC(3), Crypt::Twofish_PP(3), Crypt::Twofish::Key24(3),
Crypt::Twofish_PP::Key32(3), perl(1)
=cut
Local Variables:
mode: perl
perl-indent-level: 4
perl-continued-statement-offset: 4
perl-continued-brace-offset: 0
perl-brace-offset: -4
perl-brace-imaginary-offset: 0
lib/Crypt/Twofish_PP/Key24.pm view on Meta::CPAN
1;
__END__
=head1 NAME
Crypt::Twofish_PP::Key24 - Twofish with 24 byte (192 bits) keysize
=head1 SYNOPSIS
use Crypt::CBC;
my $cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP::Key24');
=head1 DESCRIPTION
This module is only a helper module and you should never use it
directly. Use Crypt::Twofish_PP(3) instead and see there for more
documentation.
The standard module for Cipher Block Chaining (CBC) in Perl,
Crypt::CBC(3) cannot grok with variable key sizes. However, the
Twofish algorithm is defined for key sizes of 24, 24, and 32 bytes,
but there is no way to communicate that to Crypt::CBC.
If you want to use Crypt::Twofish_PP(3) in CBC mode with a keysize of
24, simply specify B<Crypt::Twofish_PP::Key24> as the algorithm. It
is eqeuivalent to Crypt::Twofish_PP(3) but it will report a default
keysize of 24 bytes back to Crypt::CBC(3).
Note that this is not necessarily the real keysize. The method
keysize() of Crypt::Twofish_PP(3) only exists to satisfy Crypt::CBC(3).
The module will derive the real keysize from the length of the key
you supply.
=head1 AUTHOR
Copyright (C) 2003, Guido Flohr E<lt>guido@imperia.netE<gt>, all
rights reserved. See the source code for details.
This software is contributed to the Perl community by Imperia
(L<http://www.imperia.net/>).
=head1 SEE ALSO
Crypt::CBC(3), Crypt::Twofish_PP(3), Crypt::Twofish::Key24(3),
Crypt::Twofish_PP::Key32(3), perl(1)
=cut
Local Variables:
mode: perl
perl-indent-level: 4
perl-continued-statement-offset: 4
perl-continued-brace-offset: 0
perl-brace-offset: -4
perl-brace-imaginary-offset: 0
lib/Crypt/Twofish_PP/Key32.pm view on Meta::CPAN
1;
__END__
=head1 NAME
Crypt::Twofish_PP::Key32 - Twofish with 32 byte (256 bits) keysize
=head1 SYNOPSIS
use Crypt::CBC;
my $cipher = Crypt::CBC->new (key => 'my secret key',
cipher => 'Twofish_PP::Key32');
=head1 DESCRIPTION
This module is only a helper module and you should never use it
directly. Use Crypt::Twofish_PP(3) instead and see there for more
documentation.
The standard module for Cipher Block Chaining (CBC) in Perl,
Crypt::CBC(3) cannot grok with variable key sizes. However, the
Twofish algorithm is defined for key sizes of 32, 24, and 32 bytes,
but there is no way to communicate that to Crypt::CBC.
If you want to use Crypt::Twofish_PP(3) in CBC mode with a keysize of
32, simply specify B<Crypt::Twofish_PP::Key32> as the algorithm. It
is eqeuivalent to Crypt::Twofish_PP(3) but it will report a default
keysize of 32 bytes back to Crypt::CBC(3).
Note that this is not necessarily the real keysize. The method
keysize() of Crypt::Twofish_PP(3) only exists to satisfy Crypt::CBC(3).
The module will derive the real keysize from the length of the key
you supply.
=head1 AUTHOR
Copyright (C) 2003, Guido Flohr E<lt>guido@imperia.netE<gt>, all
rights reserved. See the source code for details.
This software is contributed to the Perl community by Imperia
(L<http://www.imperia.net/>).
=head1 SEE ALSO
Crypt::CBC(3), Crypt::Twofish_PP(3), Crypt::Twofish::Key24(3),
Crypt::Twofish_PP::Key32(3), perl(1)
=cut
Local Variables:
mode: perl
perl-indent-level: 4
perl-continued-statement-offset: 4
perl-continued-brace-offset: 0
perl-brace-offset: -4
perl-brace-imaginary-offset: 0
t/01twofish2.t view on Meta::CPAN
KEY=00000000000000000000000000000000 PT=00000000000000000000000000000000 CT=9F589F5CF6122C32B6BFEC2F2AE8C35A
KEY=0123456789ABCDEFFEDCBA98765432100011223344556677 PT=00000000000000000000000000000000 CT=CFD1D2E5A9BE9CDF501F13B892BD2248
KEY=0123456789ABCDEFFEDCBA987654321000112233445566778899AABBCCDDEEFF PT=00000000000000000000000000000000 CT=37527BE0052334B89F0CFCCAE87CFA20
KEY=00000000000000000000000000000000 PT=00000000000000000000000000000000 CT=9F589F5CF6122C32B6BFEC2F2AE8C35A
KEY=00000000000000000000000000000000 PT=9F589F5CF6122C32B6BFEC2F2AE8C35A CT=D491DB16E7B1C39E86CB086B789F5419
KEY=9F589F5CF6122C32B6BFEC2F2AE8C35A PT=D491DB16E7B1C39E86CB086B789F5419 CT=019F9809DE1711858FAAC3A3BA20FBC3
KEY=D491DB16E7B1C39E86CB086B789F5419 PT=019F9809DE1711858FAAC3A3BA20FBC3 CT=6363977DE839486297E661C6C9D668EB
KEY=019F9809DE1711858FAAC3A3BA20FBC3 PT=6363977DE839486297E661C6C9D668EB CT=816D5BD0FAE35342BF2A7412C246F752
KEY=6363977DE839486297E661C6C9D668EB PT=816D5BD0FAE35342BF2A7412C246F752 CT=5449ECA008FF5921155F598AF4CED4D0
KEY=816D5BD0FAE35342BF2A7412C246F752 PT=5449ECA008FF5921155F598AF4CED4D0 CT=6600522E97AEB3094ED5F92AFCBCDD10
KEY=5449ECA008FF5921155F598AF4CED4D0 PT=6600522E97AEB3094ED5F92AFCBCDD10 CT=34C8A5FB2D3D08A170D120AC6D26DBFA
KEY=6600522E97AEB3094ED5F92AFCBCDD10 PT=34C8A5FB2D3D08A170D120AC6D26DBFA CT=28530B358C1B42EF277DE6D4407FC591
KEY=34C8A5FB2D3D08A170D120AC6D26DBFA PT=28530B358C1B42EF277DE6D4407FC591 CT=8A8AB983310ED78C8C0ECDE030B8DCA4
KEY=137A24CA47CD12BE818DF4D2F4355960 PT=BCA724A54533C6987E14AA827952F921 CT=6B459286F3FFD28D49F15B1581B08E42
KEY=BCA724A54533C6987E14AA827952F921 PT=6B459286F3FFD28D49F15B1581B08E42 CT=5D9D4EEFFA9151575524F115815A12E0
KEY=000000000000000000000000000000000000000000000000 PT=00000000000000000000000000000000 CT=EFA71F788965BD4453F860178FC19101
KEY=000000000000000000000000000000000000000000000000 PT=EFA71F788965BD4453F860178FC19101 CT=88B2B2706B105E36B446BB6D731A1E88
KEY=EFA71F788965BD4453F860178FC191010000000000000000 PT=88B2B2706B105E36B446BB6D731A1E88 CT=39DA69D6BA4997D585B6DC073CA341B2
KEY=88B2B2706B105E36B446BB6D731A1E88EFA71F788965BD44 PT=39DA69D6BA4997D585B6DC073CA341B2 CT=182B02D81497EA45F9DAACDC29193A65
KEY=39DA69D6BA4997D585B6DC073CA341B288B2B2706B105E36 PT=182B02D81497EA45F9DAACDC29193A65 CT=7AFF7A70CA2FF28AC31DD8AE5DAAAB63
KEY=182B02D81497EA45F9DAACDC29193A6539DA69D6BA4997D5 PT=7AFF7A70CA2FF28AC31DD8AE5DAAAB63 CT=D1079B789F666649B6BD7D1629F1F77E
KEY=7AFF7A70CA2FF28AC31DD8AE5DAAAB63182B02D81497EA45 PT=D1079B789F666649B6BD7D1629F1F77E CT=3AF6F7CE5BD35EF18BEC6FA787AB506B
t/02cbcref.t view on Meta::CPAN
#! /usr/local/bin/perl -w
use strict;
use IO::File;
eval 'use Crypt::CBC 1.22';
print "1..5\n";
if ($@) {
print "ok # skipped in absence of Crypt::CBC 1.22 or higher\n"
x 5;
exit 0;
} else {
print "ok 1\n";
}
my @algos = qw (Twofish_PP
Twofish_PP::Key16 Twofish_PP::Key24 Twofish_PP::Key32);
for my $i (2 .. 5) {
t/02cbcref.t view on Meta::CPAN
or die;
$copying = <$fh>;
die unless defined $copying;
$fh->close;
eval {
my $key = 'Not very secret';
my $cipher;
$cipher = Crypt::CBC->new ($key, shift @algos)
or die;
my $result = $cipher->decrypt ($cipher->encrypt ($copying))
or die;
$result eq $copying or die;
};
print $@ ? "not ok $i\n" : "ok $i\n";
}
( run in 0.660 second using v1.01-cache-2.11-cpan-e1769b4cff6 )