1# Copyright 2001 Abhijit Menon-Sen <ams@toroid.org>
2
3package Crypt::TEA;
4
5use strict;
6use Carp;
7use DynaLoader;
8use vars qw( @ISA $VERSION );
9
10@ISA = qw( DynaLoader );
11($VERSION) = q$Revision: 1.26 $ =~ /([\d.]+)/;
12
13bootstrap Crypt::TEA $VERSION;
14
15sub keysize   () { 16 }
16sub blocksize () {  8 }
17
18sub new
19{
20    my ($class, $key, $rounds) = @_;
21
22    croak "Usage: ".__PACKAGE__."->new(\$key [, \$rounds])" unless $key;
23    return Crypt::TEA::setup($key, $rounds || 32);
24}
25
26sub encrypt
27{
28    my ($self, $data) = @_;
29
30    croak "Usage: \$cipher->encrypt(\$data)" unless ref($self) && $data;
31    $self->crypt($data, $data, 0);
32}
33
34sub decrypt
35{
36    my ($self, $data) = @_;
37
38    croak "Usage: \$cipher->decrypt(\$data)" unless ref($self) && $data;
39    $self->crypt($data, $data, 1);
40}
41
421;
43
44__END__
45
46=head1 NAME
47
48Crypt::TEA - Tiny Encryption Algorithm
49
50=head1 SYNOPSIS
51
52use Crypt::TEA;
53
54$cipher = Crypt::TEA->new($key);
55
56$ciphertext = $cipher->encrypt($plaintext);
57
58$plaintext  = $cipher->decrypt($ciphertext);
59
60=head1 DESCRIPTION
61
62TEA is a 64-bit symmetric block cipher with a 128-bit key and a variable
63number of rounds (32 is recommended). It has a low setup time, and
64depends on a large number of rounds for security, rather than a complex
65algorithm. It was developed by David J. Wheeler and Roger M. Needham,
66and is described at
67L<https://web-beta.archive.org/web/20131226114205/http://www.ftp.cl.cam.ac.uk:80/ftp/papers/djw-rmn/djw-rmn-tea.html>
68
69This module implements TEA encryption. It supports the Crypt::CBC
70interface, with the following functions.
71
72=head2 Functions
73
74=over
75
76=item blocksize
77
78Returns the size (in bytes) of the block (8, in this case).
79
80=item keysize
81
82Returns the size (in bytes) of the key (16, in this case).
83
84=item new($key, $rounds)
85
86This creates a new Crypt::TEA object with the specified key. The
87optional rounds parameter specifies the number of rounds of encryption
88to perform, and defaults to 32.
89
90=item encrypt($data)
91
92Encrypts blocksize() bytes of $data and returns the corresponding
93ciphertext.
94
95=item decrypt($data)
96
97Decrypts blocksize() bytes of $data and returns the corresponding
98plaintext.
99
100=back
101
102=head1 SEE ALSO
103
104L<https://web-beta.archive.org/web/20030208020932/http://www.vader.brad.ac.uk/tea/tea.shtml>
105
106Crypt::CBC, Crypt::Blowfish, Crypt::DES
107
108=head1 ACKNOWLEDGEMENTS
109
110=over 4
111
112=item Dave Paris
113
114For taking the time to discuss and review the initial version of this
115module, making several useful suggestions, and contributing tests.
116
117=item Mike Blazer and Gil Cohen
118
119For testing under Windows.
120
121=item Tony Cook
122
123For making the module work under Activeperl, testing on several
124platforms, and suggesting that I probe for features via %Config.
125
126=back
127
128=head1 AUTHOR
129
130Abhijit Menon-Sen <ams@toroid.org>
131
132Copyright 2001 Abhijit Menon-Sen. All rights reserved.
133
134This software is distributed under the terms of the Artistic License
135L<https://dev.perl.org/licenses/artistic.html>
136