[libmath-prime-util-perl] 04/72: Turn off F&T A2, need to make sure top bit is set
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:49:35 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.32
in repository libmath-prime-util-perl.
commit 7791b3cf4303fd3c1038d7a2c7b70674f4b58d68
Author: Dana Jacobsen <dana at acm.org>
Date: Wed Aug 14 00:59:11 2013 -0700
Turn off F&T A2, need to make sure top bit is set
---
lib/Math/Prime/Util.pm | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 621f42d..c24f73f 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -838,7 +838,8 @@ sub primes {
_validate_num($bits, 2) || _validate_positive_integer($bits, 2);
# Fouque and Tobouchi (2011) Algorithm 2
- if (1 && $bits > 256) {
+ # TODO: Make sure the top bit is set.
+ if (0 && $bits > 256) {
if (!defined $Math::BigInt::VERSION) {
eval { require Math::BigInt; Math::BigInt->import(try=>'GMP,Pari'); 1; }
or do { croak "Cannot load Math::BigInt"; };
@@ -851,12 +852,13 @@ sub primes {
my $target = $bits - $_Config{'maxbits'};
my $beta = 2;
$m = Math::BigInt->new(2);
+ $lambda = Math::BigInt->bone;
while ($m->copy->blog(2)->badd(1) <= $target) {
$beta = next_prime($beta);
$m *= $beta;
+ $lambda = Math::BigInt::blcm($lambda, $beta-1);
}
- # Calculate Carmichael Lambda (used to create b) and arange.
- $lambda = Math::BigInt::blcm( map { $_-1 } @{primes(3, $beta)} );
+ # Lambda should now equal carmichael_lambda($m)
$arange = Math::BigInt->new(2)->bpow($bits)->bdiv($m)->bsub(1);
my $arange_bits = $arange->copy->blog(2)->badd(1);
die "Incorrect arange" if $arange_bits > $_Config{'maxbits'};
@@ -878,7 +880,8 @@ sub primes {
my $loop_limit = 1_000_000;
while ($loop_limit-- > 0) {
my $a = $irandf->($arange);
- my $p = $m * $a + $b;
+ # Without wrapping $a like this, Math::BigInt::GMP will segfault.
+ my $p = $m * Math::BigInt->new("$a") + $b;
if ($_HAVE_GMP) {
next unless Math::Prime::Util::GMP::is_prime($p);
} else {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git
More information about the Pkg-perl-cvs-commits
mailing list