Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use ExtUtils::MakeMaker;
use lib 'inc'; # load our bundled version of Devel::CheckLib
use Devel::CheckLib;

my $compiler_available;
BEGIN {
$compiler_available = eval { require Devel::CheckLib; 1 };
}

my %require_mpugmp;
my $have_gmp = check_lib(lib => 'gmp', header => 'gmp.h');
my $have_gmp = $compiler_available && check_lib(lib => 'gmp', header => 'gmp.h');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it got tested; changing from use Devel::CheckLib to require loses the import, so you'd need to add the package in calling the function.

if ($have_gmp) {
warn "\n It looks like you have the GMP C library.\n";
warn " Adding Math::Prime::Util::GMP to dep list.\n\n";
Expand Down Expand Up @@ -63,7 +67,7 @@ WriteMakefile1(
# 1.99 fixes the FastCalc SvUV bug, we work around it.
'Math::BigInt' => '1.88',
'Math::BigFloat' => '1.59',
'Bytes::Random::Secure' => '0.23',
'Bytes::Random::Secure::Tiny' => 0,
# Add in MPU::GMP if we can
%require_mpugmp,
},
Expand Down Expand Up @@ -144,5 +148,11 @@ sub WriteMakefile1 { # Cribbed from eumm-upgrade by Alexandr Ciornii
delete $params{ABSTRACT_FROM} if $] < 5.005;
delete $params{BINARY_LOCATION} if $] < 5.005;

if (!$compiler_available) {
$params{'OBJECT'} = q<>;
delete $params{'PREREQ_PM'}{'XSLoader'};
$params{'C'} = [];
}

WriteMakefile(%params);
}
23 changes: 17 additions & 6 deletions lib/Math/Prime/Util/RandomPrimes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ sub _set_randf {
return if defined $_RANDF;

if (!defined $_IRANDF) { # Default irand: BRS nonblocking
require Bytes::Random::Secure;
$_BRS = Bytes::Random::Secure->new(NonBlocking=>1) unless defined $_BRS;
$_BRS ||= _BRS();
$_RANDF_NBIT = sub {
my($bits) = int("$_[0]");
return 0 if $bits <= 0;
Expand Down Expand Up @@ -868,10 +867,7 @@ sub random_shawe_taylor_prime_with_cert {
my $seed;
my $irandf = prime_get_config->{'irand'};
if (!defined $irandf) {
if (!defined $_BRS) {
require Bytes::Random::Secure;
$_BRS = Bytes::Random::Secure->new(NonBlocking=>1);
}
$_BRS ||= _BRS();
$seed = $_BRS->bytes(512/8);
} else {
$seed = pack("L*", map { $irandf->() } 0 .. (512>>5));
Expand Down Expand Up @@ -1088,6 +1084,21 @@ sub miller_rabin_random {
1;
}

my @BRS_CLASSES = qw(
Bytes::Random::Secure
Bytes::Random::Secure::Tiny
);

sub _BRS {
local $@;

for my $class ( @BRS_CLASSES ) {
if ( eval "require $class" ) {
return $_BRS = $class->new( NonBlocking => 1 );
}
}
}

1;

__END__
Expand Down