Mentions légales du service

Skip to content
Snippets Groups Projects

Simplify get_curve_from_param[13] with mpz_invert

Merged Seth Troisi requested to merge param_cleanup into master
2 unresolved threads
1 file
+ 14
30
Compare changes
  • Side-by-side
  • Inline
+ 14
30
@@ -232,7+232,7 @@
@@ -232,7+232,7 @@
/* Parametrization ECM_PARAM_BATCH_SQUARE */
/* Parametrization ECM_PARAM_BATCH_SQUARE */
/* Only work for 64-bit machines */
/* Only work for 64-bit machines */
/* d = (sigma^2/2^64 mod N) should be different from 0, 1, -1/8 */
/* d = (sigma^2/2^64 mod N) should be different from 0, 1, -1/8 */
int
int
get_curve_from_param1 (mpres_t A, mpres_t x0, mpz_t sigma, mpmod_t n)
get_curve_from_param1 (mpres_t A, mpres_t x0, mpz_t sigma, mpmod_t n)
{
{
@@ -242,7+242,7 @@
@@ -242,7+242,7 @@
ASSERT (GMP_NUMB_BITS == 64);
ASSERT (GMP_NUMB_BITS == 64);
mpz_mul (tmp, sigma, sigma); /* tmp = sigma^2*/
/* A=4*d-2 with d = sigma^2/2^64 */
/* Compute d = sigma^2/2^64 */
/* A=4*d-2 with d = sigma^2/2^GMP_NUMB_BITS*/
mpz_ui_pow_ui(tmp, 2, 64);
/* Compute d = sigma^2/2^GMP_NUMB_BITS */
mpz_invert(tmp, tmp, n->orig_modulus);
for (i = 0; i < GMP_NUMB_BITS; i++)
{
/* tmp = sigma^2/2^64 */
if (mpz_tstbit (tmp, 0) == 1)
mpz_mul (tmp, tmp, sigma);
mpz_add (tmp, tmp, n->orig_modulus);
mpz_mul (tmp, tmp, sigma);
mpz_div_2exp (tmp, tmp, 1);
}
mpz_mod (tmp, tmp, n->orig_modulus);
mpz_mod (tmp, tmp, n->orig_modulus);
/* TODO add d!=-1/8*/
/* TODO add d!=-1/8*/
@@ -389,28 +387,15 @@ get_curve_from_param3 (mpres_t A, mpres_t x0, mpz_t sigma, mpmod_t n)
@@ -389,28 +387,15 @@ get_curve_from_param3 (mpres_t A, mpres_t x0, mpz_t sigma, mpmod_t n)
{
{
int i;
int i;
mpz_t tmp;
mpz_t tmp;
mpz_t two32;
mpz_init (two32);
mpz_ui_pow_ui (two32, 2, 32);
mpz_init (tmp);
mpz_init (tmp);
/* sigma < 2^32 (it was generated for 32-bit machines) */
/* A=4*d-2 with d = sigma/2^32*/
/* To use it on a 64-bits machines one should multiplied it by 2^32 */
/* Compute d = sigma/2^32 */
if (GMP_NUMB_BITS == 64)
mpz_ui_pow_ui (tmp, 2, 32);
mpz_mul (tmp, sigma, two32);
mpz_invert (tmp, tmp, n->orig_modulus);
else
mpz_mul (tmp, sigma, tmp);
mpz_set (tmp, sigma);
/* A=4*d-2 with d = sigma/2^GMP_NUMB_BITS*/
/* Compute d = sigma/2^GMP_NUMB_BITS */
for (i = 0; i < GMP_NUMB_BITS; i++)
{
if (mpz_tstbit (tmp, 0) == 1)
mpz_add (tmp, tmp, n->orig_modulus);
mpz_div_2exp (tmp, tmp, 1);
}
mpz_mod (tmp, tmp, n->orig_modulus);
mpz_mod (tmp, tmp, n->orig_modulus);
 
/* TODO add d!=-1/8*/
/* TODO add d!=-1/8*/
if (mpz_sgn (tmp) == 0 || mpz_cmp_ui (tmp, 1) == 0)
if (mpz_sgn (tmp) == 0 || mpz_cmp_ui (tmp, 1) == 0)
return ECM_ERROR;
return ECM_ERROR;
@@ -422,7 +407,6 @@ get_curve_from_param3 (mpres_t A, mpres_t x0, mpz_t sigma, mpmod_t n)
@@ -422,7 +407,6 @@ get_curve_from_param3 (mpres_t A, mpres_t x0, mpz_t sigma, mpmod_t n)
mpres_set_ui (x0, 2, n);
mpres_set_ui (x0, 2, n);
mpz_clear(tmp);
mpz_clear(tmp);
mpz_clear (two32);
return ECM_NO_FACTOR_FOUND;
return ECM_NO_FACTOR_FOUND;
}
}
Loading