mirror of
https://codeberg.org/scip/Crypt--PWSafe3.git
synced 2025-12-16 20:21:01 +01:00
(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:
@@ -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' => {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user