[Ecm-commits] r2368 - trunk

cvs commits ecm-commits at lists.gforge.inria.fr
Fri Feb 1 17:30:50 CET 2013


Author: morain
Date: 2013-02-01 17:30:50 +0100 (Fri, 01 Feb 2013)
New Revision: 2368

Log:
Changing protos of ec_curve_init_* to make this clearer and easier to use.


Modified:
   trunk/addlaws.c
   trunk/addlaws.h
   trunk/cmecm.c
   trunk/ecm-impl.h
   trunk/manyecm.c
   trunk/torsions.c
Modified: trunk/addlaws.c
===================================================================
--- trunk/addlaws.c	2013-01-31 19:27:46 UTC (rev 2367)
+++ trunk/addlaws.c	2013-02-01 16:30:50 UTC (rev 2368)
@@ -1244,7 +1244,7 @@
     int ret = ECM_NO_FACTOR_FOUND;
     mpz_t e;
 
-    ec_curve_init_set(E, A, ECM_EC_TYPE_WEIERSTRASS_AFF, n);
+    ec_curve_init_set(E, ECM_EC_TYPE_WEIERSTRASS_AFF, A, n);
     ec_point_init(P, E, n);
     mpres_set(P->x, x, n);
     mpres_set(P->y, y, n);
@@ -1310,29 +1310,27 @@
 }
 
 void
-ec_curve_init(ec_curve_t E, mpmod_t n)
+ec_curve_init(ec_curve_t E, int etype, mpmod_t n)
 {
     int i;
 
-    E->type = ECM_EC_TYPE_MONTGOMERY; /* default */
+    E->type = etype;
     mpres_init(E->A, n);
     for(i = 0; i < EC_W_NBUFS; i++)
 	mpres_init (E->buf[i], n);
 }
 
 void
-ec_curve_init_set(ec_curve_t E, mpres_t A, int type, mpmod_t n)
+ec_curve_init_set(ec_curve_t E, int etype, mpres_t A, mpmod_t n)
 {
-    ec_curve_init(E, n);
-    E->type = type;
+    ec_curve_init(E, etype, n);
     mpres_set(E->A, A, n);
 }
 
 void
 ec_curve_set_z(ec_curve_t E, ec_curve_t zE, mpmod_t n)
 {
-    ec_curve_init(E, n);
-    E->type = zE->type;
+    ec_curve_init(E, zE->type, n);
     mpres_set_z(E->A, zE->A, n);
     E->disc = zE->disc;
     if(E->disc != 0){

Modified: trunk/addlaws.h
===================================================================
--- trunk/addlaws.h	2013-01-31 19:27:46 UTC (rev 2367)
+++ trunk/addlaws.h	2013-02-01 16:30:50 UTC (rev 2368)
@@ -36,8 +36,8 @@
 void ec_point_print(ec_point_t P, ec_curve_t E, mpmod_t n);
 void ec_point_set(ec_point_t Q, ec_point_t P,
 		  ATTRIBUTE_UNUSED ec_curve_t E, ATTRIBUTE_UNUSED mpmod_t n);
-void ec_curve_init(ec_curve_t E, mpmod_t n);
-void ec_curve_init_set(ec_curve_t E, mpres_t A, int type, mpmod_t n);
+void ec_curve_init(ec_curve_t E, int etype, mpmod_t n);
+void ec_curve_init_set(ec_curve_t E, int type, mpres_t A, mpmod_t n);
 void ec_curve_set_z(ec_curve_t E, ec_curve_t zE, mpmod_t n);
 void ec_curve_clear(ec_curve_t E, mpmod_t n);
 void ec_curve_print(ec_curve_t E, mpmod_t n);

Modified: trunk/cmecm.c
===================================================================
--- trunk/cmecm.c	2013-01-31 19:27:46 UTC (rev 2367)
+++ trunk/cmecm.c	2013-02-01 16:30:50 UTC (rev 2368)
@@ -60,7 +60,7 @@
     long x0;
     int i, ret = ECM_NO_FACTOR_FOUND, imax;
 
-    ec_curve_init(tE[0], n);
+    ec_curve_init(tE[0], ECM_EC_TYPE_WEIERSTRASS_AFF, n);
     ec_point_init(tP[0], tE[0], n);
     tE[0]->disc = disc;
     mpz_init_set_ui(tE[0]->sq[0], 1);
@@ -72,11 +72,12 @@
 	imax = (sqroots == NULL ? 1 : 6);
 
 	for(i = 0; i < imax; i++){
-	    if(i > 0){
-		ec_curve_init(tE[i], n);
+	    if(i == 0)
+		tE[i]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	    else{
+		ec_curve_init(tE[i], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 		ec_point_init(tP[i], tE[i], n);
 	    }
-	    tE[i]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
 	    mpz_set_ui(tE[i]->A, 0);
 	    tE[i]->disc = -3;
 	}
@@ -121,11 +122,12 @@
 	imax = (sqroots == NULL ? 1 : 4);
 
 	for(i = 0; i < imax; i++){
-	    if(i > 0){
-		ec_curve_init(tE[i], n);
+	    if(i == 0)
+		tE[i]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	    else{
+		ec_curve_init(tE[i], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 		ec_point_init(tP[i], tE[i], n);
 	    }
-	    tE[i]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
 	    tE[i]->disc = -4;
 	}
         mpz_set_ui(tE[0]->A, 9);
@@ -559,8 +561,7 @@
     ec_point_t P, omegaP;
 
     printf("# Entering ecm_rootsF_CM with disc=%d dF=%ld\n", C->disc, dF);
-    ec_curve_init(E, modulus);
-    E->type = ECM_EC_TYPE_WEIERSTRASS_AFF;
+    ec_curve_init(E, ECM_EC_TYPE_WEIERSTRASS_AFF, modulus);
     mpres_set(E->A, C->A, modulus);
     ec_point_init(P, E, modulus);
     mpres_set(P->x, C->x, modulus);
@@ -619,7 +620,7 @@
     }
     
     /* conversions */
-    ec_curve_init(E, modulus);
+    ec_curve_init(E, ECM_EC_TYPE_WEIERSTRASS_AFF, modulus);
     mpres_set(E->A, X->A, modulus);
     ec_point_init(P, E, modulus);
     ec_point_init(duP, E, modulus);
@@ -628,9 +629,6 @@
     mpres_set(P->y, X->y, modulus);
     mpres_set_ui(P->z, 1, modulus);
 
-    /* use affine Weierstrass for these two computations */
-    E->type = ECM_EC_TYPE_WEIERSTRASS_AFF;
-
     /* fd[0] <- [umin]*P */
     mpz_init_set_ui(tmp, umin);
     ec_point_mul(duP, tmp, P, E, modulus);
@@ -664,7 +662,7 @@
     int ret = ECM_NO_FACTOR_FOUND;
 
     /* conversions */
-    ec_curve_init(E, modulus);
+    ec_curve_init(E, ECM_EC_TYPE_WEIERSTRASS_AFF, modulus);
     mpres_set(E->A, state->X->A, modulus);
     ec_point_init(uP, E, modulus);
     ec_point_init(duP, E, modulus);
@@ -677,9 +675,6 @@
     mpres_set(duP->y, state->fd[1].y, modulus);
     mpres_set_ui(duP->z, 1, modulus);
 
-    /* use affine Weierstrass for these two computations */
-    E->type = ECM_EC_TYPE_WEIERSTRASS_AFF;
-
     for(i = 0; i < dF; i++){
 	mpres_get_z(G[i], uP->x, modulus);
 	if(ec_point_add(uP, uP, duP, E, modulus) == 0){

Modified: trunk/ecm-impl.h
===================================================================
--- trunk/ecm-impl.h	2013-01-31 19:27:46 UTC (rev 2367)
+++ trunk/ecm-impl.h	2013-02-01 16:30:50 UTC (rev 2368)
@@ -292,14 +292,6 @@
 } __mpmod_struct;
 typedef __mpmod_struct mpmod_t[1];
 
-void ec_point_init(ec_point_t P, ec_curve_t E, mpmod_t n);
-void ec_point_clear(ec_point_t P, ec_curve_t E, mpmod_t n);
-void ec_point_set(ec_point_t Q, ec_point_t P, ec_curve_t E, mpmod_t n);
-int ec_point_mul(ec_point_t Q, mpz_t d, ec_point_t P, ec_curve_t E, mpmod_t n);
-void ec_curve_init(ec_curve_t E, mpmod_t n);
-void ec_curve_init_set(ec_curve_t E, mpres_t A, int type, mpmod_t n);
-void ec_curve_clear(ec_curve_t E, mpmod_t n);
-
 #if defined (__cplusplus)
 extern "C" {
 #endif  

Modified: trunk/manyecm.c
===================================================================
--- trunk/manyecm.c	2013-01-31 19:27:46 UTC (rev 2367)
+++ trunk/manyecm.c	2013-02-01 16:30:50 UTC (rev 2368)
@@ -588,7 +588,7 @@
 	}
 	else
 	    Etype = bufA[0];
-	ec_curve_init(tE[*nE], n);
+	ec_curve_init(tE[*nE], ECM_EC_TYPE_WEIERSTRASS_AFF, n);
 	if(Etype == 'W'){
 	    if(fscanf(ifile, "%s %s %s", bufA, bufx, bufy) == EOF)
 		break;

Modified: trunk/torsions.c
===================================================================
--- trunk/torsions.c	2013-01-31 19:27:46 UTC (rev 2367)
+++ trunk/torsions.c	2013-02-01 16:30:50 UTC (rev 2368)
@@ -231,8 +231,7 @@
 #endif
 	/* P:=WE![x0, y0, 1]; */
 	/* convert to short Weierstrass form */
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	kubert_to_weierstrass(tE[nc], NULL, tP[nc], c, c, x0, y0, n->orig_modulus);
 	nc++;
@@ -320,7 +319,7 @@
     mpres_init(tmp, n);
     mod_from_rat_str(f, "1295/48", n->orig_modulus);
     mpres_set_z(tmp, f, n);
-    ec_curve_init_set(E, tmp, ECM_EC_TYPE_WEIERSTRASS_HOM, n);
+    ec_curve_init_set(E, ECM_EC_TYPE_WEIERSTRASS_HOM, tmp, n);
     ec_point_init(P, E, n);
     mod_from_rat_str(f, "2185/12", n->orig_modulus);
     mpres_set_z(P->x, f, n);
@@ -399,8 +398,7 @@
 	mpz_mul(b, c, d);
 	mpz_mod(b, b, n->orig_modulus);
 	/* to short Weierstrass form */
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	kubert_to_weierstrass(tE[nc], NULL, tP[nc], b, c, kx0, ky0, n->orig_modulus);
 #if DEBUG_TORSION >= 2
@@ -445,7 +443,7 @@
     mpres_init(tmp, n);
     mpz_init_set_str(f, "-9", 10);
     mpres_set_z(tmp, f, n);
-    ec_curve_init_set(E, tmp, ECM_EC_TYPE_WEIERSTRASS_HOM, n);
+    ec_curve_init_set(E, ECM_EC_TYPE_WEIERSTRASS_HOM, tmp, n);
     ec_point_init(P, E, n);
     mpz_set_str(f, "1", 10); 
     mpres_set_z(P->x, f, n);
@@ -533,8 +531,7 @@
 	mpz_mul(b, c, d);
 	mpz_mod(b, b, n->orig_modulus);
 	/* to short Weierstrass form */
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	kubert_to_weierstrass(tE[nc], NULL, tP[nc], b, c, kx0, ky0, n->orig_modulus);
 	nc++;
@@ -579,7 +576,7 @@
     mpres_init(tmp, n);
     mod_from_rat_str(f, "2/3", n->orig_modulus);
     mpres_set_z(tmp, f, n);
-    ec_curve_init_set(E, tmp, ECM_EC_TYPE_WEIERSTRASS_HOM, n);
+    ec_curve_init_set(E, ECM_EC_TYPE_WEIERSTRASS_HOM, tmp, n);
     ec_point_init(P, E, n);
     mod_from_rat_str(f, "2/3", n->orig_modulus);
     mpres_set_z(P->x, f, n);
@@ -683,8 +680,7 @@
 	mpz_mul(b, c, d);
 	mpz_mod(b, b, n->orig_modulus);
 	/* to short Weierstrass form */
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	kubert_to_weierstrass(tE[nc], NULL, tP[nc], b, c, kx0, ky0, n->orig_modulus);
 	nc++;
@@ -740,7 +736,7 @@
     mpres_init(tmp2, n);
     mpz_set_str(f, "-8", 10); 
     mpres_set_z(tmp2, f, n);
-    ec_curve_init_set(E, tmp2, ECM_EC_TYPE_WEIERSTRASS_HOM, n);
+    ec_curve_init_set(E, ECM_EC_TYPE_WEIERSTRASS_HOM, tmp2, n);
     ec_point_init(P, E, n);
     mpz_set_str(f, "12", 10); 
     mpres_set_z(P->x, f, n);
@@ -869,8 +865,7 @@
 	mpz_mul(f, f, d); mpz_add_si(f, f, -8);
 	mpz_mul(f, f, d); mpz_add_si(f, f, 1);
 	/* to Montgomery form */
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_MONTGOMERY;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_MONTGOMERY, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	if(mod_from_rat2(tE[nc]->A, f, tmp, n->orig_modulus) == 0){
             printf("found factor in Z2xZ8 (ma)\n");
@@ -972,8 +967,7 @@
 	mpz_add_ui(y0, y0, 216);
 	mpz_mod(y0, y0, n->orig_modulus);
 	mpz_set_ui(x0, 0);
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	W2W(tE[nc], NULL, tP[nc], a2, a4, NULL, x0, y0, n->orig_modulus);
 	nc++;
@@ -1022,7 +1016,7 @@
             ret = ECM_FACTOR_FOUND_STEP1;
             break;
 	}
-	ec_curve_init_set(tE[nc], D, ECM_EC_TYPE_HESSIAN, n);
+	ec_curve_init_set(tE[nc], ECM_EC_TYPE_HESSIAN, D, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	mpz_set(tE[nc]->A, D);
 	mpz_set(tP[nc]->x, u0);
@@ -1061,7 +1055,7 @@
     /* Paux:=Eaux![2, 2, 1]; */
     mpres_init(tmp, n);
     mpres_set_ui(tmp, 0, n);
-    ec_curve_init_set(E, tmp, ECM_EC_TYPE_WEIERSTRASS_HOM, n);
+    ec_curve_init_set(E, ECM_EC_TYPE_WEIERSTRASS_HOM, tmp, n);
     ec_point_init(P, E, n);
     mpz_set_str(f, "2", 10);
     mpres_set_z(P->x, f, n);
@@ -1108,8 +1102,7 @@
 	mpz_mod(num, num, n->orig_modulus);
 	mpz_mul_si(den, den, 3);
 	mpz_mod(den, den, n->orig_modulus);
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_HESSIAN;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_HESSIAN, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	if(mod_from_rat2(tE[nc]->A, num, den, n->orig_modulus) == 0){
             printf("found factor in Z3xZ6 (D)\n");
@@ -1201,8 +1194,7 @@
 	mpz_mul_si(tmp, tmp, -2);
 	mpz_mod(tmp, tmp, n->orig_modulus);
         /* to Montgomery form */
-        ec_curve_init(tE[nc], n);
-        tE[nc]->type = ECM_EC_TYPE_MONTGOMERY;
+        ec_curve_init(tE[nc], ECM_EC_TYPE_MONTGOMERY, n);
         ec_point_init(tP[nc], tE[nc], n);
 	if(mod_from_rat2(tE[nc]->A, tmp, x0, n->orig_modulus) == 0){
 	    printf("\nFactor found durint init of Z4xZ4 (a)\n");
@@ -1333,8 +1325,7 @@
 	printf(" %d", u);
 	mpz_set_ui(t, u);
 	mpz_powm_ui(t, t, 5, n->orig_modulus);
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 	/* A = -(t^4-228*t^3+494*t^2+228*t+1)/48; */
 	mpz_eval_poly(num, polyA, t, n->orig_modulus);
 	mpz_sub_si(den, n->orig_modulus, 48);
@@ -1408,8 +1399,7 @@
 	gmp_printf("b:=%Zd;\n", b);
 	gmp_printf("c:=%Zd;\n", c);
 #endif	
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	/* transform with no input point */
 	kubert_to_weierstrass(tE[nc],B,NULL,b,c,NULL,NULL,n->orig_modulus);
@@ -1482,8 +1472,7 @@
 	gmp_printf("b:=%Zd;\n", b);
 	gmp_printf("c:=%Zd;\n", c);
 #endif	
-	ec_curve_init(tE[nc], n);
-	tE[nc]->type = ECM_EC_TYPE_WEIERSTRASS_HOM;
+	ec_curve_init(tE[nc], ECM_EC_TYPE_WEIERSTRASS_HOM, n);
 	ec_point_init(tP[nc], tE[nc], n);
 	/* transform with no input point */
 	kubert_to_weierstrass(tE[nc],B,NULL,b,c,NULL,NULL,n->orig_modulus);




More information about the Ecm-commits mailing list