r1109 - in packages: . libcrypt-cbc-perl libcrypt-cbc-perl/branches libcrypt-cbc-perl/branches/upstream libcrypt-cbc-perl/branches/upstream/current libcrypt-cbc-perl/branches/upstream/current/eg libcrypt-cbc-perl/branches/upstream/current/t

Gustavo Franco stratus@costa.debian.org
Mon, 13 Jun 2005 00:41:18 +0000


Author: stratus
Date: 2005-06-13 00:41:17 +0000 (Mon, 13 Jun 2005)
New Revision: 1109

Added:
   packages/libcrypt-cbc-perl/
   packages/libcrypt-cbc-perl/branches/
   packages/libcrypt-cbc-perl/branches/upstream/
   packages/libcrypt-cbc-perl/branches/upstream/current/
   packages/libcrypt-cbc-perl/branches/upstream/current/CBC.pm
   packages/libcrypt-cbc-perl/branches/upstream/current/Changes
   packages/libcrypt-cbc-perl/branches/upstream/current/MANIFEST
   packages/libcrypt-cbc-perl/branches/upstream/current/META.yml
   packages/libcrypt-cbc-perl/branches/upstream/current/Makefile.PL
   packages/libcrypt-cbc-perl/branches/upstream/current/README
   packages/libcrypt-cbc-perl/branches/upstream/current/eg/
   packages/libcrypt-cbc-perl/branches/upstream/current/eg/des.pl
   packages/libcrypt-cbc-perl/branches/upstream/current/eg/idea.pl
   packages/libcrypt-cbc-perl/branches/upstream/current/t/
   packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael_compat.t
   packages/libcrypt-cbc-perl/branches/upstream/current/t/func.t
   packages/libcrypt-cbc-perl/branches/upstream/current/t/null_data.t
   packages/libcrypt-cbc-perl/tags/
Log:
[svn-inject] Installing original source of libcrypt-cbc-perl

Added: packages/libcrypt-cbc-perl/branches/upstream/current/CBC.pm
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/CBC.pm	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/CBC.pm	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,546 @@
+package Crypt::CBC;
+
+use Digest::MD5 'md5';
+use Carp;
+use strict;
+use vars qw($VERSION);
+$VERSION = '2.12';
+
+sub new {
+    my $class = shift;
+    my $arg1 = shift;
+    my $arg2 = shift;
+
+    my $options = {};
+
+    if (ref($arg1) eq 'HASH') {
+	$options = $arg1;
+    } else {
+	$options->{key} = $arg1;
+    }
+
+    if ($arg2) {
+	$options->{cipher} = $arg2;
+    }
+
+    my $key = $options->{key};
+    croak "Please provide an encryption/decryption key" unless defined $key;
+
+    # get key from key?
+    my $gkfk = 1;
+    $gkfk = $options->{regenerate_key} if (exists($options->{regenerate_key}));
+
+    my $cipher = $options->{cipher};
+    $cipher = 'Crypt::DES' unless $cipher;
+    $cipher = $cipher=~/^Crypt::/ ? $cipher : "Crypt::$cipher";
+    eval "require $cipher";
+    croak "Couldn't load $cipher: $@" if $@;
+    # some crypt modules use the class Crypt::, and others don't
+    $cipher =~ s/^Crypt::// unless $cipher->can('keysize');
+
+    my $iv = $options->{iv};
+
+    my $ks = eval {$cipher->keysize};
+    my $bs = eval {$cipher->blocksize};
+
+    my $padding = $options->{padding};
+    $padding ||= \&_standard_padding;
+
+    if ($padding && ref($padding) eq 'CODE') {
+      # check to see that this code does its padding correctly
+      for my $i (1..$bs-1) {
+	my $rbs = length($padding->(" "x$i,$bs,'e'));
+	croak "padding method callback does not behave properly: expected $bs bytes back, got $rbs bytes back." unless ($rbs == $bs);
+      }
+    } elsif ($padding eq 'null') {
+      $padding = \&_null_padding;
+    } elsif ($padding eq 'space') {
+      $padding = \&_space_padding;
+    } elsif ($padding eq 'oneandzeroes') {
+      $padding = \&_oneandzeroes_padding;
+    } elsif ($padding eq 'standard') {
+      $padding = \&_standard_padding;
+    } else {
+      croak "padding method $padding not supported.  Please create your own sub to do it, and pass in a coderef to that";
+    }
+
+    # Some of the cipher modules are busted and don't report the
+    # keysize (well, Crypt::Blowfish in any case).  If we detect
+    # this, and find the blowfish module in use, then assume 56.
+    # Otherwise assume the least common denominator of 8.
+    $ks ||= $cipher =~ /blowfish/i ? 56 : 8;
+    $bs ||= $ks;
+
+    if ($gkfk) {
+      # generate the keysize from the
+      # MD5 hash of the provided key.
+      my $material = md5($key);
+      # if that's not enough, keep adding to it
+      while (length($material) < $ks)  {
+	$material .= md5($material);
+      }
+	
+      $key = substr($material,0,$ks);
+    }
+
+    if (length($key) > $ks) {
+	carp "keysize is greater than allowed keysize of $ks for cipher $cipher - using only first $ks bytes";
+	$key = substr($key, 0, $ks);
+    }
+    
+    my $prepend_iv = exists $options->{'prepend_iv'} 
+       ? $options->{'prepend_iv'} 
+       : 1;
+
+    my $pcbc = exists $options->{'pcbc'} 
+       ? $options->{'pcbc'} 
+       : 0;
+
+    return bless {'crypt'     => $cipher->new($key),
+		  'iv'        => $iv,
+		  'padding'   => $padding,
+		  'blocksize' => $bs,
+                  'prepend_iv' => $prepend_iv,
+                  'pcbc'      => $pcbc,
+		  },$class;
+}
+
+sub encrypt (\$$) {
+    my ($self,$data) = @_;
+    $self->start('encrypting');
+    my $result = $self->crypt($data);
+    $result .= $self->finish;
+    $result;
+}
+
+sub decrypt (\$$){
+    my ($self,$data) = @_;
+    $self->start('decrypting');
+    my $result = $self->crypt($data);
+    $result .= $self->finish;
+    $result;
+}
+
+sub encrypt_hex (\$$) {
+    my ($self,$data) = @_;
+    return join('',unpack 'H*',$self->encrypt($data));
+}
+
+sub decrypt_hex (\$$) {
+    my ($self,$data) = @_;
+    return $self->decrypt(pack'H*',$data);
+}
+
+# call to start a series of encryption/decryption operations
+sub start (\$$) {
+    my $self = shift;
+    my $operation = shift;
+    croak "Specify <e>ncryption or <d>ecryption" unless $operation=~/^[ed]/i;
+
+    unless (defined($self->{'iv'})) {
+    	$self->{'iv'} = pack("C*",map {rand(256)} 1..8);
+    }
+
+    $self->{'buffer'} = '';
+    $self->{'decrypt'} = $operation=~/^d/i;
+}
+
+# call to encrypt/decrypt a bit of data
+sub crypt (\$$){
+    my $self = shift;
+    my $data = shift;
+    croak "crypt() called without a preceding start()"
+      unless exists $self->{'buffer'};
+
+    my $d = $self->{'decrypt'};
+
+    my $iv;
+    my $result = '';
+
+    if ( !$self->{'civ'} ) {
+	if ($d) { # decrypting
+		if (($iv) = $data=~ /^RandomIV(.{8})/s) {
+		  $self->{'iv'} = $iv;
+		  substr($data,0,16) = ''; #truncate
+		}
+	} else { # encrypting
+	  if ($self->{'prepend_iv'}) {
+	    $result = 'RandomIV';
+	    $result .= $self->{'iv'};
+	  }
+	}
+	$self->{'civ'} = $self->{'iv'};
+    }
+
+    $iv = $self->{'civ'};
+
+    $self->{'buffer'} .= $data;
+
+     my $bs = $self->{'blocksize'};
+
+    return $result unless (length($self->{'buffer'}) >= $bs);
+
+    # split into blocksize chunks
+    # used to be:
+    # my @blocks = $self->{'buffer'}=~/(.{1,$bs})/ogs;
+    # but this is a little faster (about 1.5 times)
+    my @blocks = unpack("a$bs "x(int(length($self->{'buffer'})/$bs)) . "a*", $self->{'buffer'});
+    $self->{'buffer'} = '';
+
+    if ($d) {  # when decrypting, always leave a free block at the end
+      $self->{'buffer'} = length($blocks[-1]) < $bs ? join '',splice(@blocks,-2) : pop(@blocks);
+    } else {
+      $self->{'buffer'} = pop @blocks if length($blocks[-1]) < $bs;  # what's left over
+    }
+
+    foreach my $block (@blocks) {
+      if ($d) { # decrypting
+	$result .= $iv = $iv ^ $self->{'crypt'}->decrypt($block);
+	$iv = $block unless $self->{pcbc};
+      } else { # encrypting
+	$result .= $iv = $self->{'crypt'}->encrypt($iv ^ $block);
+      }
+      $iv = $iv ^ $block if $self->{pcbc};
+    }
+    $self->{'civ'} = $iv;	        # remember the iv
+    return $result;
+}
+
+# this is called at the end to flush whatever's left
+sub finish (\$) {
+    my $self = shift;
+    my $bs    = $self->{'blocksize'};
+    my $block = defined $self->{'buffer'} ? $self->{'buffer'} : '';
+
+    $self->{civ} ||= '';
+
+    my $result;
+    if ($self->{'decrypt'}) { #decrypting
+	$block = length $block ? pack("a$bs",$block) : ''; # pad and truncate to block size
+	
+	if (length($block)) {
+	  $result = $self->{'civ'} ^ $self->{'crypt'}->decrypt($block);
+	  $result = $self->{'padding'}->($result, $bs, 'd');
+	} else {
+	  $result = '';
+	}
+
+    } else { # encrypting
+      $block  = $self->{'padding'}->($block,$bs,'e') || '';
+      $result = length $block ? $self->{'crypt'}->encrypt($self->{'civ'} ^ $block) : '';
+    }
+    delete $self->{'civ'};
+    delete $self->{'buffer'};
+    return $result;
+}
+
+sub _standard_padding ($$$) {
+  my ($b,$bs,$decrypt) = @_;
+  $b = length $b ? $b : '';
+  if ($decrypt eq 'd') {
+     substr($b, -unpack("C",substr($b,-1)))='';
+     return $b;
+  }
+  my $pad = $bs - length($b) % $bs;
+  return $b . pack("C*",($pad)x$pad);
+}
+
+sub _space_padding ($$$) {
+  my ($b,$bs,$decrypt) = @_;
+  return unless length $b;
+  $b = length $b ? $b : '';
+  if ($decrypt eq 'd') {
+     $b=~ s/ *$//s;
+     return $b;
+  }
+  return $b . pack("C*", (32) x ($bs - length($b) % $bs));
+}
+
+sub _null_padding ($$$) {
+  my ($b,$bs,$decrypt) = @_;
+  return unless length $b;
+  $b = length $b ? $b : '';
+  if ($decrypt eq 'd') {
+     $b=~ s/\0*$//s;
+     return $b;
+  }
+  return $b . pack("C*", (0) x ($bs - length($b) % $bs));
+}
+
+sub _oneandzeroes_padding ($$$) {
+  my ($b,$bs,$decrypt) = @_;
+  return unless length $b;
+  $b = length $b ? $b : '';
+  if ($decrypt eq 'd') {
+     my $hex = unpack("H*", $b);
+     $hex =~ s/80*$//s;
+     return pack("H*", $hex);
+  }
+  return $b . pack("C*", 128, (0) x ($bs - length($b) % $bs - 1) );
+}
+
+sub get_initialization_vector (\$) {
+  my $self = shift;
+  return $self->{'iv'};
+}
+
+sub set_initialization_vector (\$$) {
+  my $self = shift;
+  my $iv = shift;
+	
+  croak "Initialization vector must be 8 bytes" unless (length($iv) == 8);
+  $self->{'iv'} = $iv;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Crypt::CBC - Encrypt Data with Cipher Block Chaining Mode
+
+=head1 SYNOPSIS
+
+  use Crypt::CBC;
+  $cipher = Crypt::CBC->new( {'key'             => 'my secret key',
+                              'cipher'          => 'Blowfish',
+                              'iv'              => '$KJh#(}q',
+                              'regenerate_key'  => 0,   # default true
+                              'padding'         => 'space',
+                              'prepend_iv'      => 0,
+			      'pcbc'            => 1  #default 0
+                           });
+  
+  $ciphertext = $cipher->encrypt("This data is hush hush");
+  $plaintext = $cipher->decrypt($ciphertext);
+  
+  $cipher->start('encrypting');
+  open(F,"./BIG_FILE");
+  while (read(F,$buffer,1024)) {
+      print $cipher->crypt($buffer);
+  }
+  print $cipher->finish;
+
+
+=head1 DESCRIPTION
+
+This module is a Perl-only implementation of the cryptographic cipher
+block chaining mode (CBC).  In combination with a block cipher such as
+DES or IDEA, you can encrypt and decrypt messages of arbitrarily long
+length.  The encrypted messages are compatible with the encryption
+format used by B<SSLeay>.
+
+To use this module, you will first create a Crypt::CBC cipher object with
+new().  At the time of cipher creation, you specify an encryption key
+to use and, optionally, a block encryption algorithm.  You will then
+call the start() method to initialize the encryption or decryption
+process, crypt() to encrypt or decrypt one or more blocks of data, and
+lastly finish(), to pad and encrypt the final block.  For your
+convenience, you can call the encrypt() and decrypt() methods to
+operate on a whole data value at once.
+
+=head2 new()
+
+  $cipher = Crypt::CBC->new( {'key'             => 'my secret key',
+                              'cipher'          => 'Blowfish',
+                              'iv'              => '$KJh#(}q',
+                              'regenerate_key'  => 0,   # default true
+                              'padding'         => 'space',
+                              'prepend_iv'      => 0
+                           });
+  
+  # or (for compatibility with earlier versions)
+  $cipher = new Crypt::CBC($key,$algorithm);
+
+The new() method creates a new Crypt::CBC object.  
+
+You must provide an encryption/decryption key, which can be any series
+of characters of any length.  If regenerate_key is not specified as a
+false value, the actual key used is derived from the MD5 hash of the
+key you provide.  The cipher is optional and will default to DES unless
+specified otherwise. You may use any compatible block encryption
+algorithm that you have installed. Currently, this includes Crypt::DES,
+Crypt::DES_EDE3, Crypt::IDEA, Crypt::Blowfish, and Crypt::Rijndael. You
+may refer to them using their full names ("Crypt::IDEA") or in 
+abbreviated form ("IDEA").  
+
+An initialization vector may be specified, either by passing in a key of
+'iv' as an option to new, or by calling 
+$cipher->set_initialization_key($iv) before calling $cipher->start().  
+The IV will be ignored in decryption if the ciphertext is prepended by 
+text which matches the regex /^RandomIV.{8}/, in which case the 8 
+characters following "RandomIV" will be used as the IV. When encrypting,
+by default the ciphertext will be prepended with "RandomIVE<lt>IVE<gt>"
+(16 bytes). To disable this, set 'prepend_iv' to a false value. The 
+padding method can be specified by the 'padding' option. If no padding 
+method is specified, PKCS#5 ("standard") padding is assumed.
+
+Instead of the default cipher-block-chaining mode a modified algorithm
+PCBC can be used. It provides better error propagation characteristics
+than CBC encryption. To switch it on you have to set 'pcbc' to a true value.
+The PCBC mode is part of the des library and required e.g. in Kerberos4
+authentication procedures as mentioned in RFC 2222 and other documents.
+
+=head2 start()
+
+   $cipher->start('encrypting');
+   $cipher->start('decrypting');
+
+The start() method prepares the cipher for a series of encryption or
+decryption steps, resetting the internal state of the cipher if
+necessary.  You must provide a string indicating whether you wish to
+encrypt or decrypt.  "E" or any word that begins with an "e" indicates
+encryption.  "D" or any word that begins with a "d" indicates
+decryption.
+
+=head2 crypt()
+ 
+   $ciphertext = $cipher->crypt($plaintext);
+
+After calling start(), you should call crypt() as many times as
+necessary to encrypt the desired data.  
+
+=head2  finish()
+
+   $ciphertext = $cipher->finish();
+
+The CBC algorithm must buffer data blocks inernally until they are
+even multiples of the encryption algorithm's blocksize (typically 8
+bytes).  After the last call to crypt() you should call finish().
+This flushes the internal buffer and returns any leftover ciphertext.
+
+In a typical application you will read the plaintext from a file or
+input stream and write the result to standard output in a loop that
+might look like this:
+
+  $cipher = new Crypt::CBC('hey jude!');
+  $cipher->start('encrypting');
+  print $cipher->crypt($_) while <>;
+  print $cipher->finish();
+
+=head2 encrypt()
+
+  $ciphertext = $cipher->encrypt($plaintext)
+
+This convenience function runs the entire sequence of start(), crypt()
+and finish() for you, processing the provided plaintext and returning
+the corresponding ciphertext.
+
+=head2 decrypt()
+
+  $plaintext = $cipher->decrypt($ciphertext)
+
+This convenience function runs the entire sequence of start(), crypt()
+and finish() for you, processing the provided ciphertext and returning
+the corresponding plaintext.
+
+=head2 encrypt_hex(), decrypt_hex()
+
+  $ciphertext = $cipher->encrypt_hex($plaintext)
+  $plaintext  = $cipher->decrypt_hex($ciphertext)
+
+These are convenience functions that operate on ciphertext in a
+hexadecimal representation.  B<encrypt_hex($plaintext)> is exactly
+equivalent to B<unpack('H*',encrypt($plaintext))>.  These functions
+can be useful if, for example, you wish to place the encrypted
+
+=head2 get_initialization_vector()
+
+  $iv = $cipher->get_initialization_vector()
+
+This function will return the IV used in encryption and or decryption.
+This function may be useful to determine the random IV used when 
+encrypting if none is specified in new(). The IV is not guaranteed to
+be set when encrypting until start() is called, and when decrypting 
+until crypt() is called the first time.
+
+=head2 set_initialization_vector()
+
+  $cipher->set_initialization_vector('76543210')
+
+This function sets the IV used in encryption and/or decryption. This 
+function may be useful if the IV is not contained within the ciphertext
+string being decrypted, or if a particular IV is desired for encryption.
+If not set, a random IV will be generated. The IV is not guaranteed to
+be set when encrypting until start() is called, and when decrypting
+until crypt() is called the first time.
+
+=head2 Padding methods
+
+Use the 'padding' option to change the padding method.
+
+When the last block of plaintext is shorter than the block size,
+it must be padded. Padding methods include: "standard" (i.e., PKCS#5),
+"oneandzeroes", "space", and "null".
+
+   standard: (default) Binary safe
+      pads with the number of bytes that should be truncated. So, if 
+      blocksize is 8, then "0A0B0C" will be padded with "05", resulting
+      in "0A0B0C0505050505". If the final block is a full block of 8 
+      bytes, then a whole block of "0808080808080808" is appended.
+
+   oneandzeroes: Binary safe
+      pads with "80" followed by as many "00" necessary to fill the
+      block. If the last block is a full block and blocksize is 8, a
+      block of "8000000000000000" will be appended.
+
+   null: text only
+      pads with as many "00" necessary to fill the block. If the last 
+      block is a full block and blocksize is 8, a block of 
+      "0000000000000000" will be appended.
+
+   space: text only
+      same as "null", but with "20".
+      
+Both the standard and oneandzeroes paddings are binary safe.  The
+space and null paddings are recommended only for text data.  Which
+type of padding you use depends on whether you wish to communicate
+with an external (non Crypt::CBC library).  If this is the case, use
+whatever padding method is compatible.
+
+You can also pass in a custom padding function.  To do this, create a
+function that takes the arguments:
+
+   $padded_block = function($block,$blocksize,$direction);
+
+where $block is the current block of data, $blocksize is the size to
+pad it to, $direction is "e" for encrypting and "d" for decrypting,
+and $padded_block is the result after padding or depadding.
+
+When encrypting, the function should always return a string of
+<blocksize> length, and when decrypting, can expect the string coming
+in to always be that length. See _standard_padding(), _space_padding(),
+_null_padding(), or _oneandzeroes_padding() in the source for examples.
+
+Standard and oneandzeroes padding are recommended, as both space and
+null padding can potentially truncate more characters than they should. 
+
+=head1 EXAMPLES
+
+Two examples, des.pl and idea.pl can be found in the eg/ subdirectory
+of the Crypt-CBC distribution.  These implement command-line DES and
+IDEA encryption algorithms.
+
+=head1 LIMITATIONS
+
+The encryption and decryption process is about a tenth the speed of
+the equivalent SSLeay programs (compiled C).  This could be improved
+by implementing this module in C.  It may also be worthwhile to
+optimize the DES and IDEA block algorithms further.
+
+=head1 BUGS
+
+Please report them.
+
+=head1 AUTHOR
+
+Lincoln Stein, lstein@cshl.org
+
+This module is distributed under the ARTISTIC LICENSE using the same
+terms as Perl itself.
+
+=head1 SEE ALSO
+
+perl(1), Crypt::DES(3), Crypt::IDEA(3), rfc2898 (PKCS#5)
+
+=cut

Added: packages/libcrypt-cbc-perl/branches/upstream/current/Changes
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/Changes	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/Changes	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,70 @@
+Revision history for Perl extension Crypt::CBC.
+2.12	Thu Jun 17 11:52:04 EDT 2004
+	- quenched (again) uninitialized variable warnings
+
+2.11	Thu Jun  3 12:07:33 EDT 2004
+	-Fixed bug reported by Joshua Brown that caused certain length
+	strings to not encrypt properly if ending in a "0" character.
+
+2.10	Sat May 29 13:10:05 EDT 2004
+	-Fixed Rijndael compat problems
+
+2.09	Thu May 27 11:18:06 EDT 2004
+	-Quenched uninitialized variable warnings
+
+2.08	Wed Sep 11 08:12:49 EDT 2002
+	-Bug fix from Chris Laas to fix custom padding
+
+2.07	Thu Aug  8 14:44:52 EDT 2002
+	-Bug fixes from Stephen Waters to fix space padding
+	-Lots of regression tests from Stephen Waters
+
+2.05	Tue Jun 11 22:18:04 EDT 2002
+	-Makes zero-and-one padding compatible with Crypt::Rijndael::MODE_CBC.
+	-Lots of improvements to padding mechanisms from Stephen Waters
+
+2.04	Tue Jun 11 22:18:04 EDT 2002
+	WITHDRAWN VERSION DO NOT USE
+
+2.03	Mon Feb  4 15:41:51 EST 2002
+	-Patch from Andy Turner <turner@mikomi.org> to allow backward
+	compatibility with old versions when key length exceeded max.
+
+2.02	Thu Jan 24 00:15:52 EST 2002
+	- Default to pre-2.00 style padding, because Jody's default padding
+		method was not binary safe.
+
+2.01	Mon Dec 10 12:11:35 EST 2001
+	- Removed debugging code.
+
+2.00	Tue Oct 31, 2000
+	- Patches for foreign program compatibility, initialization vectors
+		and padding methods from Jody Biggs <jody.biggs@paymybills.com>
+
+1.25    Thu Jun  8 11:56:28 EDT 2000
+	- Bug fix didn't get into version 1.24.  Is in version 1.25
+
+1.24    Tue Jun  6 17:35:18 EDT 2000
+	- Fixed a bug that prevented a DES and an IDEA object from being
+		used simultaneously.
+
+1.22	Wed Jan 26 19:07:30 EST 2000
+	- Added support for Crypt::Blowfish (available from www.cryptix.org)
+	- Fixed failure to encrypt data files < 8 bytes
+	- Fixed -w warning when decrypting data files < 8 bytes
+	
+1.21	Mon Nov 29 17:11:17 EST 1999
+	- Generate random initialization vector.
+	- Use same encryption format as Ben Laurie's patches to OpenSSL (versions >= 0.9.5)
+
+1.20  Sun Dec 20 3:58:01 1998 MET
+	- Folded in bug fixes from Devin Carraway <aqua@sonic.net>
+	(chiefly having to do with finish() being called with a
+	zero-length buffer).
+
+1.10  Thu Sep 11 09:15:01 1998
+	- Changed package name to Crypt::CBC
+
+1.00  Tue Jun 16 07:37:35 1998
+	- original version; created by h2xs 1.18
+

Added: packages/libcrypt-cbc-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/MANIFEST	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/MANIFEST	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,11 @@
+CBC.pm
+Changes
+MANIFEST
+Makefile.PL
+README
+eg/des.pl
+eg/idea.pl
+t/Rijndael_compat.t
+t/func.t
+t/null_data.t
+META.yml                                 Module meta-data (added by MakeMaker)

Added: packages/libcrypt-cbc-perl/branches/upstream/current/META.yml
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/META.yml	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/META.yml	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,11 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Crypt-CBC
+version:      2.11
+version_from: CBC.pm
+installdirs:  site
+requires:
+    Digest::MD5:                   2.00
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17

Added: packages/libcrypt-cbc-perl/branches/upstream/current/Makefile.PL
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/Makefile.PL	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/Makefile.PL	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,14 @@
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+    'NAME'	=> 'Crypt::CBC',
+    'VERSION_FROM' => 'CBC.pm', # finds $VERSION
+    'PREREQ_PM' => {'Digest::MD5' => '2.00' },
+    'LIBS'	=> [''],   # e.g., '-lm' 
+    'DEFINE'	=> '',     # e.g., '-DHAVE_SOMETHING' 
+    'INC'	=> '',     # e.g., '-I/usr/include/other' 
+    'dist'      => {'COMPRESS'=>'gzip -9f', 'SUFFIX' => 'gz',
+	            'ZIP'=>'/usr/bin/zip','ZIPFLAGS'=>'-rl'}
+
+);

Added: packages/libcrypt-cbc-perl/branches/upstream/current/README
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/README	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/README	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,86 @@
+This is Crypt::CBC, a Perl-only implementation of the cryptographic
+cipher block chaining mode (CBC).  In combination with a block cipher
+such as Crypt::DES or Crypt::IDEA, you can encrypt and decrypt
+messages of arbitrarily long length.  The encrypted messages are
+compatible with the encryption format used by B<SSLeay>.
+
+Prerequisites
+-------------
+
+In addition to this module you will need to install the MD5 module,
+and one or more of: Crypt::DES, Crypt::DES_EDE3, Crypt::IDEA, 
+Crypt::Blowfish, or Crypt::Rijndael modules.
+
+1. Digest::MD5
+   Required for key and iteration vector generation.
+
+2. Crypt::DES
+   Required for the DES encryption algorithm.
+
+3. Crypt::DES_EDE3
+   Required for the triple DES encryption algorithm in Encrypt Decrypt 
+   Encrypt mode. Note, this depends on Crypt::DES.
+
+4. Crypt::IDEA
+   Required for the IDEA encryption algorithm.
+
+5. Crypt::Blowfish
+   Required for the Blowfish encryption algorithm.
+
+6. Crypt::Blowfish_PP
+   Required for the Blowfish_PP encryption algorithm.
+
+7. Crypt::Rijndael
+   Required for the Rijndael/AES encryption algorithm.
+
+You can find these modules on a CPAN server near you!
+
+Unfortunately, Crypt::TripleDES does not work with this module, owing
+to the fact that it does not follow the same API as the other Crypt::*
+modules.  Please write to TripleDES's author, Vipul Ved Prakash
+<mail@vipul.net> and ask him to fix this.
+
+The Cryptix site also has versions of Crypt::DES and Crypt::IDEA that
+are slightly different from the CPAN versions.  Since these seem to be
+later versions, I suggest that you download and install the entire
+Cryptix Perl distribution.  
+
+In order to get the Crypt:: modules to compile under Perl 5.005 or
+later, you must add the following line to the DES.xs, IDEA.xs and
+Blowfish.xs files:
+
+  #define sv_undef PL_sv_undef
+
+For your convenience, a patch file which will bring the Cryptix
+directory up to date is included in this distribution.  It is named
+cryptix-5.005.patch.  Use it like this:
+
+ % cd Cryptix-1.16
+ % patch -p1 < ../Crypt-CBC/cryptix-5.005.patch 
+ patching file Crypt-Blowfish/Blowfish.xs
+ patching file Crypt-DES/DES.xs
+ patching file Crypt-IDEA/IDEA.xs
+
+Then install the Cryptix modules using "perl Makefile.PL; make; make install".
+
+Installing Crypt::CBC
+---------------------
+
+The rest is easy
+
+	1. perl Makefile.PL
+	2. make
+	3. make test
+	4. make install
+
+Versions 1.22 and greater generate a random initialization vector, 
+rather than generating one based on the key.  Not only is this much 
+more secure, but it maintains compatibility with the current version of 
+OpenSSL, which does the same thing as of version 0.9.5.  For backwards
+compatibility, messages encrypted with older versions of Crypt::CBC
+can be decrypted with the newer version.  The reverse is not true --
+the beginning messages encrypted by the new version and decrypted by
+the old may be contaminated with "junk".
+
+Lincoln D. Stein
+lstein@cshl.org

Added: packages/libcrypt-cbc-perl/branches/upstream/current/eg/des.pl
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/eg/des.pl	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/eg/des.pl	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,62 @@
+#!/usr/local/bin/perl
+
+use lib '../blib/lib';
+
+use Getopt::Std;
+use Crypt::DES;
+use Crypt::CBC;
+use strict vars;
+
+my %options;
+
+getopts('edk:i:o:',\%options) || die <<USAGE;
+Usage: des.pl [options] file1 file2 file3...
+   DES encrypt/decrypt files using Cipher Block Chaining mode.
+Options:
+       -e        encrypt (default)
+       -d        decrypt
+       -k 'key'  provide key on command line
+       -i file   input file
+       -o file   output file
+USAGE
+    ;
+
+@ARGV = $options{'i'} if $options{'i'};
+push(@ARGV,'-') unless @ARGV;
+open (STDOUT,">$options{'o'}") || die "$options{'o'}: $!"
+    if $options{'o'};
+
+my $key = $options{'k'} || get_key();
+# DES used by default
+my $cipher = Crypt::CBC->new($key) || die "Couldn't create CBC object";  
+my $decrypt = $options{'d'} and !$options{'e'};
+$cipher->start($decrypt ? 'decrypt' : 'encrypt');
+
+my $in;
+while (@ARGV) {
+    my $file = shift @ARGV;
+    open(ARGV,$file) || die "$file: $!";
+    print $cipher->crypt($in) while read(ARGV,$in,1024);
+    close ARGV;
+}
+print $cipher->finish;
+
+sub get_key {
+    local($|) = 1;
+    local(*TTY);
+    open(TTY,"/dev/tty");
+    my ($key1,$key2);
+    system "stty -echo </dev/tty";
+    do {
+	print STDERR "DES key: ";
+        chomp($key1 = <TTY>);
+	print STDERR "\r\nRe-type key: ";
+        chomp($key2 = <TTY>);
+        print STDERR "\r\n";
+        print STDERR "The two keys don't match. Try again.\r\n"
+            unless $key1 eq $key2;
+    } until $key1 eq $key2;
+    system "stty echo </dev/tty";
+    close(TTY);
+    $key1;
+}


Property changes on: packages/libcrypt-cbc-perl/branches/upstream/current/eg/des.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: packages/libcrypt-cbc-perl/branches/upstream/current/eg/idea.pl
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/eg/idea.pl	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/eg/idea.pl	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,61 @@
+#!/usr/local/bin/perl
+
+use lib '../blib/lib';
+
+use Getopt::Std;
+use Crypt::IDEA;
+use Crypt::CBC;
+use strict vars;
+
+my %options;
+
+getopts('edk:i:o:',\%options) || die <<USAGE;
+Usage: idea.pl [options] file1 file2 file3...
+   IDEA encrypt/decrypt files using Cipher Block Chaining mode.
+Options:
+       -e        encrypt (default)
+       -d        decrypt
+       -k 'key'  provide key on command line
+       -i file   input file
+       -o file   output file
+USAGE
+    ;
+
+@ARGV = $options{'i'} if $options{'i'};
+push(@ARGV,'-') unless @ARGV;
+open(STDOUT,">$options{'o'}") or die "$options{'o'}: $!"
+    if $options{'o'};
+
+my $key = $options{'k'} || get_key();
+my $cipher = Crypt::CBC->new($key,'IDEA') || die "Couldn't create CBC object";  
+my $decrypt = $options{'d'} and !$options{'e'};
+$cipher->start($decrypt ? 'decrypt' : 'encrypt');
+
+my $in;
+while (@ARGV) {
+    my $file = shift @ARGV;
+    open(ARGV,$file) || die "$file: $!";
+    print $cipher->crypt($in) while read(ARGV,$in,1024);
+    close ARGV;
+}
+print $cipher->finish;
+
+sub get_key {
+    local($|) = 1;
+    local(*TTY);
+    open(TTY,"/dev/tty");
+    my ($key1,$key2);
+    system "stty -echo </dev/tty";
+    do {
+	print STDERR "IDEA key: ";
+        chomp($key1 = <TTY>);
+	print STDERR "\r\nRe-type key: ";
+        chomp($key2 = <TTY>);
+        print STDERR "\r\n";
+        print STDERR "The two keys don't match. Try again.\r\n"
+            unless $key1 eq $key2;
+    } until $key1 eq $key2;
+    system "stty echo </dev/tty";
+    close(TTY);
+    $key1;
+}


Property changes on: packages/libcrypt-cbc-perl/branches/upstream/current/eg/idea.pl
___________________________________________________________________
Name: svn:executable
   + 

Added: packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael_compat.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael_compat.t	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael_compat.t	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,85 @@
+#!/usr/local/bin/perl
+
+use strict;
+use lib '..','../blib/lib','.','./blib/lib';
+
+my ($i, $j, $test_data);
+
+eval "use Crypt::Rijndael";
+if ($@) {
+    print "1..0 # Skipped: Crypt::Rijndael not installed\n";
+    exit;
+}
+
+print "1..59\n";
+
+sub test {
+    local($^W) = 0;
+    my($num, $true,$msg) = @_;
+    print($true ? "ok $num\n" : "not ok $num $msg\n");
+}
+
+sub pad {
+   my ($s,$decrypt) = @_;
+   if ($decrypt eq 'd') {
+     $s =~ s/10*$//s;
+   } else {
+      $s .= '1' . ('0' x (16 - length($s) % 16 - 1) );
+   }
+   return $s;
+}
+
+$test_data = <<END;
+Mary had a little lamb,
+Its fleece was black as coal,
+And everywere that Mary went,
+That lamb would dig a hole.
+END
+    ;
+
+eval "use Crypt::CBC";
+
+test(1,!$@,"Couldn't load module");
+test(2,$i = Crypt::CBC->new({key => 'a' x 16, 
+                             cipher => 'Rijndael',
+                             iv => 'f' x 16,
+                             regenerate_key => 0,
+                             prepend_iv => 0,
+                             padding => 'oneandzeroes'
+                           }),
+                           "Couldn't create new object");
+test(3,$j = Crypt::Rijndael->new('a' x 16, Crypt::Rijndael->MODE_CBC),
+                           "Couldn't create new object");
+test(4,$j->set_iv('f' x 16));
+
+test(5,$i->decrypt($i->encrypt($test_data)) eq $j->decrypt($j->encrypt($test_data)),"Decrypt doesn't match");
+
+test(6,$i->decrypt($j->encrypt($test_data)) eq $test_data,"Crypt::CBC can't decrypt Rijndael encryption");
+
+test(7,$j->decrypt($i->encrypt($test_data)) eq $test_data,"Rijndael can't decrypt Crypt::CBC encryption");
+
+# now try various truncations of the whole
+my $t = $test_data;
+for (my $c=1;$c<=7;$c++) {
+  substr($t,-$c) = '';  # truncate
+  test(7+$c,$t eq pad($i->decrypt($j->encrypt(pad($t,'e'))),'d'),"Crypt::CBC can't decrypt Rijndael encryption");
+}
+
+$t = $test_data;
+for (my $c=1;$c<=7;$c++) {
+  substr($t,-$c) = '';  # truncate
+  test(14+$c,$t eq pad($j->decrypt($i->encrypt(pad($t,'e'))),'d'),"Rijndael can't decrypt Crypt::CBC encryption");
+}
+
+# now try various short strings
+for (my $c=0;$c<=18;$c++) {
+  my $t = 'i' x $c;
+  test(22+$c,$t eq pad($j->decrypt($i->encrypt(pad($t,'e'))),'d'),"Rijndael can't decrypt Crypt::CBC encryption");
+}
+
+# now try various short strings
+for (my $c=0;$c<=18;$c++) {
+  my $t = 'i' x $c;
+  test(41+$c,$t eq pad($j->decrypt($i->encrypt(pad($t,'e'))),'d'),"Rijndael can't decrypt Crypt::CBC encryption");
+}
+

Added: packages/libcrypt-cbc-perl/branches/upstream/current/t/func.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/func.t	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/func.t	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,108 @@
+#!/usr/local/bin/perl
+
+use strict;
+use lib '..','../blib/lib','.','./blib/lib';
+
+sub test;
+
+my (@mods,@pads,@in,$pad,$test_data,$mod,$tnum,$c,$i,$p);
+
+@mods = qw/Rijndael
+           Blowfish
+           Blowfish_PP
+           IDEA
+           DES
+          /;
+@pads = qw/standard oneandzeroes space null/;
+
+for $mod (@mods) {
+   eval "use Crypt::$mod(); 1" && push @in,$mod;
+}
+
+unless ($#in > -1) {
+   print "1..0 # Skipped: no cryptographic modules found\n";
+   exit;
+}
+
+# ($#in + 1): number of installed modules
+# ($#pads + 1): number of padding methods
+# 32: number of per-module, per-pad tests
+# 1: the first test -- loading Crypt::CBC module
+
+print '1..', ($#in + 1) * ($#pads + 1) * 32 + 1, "\n";
+
+sub test {
+    local($^W) = 0;
+    my($num, $true,$msg) = @_;
+    $$num++;
+    print($true ? "ok $$num\n" : "not ok $$num $msg\n");
+}
+
+$tnum = 0;
+
+eval "use Crypt::CBC";
+test(\$tnum,!$@,"Couldn't load module");
+
+for $mod (@in) {
+   for $pad (@pads) {
+
+      $test_data = <<END;
+Mary had a little lamb,
+Its fleece was black as coal,
+And everywere that Mary went,
+That lamb would dig a hole.
+END
+    ;
+
+      test(\$tnum,$i = Crypt::CBC->new({key => 'secret',
+                                        cipher => $mod,
+                                        padding => $pad
+                                      }),
+                                      "Couldn't create new object");
+
+      test(\$tnum,$c = $i->encrypt($test_data),"Couldn't encrypt");
+      test(\$tnum,$p = $i->decrypt($c),"Couldn't decrypt");
+      test(\$tnum,$p eq $test_data,"Decrypted ciphertext doesn't match plaintext");
+
+# now try various truncations of the whole string.
+# iteration 3 ends in ' ' so 'space should fail
+
+      for ($c=1;$c<=7;$c++) {
+
+         substr($test_data,-$c) = '';
+
+         if ($c == 3 && $pad eq 'space') {
+            test(\$tnum,$i->decrypt($i->encrypt($test_data)) ne $test_data);
+         } else {
+            test(\$tnum,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+         }
+      }
+
+# try various short strings
+
+      for ($c=0;$c<=18;$c++) {
+        $test_data = 'i' x $c;
+        test(\$tnum,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+      }
+
+# 'space' should fail. others should succeed.
+
+      $test_data = "This string ends in some spaces  ";
+
+      if ($pad eq 'space') { 
+         test(\$tnum,$i->decrypt($i->encrypt($test_data)) ne $test_data);
+      } else {
+         test(\$tnum,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+      }
+
+# 'null' should fail. others should succeed.
+
+      $test_data = "This string ends in a null\0";
+
+      if ($pad eq 'null') { 
+         test(\$tnum,$i->decrypt($i->encrypt($test_data)) ne $test_data);
+      } else {
+         test(\$tnum,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+      }
+   }
+}

Added: packages/libcrypt-cbc-perl/branches/upstream/current/t/null_data.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/null_data.t	2005-06-13 00:12:20 UTC (rev 1108)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/null_data.t	2005-06-13 00:41:17 UTC (rev 1109)
@@ -0,0 +1,56 @@
+#!/usr/bin/perl -w
+
+use strict;
+use lib '..','../blib/lib','.','./blib/lib';
+
+sub test;
+
+my (@mods,@pads,@in,$pad,$test_data,$mod,$tnum,$c,$i,$p);
+
+@mods = qw/Rijndael
+           Blowfish
+           Blowfish_PP
+           IDEA
+           DES
+          /;
+@pads = qw/standard oneandzeroes space null/;
+
+for $mod (@mods) {
+   eval "use Crypt::$mod(); 1" && push @in,$mod;
+}
+
+unless ($#in > -1) {
+   print "1..0 # Skipped: no cryptographic modules found\n";
+   exit;
+}
+
+print '1..', 128*($#in + 1) * ($#pads + 1) + 1, "\n";
+
+sub test {
+    local($^W) = 0;
+    my($num, $true,$msg) = @_;
+    $$num++;
+    print($true ? "ok $$num\n" : "not ok $$num $msg\n");
+}
+
+$tnum = 0;
+
+eval "use Crypt::CBC";
+test(\$tnum,!$@,"Couldn't load module");
+
+for my $mod (@in) {
+  for my $pad (@pads) {
+    my $cipher = Crypt::CBC->new({key => 'secret',
+				  cipher => $mod,
+				  padding => $pad
+				 });
+    for my $length (1..128) {
+      my $test_data = 'a'x$length . '0';
+                
+      my $encrypted = $cipher->encrypt_hex($test_data);
+      my $decrypted = $cipher->decrypt_hex($encrypted);
+      test(\$tnum,$test_data eq $decrypted,"$mod/$pad: match failed on zero-terminated data length $length");
+    }
+  }
+}
+