=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/gfs.c,v retrieving revision 1.11 retrieving revision 1.16 diff -u -p -r1.11 -r1.16 --- OpenXM_contrib2/asir2000/engine/gfs.c 2002/09/27 04:24:04 1.11 +++ OpenXM_contrib2/asir2000/engine/gfs.c 2003/01/16 00:33:28 1.16 @@ -45,7 +45,7 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/engine/gfs.c,v 1.10 2001/11/06 09:40:36 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/engine/gfs.c,v 1.15 2003/01/06 01:16:39 noro Exp $ */ #include "ca.h" #include "inline.h" @@ -661,15 +661,15 @@ int mulremum_enc(int p,int n,UM dp,int a,int b) void gfs_galois_action(GFS a,Q e,GFS *c) { - Q q; + Q p; int i,k; GFS t,s; t = a; k = QTOS(e); - STOQ(current_gfs_q,q); + STOQ(current_gfs_p,p); for ( i = 0; i < k; i++ ) { - pwrgfs(t,q,&s); t = s; + pwrgfs(t,p,&s); t = s; } *c = t; } @@ -688,31 +688,55 @@ void gfs_embed(GFS z,int k,int pm,GFS *c) } } -void qtogfs(Q a,GFS *c) -{ - int s; +/* 0 <= index <= q-1 */ - s = QTOS(a)%current_gfs_q; - if ( s < 0 ) - s += current_gfs_q; - if ( !s ) +void indextogfs(int index, GFS *c) +{ + if ( index == 0 ) *c = 0; + else if ( index >= current_gfs_q ) + error("indextogfs : exhausted"); else if ( !current_gfs_ntoi ) { - MKGFS(s,*c); + MKGFS(index,*c); } else { - MKGFS(current_gfs_ntoi[s],*c); + MKGFS(index-1,*c); } } +void itogfs(int n, GFS *c) +{ + n = _itosf(n); + if ( !n ) + *c = 0; + else { + n = IFTOF(n); + MKGFS(n,*c); + } +} + +void iftogfs(int n, GFS *c) +{ + if ( !n ) + *c = 0; + else { + MKGFS(IFTOF(n),*c); + } +} + +void qtogfs(Q a,GFS *c) +{ + int s; + + s = QTOS(a)%current_gfs_q; + itogfs(s,c); +} + void mqtogfs(MQ a,GFS *c) { if ( !a ) *c = 0; - else if ( !current_gfs_ntoi ) { - MKGFS(CONT(a),*c); - } else { - MKGFS(current_gfs_ntoi[CONT(a)],*c); - } + else + itogfs(CONT(a),c); } void gfstomq(GFS a,MQ *c) @@ -726,6 +750,21 @@ void gfstomq(GFS a,MQ *c) } } +void gfstopgfs(GFS a,V v,P *c) +{ + MQ t; + Q q; + + if ( !a ) + *c = 0; + else if ( !current_gfs_ntoi ) { + UTOMQ(CONT(a),t); + STOQ(CONT(t),q); + *c = (P)q; + } else + enc_to_p(current_gfs_p,current_gfs_iton[CONT(a)],v,c); +} + void ntogfs(Obj a,GFS *b) { P t; @@ -879,21 +918,21 @@ void pwrgfs(GFS a,Q b,GFS *c) ntogfs((Obj)a,&z); a = z; if ( !b ) - MKGFS(0,*c); + itogfs(1,c); else if ( !a ) *c = 0; - else if ( !current_gfs_ntoi ) { + else if ( !current_gfs_ntoi) { ai = pwrm(current_gfs_q,CONT(a),QTOS(b)); MKGFS(ai,*c); } else { STON(CONT(a),an); muln(an,NM(b),&tn); STON(current_gfs_q1,an); remn(tn,an,&rn); if ( !rn ) - MKGFS(0,*c); + itogfs(1,c); else if ( SGN(b) > 0 ) MKGFS(BD(rn)[0],*c); else { - MKGFS(0,t); + itogfs(1,&t); MKGFS(BD(rn)[0],s); divgfs(t,s,c); } @@ -920,6 +959,21 @@ int cmpgfs(GFS a,GFS b) } } +void pthrootgfs(GFS a,GFS *b) +{ + Q p; + int e,i; + GFS t,s; + + STOQ(characteristic_sf(),p); + e = extdeg_sf()-1; + t = a; + for ( i = 0; i < e; i++ ) { + pwrgfs(t,p,&s); t = s; + } + *b = t; +} + void randomgfs(GFS *r) { unsigned int t; @@ -927,13 +981,7 @@ void randomgfs(GFS *r) if ( !current_gfs_q1 ) error("addgfs : current_gfs_q is not set"); t = mt_genrand()%current_gfs_q; - if ( !t ) - *r = 0; - else { - if ( current_gfs_ntoi && t == (unsigned int)current_gfs_q1 ) - t = 0; - MKGFS(t,*r); - } + indextogfs(t,r); } /* arithmetic operations for 'immediate values of GFS */ @@ -1082,8 +1130,7 @@ int _pwrsf(int a,int b) a = pwrm(current_gfs_q,IFTOF(a),b); return FTOIF(a); } else { - a = IFTOF(a); - MKGFS(a,at); + iftogfs(a,&at); STOQ(b,bt); pwrgfs(at,bt,&ct); c = CONT(ct); @@ -1100,7 +1147,12 @@ int _itosf(int n) { int i; + /* XXX */ +#if 0 n %= current_gfs_p; +#else + n %= current_gfs_q; +#endif if ( !n ) return 0; i = !current_gfs_ntoi ? n : current_gfs_ntoi[n]; @@ -1112,7 +1164,7 @@ int _itosf(int n) int _isonesf(int a) { - return a == (!current_gfs_ntoi ? FTOIF(1) : FTOIF(0)); + return a == _onesf(); } int _randomsf()