Crypt-Salsa20
view release on metacpan or search on metacpan
lib/Crypt/Salsa20.pm view on Meta::CPAN
=head2 Crypt::Salsa20 vs. Crypt::CBC
The API is similar to that of the L<Crypt::CBC> module, but there are
some differences:
=over
=item 1.
There is no C<-literal_key> option. The key is I<always> interpreted
as raw bytes (and must be either 16 or 32 bytes long). If you want to
use a pasword hashing function, you have to supply your own.
=item 2.
Crypt::Salsa20 doesn't use any sort of header, trailer, padding, or
any other metadata. If you need to transmit the nonce as part of your
message, you'll need to do it manually.
=item 3.
Since encryption and decryption are the same operation with Salsa20,
the C<start> method does not require a parameter, and it is not
necessary to call it at all.
=item 4.
The C<finish> method is available, but unnecessary. In Crypt::Salsa20
it does nothing and always returns the empty string.
=back
=for Pod::Coverage
BLOCKSIZE
IS32BIT
LIMIT
=head1 ATTRIBUTES
Each attribute has a method of the same name. Calling the method with
no parameter returns the current value of the attribute. Calling it
with a parameter sets the attribute to that value (and returns the new
value).
=head2 key
The encryption key is a 16 or 32 byte string (128 or 256 bits), with
32 bytes being the recommended size. It's always interpreted as raw
bytes; if you want to use a pasword hashing function, you have to
supply your own. Setting the key does not change the IV or reset the
block counter.
=head2 iv
The nonce (IV) is an 8 byte string (64 bits). The nonce does not need
to be kept secret, but you must never encrypt two different messages
with the same key and nonce, or you have catastrophically weakened the
security of the cipher. You must supply an IV before encrypting or
decrypting, but you can omit it from the constructor and call the
C<iv> method instead. Setting the IV does not change the key, but it
does reset the block counter.
=head2 rounds
The number of cipher rounds to use. The default is 20, which is the
standard Salsa20 cipher. The standard variants are 8 or 12 rounds
(Salsa20/8 or Salsa20/12), but any even integer will work.
=head1 METHODS
=head2 new
$salsa20 = Crypt::Salsa20->new(-key => $key, ...);
This constructs a new Crypt::Salsa20 object, with attributes supplied
as S<C<< key => value >>> pairs. For compatibility with Crypt::CBC,
attribute names may have a leading hyphen (but unlike Crypt::CBC the
hyphen is not required).
The only required attribute at construction time is the key (but you
must supply an IV before encrypting or decrypting).
=head2 start
$salsa20->start;
Resets the internal block counter, starting the keystream over at the
beginning. You should also change the IV, because using the same key
and IV is a security breach.
For compatibility with the Crypt::CBC method of the same name, you can
pass a parameter (e.g. C<'decrypting'> or C<'encrypting'>), but it is
ignored. With Salsa20, encryption and decryption are the same operation,
so there's no need to indicate which one you want.
This method is primarily for Crypt::CBC compatibility. Since with
Salsa20 you don't need to specify whether you're encrypting or
decrypting, and the C<iv> method also does everything C<start> does,
you don't really need to call this method.
=head2 crypt
$ciphertext = $salsa20->crypt($plaintext);
$plaintext = $salsa20->crypt($ciphertext);
Encrypts or decrypts the provided string.
Because encryption & decryption are the same operation, it is not
necessary to call C<start> before calling C<crypt>, but you do need to
have set the IV, either by passing it to the constructor or calling
the C<iv> method.
=head2 finish
( run in 2.292 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )