Crypt-XXTEA_XS

 view release on metacpan or  search on metacpan

lib/Crypt/XXTEA_XS.pm  view on Meta::CPAN


Crypt::XXTEA_XS - Implementation of Corrected Block Tiny Encryption Algorithm

=head1 VERSION

version 0.0101

=head1 SYNOPSIS

   use Crypt::XXTEA_XS;
   use Crypt::CBC;

   my $xxtea = Crypt::XXTEA_XS->new( $key );
   my $cbc = Crypt::CBC->new( -cipher => $xxtea );

   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, Corrected Block TEA (often referred to as XXTEA) is a block cipher designed to correct weaknesses in the original Block TEA.
The cipher's designers were Roger Needham and David Wheeler of the Cambridge Computer Laboratory,
and the algorithm was presented in an unpublished technical report in October 1998 (Wheeler and Needham, 1998).
It is not subject to any patents.

Formally speaking, XXTEA is a consistent incomplete source-heavy heterogeneous UFN (unbalanced Feistel network) block cipher.
XXTEA operates on variable-length blocks that are some arbitrary multiple of 32 bits in size (minimum 64 bits).
The number of full cycles depends on the block size, but there are at least six (rising to 32 for small block sizes).

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

=head1 METHODS

=head2 keysize

Returns the maximum XXTEA key size, 16 bytes.

=head2 blocksize

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

=head2 new

    my $xxtea = Crypt::XXTEA_XS->new( $key );

This creates a new Crypt::XXTEA_XS object with the specified key.

=head2 encrypt

    $cipher_text = $xxtea->encrypt($plain_text);

lib/Crypt/XXTEA_XS.pm  view on Meta::CPAN

Encrypts blocksize() bytes of $plain_text and returns the corresponding ciphertext.

=head2 decrypt

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

Decrypts blocksize() bytes of $cipher_text and returns the corresponding plaintext.

=head1 SEE ALSO

L<Crypt::CBC>

L<Crypt::XXTEA_PP>

=head1 AUTHOR

Kars Wang <jahiy@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Kars Wang.

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::XXTEA_XS' );

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::XXTEA_XS' => [ $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.670 second using v1.01-cache-2.11-cpan-e1769b4cff6 )