version 1.11, 2002/09/27 04:24:04 |
version 1.18, 2017/02/27 05:14:54 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* 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.17 2003/05/07 06:26:49 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "inline.h" |
#include "inline.h" |
Line 511 void setmod_sf(int p,int n) |
|
Line 511 void setmod_sf(int p,int n) |
|
|
|
for ( i = 0, q = 1; i < n; i++ ) |
for ( i = 0, q = 1; i < n; i++ ) |
q *= p; |
q *= p; |
|
if ( p == current_gfs_p && q == current_gfs_q ) return; |
dp = UMALLOC(n); |
dp = UMALLOC(n); |
r = search_defpoly_and_primitive_root(p,n,dp); |
r = search_defpoly_and_primitive_root(p,n,dp); |
if ( !r ) { |
if ( !r ) { |
Line 661 int mulremum_enc(int p,int n,UM dp,int a,int b) |
|
Line 662 int mulremum_enc(int p,int n,UM dp,int a,int b) |
|
|
|
void gfs_galois_action(GFS a,Q e,GFS *c) |
void gfs_galois_action(GFS a,Q e,GFS *c) |
{ |
{ |
Q q; |
Q p; |
int i,k; |
int i,k; |
GFS t,s; |
GFS t,s; |
|
|
t = a; |
t = a; |
k = QTOS(e); |
k = QTOS(e); |
STOQ(current_gfs_q,q); |
STOQ(current_gfs_p,p); |
for ( i = 0; i < k; i++ ) { |
for ( i = 0; i < k; i++ ) { |
pwrgfs(t,q,&s); t = s; |
pwrgfs(t,p,&s); t = s; |
} |
} |
*c = t; |
*c = t; |
} |
} |
Line 688 void gfs_embed(GFS z,int k,int pm,GFS *c) |
|
Line 689 void gfs_embed(GFS z,int k,int pm,GFS *c) |
|
} |
} |
} |
} |
|
|
void qtogfs(Q a,GFS *c) |
/* 0 <= index <= q-1 */ |
{ |
|
int s; |
|
|
|
s = QTOS(a)%current_gfs_q; |
void indextogfs(int index, GFS *c) |
if ( s < 0 ) |
{ |
s += current_gfs_q; |
if ( index == 0 ) |
if ( !s ) |
|
*c = 0; |
*c = 0; |
|
else if ( index >= current_gfs_q ) |
|
error("indextogfs : exhausted"); |
else if ( !current_gfs_ntoi ) { |
else if ( !current_gfs_ntoi ) { |
MKGFS(s,*c); |
MKGFS(index,*c); |
} else { |
} 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; |
|
|
|
if ( a && (SGN(a) < 1) ) |
|
error("qtogfs : invalid argument"); |
|
s = QTOS(a)%current_gfs_q; |
|
itogfs(s,c); |
|
} |
|
|
void mqtogfs(MQ a,GFS *c) |
void mqtogfs(MQ a,GFS *c) |
{ |
{ |
if ( !a ) |
if ( !a ) |
*c = 0; |
*c = 0; |
else if ( !current_gfs_ntoi ) { |
else |
MKGFS(CONT(a),*c); |
itogfs(CONT(a),c); |
} else { |
|
MKGFS(current_gfs_ntoi[CONT(a)],*c); |
|
} |
|
} |
} |
|
|
void gfstomq(GFS a,MQ *c) |
void gfstomq(GFS a,MQ *c) |
Line 726 void gfstomq(GFS a,MQ *c) |
|
Line 753 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) |
void ntogfs(Obj a,GFS *b) |
{ |
{ |
P t; |
P t; |
Line 879 void pwrgfs(GFS a,Q b,GFS *c) |
|
Line 921 void pwrgfs(GFS a,Q b,GFS *c) |
|
|
|
ntogfs((Obj)a,&z); a = z; |
ntogfs((Obj)a,&z); a = z; |
if ( !b ) |
if ( !b ) |
MKGFS(0,*c); |
itogfs(1,c); |
else if ( !a ) |
else if ( !a ) |
*c = 0; |
*c = 0; |
else if ( !current_gfs_ntoi ) { |
else if ( !current_gfs_ntoi) { |
ai = pwrm(current_gfs_q,CONT(a),QTOS(b)); |
ai = pwrm(current_gfs_q,CONT(a),QTOS(b)); |
MKGFS(ai,*c); |
MKGFS(ai,*c); |
} else { |
} else { |
STON(CONT(a),an); muln(an,NM(b),&tn); |
STON(CONT(a),an); muln(an,NM(b),&tn); |
STON(current_gfs_q1,an); remn(tn,an,&rn); |
STON(current_gfs_q1,an); remn(tn,an,&rn); |
if ( !rn ) |
if ( !rn ) |
MKGFS(0,*c); |
itogfs(1,c); |
else if ( SGN(b) > 0 ) |
else if ( SGN(b) > 0 ) |
MKGFS(BD(rn)[0],*c); |
MKGFS(BD(rn)[0],*c); |
else { |
else { |
MKGFS(0,t); |
itogfs(1,&t); |
MKGFS(BD(rn)[0],s); |
MKGFS(BD(rn)[0],s); |
divgfs(t,s,c); |
divgfs(t,s,c); |
} |
} |
Line 920 int cmpgfs(GFS a,GFS b) |
|
Line 962 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) |
void randomgfs(GFS *r) |
{ |
{ |
unsigned int t; |
unsigned int t; |
Line 927 void randomgfs(GFS *r) |
|
Line 984 void randomgfs(GFS *r) |
|
if ( !current_gfs_q1 ) |
if ( !current_gfs_q1 ) |
error("addgfs : current_gfs_q is not set"); |
error("addgfs : current_gfs_q is not set"); |
t = mt_genrand()%current_gfs_q; |
t = mt_genrand()%current_gfs_q; |
if ( !t ) |
indextogfs(t,r); |
*r = 0; |
|
else { |
|
if ( current_gfs_ntoi && t == (unsigned int)current_gfs_q1 ) |
|
t = 0; |
|
MKGFS(t,*r); |
|
} |
|
} |
} |
|
|
/* arithmetic operations for 'immediate values of GFS */ |
/* arithmetic operations for 'immediate values of GFS */ |
Line 1082 int _pwrsf(int a,int b) |
|
Line 1133 int _pwrsf(int a,int b) |
|
a = pwrm(current_gfs_q,IFTOF(a),b); |
a = pwrm(current_gfs_q,IFTOF(a),b); |
return FTOIF(a); |
return FTOIF(a); |
} else { |
} else { |
a = IFTOF(a); |
iftogfs(a,&at); |
MKGFS(a,at); |
|
STOQ(b,bt); |
STOQ(b,bt); |
pwrgfs(at,bt,&ct); |
pwrgfs(at,bt,&ct); |
c = CONT(ct); |
c = CONT(ct); |
Line 1100 int _itosf(int n) |
|
Line 1150 int _itosf(int n) |
|
{ |
{ |
int i; |
int i; |
|
|
|
/* XXX */ |
|
#if 0 |
n %= current_gfs_p; |
n %= current_gfs_p; |
|
#else |
|
n %= current_gfs_q; |
|
#endif |
if ( !n ) |
if ( !n ) |
return 0; |
return 0; |
i = !current_gfs_ntoi ? n : current_gfs_ntoi[n]; |
i = !current_gfs_ntoi ? n : current_gfs_ntoi[n]; |
Line 1112 int _itosf(int n) |
|
Line 1167 int _itosf(int n) |
|
|
|
int _isonesf(int a) |
int _isonesf(int a) |
{ |
{ |
return a == (!current_gfs_ntoi ? FTOIF(1) : FTOIF(0)); |
return a == _onesf(); |
} |
} |
|
|
int _randomsf() |
int _randomsf() |