Crypt-XTEA-LE

 view release on metacpan or  search on metacpan

lib/Crypt/XTEA/LE.pm  view on Meta::CPAN


Crypt::XTEA::LE - Implementation of the eXtended Tiny Encryption Algorithm with little-endian support

=head1 VERSION

version 0.0107

=head1 SYNOPSIS

   use Crypt::XTEA:LE;
   use Crypt::CBC;

   my $xtea = Crypt::XTEA:LE->new( $key, 32, little_endian => 1 );
   my $cbc = Crypt::CBC->new( -cipher => $xtea );

   my $text = 'The quick brown fox jumps over the lazy dog.';
   my $cipher_text = $cbc->encrypt( $text );

   my $plain_text = $cbc->decrypt( $cipher_text );

=head1 DESCRIPTION

In cryptography, XTEA (eXtended TEA) is a block cipher designed to correct weaknesses in TEA.
The cipher's designers were David Wheeler and Roger Needham of the Cambridge Computer Laboratory,
and the algorithm was presented in an unpublished technical report in 1997 (Needham and Wheeler, 1997).
It is not subject to any patents.

Like TEA, XTEA is a 64-bit block Feistel cipher with a 128-bit key and a suggested 64 Feistel rounds (i.e 32 cycles).
Crypt::XTEA::LE, uses the recommended value of 32 by default.

This module implements XTEA encryption. It supports the Crypt::CBC interface, with the following functions.

=head1 METHODS

=head2 keysize

Returns the maximum XTEA key size, 16 bytes.

=head2 blocksize

Returns the XTEA::LE block size, which is 8 bytes. This function exists so that Crypt::XTEA:LE can work with Crypt::CBC.

=head2 new

    my $xtea = Crypt::XTEA::LE->new( $key, $rounds, little_endian => 0 );

This creates a new Crypt::XTEA::LE object with the specified key.
The optional rounds parameter specifies the number of rounds of encryption to perform, and defaults to 32.
If the key is provided as a scalar string, it is split to a series of 4x big-endian 32-bit integers. If little-endian order is required instead, the optional little_endian key can be set to 1.

=head2 encrypt

lib/Crypt/XTEA/LE.pm  view on Meta::CPAN


    $plain_text = $xtea->decrypt($cipher_text);

Decrypts blocksize() bytes of $cipher_text and returns the corresponding plaintext.
By default, the block is interpreted as 2x big-endian 32-bit integers. if little_endian => 1 was specified during new(), the block will be split into two little-endian integers instead.

=head1 SEE ALSO

Based on L<Crypt::XTEA>

L<Crypt::CBC>

L<Crypt::XTEA_PP>

=head1 AUTHOR

Kars Wang <jahiy@cpan.org>
Ahmad Fatoum <athreef@cpan.org>

=head1 COPYRIGHT AND LICENSE

t/002-cbc.t  view on Meta::CPAN

use strict;
use warnings;
use utf8;

use Test::More;

eval { require Crypt::CBC; };

plan skip_all => 'Crypt::CBC not installed' if $@;

use_ok( 'Crypt::XTEA::LE' );

my @tests = (
    {
        key           => 'qwertyuiopasdfgh',
        plain         => 'The quick brown fox jumps over the lazy dog.',
        cipher_length => 64,
    },
    {
        key           => 'asdfghjklzxcvbnm',
        plain         => q{O brave new world, That has such people in't.},
        cipher_length => 64,
    }
);

for my $test (@tests) {
    my $xtea = new_ok( 'Crypt::XTEA::LE' => [ $test->{key} ] );
    my $cbc = new_ok( 'Crypt::CBC' => [ -cipher => $xtea ] );

    my $cipher = $cbc->encrypt($test->{plain});
    is( length( $cipher ), $test->{cipher_length}, 'cbc encryption test' );
    my $plain = $cbc->decrypt( $cipher );
    is( $plain, $test->{plain}, 'cbc decryption test' );
}

done_testing;



( run in 0.475 second using v1.01-cache-2.11-cpan-e1769b4cff6 )