Crypt::Rabbit - A new stream cipher based on the properties of counter


Crypt-Rabbit documentation Contained in the Crypt-Rabbit distribution.

Index


Code Index:

NAME

Top

Crypt::Rabbit - A new stream cipher based on the properties of counter assisted stream ciphers

SYNOPSIS

Top

    use Crypt::Rabbit;

    $cipher = new Crypt::Rabbit $key;
    $ciphertext = $cipher->encrypt($plaintext);
    $ks = $cipher->keysize();
    $plaintext  = $cipher->decrypt($ciphertext);

DESCRIPTION

Top

Rabbit is a new stream cipher based on the properties of counter assisted stream ciphers, invented by Martin Boesgaard, Mette Vesterager, Thomas Pedersen, Jesper Christiansen, and Ove Scavenius of Cryptico A/S.

This module supports the following methods:

new()

Initializes the internal states of Rabbit

encrypt($data)

Encrypts the data stream $data

decrypt($data)

Decrypts the data stream $data

decrypt($data) is the same as encrypt($data)

keysize()

Returns the size (in bytes) of the key used (16, in this case)

CAVEAT

Top

The internal states of Rabbit are updated every time encrypt() or decrypt() are called. And since encryption/decryption depends on the internal states, a plaintext encrypted with a call to encrypt() will not decrypt to the original message by just a call to decrypt(). The proper way to decrypt a ciphertext is to re-initialize the internal states (by calling new()) first before calling decrypt().

BUG

Top

For the sake of simplicity, the C implementation encrypts and decrypts data in multiples of 16 bytes. If the last block of data is not a multiple of 16 bytes, it is padded with null characters before encryption. The resulting ciphertext is then truncated to the original message length before being output. An undesirable consequence of this is that encryption/decryption always starts at multiples of 16 bytes of the pseudorandom data stream produced by Rabbit. Improvements are most welcome. Please read contact.html for contact information.

COPYRIGHT AND LICENSE

Top


Crypt-Rabbit documentation Contained in the Crypt-Rabbit distribution.

package Crypt::Rabbit;

use strict;
use warnings;
require Exporter;

our @EXPORT_OK = qw(new encrypt decrypt keysize rounds);
our $VERSION = '1.0.0';
our @ISA = qw(Exporter);

require XSLoader;
XSLoader::load('Crypt::Rabbit', $VERSION);

# Preloaded methods go here.

sub keysize { 16 }    # 16 bytes
sub rounds { 1 }      # may be useful for some applications

sub encrypt {
    my ($class, $str) = @_;
    my $len = length $str;
    my $pad = pack "a" x ((16 - ($len % 16)) % 16), \000;
    $str .= $pad;
    my $ciphertext = rabbit_enc($class, $str);
    return substr($ciphertext, 0, $len);
}

sub decrypt {
    my ($class, $str) = @_;
    my $len = length $str;
    my $pad = pack "a" x ((16 - ($len % 16)) % 16), \000;
    $str .= $pad;
    my $ciphertext = rabbit_enc($class, $str);
    return substr($ciphertext, 0, $len);
}

1;

__END__