[libmath-prime-util-perl] 06/40: Add F-U compositeness test, and tighted ECPP certificate conditions
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:49:02 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.30
in repository libmath-prime-util-perl.
commit 6281c5a822ddb22b509004672783a994ff8dba41
Author: Dana Jacobsen <dana at acm.org>
Date: Mon Jun 24 08:31:57 2013 -0700
Add F-U compositeness test, and tighted ECPP certificate conditions
---
Changes | 7 +++++++
lib/Math/Prime/Util.pm | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
mulmod.h | 5 +++--
3 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/Changes b/Changes
index 1891e0f..200f32f 100644
--- a/Changes
+++ b/Changes
@@ -5,6 +5,13 @@ Revision history for Perl extension Math::Prime::Util.
- Fixed a rare refcount / bignum / callback issue.
+ - Small mulmod speedup for non-gcc/x86_64 platforms.
+
+ - Add more conditions to ECPP block verification.
+
+ - Added:
+ is_frobenius_underwood_pseudoprime
+
0.29 30 May 2013
- Fix a signed vs. unsigned char issue in ranged moebius. Thanks to the
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index a0d42ca..c78f1fa 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -19,6 +19,7 @@ our @EXPORT_OK =
prime_certificate verify_prime
is_pseudoprime is_strong_pseudoprime is_lucas_pseudoprime
is_strong_lucas_pseudoprime is_extra_strong_lucas_pseudoprime
+ is_frobenius_underwood_pseudoprime
is_aks_prime
miller_rabin
primes
@@ -1627,6 +1628,17 @@ sub is_extra_strong_lucas_pseudoprime {
return Math::Prime::Util::PP::is_extra_strong_lucas_pseudoprime($n);
}
+sub is_frobenius_underwood_pseudoprime {
+ my($n) = shift;
+ _validate_num($n) || _validate_positive_integer($n);
+ return _XS_is_frobenius_underwood_pseudoprime($n)
+ if ref($n) ne 'Math::BigInt' && $n <= $_XS_MAXVAL;
+ return Math::Prime::Util::GMP::is_frobenius_underwood_pseudoprime("$n")
+ if $_HAVE_GMP
+ && defined &Math::Prime::Util::GMP::is_frobenius_underwood_pseudoprime;
+ return Math::Prime::Util::PP::is_frobenius_underwood_pseudoprime($n);
+}
+
sub miller_rabin {
#warn "miller_rabin() is deprecated. Use is_strong_pseudoprime instead.";
return is_strong_pseudoprime(@_);
@@ -2016,6 +2028,10 @@ sub verify_prime {
$q = $n->copy->bzero->badd("$q") unless ref($q) eq 'Math::BigInt';
$Px = $n->copy->bzero->badd("$Px") unless ref($Px) eq 'Math::BigInt';
$Py = $n->copy->bzero->badd("$Py") unless ref($Py) eq 'Math::BigInt';
+ if ( $ni <= 0 ) {
+ print "primality fail: AGKM block n is 0 or negative\n" if $verbose;
+ return 0;
+ }
if (Math::BigInt::bgcd($ni, 6) != 1) {
print "primality fail: AGKM block n '$ni' is divisible by 2 or 3\n" if $verbose;
return 0;
@@ -2025,6 +2041,26 @@ sub verify_prime {
print "primality fail: AGKM block gcd 4a^3+27b^2,n incorrect\n" if $verbose;
return 0;
}
+ if ( ($Py*$Py % $ni) != (($Px*$Px*$Px + $a*$Px + $b) % $ni) ) {
+ print "primality fail: AGKM block y^2 != x^3 + ax + b\n" if $verbose;
+ return 0;
+ }
+ if ( $m < ($ni - 2*$ni->copy->bsqrt + 1)) {
+ print "primality fail: AGKM block m too small\n" if $verbose;
+ return 0;
+ }
+ if ( $m > ($ni + 2*$ni->copy->bsqrt + 1)) {
+ print "primality fail: AGKM block m too large\n" if $verbose;
+ return 0;
+ }
+ if ( $q > $ni || $q <= 0 ) {
+ print "primality fail: AGKM block q invalid\n" if $verbose;
+ return 0;
+ }
+ if ( ($m == $q) || ($m % $q) != 0 ) {
+ print "primality fail: AGKM block m is not a multiple of q\n" if $verbose;
+ return 0;
+ }
if ($q <= $ni->copy->broot(4)->badd(1)->bpow(2)) {
print "primality fail: AGKM block q is too small\n" if $verbose;
return 0;
@@ -2959,6 +2995,15 @@ but uses different starting parameters so is not directly comparable.
Removing primes, this produces the sequence
L<OEIS A217719|http://oeis.org/A217719>.
+=head2 is_frobenius_underwood_pseudoprime
+
+Takes a positive number as input, and returns 1 if the input passes the minimal
+lambda+2 test (see Underwood 2012 "Quadratic Compositeness Tests"), where
+C<(L+2)^(n-1) = 5 + 2x mod (n, L^2 - Lx + 1)>. The computational cost for this
+is between the cost of 2 and 3 strong pseudoprime tests. There are no known
+counterexamples, but this is not a well studied test.
+
+
=head2 is_prob_prime
@@ -3114,8 +3159,14 @@ A certificate is an array holding an C<n-cert>. An C<n-cert> is one of:
- the final q can be proved with BPSW.
- for each block:
- N is the same as the preceding block's q
+ - N >= 0
- N is not divisible by 2 or 3
- gcd( 4a^3 + 27b^2, N ) == 1;
+ - Py^2 = Px^3 + a*Px + b mod N
+ - m >= (N - 2*sqrt(N) + 1)
+ - m <= (N + 2*sqrt(N) + 1)
+ - q >= 0 and q <= n
+ - m != q and (m % q) == 0
- q > (N^1/4+1)^2
- U = (m/q)P is not the point at infinity
- V = qU is the point at infinity
diff --git a/mulmod.h b/mulmod.h
index 55f1526..d44d58b 100644
--- a/mulmod.h
+++ b/mulmod.h
@@ -63,8 +63,9 @@
/* Do it by hand */
static INLINE UV _mulmod(UV a, UV b, UV m) {
UV r = 0;
- a %= m; /* These are wasteful given that careful attention from the */
- b %= m; /* caller should make them unnecessary. */
+ if (a >= m) a %= m; /* Careful attention from the caller should make */
+ if (b >= m) b %= m; /* these unnecessary. */
+ if (a < b) { UV t = a; a = b; b = t; }
while (b > 0) {
if (b & 1) r = ((m-r) > a) ? r+a : r+a-m; /* r = (r + a) % m */
b >>= 1;
--
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