DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

Crypt::SEAL2



NAME

Crypt::SEAL2 - The SEAL stream cipher, version 2.0


SYNOPSIS

    use Crypt::SEAL2;
    $cipher = new Crypt::SEAL2 $key;
    $ciphertext = $cipher->encrypt($plaintext);
    $cipher->reset();
    $ks = $cipher->keysize();
    $plaintext  = $cipher->decrypt($ciphertext);
    $cipher->repos($position);


DESCRIPTION

SEAL2 is the second version of the stream cipher, SEAL, designed by Don Coppersmith and Phillip Rogaway.

This module supports the following functions:

new()

Creates a pseudorandom string (PRS), using a user-supplied key as a seed to the pseudorandom generator of SEAL2. A PRS pointer initially points at the beginning of the PRS.

encrypt($data)

Encrypts the data stream $data by XOR-ing it with the PRS, starting at the position being pointed to by the PRS pointer, and returns the resulting ciphertext. The PRS pointer is advanced 1 byte position for every byte of $data that is encrypted.

decrypt($data)

Decrypts the data stream $data by XOR-ing it with the PRS, starting at the position being pointed to by the PRS pointer, and returns the resulting plaintext. The PRS pointer is advanced 1 byte position for every byte of $data that is decrypted.

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

reset()

Every time a call to either encrypt() or decrypt() is performed, the PRS pointer is advanced. Therefore, it is necessary to reset() the pointer in order to encrypt/decrypt the data stream correctly. Alternatively, you may use repos() to manually re-position the PRS pointer to where the encryption/decryption will start (see next function).

repos($position)

Re-positions the PRS pointer at byte position $position

keysize()

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

Note

Since the pseudorandom sequence generated by SEAL2 is XOR-ed with the data stream, a call to encrypt is the same as a call to decrypt. Mathematically,

                    P xor R = C
                    C xor R = P


EXAMPLE

    #!/usr/local/bin/perl
    use diagnostics;
    use strict;
    use warnings;
    use Crypt::SEAL2;
    my $key = pack "H40", "00112233445566778899aabbccddeeff00112233";
    my $cipher = new Crypt::SEAL2 $key;
    my $plaintext1 = pack "H16", "0123456789abcdef";
    print "old plaintext1  : ", unpack("H*", $plaintext1), "\n";
    my $ciphertext1 = $cipher->encrypt($plaintext1);
    print "ciphertext1     : ", unpack("H*", $ciphertext1), "\n";
    $cipher->reset();
    my $decrypted1 = $cipher->decrypt($ciphertext1);
    print "new plaintext1  : ", unpack("H*", $decrypted1), "\n";
    print "\n";
    my $plaintext2 = pack "H40", "fedcba98765432100123456789abcdef01234567";
    print "old plaintext2  : ", unpack("H*", $plaintext2), "\n";
    $cipher->reset();
    my $ciphertext2 = $cipher->encrypt($plaintext2);
    print "ciphertext2     : ", unpack("H*", $ciphertext2), "\n";
    $cipher->reset();
    my $decrypted2 = $cipher->decrypt($ciphertext2);
    print "new plaintext2  : ", unpack("H*", $decrypted2), "\n";


CAVEAT

SEAL2 is designed to generate up to 2^48 bytes of output per seed. In 1997, Handschuh and Gilbert showed, however, that the output stream can be distinguished from a random sequence after only seeing roughly 2^34 bytes of output. Thus, it is prudent to avoid using the same seed for more than 2^34 bytes of output.


COPYRIGHT AND LICENSE

Copyright (C) 2003 Julius C. Duque. Please read contact.html that comes with this distribution for details on how to contact the author.

This library is free software; you can redistribute it and/or modify it under the same terms as the GNU General Public License.