[svn] gcry - r1125 - branches/LIBGCRYPT-2.0-MO/src/subsystems/prime
svn author mo
cvs at cvs.gnupg.org
Sun Oct 9 16:00:54 CEST 2005
Author: mo
Date: 2005-10-09 16:00:53 +0200 (Sun, 09 Oct 2005)
New Revision: 1125
Modified:
branches/LIBGCRYPT-2.0-MO/src/subsystems/prime/ChangeLog
branches/LIBGCRYPT-2.0-MO/src/subsystems/prime/core.c
Log:
prime/ChangeLog:
2005-10-09 Moritz Schulte <moritz at g10code.com>
Merged changes made by Werner to trunk from 2005-08-22:
* core.c (check_prime): New arg RM_ROUNDS.
(prime_generate_internal): Call it here with 5 rounds as used
before.
(_gcry_prime_check): But here with 64 rounds.
(is_prime): Make sure never to use less than 5 rounds.
Modified: branches/LIBGCRYPT-2.0-MO/src/subsystems/prime/ChangeLog
===================================================================
--- branches/LIBGCRYPT-2.0-MO/src/subsystems/prime/ChangeLog 2005-10-09 13:32:35 UTC (rev 1124)
+++ branches/LIBGCRYPT-2.0-MO/src/subsystems/prime/ChangeLog 2005-10-09 14:00:53 UTC (rev 1125)
@@ -1,3 +1,12 @@
+2005-10-09 Moritz Schulte <moritz at g10code.com>
+
+ Merged changes made by Werner to trunk from 2005-08-22:
+ * core.c (check_prime): New arg RM_ROUNDS.
+ (prime_generate_internal): Call it here with 5 rounds as used
+ before.
+ (_gcry_prime_check): But here with 64 rounds.
+ (is_prime): Make sure never to use less than 5 rounds.
+
2005-09-23 Moritz Schulte <moritz at g10code.com>
Reorganized source tree.
@@ -2,3 +11,3 @@
- New file: core.c (based on former file cipher/prime.c).
+ New file: core.c (based on former file cipher/primegen.c).
New files: gcrypt-prime-common.h, gcrypt-prime.h,
Modified: branches/LIBGCRYPT-2.0-MO/src/subsystems/prime/core.c
===================================================================
--- branches/LIBGCRYPT-2.0-MO/src/subsystems/prime/core.c 2005-10-09 13:32:35 UTC (rev 1124)
+++ branches/LIBGCRYPT-2.0-MO/src/subsystems/prime/core.c 2005-10-09 14:00:53 UTC (rev 1125)
@@ -39,7 +39,8 @@
void *extra_check_arg);
static int check_prime (gcry_core_context_t ctx,
gcry_core_mpi_t prime, gcry_core_mpi_t val_2,
- gcry_prime_check_func_t cb_func, void *cb_arg);
+ int rm_rounds, gcry_prime_check_func_t cb_func,
+ void *cb_arg);
static int is_prime (gcry_core_context_t ctx, gcry_core_mpi_t n, int steps, int *count);
static void m_out_of_n (gcry_core_context_t ctx, char *array, int m, int n);
@@ -359,9 +360,8 @@
else
count2 = 0;
}
- while (!
- ((nprime == pbits)
- && check_prime (ctx, prime, val_2, cb_func, cb_arg)));
+ while (! ((nprime == pbits)
+ && check_prime (ctx, prime, val_2, 5, cb_func, cb_arg)));
if (GCRY_CORE_DEBUGGING_PRIME (ctx))
{
@@ -636,11 +636,12 @@
/****************
* Returns: true if this may be a prime
+ * RM_ROUNDS gives the number of Rabin-Miller tests to run.
*/
static int
check_prime (gcry_core_context_t ctx,
gcry_core_mpi_t prime, gcry_core_mpi_t val_2,
- gcry_prime_check_func_t cb_func, void *cb_arg)
+ int rm_rounds, gcry_prime_check_func_t cb_func, void *cb_arg)
{
int count = 0;
@@ -680,7 +681,7 @@
if (!cb_func || cb_func (cb_arg, GCRY_PRIME_CHECK_AT_MAYBE_PRIME, prime))
{
/* Perform stronger tests. */
- if (is_prime (ctx, prime, 5, &count))
+ if (is_prime (ctx, prime, rm_rounds, &count))
{
if (!cb_func
|| cb_func (cb_arg, GCRY_PRIME_CHECK_AT_GOT_PRIME, prime))
@@ -708,6 +709,9 @@
int rc = 0;
unsigned nbits = gcry_core_mpi_get_nbits (ctx, n);
+ if (steps < 5) /* Make sure that we do at least 5 rounds. */
+ steps = 5;
+
gcry_core_mpi_sub_ui (ctx, nminus1, n, 1);
/* Find q and k, so that n = 1 + 2^k * q . */
@@ -945,7 +949,9 @@
gcry_error_t err = 0;
gcry_core_mpi_t val_2 = gcry_core_mpi_alloc_set_ui (ctx, 2); /* Used by the Fermat test. */
- if (!check_prime (ctx, x, val_2, NULL, NULL))
+ /* We use 64 rounds because the prime we are going to test is not
+ guaranteed to be a random one. */
+ if (! check_prime (ctx, x, val_2, 64, NULL, NULL))
err = gcry_core_error (GPG_ERR_NO_PRIME);
gcry_core_mpi_release (ctx, val_2);
More information about the Gnupg-commits
mailing list