Crypt-RS14_PP

 view release on metacpan or  search on metacpan

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

#!perl -w

=begin PerlDox

=head1 NAME

=cut

package Crypt::RS14_PP; #< A pure Perl implementation of RS14, aka "Spritz", encryption algorithm.
our $VERSION = '0.03';  #<

=head1 SYNOPSIS

    use Crypt::RS14_PP;

    my $key   = '16 to 64 bytes of key';
    my $rs14  = Crypt::RS14_PP->new($key);
    my $ctext = $rs14->encrypt('This is my plain text.');
    $rs14->set_key($key);
    my $ptext = $rs14->encrypt($ctext); # or decrypt as both do the same
    print "$ptext\n"; # prints 'This is my plain text.'

=head1 DESCRIPTION

RS14, aka "Spritz", is an encryption algorithm, proposed by Ron Rivist
and Jacob Schuldt, as a replacement for RC4, created by Ron Rivist.
RS14, like RC4, is a stream algorithm. It takes the basic concepts behind
RC4, enhancing and updating them for greater security.

Being pure Perl, this module is really just a testing tool. An XS or
Inline::C implementation will provide far better performance.

I<Note:> While this module's API is a superset of the Crypt:: API, the RS14
algorithm is not intended for use with Crypt::CBC or similar. By its
nature, it already operates in OFB (Output Feedback) mode.

I<Note:> Only the encrypt/decrypt capabilities of RS14 are implemented.

I<Note:> In this module, encrypt/decrypt use bitwise exclusive-or (C<^>) to
encipher/decipher the input, as this is commonly used in stream ciphers.
As a consequence, encrypt and decrypt are the same. Other operations are
possible. This not specified in the algorithm specification.

I<Note:> To encrypt "wide characters", such as Unicode, the character stream
B<must> be encoded into a byte stream before encrypting. (For Unicode, use
UTF-8 encoding.) Whatever encoding is used, security is enhanced by excluding
any byte order marks.

=cut

use warnings;
use strict;

# only load Carp if needed
sub _carp
{
    require Carp;
    Carp::carp(@_);
}
sub _croak
{
    require Carp;
    Carp::croak(@_);
}

# Tried C<use integer;> but causes bitwise ops to treat numbers as signed (see Perl documentation)

## @internal

=head2 Constants

=cut

use constant {
    N   => 256,   #< Number of elements in S-Box.
                  #  @note This implementation is byte oriented, so N == 256
                  #  @note This implementation assumes N is a power of 2. If not,
                  #  update of w will need enhancement to ensure gcd(N,w) == 1,
                  #  i.e., N and w must be relatively prime.
};

use constant {
    A   => N + 0, #< index of a (number of nibbles absorbed) in instance array
    I   => N + 1, #< index of i (an internal state index) in instance array
    J   => N + 2, #< index of j (an internal state index) in instance array
    K   => N + 3, #< index of k (an internal state index) in instance array
    W   => N + 4, #< index of w (an internal state index) in instance array
    Z   => N + 5, #< index of z (output state index) in instance array
    M   => N - 1, #< mask for modulo-N operations
};

## @endinternal

=head2 Class Methods



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