(needs careful review)

Attempt to improve performance.

Previous implementation happened to be very slow (on my laptop it took 5
minutes to read small pwsafe file and save it back). I profiled the code
and it turned out, this cost was totally dominated by the
Crypt::PWSafe3::random function (which on every call accesses system
random seed).

I replaced it with Bytes::Random::Secure which seeds using OS crypto but
afterwards uses embedded generator. Performance improvement is drastical,
the same read&save takes about half a second on the same laptop.
This commit is contained in:
Marcin Kasperski
2012-11-18 00:46:34 +01:00
parent aacfeeb474
commit 3bbb724b08
2 changed files with 12 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ WriteMakefile(
'Crypt::Random' => 1.25,
'Data::UUID' => 1.217,
'Shell' => 0.5,
'Bytes::Random::Secure' => 0.09,
},
'AUTHOR' => 'Thomas Linden <tlinden@cpan.org>',
'clean' => {

View File

@@ -621,12 +621,19 @@ sub writebytes {
}
}
# This is original, very slow random
#sub random {
# #
# # helper, return some secure random bytes
# my($this, $len) = @_;
# my $bits = makerandom(Size => 256, Strength => 1);
# return substr($bits, 0, $len);
#}
use Bytes::Random::Secure qw(random_bytes random_bytes_hex);
sub random {
#
# helper, return some secure random bytes
my($this, $len) = @_;
my $bits = makerandom(Size => 256, Strength => 1);
return substr($bits, 0, $len);
return random_bytes($len);
}
sub getheader {