version 1.2, 2000/08/21 08:31:17 |
version 1.5, 2001/10/09 01:36:02 |
|
|
* shall be made on your publication or presentation in any form of the |
* shall be made on your publication or presentation in any form of the |
* results obtained by use of the SOFTWARE. |
* results obtained by use of the SOFTWARE. |
* (4) In the event that you modify the SOFTWARE, you shall notify FLL by |
* (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 |
* for such modification or the source code of the modified part of the |
* SOFTWARE. |
* SOFTWARE. |
* |
* |
|
|
* 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/asm/ddM.c,v 1.1.1.1 1999/12/03 07:39:06 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/asm/ddM.c,v 1.4 2001/06/25 05:30:48 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
#include "inline.h" |
#include "inline.h" |
|
|
void ksquareummain(int,UM,UM); |
|
void kmulummain(int,UM,UM,UM); |
|
void c_copyum(UM,int,int *); |
|
void copyum(UM,UM); |
|
void extractum(UM,int,int,UM); |
|
void ksquareum(int,UM,UM); |
|
void kmulum(int,UM,UM,UM); |
|
|
|
/* |
/* |
* mod is declared as 'int', because several xxxum functions contains signed |
* mod is declared as 'int', because several xxxum functions contains signed |
* integer addition/subtraction. So mod should be less than 2^31. |
* integer addition/subtraction. So mod should be less than 2^31. |
*/ |
*/ |
|
|
void mulum(mod,p1,p2,pr) |
void mulum(int mod,UM p1,UM p2,UM pr) |
int mod; |
|
UM p1,p2,pr; |
|
{ |
{ |
int *pc1,*pcr; |
int *pc1,*pcr; |
int *c1,*c2,*cr; |
int *c1,*c2,*cr; |
|
|
DEG(pr) = d1 + d2; |
DEG(pr) = d1 + d2; |
} |
} |
|
|
void mulsum(mod,p,n,pr) |
void mulsum(int mod,UM p,int n,UM pr) |
int mod,n; |
|
UM p,pr; |
|
{ |
{ |
int *sp,*dp; |
int *sp,*dp; |
int i; |
int i; |
|
|
} |
} |
} |
} |
|
|
int divum(mod,p1,p2,pq) |
int divum(int mod,UM p1,UM p2,UM pq) |
int mod; |
|
UM p1,p2,pq; |
|
{ |
{ |
int *pc1,*pct; |
int *pc1,*pct; |
int *c1,*c2,*ct; |
int *c1,*c2,*ct; |
|
|
return i; |
return i; |
} |
} |
|
|
void diffum(mod,f,fd) |
void diffum(int mod,UM f,UM fd) |
int mod; |
|
UM f,fd; |
|
{ |
{ |
int *dp,*sp; |
int *dp,*sp; |
int i; |
int i; |
|
#if !defined(VISUAL) |
UL ltmp; |
UL ltmp; |
|
#endif |
|
|
for ( i = DEG(f), dp = COEF(fd)+i-1, sp = COEF(f)+i; |
for ( i = DEG(f), dp = COEF(fd)+i-1, sp = COEF(f)+i; |
i >= 1; i--, dp--, sp-- ) { |
i >= 1; i--, dp--, sp-- ) { |
|
|
degum(fd,DEG(f) - 1); |
degum(fd,DEG(f) - 1); |
} |
} |
|
|
unsigned int pwrm(mod,a,n) |
unsigned int pwrm(int mod,int a,int n) |
int mod,a; |
|
int n; |
|
{ |
{ |
unsigned int s,t; |
unsigned int s,t; |
|
|
|
|
} |
} |
} |
} |
|
|
unsigned int invm(s,mod) |
unsigned int invm(unsigned int s,int mod) |
unsigned int s; |
|
int mod; |
|
{ |
{ |
unsigned int r,a2,q; |
unsigned int r,a2,q; |
unsigned int f1,f2,a1; |
unsigned int f1,f2,a1; |
|
|
return a2; |
return a2; |
} |
} |
|
|
unsigned int rem(n,m) |
unsigned int rem(N n,int m) |
N n; |
|
unsigned int m; |
|
{ |
{ |
unsigned int *x; |
unsigned int *x; |
unsigned int t,r; |
unsigned int t,r; |
|
|
} |
} |
|
|
#ifndef sparc |
#ifndef sparc |
void addpadic(mod,n,n1,n2) |
void addpadic(int mod,int n,unsigned int *n1,unsigned int *n2) |
int mod; |
|
int n; |
|
unsigned int *n1,*n2; |
|
{ |
{ |
unsigned int carry,tmp; |
unsigned int carry,tmp; |
int i; |
int i; |
Line 242 unsigned int *n1,*n2; |
|
Line 219 unsigned int *n1,*n2; |
|
} |
} |
#endif |
#endif |
|
|
void mulpadic(mod,n,n1,n2,nr) |
void mulpadic(int mod,int n,unsigned int *n1,unsigned int *n2,unsigned int *nr) |
int mod; |
|
int n; |
|
unsigned int *n1; |
|
unsigned int *n2,*nr; |
|
{ |
{ |
unsigned int *pn1,*pnr; |
unsigned int *pn1,*pnr; |
unsigned int carry,mul; |
unsigned int carry,mul; |
Line 264 unsigned int *n2,*nr; |
|
Line 237 unsigned int *n2,*nr; |
|
|
|
extern up_kara_mag; |
extern up_kara_mag; |
|
|
void kmulum(mod,n1,n2,nr) |
void kmulum(int mod,UM n1,UM n2,UM nr) |
UM n1,n2,nr; |
|
{ |
{ |
UM n,t,s,m,carry; |
UM n,t,s,m,carry; |
int d,d1,d2,len,i,l; |
int d,d1,d2,len,i,l; |
|
|
carry = W_UMALLOC(d2+1); |
carry = W_UMALLOC(d2+1); |
t = W_UMALLOC(d1+d2+1); |
t = W_UMALLOC(d1+d2+1); |
s = W_UMALLOC(d1+d2+1); |
s = W_UMALLOC(d1+d2+1); |
for ( carry = 0, i = 0, r = r0; i < d; i++, r += d2 ) { |
for ( DEG(carry) = -1, i = 0, r = r0; i < d; i++, r += d2 ) { |
extractum(n1,i*d2,d2,m); |
extractum(n1,i*d2,d2,m); |
if ( m ) { |
if ( m ) { |
kmulum(mod,m,n2,t); |
kmulum(mod,m,n2,t); |
|
|
bcopy((char *)r0,(char *)COEF(nr),l*sizeof(int)); |
bcopy((char *)r0,(char *)COEF(nr),l*sizeof(int)); |
} |
} |
|
|
void ksquareum(mod,n1,nr) |
void ksquareum(int mod,UM n1,UM nr) |
int mod; |
|
UM n1,nr; |
|
{ |
{ |
int d1; |
int d1; |
|
|
|
|
ksquareummain(mod,n1,nr); |
ksquareummain(mod,n1,nr); |
} |
} |
|
|
void extractum(n,index,len,nr) |
void extractum(UM n,int index,int len,UM nr) |
UM n; |
|
int index,len; |
|
UM nr; |
|
{ |
{ |
int *m; |
int *m; |
int l; |
int l; |
|
|
} |
} |
} |
} |
|
|
void copyum(n1,n2) |
void copyum(UM n1,UM n2) |
UM n1,n2; |
|
{ |
{ |
n2->d = n1->d; |
n2->d = n1->d; |
bcopy((char *)n1->c,(char *)n2->c,(n1->d+1)*sizeof(int)); |
bcopy((char *)n1->c,(char *)n2->c,(n1->d+1)*sizeof(int)); |
} |
} |
|
|
void c_copyum(n,len,p) |
void c_copyum(UM n,int len,int *p) |
UM n; |
|
int len; |
|
int *p; |
|
{ |
{ |
if ( n ) |
if ( n ) |
bcopy((char *)COEF(n),(char *)p,MIN((DEG(n)+1),len)*sizeof(int)); |
bcopy((char *)COEF(n),(char *)p,MIN((DEG(n)+1),len)*sizeof(int)); |
} |
} |
|
|
void kmulummain(mod,n1,n2,nr) |
void kmulummain(int mod,UM n1,UM n2,UM nr) |
int mod; |
|
UM n1,n2,nr; |
|
{ |
{ |
int d1,d2,h,len; |
int d1,d2,h,len; |
UM n1lo,n1hi,n2lo,n2hi,hi,lo,mid1,mid2,mid,s1,s2,t1,t2; |
UM n1lo,n1hi,n2lo,n2hi,hi,lo,mid1,mid2,mid,s1,s2,t1,t2; |
|
|
copyum(t1,nr); |
copyum(t1,nr); |
} |
} |
|
|
void ksquareummain(mod,n1,nr) |
void ksquareummain(int mod,UM n1,UM nr) |
int mod; |
|
UM n1,nr; |
|
{ |
{ |
int d1,h,len; |
int d1,h,len; |
UM n1lo,n1hi,hi,lo,mid1,mid2,mid,s1,t1,t2; |
UM n1lo,n1hi,hi,lo,mid1,mid2,mid,s1,t1,t2; |