Crypt-PWSafe3

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "ExtUtils::MakeMaker" : "0"
         }
      },
      "configure" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "Crypt::CBC" : "2.3",
            "Crypt::ECB" : "1.45",
            "Crypt::Random" : "1.25",
            "Crypt::Twofish" : "2.14",
            "Data::UUID" : "1.217",
            "Digest::HMAC" : "1",
            "Digest::SHA" : "1",
            "File::Temp" : "0",
            "Shell" : "0.5"
         }
      }

META.yml  view on Meta::CPAN

license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: Crypt-PWSafe3
no_index:
  directory:
    - t
    - inc
requires:
  Crypt::CBC: '2.3'
  Crypt::ECB: '1.45'
  Crypt::Random: '1.25'
  Crypt::Twofish: '2.14'
  Data::UUID: '1.217'
  Digest::HMAC: '1'
  Digest::SHA: '1'
  File::Temp: '0'
  Shell: '0.5'
resources:
  bugtracker: http://github.com/tlinden/Crypt--PWSafe3

Makefile.PL  view on Meta::CPAN

    warn("Optional module $module not installed, $optional{$module}\n");
  }
}


my %params = (
	      'NAME'         => 'Crypt::PWSafe3',
	      'VERSION_FROM' => 'lib/Crypt/PWSafe3.pm',
	      'PREREQ_PM'    => { 'Digest::HMAC'   => 1.00,
				  'Digest::SHA'    => 1.00,
				  'Crypt::CBC'     => 2.30,
				  'Crypt::ECB'     => 1.45,
				  'Crypt::Twofish' => 2.14,
				  'Crypt::Random'  => 1.25,
				  'Data::UUID'     => 1.217,
				  'Shell'          => 0.5,
				  'File::Temp'     => 0,
				},
	      'AUTHOR'       => 'T.v.Dein <tlinden@cpan.org>',
	      'clean'        => {
				 FILES                   => 't/*.out *~ */*~ */*/*~ */*/*/*~'

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


package Crypt::PWSafe3;

use strict;

use Config;

use Carp::Heavy;
use Carp;

use Crypt::CBC;
use Crypt::ECB;
use Crypt::Twofish;
use Digest::HMAC;
use Digest::SHA;
use Crypt::Random qw( makerandom );
use Data::UUID;
use File::Copy qw(copy move);
use File::Temp;
use File::Spec;
use FileHandle;

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


  # create key k + l
  $this->keyk( $crypt->decrypt( $this->b1() ) . $crypt->decrypt( $this->b2() ));
  $this->keyl( $crypt->decrypt( $this->b3() ) . $crypt->decrypt( $this->b4() ));

  # create IV
  $this->iv( $this->random(16) );

  # create hmac'er and cipher for actual encryption
  $this->{hmacer} = Digest::HMAC->new($this->keyl, "Crypt::PWSafe3::SHA256");
  $this->{cipher} = Crypt::CBC->new(
				    -key    => $this->keyk,
				    -iv     => $this->iv,
				    -cipher => 'Twofish',
				    -header => 'none',
				    -padding => 'null',
				    -literal_key => 1,
				    -keysize => 32,
				    -blocksize => 16
				   );

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

  $crypt->cipher('Twofish') || die $crypt->errstring;
  $crypt->key( $this->strechedpw() );

  $this->keyk($crypt->decrypt($this->b1) . $crypt->decrypt($this->b2));
  $this->keyl($crypt->decrypt($this->b3) . $crypt->decrypt($this->b4));

  $this->iv( $this->readbytes(16) );

  # create hmac'er and cipher for actual encryption
  $this->{hmacer} = Digest::HMAC->new($this->keyl, "Crypt::PWSafe3::SHA256");
  $this->{cipher} = Crypt::CBC->new(
				   -key    => $this->keyk,
				   -iv     => $this->iv,
				   -cipher => 'Twofish',
				   -header => 'none',
				   -padding => 'null',
				   -literal_key => 1,
				   -keysize => 32,
				   -blocksize => 16
				  );

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

  $crypt->padding('none');
  $crypt->cipher('Twofish');
  $crypt->key( $this->strechedpw() );

  $this->keyk($crypt->decrypt($this->b1) . $crypt->decrypt($this->b2));
  $this->keyl($crypt->decrypt($this->b3) . $crypt->decrypt($this->b4));

  $this->writebytes($this->iv);

  $this->{hmacer} = Digest::HMAC->new($this->keyl, "Crypt::PWSafe3::SHA256");
  $this->{cipher} = Crypt::CBC->new(
				   -key    => $this->keyk,
				   -iv     => $this->iv,
				   -cipher => 'Twofish',
				   -header => 'none',
				   -padding => 'null',
				   -literal_key => 1,
				   -keysize => 32,
				   -blocksize => 16
				  );

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

  return $clear;
}

sub encrypt {
  #
  # helper, encrypt a string
  my ($this, $data) = @_;
  my $raw = $this->{cipher}->encrypt($data);
  if (length($raw) > 16) {
    # we use only the last 16byte block as next iv
    # if data is more than 1 blocks then Crypt::CBC
    # has already updated the iv for the inner blocks
    $raw = substr($raw, -16, 16);
  }
  $this->{cipher}->iv($raw);
  return $raw;
}

sub hmacer {
  #
  # helper, hmac generator

lib/Crypt/PWSafe3/Databaseformat.pm  view on Meta::CPAN

plaintext encrypted with the passphrase-derived key that allows an
attacker to mount an attack that bypasses the key stretching
algorithm.)

2.7 B3 and B4 are two 128-bit blocks encrypted with Twofish using P' as the
key, in ECB mode. These blocks contain the 256 bit random key L that is
used to calculate the HMAC (keyed-hash message authentication code) of the
encrypted data. See description of EOF field below for more details.
Implementation Note: K and L must NOT be related.

2.8 IV is the 128-bit random Initial Value for CBC mode.

2.9 All following records are encrypted using Twofish in CBC mode, with K
as the encryption key.

2.9.1 HDR: The database header. The header consists of one or more typed
fields (as defined in section 3.2), terminated by the 'END' type field. The
version number field is mandatory. Aside from the 'END' field, no
order is assumed on the field types.

2.9.2 R1..Rn: The actual database records. Each record consists of one or
more typed fields (as defined in Section 3.2), terminated by the 'END' type
field. The UUID, Title, and Password fields are mandatory. All non-



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