=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/N.c,v retrieving revision 1.2 retrieving revision 1.8 diff -u -p -r1.2 -r1.8 --- OpenXM_contrib2/asir2000/engine/N.c 2000/08/21 08:31:25 1.2 +++ OpenXM_contrib2/asir2000/engine/N.c 2007/02/18 05:36:27 1.8 @@ -23,7 +23,7 @@ * shall be made on your publication or presentation in any form of the * results obtained by use of the SOFTWARE. * (4) In the event that you modify the SOFTWARE, you shall notify FLL by - * e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification + * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification * for such modification or the source code of the modified part of the * SOFTWARE. * @@ -45,19 +45,13 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/engine/N.c,v 1.1.1.1 1999/12/03 07:39:08 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/engine/N.c,v 1.7 2004/12/04 09:39:27 noro Exp $ */ #include "ca.h" #include "base.h" -void addn(); -int subn(); -void _bshiftn(); -void dupn(); - -#if defined(VISUAL) || defined(i386) -void addn(n1,n2,nr) -N n1,n2,*nr; +#if defined(VISUAL) || ( defined(i386) && !defined(__DARWIN__) ) +void addn(N n1,N n2,N *nr) { unsigned int *m1,*m2,*mr; unsigned int c; @@ -138,8 +132,7 @@ N n1,n2,*nr; } } -int subn(n1,n2,nr) -N n1,n2,*nr; +int subn(N n1,N n2,N *nr) { N r; unsigned int *m1,*m2,*mr,br; @@ -245,8 +238,7 @@ N n1,n2,*nr; } } -void _addn(n1,n2,nr) -N n1,n2,nr; +void _addn(N n1,N n2,N nr) { unsigned int *m1,*m2,*mr; unsigned int c; @@ -326,8 +318,7 @@ N n1,n2,nr; } } -int _subn(n1,n2,nr) -N n1,n2,nr; +int _subn(N n1,N n2,N nr) { unsigned int *m1,*m2,*mr,br; unsigned int tmp,t; @@ -433,8 +424,7 @@ N n1,n2,nr; } #else -void addn(n1,n2,nr) -N n1,n2,*nr; +void addn(N n1,N n2,N *nr) { unsigned int *m1,*m2,*mr,i,c; N r; @@ -475,8 +465,7 @@ N n1,n2,*nr; } } -int subn(n1,n2,nr) -N n1,n2,*nr; +int subn(N n1,N n2,N *nr) { N r; unsigned int *m1,*m2,*mr,i,br; @@ -534,8 +523,7 @@ N n1,n2,*nr; } } -void _addn(n1,n2,nr) -N n1,n2,nr; +void _addn(N n1,N n2,N nr) { unsigned int *m1,*m2,*mr,i,c; int d1,d2; @@ -574,8 +562,7 @@ N n1,n2,nr; } } -int _subn(n1,n2,nr) -N n1,n2,nr; +int _subn(N n1,N n2,N nr) { N r; unsigned int *m1,*m2,*mr,i,br; @@ -635,11 +622,7 @@ N n1,n2,nr; /* a2 += a1; n2 >= n1 */ -void addarray_to(a1,n1,a2,n2) -unsigned int *a1; -int n1; -unsigned int *a2; -int n2; +void addarray_to(unsigned int *a1,int n1,unsigned int *a2,int n2) { int i; unsigned int c,tmp; @@ -664,9 +647,7 @@ int n2; *a2 = c; } -void pwrn(n,e,nr) -N n,*nr; -int e; +void pwrn(N n,int e,N *nr) { N nw,nw1; @@ -683,33 +664,33 @@ int e; FREEN(nw); } + + extern int igcd_algorithm; -void gcdEuclidn(); +void gcdEuclidn(), gcdn_HMEXT(); -void gcdn(n1,n2,nr) -N n1,n2,*nr; +void lcmn(N n1,N n2,N *nr) { - N m1,m2,g; + N g,t; + gcdn(n1,n2,&g); + divsn(n1,g,&t); + muln(t,n2,nr); +} + +void gcdn(N n1,N n2,N *nr) +{ if ( !igcd_algorithm ) gcdEuclidn(n1,n2,nr); else { - if ( !n1 ) - *nr = n2; - else if ( !n2 ) - *nr = n1; - else { - n32ton27(n1,&m1); - n32ton27(n2,&m2); - gcdBinary_27n(m1,m2,&g); - n27ton32(g,nr); - } + gcdn_HMEXT(n1,n2,nr); } } -void gcdEuclidn(n1,n2,nr) -N n1,n2,*nr; +#include "Ngcd.c" + +void gcdEuclidn(N n1,N n2,N *nr) { N m1,m2,q,r; unsigned int i1,i2,ir; @@ -733,7 +714,8 @@ N n1,n2,*nr; m1 = m2; m2 = r; } } - for ( i1 = BD(m1)[0], i2 = BD(m2)[0]; ir = i1 % i2; i1 = i2, i2 = ir ); + for ( i1 = BD(m1)[0], i2 = BD(m2)[0]; ir = i1 % i2; i2 = ir ) + i1 = i2; if ( i2 == 1 ) COPY(ONEN,*nr); else { @@ -742,8 +724,7 @@ N n1,n2,*nr; } } -int cmpn(n1,n2) -N n1,n2; +int cmpn(N n1,N n2) { int i; unsigned int *m1,*m2; @@ -770,10 +751,7 @@ N n1,n2; } } -void bshiftn(n,b,r) -N n; -int b; -N *r; +void bshiftn(N n,int b,N *r) { int w,l,nl,i,j; N z; @@ -841,10 +819,7 @@ N *r; } #if 0 -void _bshiftn(n,b,z) -N n; -int b; -N z; +void _bshiftn(N n,int b,N z) { int w,l,nl,i,j; unsigned int msw; @@ -911,10 +886,7 @@ N z; } #endif -void shiftn(n,w,r) -N n; -int w; -N *r; +void shiftn(N n,int w,N *r) { int l,nl; N z; @@ -938,9 +910,7 @@ N *r; } } -void randomn(bits,r) -int bits; -N *r; +void randomn(int bits,N *r) { int l,i; unsigned int *tb; @@ -960,21 +930,23 @@ N *r; PL(t) = i+1; } -void freen(n) -N n; +void freen(N n) { if ( n && (n != ONEN) ) free(n); } -int n_bits(n) -N n; +/* accepts Z */ +int n_bits(N n) { - unsigned int l,i,t; + unsigned int i,t; + int l; if ( !n ) return 0; - l = PL(n); t = BD(n)[l-1]; + l = PL(n); + if ( l < 0 ) l = -l; + t = BD(n)[l-1]; for ( i = 0; t; t>>=1, i++); return i + (l-1)*BSH; }