r1707 - in packages/libcrypt-cbc-perl/branches/upstream/current: .
eg t
Krzysztof Krzyzaniak
eloy at costa.debian.org
Tue Dec 20 09:54:51 UTC 2005
Author: eloy
Date: 2005-12-20 09:54:25 +0000 (Tue, 20 Dec 2005)
New Revision: 1707
Added:
packages/libcrypt-cbc-perl/branches/upstream/current/eg/aes.pl
packages/libcrypt-cbc-perl/branches/upstream/current/t/Blowfish.t
packages/libcrypt-cbc-perl/branches/upstream/current/t/Blowfish_PP.t
packages/libcrypt-cbc-perl/branches/upstream/current/t/CAST5.t
packages/libcrypt-cbc-perl/branches/upstream/current/t/DES.t
packages/libcrypt-cbc-perl/branches/upstream/current/t/IDEA.t
packages/libcrypt-cbc-perl/branches/upstream/current/t/PCBC.t
packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael.t
Modified:
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/eg/des.pl
packages/libcrypt-cbc-perl/branches/upstream/current/eg/idea.pl
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
Log:
Load /tmp/tmp.pj8dJu/libcrypt-cbc-perl-2.15 into
packages/libcrypt-cbc-perl/branches/upstream/current.
Modified: packages/libcrypt-cbc-perl/branches/upstream/current/CBC.pm
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/CBC.pm 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/CBC.pm 2005-12-20 09:54:25 UTC (rev 1707)
@@ -4,64 +4,83 @@
use Carp;
use strict;
use vars qw($VERSION);
-$VERSION = '2.12';
+$VERSION = '2.15';
+use constant RANDOM_DEVICE => '/dev/urandom';
+
sub new {
my $class = shift;
- my $arg1 = shift;
- my $arg2 = shift;
my $options = {};
- if (ref($arg1) eq 'HASH') {
- $options = $arg1;
- } else {
- $options->{key} = $arg1;
+ # hashref arguments
+ if (ref $_[0] eq 'HASH') {
+ $options = shift;
}
- if ($arg2) {
- $options->{cipher} = $arg2;
+ # CGI style arguments
+ elsif ($_[0] =~ /^-[a-zA-Z]{1,20}$/) {
+ my %tmp = @_;
+ while ( my($key,$value) = each %tmp) {
+ $key =~ s/^-//;
+ $options->{lc $key} = $value;
+ }
}
- my $key = $options->{key};
- croak "Please provide an encryption/decryption key" unless defined $key;
+ else {
+ $options->{key} = shift;
+ $options->{cipher} = shift;
+ }
- # get key from key?
- my $gkfk = 1;
- $gkfk = $options->{regenerate_key} if (exists($options->{regenerate_key}));
+ # "key" is a misnomer here, because it is actually usually a passphrase that is used
+ # to derive the true key
+ my $pass = $options->{key};
+ croak "Please provide an encryption/decryption key" unless defined $pass;
+ # confusing logic, but if the regenerate_key option is present but false, we
+ # use the passphrase for the key
+ my $key = $pass if $options->{literal_key}
+ or (exists $options->{regenerate_key} && !$options->{regenerate_key});
+ my $salt = $options->{salt};
+
+ # if salt is equal to the string "1", then we replace it with random bytes
+ $salt = $class->_get_random_bytes(8) if $salt and $salt eq '1';
+
+ my $prepend_header = 1;
+ for ('prepend_iv','add_header') {
+ $prepend_header = 0 if exists $options->{$_} && !$options->{$_};
+ }
+
+ # note: iv will be autogenerated by start() if not specified in options
+ my $iv = $options->{iv};
+ croak "Initialization vector must be 8 bytes" if $prepend_header && defined $iv && length $iv != 8;
+
my $cipher = $options->{cipher};
$cipher = 'Crypt::DES' unless $cipher;
$cipher = $cipher=~/^Crypt::/ ? $cipher : "Crypt::$cipher";
- eval "require $cipher";
- croak "Couldn't load $cipher: $@" if $@;
+ eval "require $cipher; 1" or croak "Couldn't load $cipher: $@";
+
# 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;
+ my $padding = $options->{padding} || 'standard';
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);
+ 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";
+ $padding = $padding eq 'null' ? \&_null_padding
+ :$padding eq 'space' ? \&_space_padding
+ :$padding eq 'oneandzeroes' ? \&_oneandzeroes_padding
+ :$padding eq 'standard' ? \&_standard_padding
+ :croak "'$padding' padding not supported. See perldoc Crypt::CBC for instructions on creating your own.";
}
# Some of the cipher modules are busted and don't report the
@@ -71,37 +90,23 @@
$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 (defined $key && 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);
}
- 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 = $options->{'pcbc'};
- 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,
+ return bless {'cipher' => $cipher,
+ 'passphrase' => $pass,
+ 'key' => $key,
+ 'iv' => $iv,
+ 'salt' => $salt,
+ 'padding' => $padding,
+ 'blocksize' => $bs,
+ 'keysize' => $ks,
+ 'prepend_header' => $prepend_header,
+ 'pcbc' => $pcbc,
},$class;
}
@@ -137,10 +142,6 @@
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;
}
@@ -149,41 +150,26 @@
sub crypt (\$$){
my $self = shift;
my $data = shift;
+
+ my $result;
+
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'};
+ unless ($self->{civ}) { # block cipher has not yet been initialized
+ $result = $self->_generate_iv_and_cipher_from_datastream(\$data) if $d;
+ $result = $self->_generate_iv_and_cipher_from_options() unless $d;
}
- $iv = $self->{'civ'};
-
+ my $iv = $self->{'civ'};
$self->{'buffer'} .= $data;
- my $bs = $self->{'blocksize'};
+ 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'} = '';
@@ -234,6 +220,126 @@
return $result;
}
+# this subroutine will generate the actual {en,de}cryption key, the iv
+# and the block cipher object. This is called when reading from a datastream
+# and so it uses previous values of salt or iv if they are encoded in datastream
+# header
+sub _generate_iv_and_cipher_from_datastream {
+ my $self = shift;
+ my $input_stream = shift;
+
+ # if the input stream contains the salt, then it is used to derive the
+ # IV and the encryption key from the passphrase
+ if (my($salt) = $$input_stream =~ /^Salted__(.{8})/s) {
+ $self->{salt} = $salt; # Replace manually-specified salt
+ undef $self->{key}; # reset the key and iv
+ undef $self->{iv};
+ substr($$input_stream,0,16) = '';
+ }
+
+ # if the input stream contains the IV, then we use it to set the IV
+ elsif ( my($iv) = $$input_stream =~ /^RandomIV(.{8})/s) {
+ undef $self->{salt}; # message contents overrides salt option
+ $self->{'iv'} = $iv;
+ substr($$input_stream,0,16) = ''; # truncate
+ }
+
+ if (my $salt = $self->{salt}) {
+ my ($key,$iv) = $self->_salted_key_and_iv($self->{passphrase},$salt);
+ $self->{key} ||= $key; # don't replace manually-specified key
+ $self->{iv} ||= $iv; # don't replace manually-specified IV
+ } else {
+ $self->{key} ||= $self->_key_from_key($self->{passphrase}); # don't replace manually-specified key
+ }
+
+ # we should have the key and iv now, or we are dead in the water
+ croak "Cipher stream did not contain IV or salt, and you did not specify these values in new()"
+ unless $self->{key} && $self->{iv};
+
+ $self->{civ} = $self->{iv}; # 'civ' == "current IV"
+
+ # now we can generate the crypt object itself
+ $self->{crypt} = $self->{cipher}->new($self->{key})
+ or croak "Could not create $self->{cipher} object: $@";
+
+ return '';
+}
+
+sub _generate_iv_and_cipher_from_options {
+ my $self = shift;
+
+ my $result = '';
+
+ # if salt is provided, then we use that to generate our key and iv
+ if (my $salt = $self->{salt}) {
+ my ($key,$iv) = $self->_salted_key_and_iv($self->{passphrase},$salt);
+ $self->{key} ||= $key;
+ $self->{iv} ||= $iv;
+ $result = "Salted__${salt}" if $self->{'prepend_header'};
+ }
+
+ else {
+ $self->{key} ||= $self->_key_from_key($self->{passphrase});
+ $self->{iv} ||= $self->_get_random_bytes(8);
+ $result = "RandomIV$self->{iv}" if $self->{'prepend_header'};
+ }
+
+ croak "key and/or iv are missing" unless $self->{key} && $self->{iv};
+
+ $self->{crypt} = $self->{cipher}->new($self->{key})
+ or croak "Could not create $self->{cipher} object: $@";
+ $self->{'civ'} = $self->{'iv'};
+
+ return $result;
+}
+
+sub _key_from_key {
+ my $self = shift;
+ my $pass = shift;
+ my $ks = $self->{keysize};
+
+ my $material = md5($pass);
+ while (length($material) < $ks) {
+ $material .= md5($material);
+ }
+ return substr($material,0,$ks);
+}
+
+sub _salted_key_and_iv {
+ my $self = shift;
+ my ($pass,$salt) = @_;
+
+ croak "Salt must be 8 bytes long" unless length $salt == 8;
+
+ my $key_len = $self->{keysize};
+ my $iv_len = $self->{blocksize};
+
+ my $desired_len = $key_len+$iv_len;
+
+ my $data = '';
+ my $d = '';
+
+ while (length $data < $desired_len) {
+ $d = md5($d . $pass . $salt);
+ $data .= $d;
+ }
+ return (substr($data,0,$key_len),substr($data,$key_len,$iv_len));
+}
+
+sub _get_random_bytes {
+ my $self = shift;
+ my $length = shift;
+ my $result;
+
+ if (-r RANDOM_DEVICE && open(F,RANDOM_DEVICE)) {
+ read(F,$result,$length);
+ close F;
+ } else {
+ $result = pack("C*",map {rand(256)} 1..$length);
+ }
+ $result;
+}
+
sub _standard_padding ($$$) {
my ($b,$bs,$decrypt) = @_;
$b = length $b ? $b : '';
@@ -292,6 +398,44 @@
$self->{'iv'} = $iv;
}
+sub salt {
+ my $self = shift;
+ my $d = $self->{salt};
+ $self->{salt} = shift if @_;
+ $d;
+}
+
+sub iv {
+ my $self = shift;
+ my $d = $self->{iv};
+ $self->{iv} = shift if @_;
+ $d;
+}
+
+sub key {
+ my $self = shift;
+ my $d = $self->{key};
+ $self->{key} = shift if @_;
+ $d;
+}
+
+sub passphrase {
+ my $self = shift;
+ my $d = $self->{passphrase};
+ if (@_) {
+ undef $self->{key};
+ undef $self->{iv};
+ $self->{passphrase} = shift;
+ }
+ $d;
+}
+
+sub cipher { shift->{cipher} }
+sub padding { shift->{padding} }
+sub keysize { shift->{keysize} }
+sub blocksize { shift->{blocksize} }
+sub pcbc { shift->{pcbc} }
+
1;
__END__
@@ -302,18 +446,14 @@
=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
- });
-
+ $cipher = Crypt::CBC->new( -key => 'my secret key',
+ -cipher => 'Blowfish',
+ -salt => 1,
+ );
+
$ciphertext = $cipher->encrypt("This data is hush hush");
$plaintext = $cipher->decrypt($ciphertext);
-
+
$cipher->start('encrypting');
open(F,"./BIG_FILE");
while (read(F,$buffer,1024)) {
@@ -328,7 +468,8 @@
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>.
+format used by B<SSLeay>, and can be made compatible with the newer
+B<OpenSSL> package by specifying the B<-salt> argument.
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
@@ -341,46 +482,121 @@
=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);
+ $cipher = Crypt::CBC->new( -key => 'my secret key',
+ -cipher => 'Blowfish',
+ -salt => 1
+ );
-The new() method creates a new Crypt::CBC object.
+ # or (for compatibility with versions prior to 2.13)
+ $cipher = Crypt::CBC->new( {key => 'my secret key',
+ cipher => 'Blowfish',
+ salt => 1}
+ );
-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
+
+ # or (for compatibility with versions prior to 2.0)
+ $cipher = new Crypt::CBC('my secret key','Blowfish');
+
+The new() method creates a new Crypt::CBC object. It accepts a list of
+-argument => value pairs selected from the following list:
+
+ Argument Description
+ -------- -----------
+
+ -key The encryption/decryption key (required)
+
+ -cipher The cipher algorithm (defaults to Crypt::DES)
+
+ -salt Enables OpenSSL-compatibility. If equal to a value
+ of "1" then causes a random salt to be generated
+ and used to derive the encryption key and IV. Other
+ true values are taken to be the literal salt.
+
+ -iv The initialization vector (IV)
+
+ -padding The padding method, one of "standard", "space",
+ "onesandzeroes", or "null". (default "standard")
+
+ -literal_key If true, the key provided by "key" is used directly
+ for encryption/decryption. Otherwise the actual
+ key used will be a hash of the provided key.
+ (default false)
+
+ -pcbc Whether to use the PCBC chaining algorithm rather than
+ the standard CBC algorithm (default false).
+
+ -add_header Whether to add the salt and IV to the header of the output
+ cipher text.
+
+ -regenerate_key [deprecated; use literal_key instead]
+ Whether to use a hash of the provided key to generate
+ the actual encryption key (default true)
+
+ -prepend_iv [deprecated; use add_header instead]
+ Whether to prepend the IV to the beginning of the
+ encrypted stream (default true)
+
+You must provide an encryption/decryption B<-key>, which can be any
+series of characters of any length. If B<-regenerate_key> is true (the
+default), then the actual key used is derived from the MD5 hash of the
+key you provide; otherwise the actual binary bits of the key are used.
+
+The B<-cipher> option specifies which block cipher algorithm to use to
+encode each section of the message. This argument is optional and
+will default to the quick-but-not-very-secure DES algorithm 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").
+algorithm that you have installed. Currently, this includes
+Crypt::DES, Crypt::DES_EDE3, Crypt::IDEA, Crypt::Blowfish,
+Crypt::CAST5 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.
+The B<-salt> argument actives an OpenSSL-compatible method of
+generating the encryption/decryption key and IV. If salt has the value
+"1", then a random salt is computed (highly recommended). Any other
+non-false value will be interpreted as the bytes of the actual salt to
+use. If you provide the salt, it must be exactly 8 bytes in length.
+It is highly recommended that you use -salt=>1, as this may become the
+default in future versions of this module.
-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.
+The initialization vector (IV) is used to start the CBC chaining
+algorithm. Unless you have also specified a false value for
+B<-add_header>, the IV should be exactly 8 bytes in length. The IV may
+be specified manually by passing in a key of B<-iv> as an option to
+new() or by calling $cipher->set_initialization_vector($iv) before
+calling $cipher->start(). If no IV is specified, then one will be
+generated randomly for you. This is backwardly compatible with CBC
+encrypted streams generated by the older SSLEay library.
+The B<-padding> argument controls how the last few bytes of the
+encrypted stream are dealt with when they not an exact multiple of the
+cipher block length. The default is "standard", the method specified
+in PKCS#5.
+
+The B<-pcbc> argument, if true, activates a modified chaining mode
+known as PCBC. It provides better error propagation characteristics
+than the default CBC encryption and is required for authenticating to
+Kerberos4 systems (see RFC 2222).
+
+When generating ciphertext, the IV or salt are inserted into the
+encrypted data as a 16 byte header. If the B<-salt> option was
+specified, the header will consist of the string "Salted__" followed
+by 8 bytes of salt data. Otherwise the header will consist of
+"RandomIV" followed by 8 bytes of IV data. During decryption, if the
+ciphertext is found to contain either of these headers, the IV or salt
+will be retrieved and used during the decryption process, ignoring any
+values that you might have set manually.
+
+You may disable the generation of the header, by specifying a false
+value for B<-add_header>. You will then have to provide the correct
+values of IV or salt when you decrypt the resulting ciphertext.
+
+For compatibility with earlier versions of this module, you can
+provide new() with a hashref containing key/value pairs. The key names
+are the same as the arguments described earlier, but without the
+initial hyphen. You may also call new() with one or two positional
+arguments, in which case the first argument is taken to be the key and
+the second to be the optional block cipher algorithm.
+
=head2 start()
$cipher->start('encrypting');
@@ -449,22 +665,58 @@
$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.
+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.
+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. Note that the IV must be 8 bytes in length.
+=head2 iv()
+
+ $iv = $cipher->iv();
+ $cipher->iv($new_iv);
+
+As above, but using a single method call.
+
+=head2 key()
+
+ $key = $cipher->key();
+ $cipher->key($new_key);
+
+Get or set the actual key used for encryption/decryption. When
+encrypting, the key is not guaranteed to exist until start() is
+called, and when decrypting, the key is not guaranteed to exist until
+after the first call to crypt(). The key must match the length
+required by the underlying block cipher.
+
+=head2 salt()
+
+ $salt = $cipher->salt();
+ $cipher->salt($new_salt);
+
+Get or set the salt used for deriving the encryption key and IV when
+in OpenSSL compatibility mode.
+
+=head2 passphrase()
+
+ $passphrase = $cipher->passphrase();
+ $cipher->passphrase($new_passphrase);
+
+This gets or sets the value of the B<key> passed to new() when
+B<literal_key> is false.
+
+=head2 cipher(), padding(), keysize(), blocksize(), pcbc()
+
+These read-only methods return the identity of the chosen block cipher
+algorithm, padding method, key and block size of the chosen block
+cipher, and whether PCBC chaining is in effect.
+
=head2 Padding methods
Use the 'padding' option to change the padding method.
Modified: packages/libcrypt-cbc-perl/branches/upstream/current/Changes
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/Changes 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/Changes 2005-12-20 09:54:25 UTC (rev 1707)
@@ -1,4 +1,14 @@
Revision history for Perl extension Crypt::CBC.
+2.14 Thu May 5 16:08:15 EDT 2005
+ - RandomIV in message header overrides manually-supplied -salt, as one
+ would expect it should.
+
+2.13 Fri Apr 22 13:01:32 EDT 200
+ - Added OpenSSL compatibility
+ - Salt and IV generators take advantage of /dev/urandom device, if available
+ - Reorganized internal structure for coding clarity
+ - Added regression test for PCBC mode
+
2.12 Thu Jun 17 11:52:04 EDT 2004
- quenched (again) uninitialized variable warnings
Modified: packages/libcrypt-cbc-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/MANIFEST 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/MANIFEST 2005-12-20 09:54:25 UTC (rev 1707)
@@ -1,11 +1,19 @@
CBC.pm
Changes
MANIFEST
+META.yml Module meta-data (added by MakeMaker)
Makefile.PL
README
+eg/aes.pl
eg/des.pl
eg/idea.pl
+t/Blowfish.t
+t/Blowfish_PP.t
+t/CAST5.t
+t/DES.t
+t/IDEA.t
+t/PCBC.t
+t/Rijndael.t
t/Rijndael_compat.t
t/func.t
t/null_data.t
-META.yml Module meta-data (added by MakeMaker)
Modified: packages/libcrypt-cbc-perl/branches/upstream/current/META.yml
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/META.yml 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/META.yml 2005-12-20 09:54:25 UTC (rev 1707)
@@ -1,7 +1,7 @@
# 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: 2.15
version_from: CBC.pm
installdirs: site
requires:
Added: packages/libcrypt-cbc-perl/branches/upstream/current/eg/aes.pl
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/eg/aes.pl 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/eg/aes.pl 2005-12-20 09:54:25 UTC (rev 1707)
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+use lib '../blib/lib';
+
+use Getopt::Std;
+use Crypt::CBC;
+use strict vars;
+
+my %options;
+
+getopts('edk:i:o:',\%options) || die <<USAGE;
+Usage: aes.pl [options] file1 file2 file3...
+ AES 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
+
+(NB: The Rijndael cipher is the basis for AES)
+USAGE
+ ;
+
+ at 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 => $key,
+ -cipher => 'Rijndael',
+ -salt => 1,
+ ) || 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 "AES 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/aes.pl
___________________________________________________________________
Name: svn:executable
+ *
Modified: packages/libcrypt-cbc-perl/branches/upstream/current/eg/des.pl
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/eg/des.pl 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/eg/des.pl 2005-12-20 09:54:25 UTC (rev 1707)
@@ -1,9 +1,8 @@
-#!/usr/local/bin/perl
+#!/usr/bin/perl
use lib '../blib/lib';
use Getopt::Std;
-use Crypt::DES;
use Crypt::CBC;
use strict vars;
@@ -28,7 +27,9 @@
my $key = $options{'k'} || get_key();
# DES used by default
-my $cipher = Crypt::CBC->new($key) || die "Couldn't create CBC object";
+my $cipher = Crypt::CBC->new(-key => $key,
+ -cipher=> 'DES',
+ -salt => 1) || die "Couldn't create CBC object";
my $decrypt = $options{'d'} and !$options{'e'};
$cipher->start($decrypt ? 'decrypt' : 'encrypt');
Property changes on: packages/libcrypt-cbc-perl/branches/upstream/current/eg/des.pl
___________________________________________________________________
Name: svn:executable
-
+ *
Modified: packages/libcrypt-cbc-perl/branches/upstream/current/eg/idea.pl
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/eg/idea.pl 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/eg/idea.pl 2005-12-20 09:54:25 UTC (rev 1707)
@@ -1,4 +1,4 @@
-#!/usr/local/bin/perl
+#!/usr/bin/perl
use lib '../blib/lib';
@@ -27,7 +27,10 @@
if $options{'o'};
my $key = $options{'k'} || get_key();
-my $cipher = Crypt::CBC->new($key,'IDEA') || die "Couldn't create CBC object";
+my $cipher = Crypt::CBC->new(-key => $key,
+ -cipher => 'IDEA',
+ -salt => 1,
+ ) || die "Couldn't create CBC object";
my $decrypt = $options{'d'} and !$options{'e'};
$cipher->start($decrypt ? 'decrypt' : 'encrypt');
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/Blowfish.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/Blowfish.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/Blowfish.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -0,0 +1,52 @@
+#!/usr/local/bin/perl
+
+use lib '..','../blib/lib','.','./blib/lib';
+
+eval "use Crypt::Blowfish()";
+if ($@) {
+ print "1..0 # Skipped: Crypt::Blowfish not installed\n";
+ exit;
+}
+
+print "1..33\n";
+
+sub test {
+ local($^W) = 0;
+ my($num, $true,$msg) = @_;
+ print($true ? "ok $num\n" : "not ok $num $msg\n");
+}
+
+$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=>'secret',-cipher=>'Blowfish'),"Couldn't create new object");
+test(3,$c = $i->encrypt($test_data),"Couldn't encrypt");
+test(4,$p = $i->decrypt($c),"Couldn't decrypt");
+test(5,$p eq $test_data,"Decrypted ciphertext doesn't match plaintext");
+
+# now try various truncations of the whole
+for (my $c=1;$c<=7;$c++) {
+ substr($test_data,-$c) = ''; # truncate
+ test(5+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+# now try various short strings
+for (my $c=0;$c<=18;$c++) {
+ $test_data = 'i' x $c;
+ test (13+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+# make sure that strings that end in spaces or nulls are treated correctly
+$test_data = "This string ends in a null\0";
+test (32,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+
+$test_data = "This string ends in some spaces ";
+test (33,$i->decrypt($i->encrypt($test_data)) eq $test_data);
Added: packages/libcrypt-cbc-perl/branches/upstream/current/t/Blowfish_PP.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/Blowfish_PP.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/Blowfish_PP.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -0,0 +1,53 @@
+#!/usr/local/bin/perl
+
+use lib '..','../blib/lib','.','./blib/lib';
+
+eval "use Crypt::Blowfish_PP()";
+if ($@) {
+ print "1..0 # Skipped: Crypt::Blowfish_PP not installed\n";
+ exit;
+}
+
+print "1..33\n";
+
+sub test {
+ local($^W) = 0;
+ my($num, $true,$msg) = @_;
+ print($true ? "ok $num\n" : "not ok $num $msg\n");
+}
+
+$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('secret','Blowfish_PP'),"Couldn't create new object");
+test(3,$c = $i->encrypt($test_data),"Couldn't encrypt");
+test(4,$p = $i->decrypt($c),"Couldn't decrypt");
+test(5,$p eq $test_data,"Decrypted ciphertext doesn't match plaintext");
+
+# now try various truncations of the whole
+for (my $c=1;$c<=7;$c++) {
+ substr($test_data,-$c) = ''; # truncate
+ test(5+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+# now try various short strings
+for (my $c=0;$c<=18;$c++) {
+ $test_data = 'i' x $c;
+ test (13+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+
+# make sure that strings that end in spaces or nulls are treated correctly
+$test_data = "This string ends in a null\0";
+test (32,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+
+$test_data = "This string ends in some spaces ";
+test (33,$i->decrypt($i->encrypt($test_data)) eq $test_data);
Added: packages/libcrypt-cbc-perl/branches/upstream/current/t/CAST5.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/CAST5.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/CAST5.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -0,0 +1,52 @@
+#!/usr/local/bin/perl
+
+use lib '..','../blib/lib','.','./blib/lib';
+
+eval "use Crypt::CAST5()";
+if ($@) {
+ print "1..0 # Skipped: Crypt::CAST5 not installed\n";
+ exit;
+}
+
+print "1..33\n";
+
+sub test {
+ local($^W) = 0;
+ my($num, $true,$msg) = @_;
+ print($true ? "ok $num\n" : "not ok $num $msg\n");
+}
+
+$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=>'secret',cipher=>'CAST5'}),"Couldn't create new object");
+test(3,$c = $i->encrypt($test_data),"Couldn't encrypt");
+test(4,$p = $i->decrypt($c),"Couldn't decrypt");
+test(5,$p eq $test_data,"Decrypted ciphertext doesn't match plaintext");
+
+# now try various truncations of the whole
+for (my $c=1;$c<=7;$c++) {
+ substr($test_data,-$c) = ''; # truncate
+ test(5+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+# now try various short strings
+for (my $c=0;$c<=18;$c++) {
+ $test_data = 'i' x $c;
+ test (13+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+# make sure that strings that end in spaces or nulls are treated correctly
+$test_data = "This string ends in a null\0";
+test (32,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+
+$test_data = "This string ends in some spaces ";
+test (33,$i->decrypt($i->encrypt($test_data)) eq $test_data);
Added: packages/libcrypt-cbc-perl/branches/upstream/current/t/DES.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/DES.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/DES.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -0,0 +1,53 @@
+#!/usr/local/bin/perl
+
+use lib '..','../blib/lib','.','./blib/lib';
+
+eval "use Crypt::DES()";
+if ($@) {
+ print "1..0 # Skipped: Crypt::DES not installed\n";
+ exit;
+}
+
+print "1..33\n";
+
+sub test {
+ local($^W) = 0;
+ my($num, $true,$msg) = @_;
+ print($true ? "ok $num\n" : "not ok $num $msg\n");
+}
+
+$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('secret','DES'),"Couldn't create new object");
+test(3,$c = $i->encrypt($test_data),"Couldn't encrypt");
+test(4,$p = $i->decrypt($c),"Couldn't decrypt");
+test(5,$p eq $test_data,"Decrypted ciphertext doesn't match plaintext");
+
+# now try various truncations of the whole
+for (my $c=1;$c<=7;$c++) {
+ substr($test_data,-$c) = ''; # truncate
+ test(5+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+# now try various short strings
+for (my $c=0;$c<=18;$c++) {
+ $test_data = 'i' x $c;
+ test (13+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+
+# make sure that strings that end in spaces or nulls are treated correctly
+$test_data = "This string ends in a null\0";
+test (32,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+
+$test_data = "This string ends in some spaces ";
+test (33,$i->decrypt($i->encrypt($test_data)) eq $test_data);
Added: packages/libcrypt-cbc-perl/branches/upstream/current/t/IDEA.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/IDEA.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/IDEA.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -0,0 +1,53 @@
+#!/usr/local/bin/perl
+
+use lib '..','../blib/lib','.','./blib/lib';
+
+eval "use Crypt::IDEA()";
+if ($@) {
+ print "1..0 # Skipped: Crypt::IDEA not installed\n";
+ exit;
+}
+
+print "1..33\n";
+
+sub test {
+ local($^W) = 0;
+ my($num, $true,$msg) = @_;
+ print($true ? "ok $num\n" : "not ok $num $msg\n");
+}
+
+$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('secret','IDEA'),"Couldn't create new object");
+test(3,$c = $i->encrypt($test_data),"Couldn't encrypt");
+test(4,$p = $i->decrypt($c),"Couldn't decrypt");
+test(5,$p eq $test_data,"Decrypted ciphertext doesn't match plaintext");
+
+# now try various truncations of the whole
+for (my $c=1;$c<=7;$c++) {
+ substr($test_data,-$c) = ''; # truncate
+ test(5+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+# now try various short strings
+for (my $c=0;$c<=18;$c++) {
+ $test_data = 'i' x $c;
+ test (13+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+
+# make sure that strings that end in spaces or nulls are treated correctly
+$test_data = "This string ends in a null\0";
+test (32,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+
+$test_data = "This string ends in some spaces ";
+test (33,$i->decrypt($i->encrypt($test_data)) eq $test_data);
Added: packages/libcrypt-cbc-perl/branches/upstream/current/t/PCBC.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/PCBC.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/PCBC.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -0,0 +1,57 @@
+#!/usr/local/bin/perl
+
+use lib '..','../blib/lib','.','./blib/lib';
+
+eval "use Crypt::DES()";
+if ($@) {
+ print "1..0 # Skipped: Crypt::DES not installed\n";
+ exit;
+}
+
+print "1..33\n";
+
+sub test {
+ local($^W) = 0;
+ my($num, $true,$msg) = @_;
+ print($true ? "ok $num\n" : "not ok $num $msg\n");
+}
+
+$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=>'secret',
+ -cipher=>'DES',
+ -salt =>1,
+ -pcbc=>1,
+ ),"Couldn't create new object");
+test(3,$c = $i->encrypt($test_data),"Couldn't encrypt");
+test(4,$p = $i->decrypt($c),"Couldn't decrypt");
+test(5,$p eq $test_data,"Decrypted ciphertext doesn't match plaintext");
+
+# now try various truncations of the whole
+for (my $c=1;$c<=7;$c++) {
+ substr($test_data,-$c) = ''; # truncate
+ test(5+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+# now try various short strings
+for (my $c=0;$c<=18;$c++) {
+ $test_data = 'i' x $c;
+ test (13+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+
+# make sure that strings that end in spaces or nulls are treated correctly
+$test_data = "This string ends in a null\0";
+test (32,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+
+$test_data = "This string ends in some spaces ";
+test (33,$i->decrypt($i->encrypt($test_data)) eq $test_data);
Added: packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -0,0 +1,53 @@
+#!/usr/local/bin/perl
+
+use lib '..','../blib/lib','.','./blib/lib';
+
+eval "use Crypt::Rijndael()";
+if ($@) {
+ print "1..0 # Skipped: Crypt::Rijndael not installed\n";
+ exit;
+}
+
+print "1..33\n";
+
+sub test {
+ local($^W) = 0;
+ my($num, $true,$msg) = @_;
+ print($true ? "ok $num\n" : "not ok $num $msg\n");
+}
+
+$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('secret','Rijndael'),"Couldn't create new object");
+test(3,$c = $i->encrypt($test_data),"Couldn't encrypt");
+test(4,$p = $i->decrypt($c),"Couldn't decrypt");
+test(5,$p eq $test_data,"Decrypted ciphertext doesn't match plaintext");
+
+# now try various truncations of the whole
+for (my $c=1;$c<=7;$c++) {
+ substr($test_data,-$c) = ''; # truncate
+ test(5+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+# now try various short strings
+for (my $c=0;$c<=18;$c++) {
+ $test_data = 'i' x $c;
+ test (13+$c,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+}
+
+
+# make sure that strings that end in spaces or nulls are treated correctly
+$test_data = "This string ends in a null\0";
+test (32,$i->decrypt($i->encrypt($test_data)) eq $test_data);
+
+$test_data = "This string ends in some spaces ";
+test (33,$i->decrypt($i->encrypt($test_data)) eq $test_data);
Modified: packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael_compat.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael_compat.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/Rijndael_compat.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -40,13 +40,13 @@
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'
- }),
+test(2,$i = Crypt::CBC->new(-key => 'a' x 16,
+ -cipher => 'Rijndael',
+ -iv => 'f' x 16,
+ -literal_key => 1,
+ -add_header => 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");
Modified: packages/libcrypt-cbc-perl/branches/upstream/current/t/func.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/func.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/func.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -54,10 +54,10 @@
END
;
- test(\$tnum,$i = Crypt::CBC->new({key => 'secret',
- cipher => $mod,
- padding => $pad
- }),
+ 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");
Modified: packages/libcrypt-cbc-perl/branches/upstream/current/t/null_data.t
===================================================================
--- packages/libcrypt-cbc-perl/branches/upstream/current/t/null_data.t 2005-12-19 23:02:48 UTC (rev 1706)
+++ packages/libcrypt-cbc-perl/branches/upstream/current/t/null_data.t 2005-12-20 09:54:25 UTC (rev 1707)
@@ -40,13 +40,12 @@
for my $mod (@in) {
for my $pad (@pads) {
- my $cipher = Crypt::CBC->new({key => 'secret',
- cipher => $mod,
- padding => $pad
- });
+ 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");
More information about the Pkg-perl-cvs-commits
mailing list