Commit 41c4bcef authored by Andreas Enge's avatar Andreas Enge
Browse files

Add an optional primality test before starting ECPP.

* lib/cm.h (cm_ecpp): Add a boolean parameter trust.
* lib/ecpp.c (cm_ecpp): Add parameter trust and call to primality test.
* src/params.h (evaluate_parameters_ecpp): Add parameter trust.
* src/params.c (print_t_options): New function.
  (print_help_ecpp): Call new function.
  (evaluate_parameters_ecpp): Add and handle parameter.
* src/ecpp (main), src/ecpp-mpi.c (main), tests/tecpp.c (test_ecpp):
  Adapt function calls.
* NEWS: Document the change.
* doc/cm.texi: Document the changes and drop the description of a
  parameter that has not been present for a while.
parent a446b199
......@@ -8,6 +8,8 @@ Changes in version 0.4.1 ("Fitzebohnen"):
memory in the MPI version.
- When ECPP certificates are output to a file, a second file in Primo
format is created automatically.
- ECPP certificate creation uses class field towers unconditionally.
- An optional primality test is carried out before starting ECPP.
Changes in version 0.4 ("Fitzebohnen"):
- increase minimal version number for mpfrcx to 0.6.3 and for
......
......@@ -632,7 +632,7 @@ implements the asymptotically fast version fastECPP of
Certificates are computed and printed in a format compatible with
PARI/GP.
@deftypefun void cm_ecpp (mpz_t @var{N}, const char* @var{modpoldir}, bool @var{pari}, bool @var{print}, bool @var{check}, bool @var{verbose}, bool @var{debug})
@deftypefun void cm_ecpp (mpz_t @var{N}, const char* @var{modpoldir}, bool @var{print}, bool @var{trust}, bool @var{check}, bool @var{verbose}, bool @var{debug})
Given a prime number @var{N}, the function computes an ECPP certificate
and prints it to screen if @var{print} is set to @code{true}.
If @var{check} is set to @code{true}, then the certificate is checked;
......@@ -641,11 +641,8 @@ The directory @var{modpoldir}, usually @code{/usr/local/share/cm}, in which
modular polynomials are stored, is required to be passed to
@code{cm_curve_and_point}.
If set to @code{true}, the argument @var{pari} indicates that the first
step of the algorithm, instead of being executed with code of the CM
library, is to be taken from a separate implementation copied from
PARI/GP version 2.11. This is obsolete and only useful for comparison
purposes; @code{false} should be used instead.
If @var{trust} is set to @code{true}, then the input number is trusted to
be pseudoprime; otherwise a quick primality test is run.
If @var{verbose} is set to @code{true}, some information is printed on
screen during execution.
......@@ -868,6 +865,13 @@ computes and checks an ECPP certificate for the first prime with
1001 digits and stores it into the file @code{cert-1000}, while
outputting debug information on screen.
By default, the code carries out a quick (as opposed to thorough)
primality test, which is meant to catch typos and obvious errors.
If the number is trusted to be pseudoprime since this has been tested
independently, the command line switch @code{-t} can be added to drop
this test.
@node References
@unnumbered References
......
......@@ -314,8 +314,8 @@ extern void cm_curve_and_point (mpz_ptr a, mpz_ptr b, mpz_ptr x, mpz_ptr y,
const char* modpoldir, bool print, bool verbose);
/* functions for ECPP */
extern bool cm_ecpp (mpz_srcptr N, const char* modpoldir,
bool print, char *filename, bool check, bool verbose, bool debug);
extern bool cm_ecpp (mpz_srcptr N, const char* modpoldir, bool print,
char *filename, bool trust, bool check, bool verbose, bool debug);
/* functions for MPI */
void cm_mpi_init (bool debug);
......
......@@ -1626,8 +1626,8 @@ static void ecpp2 (mpz_t **cert2, mpz_t **cert1, int depth, char *filename,
/*****************************************************************************/
bool cm_ecpp (mpz_srcptr N, const char* modpoldir,
bool print, char *filename, bool check, bool verbose, bool debug)
bool cm_ecpp (mpz_srcptr N, const char* modpoldir, bool print,
char *filename, bool trust, bool check, bool verbose, bool debug)
/* Assuming that N is a (probable) prime, compute an ECPP certificate.
modpoldir gives the directory where modular polynomials are stored;
it is passed through to the function computing a curve from a root
......@@ -1635,6 +1635,8 @@ bool cm_ecpp (mpz_srcptr N, const char* modpoldir,
If filename is different from NULL, the final ECPP certificate is
output to the file, and the stage 1 and stage 2 certificates are
read from (partially) and written to temporary files.
If trust is set to true, then N is trusted to be a probable prime;
otherwise a quick primality test is run.
print indicates whether the result is printed to stdout.
check indicates whether the certificate should be checked.
If yes, the return value of the function is the result of the check;
......@@ -1656,6 +1658,20 @@ bool cm_ecpp (mpz_srcptr N, const char* modpoldir,
double t;
FILE *f;
if (!trust) {
cm_timer_start (clock);
if (!mpz_probab_prime_p (N, 1)) {
printf ("***** Error: cm_ecpp called with composite number.\n");
exit (1);
}
else {
cm_timer_stop (clock);
if (verbose)
printf ("--- Time for primality test: %.1f (%.1f)\n",
cm_timer_get (clock), cm_timer_wc_get (clock));
}
}
if (filename != NULL) {
i = strlen (filename) + 7;
filename1 = (char *) malloc (i * sizeof (char));
......
......@@ -33,17 +33,13 @@ int main (int argc, char* argv [])
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
if (rank == 0) {
mpz_t n;
bool print, verbose, debug, check;
bool print, verbose, debug, trust, check;
char *filename;
mpz_init (n);
evaluate_parameters_ecpp (argc, argv, n, &print, &filename,
&verbose, &debug, &check);
cm_ecpp (n, CM_MODPOLDIR,
print /* print */,
filename /* filename */,
check /* check */,
verbose /* verbose */,
debug /* debug */);
&verbose, &debug, &trust, &check);
cm_ecpp (n, CM_MODPOLDIR, print, filename, trust, check, verbose,
debug);
mpz_clear (n);
}
cm_mpi_clear ();
......
......@@ -26,20 +26,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int main (int argc, char* argv [])
{
mpz_t n;
bool print, verbose, debug, check;
bool print, verbose, debug, trust, check;
char *filename;
mpz_init (n);
cm_pari_init ();
evaluate_parameters_ecpp (argc, argv, n, &print, &filename, &verbose,
&debug, &check);
cm_ecpp (n, CM_MODPOLDIR,
print /* print */,
filename /* filename */,
check /* check */,
verbose /* verbose */,
debug /* debug */);
&debug, &trust, &check);
cm_ecpp (n, CM_MODPOLDIR, print, filename, trust, check, verbose, debug);
cm_pari_clear ();
mpz_clear (n);
......
......@@ -33,6 +33,7 @@ static void print_p_options (void);
static void print_f_options (void);
static void print_g_options (void);
static void print_c_options (void);
static void print_t_options (void);
static void print_help (void);
static void print_help_ecpp (void);
static void print_libraries (void);
......@@ -95,6 +96,14 @@ static void print_g_options (void)
/*****************************************************************************/
static void print_t_options (void)
{
printf ("-t trusts the number to be prime and disables the initial "
"primality test.\n");
}
/*****************************************************************************/
static void print_c_options (void)
{
printf ("-c enables checking of the certificate.\n");
......@@ -117,13 +126,14 @@ static void print_help (void)
static void print_help_ecpp (void)
{
printf ("The following options are recognised: "
"'-n', '-p', '-f', '-v', '-g', '-c', '-h'.\n"
"'-n', '-p', '-f', '-v', '-g', '-t', '-c', '-h'.\n"
"-h prints this help.\n");
print_n_options ();
print_p_options ();
print_f_options ();
print_v_options ();
print_g_options ();
print_t_options ();
print_c_options ();
}
......@@ -238,7 +248,8 @@ void evaluate_parameters (int argc, char* argv [], int_cl_t *d,
/*****************************************************************************/
void evaluate_parameters_ecpp (int argc, char* argv [], mpz_ptr n,
bool *print, char **filename, bool *verbose, bool *debug, bool *check)
bool *print, char **filename, bool *verbose, bool *debug,
bool *trust, bool *check)
/* Since ECPP requires different parameter types, the easiest solution
appears to be a separate function, albeit with a lot of copy and
paste. */
......@@ -250,9 +261,10 @@ void evaluate_parameters_ecpp (int argc, char* argv [], mpz_ptr n,
*verbose = false;
*debug = false;
*check = false;
*trust = false;
*filename = NULL;
while ((opt = getopt (argc, argv, "hn:pf:gvc")) != -1) {
while ((opt = getopt (argc, argv, "hn:pf:gvtc")) != -1) {
switch (opt) {
case 'v':
*verbose = true;
......@@ -264,6 +276,9 @@ void evaluate_parameters_ecpp (int argc, char* argv [], mpz_ptr n,
*verbose = true;
*debug = true;
break;
case 't':
*trust = true;
break;
case 'c':
*check = true;
break;
......
......@@ -2,7 +2,7 @@
params.h - header file for params.c
Copyright (C) 2009, 2010, 2015, 2021 Andreas Enge
Copyright (C) 2009, 2010, 2015, 2021, 2022 Andreas Enge
This file is part of CM.
......@@ -37,7 +37,7 @@ extern void evaluate_parameters (int argc, char* argv [], int_cl_t *d,
char *invariant, bool *verbose);
extern void evaluate_parameters_ecpp (int argc, char* argv [],
mpz_ptr n, bool *output, char** filename, bool *verbose, bool *debug,
bool *check);
bool *trust, bool *check);
#if defined (__cplusplus)
}
......
......@@ -33,6 +33,7 @@ static void test_ecpp (mpz_srcptr n)
res = cm_ecpp (n, CM_MODPOLDIR,
false /* print */,
NULL /* filename */,
true /* trust */,
true /* check */,
false /* verbose */,
false /* debug */);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment