version 1.7, 2001/06/21 07:47:02 |
version 1.14, 2002/12/18 06:15:40 |
|
|
* 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.6 2001/06/20 09:30:34 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/gfs.c,v 1.13 2002/09/30 06:13:07 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
|
#include "inline.h" |
|
|
/* q = p^n */ |
/* q = p^n */ |
|
|
Line 59 int *current_gfs_plus1; |
|
Line 60 int *current_gfs_plus1; |
|
int *current_gfs_ntoi; |
int *current_gfs_ntoi; |
int *current_gfs_iton; |
int *current_gfs_iton; |
|
|
void chsgngfs(); |
|
void generate_defpoly_um(); |
|
|
|
struct prim_root_info { |
struct prim_root_info { |
int p; |
int p; |
int extdeg; |
int extdeg; |
Line 69 struct prim_root_info { |
|
Line 67 struct prim_root_info { |
|
int prim_root; |
int prim_root; |
}; |
}; |
|
|
|
/* if p >= SF_THRESHOLD, usual representation is used */ |
|
|
|
#define SF_THRESHOLD 16384 |
|
|
struct prim_root_info prim_root_info_tab[] = { |
struct prim_root_info prim_root_info_tab[] = { |
{2,1,0,0}, {2,2,7,2}, {2,3,11,2}, {2,4,19,2}, {2,5,37,2}, {2,6,67,2}, |
{2,1,0,0}, {2,2,7,2}, {2,3,11,2}, {2,4,19,2}, {2,5,37,2}, {2,6,67,2}, |
{2,7,131,2}, {2,8,283,3}, {2,9,515,7}, {2,10,1033,2}, {2,11,2053,2}, |
{2,7,131,2}, {2,8,283,3}, {2,9,515,7}, {2,10,1033,2}, {2,11,2053,2}, |
Line 473 struct prim_root_info prim_root_info_tab[] = { |
|
Line 475 struct prim_root_info prim_root_info_tab[] = { |
|
{16349,1,0,2}, {16361,1,0,3}, {16363,1,0,2}, {16369,1,0,7}, {16381,1,0,2}, |
{16349,1,0,2}, {16361,1,0,3}, {16363,1,0,2}, {16369,1,0,7}, {16381,1,0,2}, |
}; |
}; |
|
|
void dec_um(p,a,u) |
void dec_um(int p,int a,UM u) |
int p,a; |
|
UM u; |
|
{ |
{ |
int i; |
int i; |
|
|
|
|
* current_gfs_iton[p-1] = 0 |
* current_gfs_iton[p-1] = 0 |
*/ |
*/ |
|
|
void setmod_sf(p,n) |
void setmod_sf(int p,int n) |
int p,n; |
|
{ |
{ |
int r,i,q1,q,t,t1; |
int r,i,q1,q,t,t1; |
UM dp; |
UM dp; |
|
|
|
if ( p >= SF_THRESHOLD ) { |
|
if ( n > 1 ) |
|
error("setmod_ff : p^n is too large"); |
|
current_gfs_p = p; |
|
current_gfs_q = p; |
|
current_gfs_q1 = p-1; |
|
current_gfs_ext = 0; |
|
current_gfs_ntoi = 0; |
|
current_gfs_iton = 0; |
|
current_gfs_plus1 = 0; |
|
return; |
|
} |
|
|
for ( i = 0, q = 1; i < n; i++ ) |
for ( i = 0, q = 1; i < n; i++ ) |
q *= p; |
q *= p; |
dp = UMALLOC(n); |
dp = UMALLOC(n); |
|
|
if ( !r ) { |
if ( !r ) { |
generate_defpoly_um(p,n,dp); |
generate_defpoly_um(p,n,dp); |
r = generate_primitive_root_enc(p,n,dp); |
r = generate_primitive_root_enc(p,n,dp); |
|
if ( !r ) |
|
error("setmod_sf : primitive root not found"); |
} |
} |
current_gfs_p = p; |
current_gfs_p = p; |
current_gfs_q = q; |
current_gfs_q = q; |
|
|
} |
} |
} |
} |
|
|
int search_defpoly_and_primitive_root(p,n,dp) |
int search_defpoly_and_primitive_root(int p,int n,UM dp) |
int p,n; |
|
UM dp; |
|
{ |
{ |
int l,min,max,mid,p1,i,ind,t; |
int l,min,max,mid,p1,i,ind,t; |
|
|
|
|
return prim_root_info_tab[i].prim_root; |
return prim_root_info_tab[i].prim_root; |
} |
} |
|
|
void generate_defpoly_um(p,n,dp) |
void generate_defpoly_um(int p,int n,UM dp) |
int p,n; |
|
UM dp; |
|
{ |
{ |
int i,j,a,c,q; |
int i,j,a,q; |
UM wf,wdf,wgcd; |
UM wf,wdf,wgcd; |
|
|
wf = W_UMALLOC(n); |
wf = W_UMALLOC(n); |
|
|
} |
} |
} |
} |
|
|
int generate_primitive_root_enc(p,n,dp) |
int generate_primitive_root_enc(int p,int n,UM dp) |
int p,n; |
|
UM dp; |
|
{ |
{ |
int i,r,rj,j,q; |
int i,r,rj,j,q; |
|
|
|
|
if ( j == q-1 ) |
if ( j == q-1 ) |
return r; |
return r; |
} |
} |
|
/* not found */ |
|
return 0; |
} |
} |
|
|
/* [a(p)]*[b(p)] in GF(p^n) -> [a(x)*b(x) mod dp(x)]_{x->p} */ |
/* [a(p)]*[b(p)] in GF(p^n) -> [a(x)*b(x) mod dp(x)]_{x->p} */ |
|
|
int mulremum_enc(p,n,dp,a,b) |
int mulremum_enc(int p,int n,UM dp,int a,int b) |
int p,n; |
|
UM dp; |
|
int a,b; |
|
{ |
{ |
int i,dr,r; |
int i,dr,r; |
UM wa,wb,wc,wq; |
UM wa,wb,wc,wq; |
|
|
return r; |
return r; |
} |
} |
|
|
void gfs_galois_action(a,e,c) |
/* sigma : alpha -> alpha^q */ |
GFS a; |
|
Q e; |
void gfs_galois_action(GFS a,Q e,GFS *c) |
GFS *c; |
|
{ |
{ |
Q p; |
Q q; |
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_p,p); |
STOQ(current_gfs_q,q); |
for ( i = 0; i < k; i++ ) { |
for ( i = 0; i < k; i++ ) { |
pwrgfs(t,p,&s); t = s; |
pwrgfs(t,q,&s); t = s; |
} |
} |
*c = t; |
*c = t; |
} |
} |
|
|
void qtogfs(a,c) |
/* GF(pn)={0,1,a,a^2,...} -> GF(pm)={0,1,b,b^2,...}; a->b^k */ |
Q a; |
|
GFS *c; |
void gfs_embed(GFS z,int k,int pm,GFS *c) |
{ |
{ |
int s; |
int t; |
|
|
s = QTOS(a)%current_gfs_q; |
if ( !z ) |
if ( s < 0 ) |
|
s += current_gfs_q; |
|
if ( !s ) |
|
*c = 0; |
*c = 0; |
else |
else { |
MKGFS(current_gfs_ntoi[s],*c); |
t = dmar(k,CONT(z),0,pm-1); |
|
MKGFS(t,*c); |
|
} |
} |
} |
|
|
void mqtogfs(a,c) |
/* 0 <= index <= q-1 */ |
MQ a; |
|
GFS *c; |
void indextogfs(int index, GFS *c) |
{ |
{ |
if ( !a ) |
if ( index == 0 ) |
*c = 0; |
*c = 0; |
|
else if ( index >= current_gfs_q ) |
|
error("indextogfs : exhausted"); |
|
else if ( !current_gfs_ntoi ) { |
|
MKGFS(index,*c); |
|
} else { |
|
MKGFS(index-1,*c); |
|
} |
|
} |
|
|
|
void itogfs(int n, GFS *c) |
|
{ |
|
n = _itosf(n); |
|
if ( !n ) |
|
*c = 0; |
else { |
else { |
MKGFS(current_gfs_ntoi[CONT(a)],*c); |
n = IFTOF(n); |
|
MKGFS(n,*c); |
} |
} |
} |
} |
|
|
void gfstomq(a,c) |
void iftogfs(int n, GFS *c) |
GFS a; |
|
MQ *c; |
|
{ |
{ |
if ( !a ) |
if ( !n ) |
*c = 0; |
*c = 0; |
else { |
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 |
|
itogfs(CONT(a),c); |
|
} |
|
|
|
void gfstomq(GFS a,MQ *c) |
|
{ |
|
if ( !a ) |
|
*c = 0; |
|
else if ( !current_gfs_ntoi ) { |
|
UTOMQ(CONT(a),*c); |
|
} else { |
UTOMQ(current_gfs_iton[CONT(a)],*c); |
UTOMQ(current_gfs_iton[CONT(a)],*c); |
} |
} |
} |
} |
|
|
void ntogfs(a,b) |
void ntogfs(Obj a,GFS *b) |
Obj a; |
|
GFS *b; |
|
{ |
{ |
P t; |
P t; |
|
|
|
|
if ( !a || (OID(a)==O_N && NID(a) == N_GFS) ) |
if ( !a || (OID(a)==O_N && NID(a) == N_GFS) ) |
*b = (GFS)a; |
*b = (GFS)a; |
else if ( OID(a) == O_N && NID(a) == N_M ) |
else if ( OID(a) == O_N && NID(a) == N_M ) |
mqtogfs(a,b); |
mqtogfs((MQ)a,b); |
else if ( OID(a) == O_N && NID(a) == N_Q ) { |
else if ( OID(a) == O_N && NID(a) == N_Q ) { |
ptomp(current_gfs_p,(P)a,&t); mqtogfs(t,b); |
ptomp(current_gfs_p,(P)a,&t); mqtogfs((MQ)t,b); |
} else |
} else |
error("ntogfs : invalid argument"); |
error("ntogfs : invalid argument"); |
} |
} |
|
|
void addgfs(a,b,c) |
void addgfs(GFS a,GFS b,GFS *c) |
GFS a,b; |
|
GFS *c; |
|
{ |
{ |
int ai,bi,ci; |
int ai,bi,ci; |
GFS z; |
GFS z; |
|
|
ntogfs(a,&z); a = z; |
ntogfs((Obj)a,&z); a = z; |
ntogfs(b,&z); b = z; |
ntogfs((Obj)b,&z); b = z; |
if ( !a ) |
if ( !a ) |
*c = b; |
*c = b; |
else if ( !b ) |
else if ( !b ) |
*c = a; |
*c = a; |
else { |
else if ( !current_gfs_ntoi ) { |
ai = CONT(a); bi = CONT(b); |
ai = CONT(a); bi = CONT(b); |
|
ci = ai+bi-current_gfs_q; |
|
if ( ci == 0 ) |
|
*c = 0; |
|
else { |
|
if ( ci < 0 ) |
|
ci += current_gfs_q; |
|
MKGFS(ci,*c); |
|
} |
|
} else { |
|
ai = CONT(a); bi = CONT(b); |
if ( ai > bi ) { |
if ( ai > bi ) { |
/* tab[ai]+tab[bi] = tab[bi](tab[ai-bi]+1) */ |
/* tab[ai]+tab[bi] = tab[bi](tab[ai-bi]+1) */ |
ci = current_gfs_plus1[ai-bi]; |
ci = current_gfs_plus1[ai-bi]; |
|
|
} |
} |
} |
} |
|
|
void subgfs(a,b,c) |
void subgfs(GFS a,GFS b,GFS *c) |
GFS a,b; |
|
GFS *c; |
|
{ |
{ |
GFS t,z; |
GFS t,z; |
|
|
ntogfs(a,&z); a = z; |
ntogfs((Obj)a,&z); a = z; |
ntogfs(b,&z); b = z; |
ntogfs((Obj)b,&z); b = z; |
if ( !b ) |
if ( !b ) |
*c = a; |
*c = a; |
else { |
else { |
|
|
} |
} |
} |
} |
|
|
void mulgfs(a,b,c) |
void mulgfs(GFS a,GFS b,GFS *c) |
GFS a,b; |
|
GFS *c; |
|
{ |
{ |
int ai; |
int ai,bi,ci; |
GFS z; |
GFS z; |
|
|
ntogfs(a,&z); a = z; |
ntogfs((Obj)a,&z); a = z; |
ntogfs(b,&z); b = z; |
ntogfs((Obj)b,&z); b = z; |
if ( !a || !b ) |
if ( !a || !b ) |
*c = 0; |
*c = 0; |
else { |
else if ( !current_gfs_ntoi ) { |
|
ai = CONT(a); bi = CONT(b); |
|
DMAR(ai,bi,0,current_gfs_q,ci); |
|
MKGFS(ci,*c); |
|
} else { |
ai = CONT(a) + CONT(b); |
ai = CONT(a) + CONT(b); |
if ( ai >= current_gfs_q1 ) |
if ( ai >= current_gfs_q1 ) |
ai -= current_gfs_q1; |
ai -= current_gfs_q1; |
|
|
} |
} |
} |
} |
|
|
void divgfs(a,b,c) |
void divgfs(GFS a,GFS b,GFS *c) |
GFS a,b; |
|
GFS *c; |
|
{ |
{ |
int ai; |
int ai,bi,ci; |
GFS z; |
GFS z; |
|
|
ntogfs(a,&z); a = z; |
ntogfs((Obj)a,&z); a = z; |
ntogfs(b,&z); b = z; |
ntogfs((Obj)b,&z); b = z; |
if ( !b ) |
if ( !b ) |
error("divgfs : division by 0"); |
error("divgfs : division by 0"); |
else if ( !a ) |
else if ( !a ) |
*c = 0; |
*c = 0; |
else { |
else if ( !current_gfs_ntoi ) { |
|
ai = CONT(a); bi = invm(CONT(b),current_gfs_q); |
|
DMAR(ai,bi,0,current_gfs_q,ci); |
|
MKGFS(ci,*c); |
|
} else { |
ai = CONT(a) - CONT(b); |
ai = CONT(a) - CONT(b); |
if ( ai < 0 ) |
if ( ai < 0 ) |
ai += current_gfs_q1; |
ai += current_gfs_q1; |
|
|
} |
} |
} |
} |
|
|
void chsgngfs(a,c) |
void chsgngfs(GFS a,GFS *c) |
GFS a,*c; |
|
{ |
{ |
int ai; |
int ai; |
GFS z; |
GFS z; |
|
|
ntogfs(a,&z); a = z; |
ntogfs((Obj)a,&z); a = z; |
if ( !a ) |
if ( !a ) |
*c = 0; |
*c = 0; |
else if ( current_gfs_q1&1 ) |
else if ( !current_gfs_ntoi ) { |
|
ai = current_gfs_q - CONT(a); |
|
MKGFS(ai,*c); |
|
} else if ( current_gfs_q1&1 ) |
*c = a; |
*c = a; |
else { |
else { |
/* r^((q-1)/2) = -1 */ |
/* r^((q-1)/2) = -1 */ |
|
|
} |
} |
} |
} |
|
|
void pwrgfs(a,b,c) |
void pwrgfs(GFS a,Q b,GFS *c) |
GFS a; |
|
Q b; |
|
GFS *c; |
|
{ |
{ |
N an,tn,rn; |
N an,tn,rn; |
GFS t,s,z; |
GFS t,s,z; |
|
int ai; |
|
|
ntogfs(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 { |
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(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); |
} |
} |
} |
} |
} |
} |
|
|
int cmpgfs(a,b) |
int cmpgfs(GFS a,GFS b) |
GFS a,b; |
|
{ |
{ |
GFS z; |
GFS z; |
|
|
ntogfs(a,&z); a = z; |
ntogfs((Obj)a,&z); a = z; |
if ( !a ) |
if ( !a ) |
return !b ? 0 : -1; |
return !b ? 0 : -1; |
else |
else |
|
|
} |
} |
} |
} |
|
|
void randomgfs(r) |
void pthrootgfs(GFS a,GFS *b) |
GFS *r; |
|
{ |
{ |
|
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; |
unsigned int t; |
|
|
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 ( t == current_gfs_q1 ) |
|
t = 0; |
|
MKGFS(t,*r); |
|
} |
|
} |
} |
|
|
/* arithmetic operations for 'immediate values of GFS */ |
/* arithmetic operations for 'immediate values of GFS */ |
|
|
int _addsf(a,b) |
int _addsf(int a,int b) |
int a,b; |
|
{ |
{ |
if ( !a ) |
if ( !a ) |
return b; |
return b; |
|
|
return a; |
return a; |
|
|
a = IFTOF(a); b = IFTOF(b); |
a = IFTOF(a); b = IFTOF(b); |
|
|
|
if ( !current_gfs_ntoi ) { |
|
a = a+b-current_gfs_q; |
|
if ( a == 0 ) |
|
return 0; |
|
else { |
|
if ( a < 0 ) |
|
a += current_gfs_q; |
|
return FTOIF(a); |
|
} |
|
} |
|
|
if ( a > b ) { |
if ( a > b ) { |
/* tab[a]+tab[b] = tab[b](tab[a-b]+1) */ |
/* tab[a]+tab[b] = tab[b](tab[a-b]+1) */ |
a = current_gfs_plus1[a-b]; |
a = current_gfs_plus1[a-b]; |
|
|
} |
} |
} |
} |
|
|
int _chsgnsf(a) |
int _chsgnsf(int a) |
int a; |
|
{ |
{ |
if ( !a ) |
if ( !a ) |
return 0; |
return 0; |
else if ( current_gfs_q1&1 ) |
else if ( !current_gfs_ntoi ) { |
|
a = current_gfs_q-IFTOF(a); |
|
return FTOIF(a); |
|
} else if ( current_gfs_q1&1 ) |
return a; |
return a; |
else { |
else { |
/* r^((q-1)/2) = -1 */ |
/* r^((q-1)/2) = -1 */ |
|
|
} |
} |
} |
} |
|
|
int _subsf(a,b) |
int _subsf(int a,int b) |
int a,b; |
|
{ |
{ |
if ( !a ) |
if ( !a ) |
return _chsgnsf(b); |
return _chsgnsf(b); |
|
|
return _addsf(a,_chsgnsf(b)); |
return _addsf(a,_chsgnsf(b)); |
} |
} |
|
|
int _mulsf(a,b) |
int _mulsf(int a,int b) |
int a,b; |
|
{ |
{ |
|
int c; |
|
|
if ( !a || !b ) |
if ( !a || !b ) |
return 0; |
return 0; |
else { |
else if ( !current_gfs_ntoi ) { |
|
a = IFTOF(a); b = IFTOF(b); |
|
DMAR(a,b,0,current_gfs_q,c); |
|
return FTOIF(c); |
|
} else { |
a = IFTOF(a) + IFTOF(b); |
a = IFTOF(a) + IFTOF(b); |
if ( a >= current_gfs_q1 ) |
if ( a >= current_gfs_q1 ) |
a -= current_gfs_q1; |
a -= current_gfs_q1; |
|
|
} |
} |
} |
} |
|
|
int _invsf(a) |
int _invsf(int a) |
int a; |
|
{ |
{ |
if ( !a ) |
if ( !a ) { |
error("_invsf : division by 0"); |
error("_invsf : division by 0"); |
else { |
/* NOTREACHED */ |
|
return -1; |
|
} else if ( !current_gfs_ntoi ) { |
|
a = invm(IFTOF(a),current_gfs_q); |
|
return FTOIF(a); |
|
} else { |
a = current_gfs_q1 - IFTOF(a); |
a = current_gfs_q1 - IFTOF(a); |
return FTOIF(a); |
return FTOIF(a); |
} |
} |
} |
} |
|
|
int _divsf(a,b) |
int _divsf(int a,int b) |
int a,b; |
|
{ |
{ |
if ( !b ) |
int c; |
|
|
|
if ( !b ) { |
error("_divsf : division by 0"); |
error("_divsf : division by 0"); |
else if ( !a ) |
/* NOTREACHED */ |
|
return -1; |
|
} else if ( !current_gfs_ntoi ) { |
|
b = invm(IFTOF(b),current_gfs_q); |
|
a = IFTOF(a); |
|
DMAR(a,b,0,current_gfs_q,c); |
|
return FTOIF(c); |
|
} else if ( !a ) |
return 0; |
return 0; |
else { |
else { |
a = IFTOF(a) - IFTOF(b); |
a = IFTOF(a) - IFTOF(b); |
|
|
} |
} |
} |
} |
|
|
int _pwrsf(a,b) |
int _pwrsf(int a,int b) |
int a,b; |
|
{ |
{ |
GFS at,ct; |
GFS at,ct; |
Q bt; |
Q bt; |
|
|
return _onesf(); |
return _onesf(); |
else if ( !a ) |
else if ( !a ) |
return 0; |
return 0; |
else { |
if ( !current_gfs_ntoi ) { |
a = IFTOF(a); |
a = pwrm(current_gfs_q,IFTOF(a),b); |
MKGFS(a,at); |
return FTOIF(a); |
|
} else { |
|
iftogfs(a,&at); |
STOQ(b,bt); |
STOQ(b,bt); |
pwrgfs(at,bt,&ct); |
pwrgfs(at,bt,&ct); |
c = CONT(ct); |
c = CONT(ct); |
|
|
|
|
int _onesf() |
int _onesf() |
{ |
{ |
return FTOIF(0); |
return !current_gfs_ntoi ? FTOIF(1) : FTOIF(0); |
} |
} |
|
|
int _itosf(n) |
int _itosf(int n) |
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]; |
i = !current_gfs_ntoi ? n : current_gfs_ntoi[n]; |
i = FTOIF(i); |
i = FTOIF(i); |
if ( n < 0 ) |
if ( n < 0 ) |
i = _chsgnsf(i); |
i = _chsgnsf(i); |
return i; |
return i; |
} |
} |
|
|
int _isonesf(a) |
int _isonesf(int a) |
int a; |
|
{ |
{ |
return a == FTOIF(0); |
return a == _onesf(); |
} |
} |
|
|
int _randomsf() |
int _randomsf() |
{ |
{ |
int t; |
int t; |
|
|
t = (int) (mt_genrand() % current_gfs_q1); |
t = (int) (mt_genrand() % current_gfs_q); |
if ( !t ) |
if ( !current_gfs_ntoi ) |
return 0; |
return t ? FTOIF(t) : 0; |
else |
else |
return FTOIF(t); |
return t!=current_gfs_q1 ? FTOIF(t) : 0; |
} |
} |
|
|
int field_order_sf() |
int field_order_sf() |
Line 1079 int characteristic_sf() |
|
Line 1175 int characteristic_sf() |
|
|
|
int extdeg_sf() |
int extdeg_sf() |
{ |
{ |
return UDEG(current_gfs_ext); |
if ( !current_gfs_ext ) |
|
return 1; |
|
else |
|
return UDEG(current_gfs_ext); |
} |
} |