Crypt-TEA_XS

 view release on metacpan or  search on metacpan

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


Crypt::TEA_XS - Implementation of the Tiny Encryption Algorithm

=head1 VERSION

version 0.01

=head1 SYNOPSIS

   use Crypt::TEA_XS;
   use Crypt::CBC;

   my $tea = Crypt::TEA_XS->new( $key );
   my $cbc = Crypt::CBC->new( -cipher => $tea );

   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

TEA is a 64-bit symmetric block cipher with a 128-bit key and a variable number of rounds (32 is recommended).
It has a low setup time, and depends on a large number of rounds for security, rather than a complex algorithm.
It was developed by David J. Wheeler and Roger M. Needham,
and is described at L<http://www.ftp.cl.cam.ac.uk/ftp/papers/djw-rmn/djw-rmn-tea.html>

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

=head1 METHODS

=head2 keysize

Returns the maximum TEA key size, 16 bytes.

=head2 blocksize

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

=head2 new

    my $tea = Crypt::TEA_XS->new( $key, $rounds );

This creates a new Crypt::TEA_XS object with the specified key.
The optional rounds parameter specifies the number of rounds of encryption to perform, and defaults to 32.

=head2 encrypt

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

=head2 decrypt

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

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

=head1 SEE ALSO

L<http://www.vader.brad.ac.uk/tea/tea.shtml>

L<Crypt::CBC>

L<Crypt::TEA_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::TEA_XS' );

my @tests = (
    {
        key           => 'qwertyuiopasdfgh',
        plain         => 'The quick brown fox jumps over the lazy dog.',
        cipher_length => 64,
    },
    {
        key           => 'asdfghjklzxcvbnm',
        plain         => 'Freedom is the freedom to say that two plus two make four.',
        cipher_length => 80,
    }
);

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

    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.477 second using v1.01-cache-2.11-cpan-e1769b4cff6 )