version 1.1.1.1, 1999/12/03 07:39:08 |
version 1.4, 2001/10/09 01:36:13 |
|
|
/* $OpenXM: OpenXM/src/asir99/engine/up2.c,v 1.1.1.1 1999/11/10 08:12:26 noro Exp $ */ |
/* |
|
* Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED |
|
* All rights reserved. |
|
* |
|
* FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited, |
|
* non-exclusive and royalty-free license to use, copy, modify and |
|
* redistribute, solely for non-commercial and non-profit purposes, the |
|
* computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and |
|
* conditions of this Agreement. For the avoidance of doubt, you acquire |
|
* only a limited right to use the SOFTWARE hereunder, and FLL or any |
|
* third party developer retains all rights, including but not limited to |
|
* copyrights, in and to the SOFTWARE. |
|
* |
|
* (1) FLL does not grant you a license in any way for commercial |
|
* purposes. You may use the SOFTWARE only for non-commercial and |
|
* non-profit purposes only, such as academic, research and internal |
|
* business use. |
|
* (2) The SOFTWARE is protected by the Copyright Law of Japan and |
|
* international copyright treaties. If you make copies of the SOFTWARE, |
|
* with or without modification, as permitted hereunder, you shall affix |
|
* to all such copies of the SOFTWARE the above copyright notice. |
|
* (3) An explicit reference to this SOFTWARE and its copyright owner |
|
* 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@sec.flab.fujitsu.co.jp of the detailed specification |
|
* for such modification or the source code of the modified part of the |
|
* SOFTWARE. |
|
* |
|
* THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL |
|
* MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND |
|
* EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS |
|
* FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES' |
|
* RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY |
|
* MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY. |
|
* UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT, |
|
* OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY |
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL |
|
* DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES |
|
* ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES |
|
* FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY |
|
* DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF |
|
* SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART |
|
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
|
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
|
* |
|
* $OpenXM: OpenXM_contrib2/asir2000/engine/up2.c,v 1.3 2000/08/22 05:04:06 noro Exp $ |
|
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
|
|
void find_root_up2(); |
|
|
|
#define INLINE |
#define INLINE |
|
|
#if defined(VISUAL) |
#if defined(VISUAL) |
|
|
a[q+1] ^= (w>>(32-s));\ |
a[q+1] ^= (w>>(32-s));\ |
} |
} |
|
|
void ptoup2(n,nr) |
void ptoup2(P n,UP2 *nr) |
P n; |
|
UP2 *nr; |
|
{ |
{ |
DCP dc; |
DCP dc; |
UP2 r,s; |
UP2 r,s; |
|
|
} |
} |
} |
} |
|
|
void ptoup2_sparse(n,nr) |
void ptoup2_sparse(P n,UP2 *nr) |
P n; |
|
UP2 *nr; |
|
{ |
{ |
DCP dc; |
DCP dc; |
UP2 s; |
UP2 s; |
|
|
} |
} |
} |
} |
|
|
void up2top(n,nr) |
void up2top(UP2 n,P *nr) |
UP2 n; |
|
P *nr; |
|
{ |
{ |
int i,d; |
int i,d; |
DCP dc0,dc; |
DCP dc0,dc; |
|
|
} |
} |
} |
} |
|
|
void up2tovect(n,nr) |
void up2tovect(UP2 n,VECT *nr) |
UP2 n; |
|
VECT *nr; |
|
{ |
{ |
int i,d; |
int i,d; |
VECT v; |
VECT v; |
|
|
} |
} |
} |
} |
|
|
void up2ton(p,n) |
void up2ton(UP2 p,Q *n) |
UP2 p; |
|
Q *n; |
|
{ |
{ |
N nm; |
N nm; |
int w; |
int w; |
|
|
} |
} |
} |
} |
|
|
void ntoup2(n,p) |
void ntoup2(Q n,UP2 *p) |
Q n; |
|
UP2 *p; |
|
{ |
{ |
N nm; |
N nm; |
UP2 t; |
UP2 t; |
|
|
} |
} |
} |
} |
|
|
void gen_simpup2(p,m,r) |
void gen_simpup2(UP2 p,GEN_UP2 m,UP2 *r) |
UP2 p; |
|
GEN_UP2 m; |
|
UP2 *r; |
|
{ |
{ |
if ( lm_lazy || !m ) |
if ( lm_lazy || !m ) |
*r = p; |
*r = p; |
|
|
*r = 0; |
*r = 0; |
} |
} |
|
|
void gen_simpup2_destructive(p,m) |
void gen_simpup2_destructive(UP2 p,GEN_UP2 m) |
UP2 p; |
|
GEN_UP2 m; |
|
{ |
{ |
UP2 t; |
UP2 t; |
|
|
|
|
remup2_sparse_destructive(p,m->sparse); |
remup2_sparse_destructive(p,m->sparse); |
} |
} |
|
|
void gen_invup2(p,m,r) |
void gen_invup2(UP2 p,GEN_UP2 m,UP2 *r) |
UP2 p; |
|
GEN_UP2 m; |
|
UP2 *r; |
|
{ |
{ |
if ( !m ) |
if ( !m ) |
error("gen_invup2 : invalid modulus"); |
error("gen_invup2 : invalid modulus"); |
|
|
invup2(p,m->dense,r); |
invup2(p,m->dense,r); |
} |
} |
|
|
void gen_pwrmodup2(a,b,m,c) |
void gen_pwrmodup2(UP2 a,Q b,GEN_UP2 m,UP2 *c) |
UP2 a; |
|
Q b; |
|
GEN_UP2 m; |
|
UP2 *c; |
|
{ |
{ |
if ( !m ) |
if ( !m ) |
pwrmodup2(a,b,0,c); |
pwrmodup2(a,b,0,c); |
|
|
pwrmodup2_sparse(a,b,m->sparse,c); |
pwrmodup2_sparse(a,b,m->sparse,c); |
} |
} |
|
|
void simpup2(p,m,r) |
void simpup2(UP2 p,UP2 m,UP2 *r) |
UP2 p,m; |
|
UP2 *r; |
|
{ |
{ |
if ( !lm_lazy && m ) |
if ( !lm_lazy && m ) |
remup2(p,m,r); |
remup2(p,m,r); |
|
|
*r = p; |
*r = p; |
} |
} |
|
|
int degup2(a) |
int degup2(UP2 a) |
UP2 a; |
|
{ |
{ |
unsigned int l,i,t; |
unsigned int l,i,t; |
|
|
|
|
} |
} |
} |
} |
|
|
int degup2_sparse(a) |
int degup2_sparse(UP2 a) |
UP2 a; |
|
{ |
{ |
if ( !a || !a->w ) |
if ( !a || !a->w ) |
return -1; |
return -1; |
|
|
return a->b[0]; |
return a->b[0]; |
} |
} |
|
|
int degup2_1(a) |
int degup2_1(unsigned int a) |
unsigned int a; |
|
{ |
{ |
int i; |
int i; |
|
|
|
|
return i-1; |
return i-1; |
} |
} |
|
|
void addup2(a,b,c) |
void addup2(UP2 a,UP2 b,UP2 *c) |
UP2 a,b; |
|
UP2 *c; |
|
{ |
{ |
int i; |
int i; |
UP2 t; |
UP2 t; |
|
|
} |
} |
} |
} |
|
|
void subup2(a,b,c) |
void subup2(UP2 a,UP2 b,UP2 *c) |
UP2 a,b; |
|
UP2 *c; |
|
{ |
{ |
addup2(a,b,c); |
addup2(a,b,c); |
} |
} |
|
|
--------------------- |
--------------------- |
*/ |
*/ |
|
|
INLINE void mulup2_n1(s,w,m,r) |
INLINE void mulup2_n1(unsigned int *s,int w,unsigned int m,unsigned int *r) |
unsigned int *s,*r; |
|
int w; |
|
unsigned int m; |
|
{ |
{ |
int i; |
int i; |
unsigned int _u,_l,t; |
unsigned int _u,_l,t; |
|
|
} |
} |
} |
} |
|
|
INLINE void mulup2_nh(s,w,m,r) |
INLINE void mulup2_nh(unsigned int *s,int w,unsigned int m,unsigned int *r) |
unsigned int *s,*r; |
|
int w; |
|
unsigned int m; /* 0 <= b <= 0xffff */ |
|
{ |
{ |
int i; |
int i; |
unsigned int u,l; |
unsigned int u,l; |
Line 429 unsigned int m; /* 0 <= b <= 0xffff */ |
|
Line 436 unsigned int m; /* 0 <= b <= 0xffff */ |
|
} |
} |
} |
} |
|
|
void _mulup2_1(a,b,c) |
void _mulup2_1(UP2 a,unsigned int b,UP2 c) |
UP2 a,c; |
|
unsigned int b; |
|
{ |
{ |
int w; |
int w; |
|
|
|
|
} |
} |
} |
} |
|
|
void _mulup2_h(a,b,c) |
void _mulup2_h(UP2 a,unsigned int b,UP2 c) |
UP2 a,c; |
|
unsigned int b; /* 0 <= b <= 0xffff */ |
|
{ |
{ |
int w; |
int w; |
|
|
Line 462 unsigned int b; /* 0 <= b <= 0xffff */ |
|
Line 465 unsigned int b; /* 0 <= b <= 0xffff */ |
|
} |
} |
} |
} |
|
|
void mulup2(a,b,c) |
void mulup2(UP2 a,UP2 b,UP2 *c) |
UP2 a,b; |
|
UP2 *c; |
|
{ |
{ |
UP2 t; |
UP2 t; |
int wa,wb,w; |
int wa,wb,w; |
|
|
} |
} |
} |
} |
|
|
void _kmulup2_(a,b,w,c) |
void _kmulup2_(unsigned int *a,unsigned int *b,int w,unsigned int *c) |
unsigned int *a,*b,*c; |
|
int w; |
|
{ |
{ |
switch ( w ) { |
switch ( w ) { |
case 1: GF2M_MUL_1(c[1],c[0],*a,*b); break; |
case 1: GF2M_MUL_1(c[1],c[0],*a,*b); break; |
|
|
} |
} |
} |
} |
|
|
void _mulup2_nn(a,b,w,c) |
void _mulup2_nn(unsigned int *a,unsigned int *b,int w,unsigned int *c) |
unsigned int *a,*b,*c; |
|
int w; |
|
{ |
{ |
int wlow,whigh; |
int wlow,whigh; |
struct _oUP2 ablow,abhigh,alow,ahigh,blow,bhigh,aa,bb,mid,cmid; |
struct _oUP2 ablow,abhigh,alow,ahigh,blow,bhigh,aa,bb,mid,cmid; |
|
|
_addtoup2_(&mid,&cmid); |
_addtoup2_(&mid,&cmid); |
} |
} |
|
|
void _mulup2(a,b,c) |
void _mulup2(UP2 a,UP2 b,UP2 c) |
UP2 a,b,c; |
|
{ |
{ |
int wa,wb,w; |
int wa,wb,w; |
int i; |
int i; |
|
|
_adjup2(c); |
_adjup2(c); |
} |
} |
|
|
void _mulup2_(a,b,c) |
void _mulup2_(_UP2 a,_UP2 b,_UP2 c) |
_UP2 a,b,c; |
|
{ |
{ |
int wa,wb,w; |
int wa,wb,w; |
int i; |
int i; |
|
|
_adjup2_(c); |
_adjup2_(c); |
} |
} |
|
|
void squareup2(n,nr) |
void squareup2(UP2 n,UP2 *nr) |
UP2 n; |
|
UP2 *nr; |
|
{ |
{ |
int w,w2,i; |
int w,w2,i; |
unsigned int s; |
unsigned int s; |
|
|
} |
} |
} |
} |
|
|
void _squareup2(n,nr) |
void _squareup2(UP2 n,UP2 nr) |
UP2 n; |
|
UP2 nr; |
|
{ |
{ |
int w,w2,i; |
int w,w2,i; |
unsigned int s; |
unsigned int s; |
|
|
} |
} |
} |
} |
|
|
void _adjup2(n) |
void _adjup2(UP2 n) |
UP2 n; |
|
{ |
{ |
int i; |
int i; |
unsigned int *nb; |
unsigned int *nb; |
|
|
n->w = i; |
n->w = i; |
} |
} |
|
|
void _adjup2_(n) |
void _adjup2_(_UP2 n) |
_UP2 n; |
|
{ |
{ |
int i; |
int i; |
unsigned int *nb; |
unsigned int *nb; |
|
|
n->w = i; |
n->w = i; |
} |
} |
|
|
void _addup2(a,b,c) |
void _addup2(UP2 a,UP2 b,UP2 c) |
UP2 a,b,c; |
|
{ |
{ |
int i,wa,wb,w; |
int i,wa,wb,w; |
UP2 t; |
UP2 t; |
|
|
|
|
/* a += b */ |
/* a += b */ |
|
|
void _addup2_destructive(a,b) |
void _addup2_destructive(UP2 a,UP2 b) |
UP2 a,b; |
|
{ |
{ |
int i,wa,wb; |
int i,wa,wb; |
unsigned int *ab,*bb; |
unsigned int *ab,*bb; |
|
|
} |
} |
} |
} |
|
|
void _addup2_(a,b,c) |
void _addup2_(_UP2 a,_UP2 b,_UP2 c) |
_UP2 a,b,c; |
|
{ |
{ |
int i,wa,wb,w; |
int i,wa,wb,w; |
_UP2 t; |
_UP2 t; |
|
|
c->w = wa; |
c->w = wa; |
} |
} |
|
|
void _addtoup2_(a,b) |
void _addtoup2_(_UP2 a,_UP2 b) |
_UP2 a,b; |
|
{ |
{ |
int i,wa; |
int i,wa; |
unsigned int *ab,*bb; |
unsigned int *ab,*bb; |
|
|
|
|
/* 8bit x 8bit; also works if deg(a*b) < 32 */ |
/* 8bit x 8bit; also works if deg(a*b) < 32 */ |
|
|
unsigned int mulup2_bb(a,b) |
unsigned int mulup2_bb(unsigned int a,unsigned int b) |
unsigned int a,b; |
|
{ |
{ |
unsigned int t; |
unsigned int t; |
|
|
Line 789 void init_up2_tab() |
|
Line 773 void init_up2_tab() |
|
deg(b)=BSH-1, deg(a)<=BSH-1 => deg(q)<=BSH-1, deg(r)<=BSH-2 |
deg(b)=BSH-1, deg(a)<=BSH-1 => deg(q)<=BSH-1, deg(r)<=BSH-2 |
*/ |
*/ |
|
|
INLINE unsigned int quoup2_11(a,b) |
INLINE unsigned int quoup2_11(unsigned int a,unsigned int b) |
unsigned int a,b; |
|
{ |
{ |
unsigned int q,i; |
unsigned int q,i; |
|
|
Line 803 unsigned int a,b; |
|
Line 786 unsigned int a,b; |
|
return q; |
return q; |
} |
} |
|
|
void divup2_1(a1,a2,e1,e2,qp,rp) |
void divup2_1(unsigned int a1,unsigned int a2,int e1,int e2,unsigned int *qp,unsigned int *rp) |
unsigned int a1,a2; |
|
int e1,e2; |
|
unsigned int *qp,*rp; |
|
{ |
{ |
int i; |
int i; |
unsigned t,q; |
unsigned t,q; |
Line 821 unsigned int *qp,*rp; |
|
Line 801 unsigned int *qp,*rp; |
|
*qp = q; *rp = a1; |
*qp = q; *rp = a1; |
} |
} |
|
|
void qrup2(a,b,q,r) |
void qrup2(UP2 a,UP2 b,UP2 *q,UP2 *r) |
UP2 a,b; |
|
UP2 *q,*r; |
|
{ |
{ |
unsigned int msa,msb,t,q0; |
unsigned int msa,msb,t,q0; |
int s,i,wq,wb; |
int s,i,wq,wb; |
|
|
|
|
/* q->w >= a->w-b->w+2, r->w >= b->w */ |
/* q->w >= a->w-b->w+2, r->w >= b->w */ |
|
|
void _qrup2(a,b,q,r) |
void _qrup2(UP2 a,UP2 b,UP2 q,UP2 r) |
UP2 a,b; |
|
UP2 q,r; |
|
{ |
{ |
unsigned int msa,msb,t,q0; |
unsigned int msa,msb,t,q0; |
int s,i,wq,wb; |
int s,i,wq,wb; |
|
|
r->w = i+1; |
r->w = i+1; |
} |
} |
|
|
void remup2(a,b,c) |
void remup2(UP2 a,UP2 b,UP2 *c) |
UP2 a,b; |
|
UP2 *c; |
|
{ |
{ |
unsigned int msa,msb,t,q; |
unsigned int msa,msb,t,q; |
int s,i,wq,wb; |
int s,i,wq,wb; |
|
|
} |
} |
} |
} |
|
|
void _remup2(a,b,c) |
void _remup2(UP2 a,UP2 b,UP2 c) |
UP2 a,b,c; |
|
{ |
{ |
unsigned int msa,msb,t,q; |
unsigned int msa,msb,t,q; |
int s,i,wq,wb; |
int s,i,wq,wb; |
|
|
|
|
/* b = b->w|b->b[0]|b->b[1]|... -> b = x^b->[0]+x^b->[1]+... (b->w terms) */ |
/* b = b->w|b->b[0]|b->b[1]|... -> b = x^b->[0]+x^b->[1]+... (b->w terms) */ |
|
|
void remup2_sparse(a,b,c) |
void remup2_sparse(UP2 a,UP2 b,UP2 *c) |
UP2 a,b; |
|
UP2 *c; |
|
{ |
{ |
int i,j,k,wa,wb,d,ds,db,dr,r; |
int i,j,k,wa,wb,d,ds,db,dr,r; |
unsigned int ha,hb; |
unsigned int ha,hb; |
|
|
} |
} |
} |
} |
|
|
void remup2_sparse_destructive(a,b) |
void remup2_sparse_destructive(UP2 a,UP2 b) |
UP2 a,b; |
|
{ |
{ |
int i,j,k,wb,d,ds,db,dr,r; |
int i,j,k,wb,d,ds,db,dr,r; |
unsigned int ha,hb; |
unsigned int ha,hb; |
|
|
|
|
/* b = x^d+x^(d-1)+...+1 */ |
/* b = x^d+x^(d-1)+...+1 */ |
|
|
void remup2_type1_destructive(a,d) |
void remup2_type1_destructive(UP2 a,int d) |
UP2 a; |
|
int d; |
|
{ |
{ |
int i,k,ds,db,dr; |
int i,k,ds,db,dr; |
unsigned int ha,hb,r; |
unsigned int ha,hb,r; |
|
|
|
|
/* b = x^b->b[0]+x^b->b[1]+1 */ |
/* b = x^b->b[0]+x^b->b[1]+1 */ |
|
|
void remup2_3_destructive(a,b) |
void remup2_3_destructive(UP2 a,UP2 b) |
UP2 a,b; |
|
{ |
{ |
int i,k,d,ds,db,db1,dr; |
int i,k,d,ds,db,db1,dr; |
unsigned int ha,hb,r; |
unsigned int ha,hb,r; |
|
|
|
|
/* b = x^b->b[0]+x^b->b[1]+x^b->b[2]+x^b->b[3]+1 */ |
/* b = x^b->b[0]+x^b->b[1]+x^b->b[2]+x^b->b[3]+1 */ |
|
|
void remup2_5_destructive(a,b) |
void remup2_5_destructive(UP2 a,UP2 b) |
UP2 a,b; |
|
{ |
{ |
int i,d,ds,db,db1,db2,db3,dr; |
int i,d,ds,db,db1,db2,db3,dr; |
int k,k1,k2,k3; |
int k,k1,k2,k3; |
|
|
_adjup2(a); |
_adjup2(a); |
} |
} |
|
|
void _invup2_1(f1,f2,a1,b1) |
void _invup2_1(unsigned int f1,unsigned int f2,unsigned int *a1,unsigned int *b1) |
unsigned int f1,f2,*a1,*b1; |
|
{ |
{ |
unsigned int p1,p2,p3,q1,q2,q3,g1,g2,q,r; |
unsigned int p1,p2,p3,q1,q2,q3,g1,g2,q,r; |
int d1,d2; |
int d1,d2; |
Line 1256 unsigned int f1,f2,*a1,*b1; |
|
Line 1221 unsigned int f1,f2,*a1,*b1; |
|
*a1 = p1; *b1 = q1; |
*a1 = p1; *b1 = q1; |
} |
} |
|
|
void _gcdup2_1(f1,f2,gcd) |
void _gcdup2_1(unsigned int f1,unsigned int f2,unsigned int *gcd) |
unsigned int f1,f2,*gcd; |
|
{ |
{ |
unsigned int g1,g2,q,r; |
unsigned int g1,g2,q,r; |
int d1,d2; |
int d1,d2; |
Line 1293 void up2_show_eg() { |
|
Line 1257 void up2_show_eg() { |
|
printf("\n"); |
printf("\n"); |
} |
} |
|
|
void invup2(a,m,inv) |
void invup2(UP2 a,UP2 m,UP2 *inv) |
UP2 a,m; |
|
UP2 *inv; |
|
{ |
{ |
int w,e1,e2,d1,d2; |
int w,e1,e2,d1,d2; |
UP2 g1,g2,g3,a1,a2,a3,q,r,w1,w2,t; |
UP2 g1,g2,g3,a1,a2,a3,q,r,w1,w2,t; |
|
|
} |
} |
} |
} |
|
|
void gcdup2(a,m,gcd) |
void gcdup2(UP2 a,UP2 m,UP2 *gcd) |
UP2 a,m; |
|
UP2 *gcd; |
|
{ |
{ |
int w,e1,e2,d1,d2; |
int w,e1,e2,d1,d2; |
UP2 g1,g2,g3,q,r,w1,w2,t; |
UP2 g1,g2,g3,q,r,w1,w2,t; |
|
|
} |
} |
} |
} |
|
|
void chsgnup2(a,c) |
void chsgnup2(UP2 a,UP2 *c) |
UP2 a,*c; |
|
{ |
{ |
*c = a; |
*c = a; |
} |
} |
|
|
void pwrmodup2(a,b,m,c) |
void pwrmodup2(UP2 a,Q b,UP2 m,UP2 *c) |
UP2 a; |
|
Q b; |
|
UP2 m; |
|
UP2 *c; |
|
{ |
{ |
N n; |
N n; |
UP2 y,t,t1; |
UP2 y,t,t1; |
|
|
} |
} |
} |
} |
|
|
void pwrmodup2_sparse(a,b,m,c) |
void pwrmodup2_sparse(UP2 a,Q b,UP2 m,UP2 *c) |
UP2 a; |
|
Q b; |
|
UP2 m; |
|
UP2 *c; |
|
{ |
{ |
N n; |
N n; |
UP2 y,t,t1; |
UP2 y,t,t1; |
|
|
} |
} |
} |
} |
|
|
int compup2(n1,n2) |
int compup2(UP2 n1,UP2 n2) |
UP2 n1,n2; |
|
{ |
{ |
int i; |
int i; |
unsigned int *m1,*m2; |
unsigned int *m1,*m2; |
|
|
} |
} |
} |
} |
|
|
void _copyup2(n,r) |
void _copyup2(UP2 n,UP2 r) |
UP2 n,r; |
|
{ |
{ |
r->w = n->w; |
r->w = n->w; |
bcopy(n->b,r->b,n->w*sizeof(unsigned int)); |
bcopy(n->b,r->b,n->w*sizeof(unsigned int)); |
} |
} |
|
|
void _bshiftup2(n,b,r) |
void _bshiftup2(UP2 n,int b,UP2 r) |
UP2 n; |
|
int b; |
|
UP2 r; |
|
{ |
{ |
int w,l,nl,i,j; |
int w,l,nl,i,j; |
unsigned int msw; |
unsigned int msw; |
|
|
} |
} |
} |
} |
|
|
void _bshiftup2_destructive(n,b) |
void _bshiftup2_destructive(UP2 n,int b) |
UP2 n; |
|
int b; |
|
{ |
{ |
int w,l,nl,i,j; |
int w,l,nl,i,j; |
unsigned int msw; |
unsigned int msw; |
|
|
} |
} |
} |
} |
|
|
void diffup2(f,r) |
void diffup2(UP2 f,UP2 *r) |
UP2 f; |
|
UP2 *r; |
|
{ |
{ |
int d,i,w; |
int d,i,w; |
UP2 t; |
UP2 t; |
|
|
} |
} |
} |
} |
|
|
int sqfrcheckup2(f) |
int sqfrcheckup2(UP2 f) |
UP2 f; |
|
{ |
{ |
UP2 df,g; |
UP2 df,g; |
|
|
|
|
return 1; |
return 1; |
} |
} |
|
|
int irredcheckup2(f) |
int irredcheckup2(UP2 f) |
UP2 f; |
|
{ |
{ |
int n,w,i,j,k,hcol; |
int n,w,i,j,k,hcol; |
unsigned int hbit; |
unsigned int hbit; |
|
|
return 1; |
return 1; |
} |
} |
|
|
int irredcheck_dddup2(f) |
int irredcheck_dddup2(UP2 f) |
UP2 f; |
|
{ |
{ |
UP2 x,u,t,s,gcd; |
UP2 x,u,t,s,gcd; |
int n,i; |
int n,i; |
|
|
return 1; |
return 1; |
} |
} |
|
|
void _copy_up2bits(p,mat,pos) |
void _copy_up2bits(UP2 p,unsigned int **mat,int pos) |
UP2 p; |
|
unsigned int **mat; |
|
int pos; |
|
{ |
{ |
int d,col,j,jcol,jsh; |
int d,col,j,jcol,jsh; |
unsigned int bit; |
unsigned int bit; |
|
|
mat[pos][col] ^= bit; |
mat[pos][col] ^= bit; |
} |
} |
|
|
int compute_multiplication_matrix(p0,mp) |
int compute_multiplication_matrix(P p0,GF2MAT *mp) |
P p0; |
|
GF2MAT *mp; |
|
{ |
{ |
UP2 p; |
UP2 p; |
int n,w,i,j,k,l; |
int n,w,i,j,k,l; |
|
|
#define GF2N_PBTOPB 0 |
#define GF2N_PBTOPB 0 |
#define GF2N_NBTOPB 1 |
#define GF2N_NBTOPB 1 |
|
|
void compute_change_of_basis_matrix_with_root(P,P,int,GF2N,GF2MAT *,GF2MAT *); |
|
|
|
/* |
/* |
* if 'to' = GF2N_NBTOPB then p0 must be a normal poly. |
* if 'to' = GF2N_NBTOPB then p0 must be a normal poly. |
* rep0 x m01 -> rep1, rep1 x m10 -> rep0 |
* rep0 x m01 -> rep1, rep1 x m10 -> rep0 |
*/ |
*/ |
|
|
void compute_change_of_basis_matrix(p0,p1,to,m01,m10) |
void compute_change_of_basis_matrix(P p0,P p1,int to,GF2MAT *m01,GF2MAT *m10) |
P p0,p1; |
|
int to; |
|
GF2MAT *m01,*m10; |
|
{ |
{ |
UP2 up0; |
UP2 up0; |
int n,w; |
int n,w; |
unsigned int **p01,**p10; |
|
GF2N root; |
GF2N root; |
|
|
setmod_gf2n(p1); |
setmod_gf2n(p1); |
Line 1886 GF2MAT *m01,*m10; |
|
Line 1814 GF2MAT *m01,*m10; |
|
compute_change_of_basis_matrix_with_root(p0,p1,to,root,m01,m10); |
compute_change_of_basis_matrix_with_root(p0,p1,to,root,m01,m10); |
} |
} |
|
|
void compute_change_of_basis_matrix_with_root(p0,p1,to,root,m01,m10) |
void compute_change_of_basis_matrix_with_root(P p0,P p1,int to,GF2N root,GF2MAT *m01,GF2MAT *m10) |
P p0,p1; |
|
int to; |
|
GF2N root; |
|
GF2MAT *m01,*m10; |
|
{ |
{ |
UP2 up0,t,u,s; |
UP2 up0,t,u,s; |
int n,w,i; |
int n,w,i; |
unsigned int **a,**b,**g,**h; |
|
unsigned int **p01,**p10; |
unsigned int **p01,**p10; |
P tmp; |
P tmp; |
|
|
Line 1937 GF2MAT *m01,*m10; |
|
Line 1860 GF2MAT *m01,*m10; |
|
* |
* |
*/ |
*/ |
|
|
int compute_representation_conversion_matrix(p0,np,pn) |
int compute_representation_conversion_matrix(P p0,GF2MAT *np,GF2MAT *pn) |
P p0; |
|
GF2MAT *np,*pn; |
|
{ |
{ |
UP2 x,s; |
UP2 x,s; |
int n,w,i; |
int n,w,i; |
Line 1968 GF2MAT *np,*pn; |
|
Line 1889 GF2MAT *np,*pn; |
|
return 1; |
return 1; |
} |
} |
|
|
void mul_nb(mat,a,b,c) |
void mul_nb(GF2MAT mat,unsigned int *a,unsigned int *b,unsigned int *c) |
GF2MAT mat; |
|
unsigned int *a,*b,*c; |
|
{ |
{ |
int n,w,i; |
int n,w,i; |
unsigned int *wa,*wb,*t; |
unsigned int *wa,*wb,*t; |
Line 1999 unsigned int *a,*b,*c; |
|
Line 1918 unsigned int *a,*b,*c; |
|
a=(c0,c1,...,c{n-1})->(c1,c2,...,c{n-1},c0) |
a=(c0,c1,...,c{n-1})->(c1,c2,...,c{n-1},c0) |
*/ |
*/ |
|
|
void leftshift(a,n) |
void leftshift(unsigned int *a,int n) |
unsigned int *a; |
|
int n; |
|
{ |
{ |
int r,w,i; |
int r,w,i; |
unsigned int msb; |
unsigned int msb; |
|
|
a[w-1] &= (1<<r)-1; |
a[w-1] &= (1<<r)-1; |
} |
} |
|
|
void mat_to_gf2mat(a,b) |
void mat_to_gf2mat(MAT a,unsigned int ***b) |
MAT a; |
|
unsigned int ***b; |
|
{ |
{ |
int n,w,i,j; |
int n,w,i,j; |
unsigned int **m; |
unsigned int **m; |
Line 2032 unsigned int ***b; |
|
Line 1947 unsigned int ***b; |
|
m[i][j/BSH] |= 1<<(j%BSH); |
m[i][j/BSH] |= 1<<(j%BSH); |
} |
} |
|
|
void gf2mat_to_mat(a,n,b) |
void gf2mat_to_mat(unsigned int **a,int n,MAT *b) |
unsigned int **a; |
|
MAT *b; |
|
{ |
{ |
int w,i,j; |
int w,i,j; |
MAT m; |
MAT m; |
|
|
m->body[i][j] = (pointer)ONE; |
m->body[i][j] = (pointer)ONE; |
} |
} |
|
|
void mulgf2mat(n,a,b,c) |
void mulgf2mat(int n,unsigned int **a,unsigned int **b,unsigned int **c) |
int n; |
|
unsigned int **a,**b,**c; |
|
{ |
{ |
int i,j,k,w; |
int i,j,k,w; |
|
|
Line 2065 unsigned int **a,**b,**c; |
|
Line 1976 unsigned int **a,**b,**c; |
|
|
|
/* c = a*b; where a, c are row vectors */ |
/* c = a*b; where a, c are row vectors */ |
|
|
void mulgf2vectmat(n,a,b,c) |
void mulgf2vectmat(int n,unsigned int *a,unsigned int **b,unsigned int *c) |
int n; |
|
unsigned int *a; |
|
unsigned int **b; |
|
unsigned int *c; |
|
{ |
{ |
int j,k,w; |
int j,k,w; |
|
|
Line 2081 unsigned int *c; |
|
Line 1988 unsigned int *c; |
|
c[k] ^= b[j][k]; |
c[k] ^= b[j][k]; |
} |
} |
|
|
int mulgf2vectvect(n,a,b) |
int mulgf2vectvect(int n,unsigned int *a,unsigned int *b) |
int n; |
|
unsigned int *a,*b; |
|
{ |
{ |
unsigned int t,r; |
unsigned int t,r; |
int i,w; |
int i,w; |
Line 2095 unsigned int *a,*b; |
|
Line 2000 unsigned int *a,*b; |
|
return r; |
return r; |
} |
} |
|
|
int invgf2mat(n,a,b) |
int invgf2mat(int n,unsigned int **a,unsigned int **b) |
int n; |
|
unsigned int **a,**b; |
|
{ |
{ |
int i,j,k,hcol,hbit,w; |
int i,j,k,hcol,hbit,w; |
unsigned int *u; |
unsigned int *u; |
Line 2136 unsigned int **a,**b; |
|
Line 2039 unsigned int **a,**b; |
|
return 1; |
return 1; |
} |
} |
|
|
INLINE void _mulup2_11(a1,a2,ar) |
INLINE void _mulup2_11(unsigned int a1,unsigned int a2,unsigned int *ar) |
unsigned int a1,a2; |
|
unsigned int *ar; |
|
{ |
{ |
GF2M_MUL_1(ar[1],ar[0],a1,a2); |
GF2M_MUL_1(ar[1],ar[0],a1,a2); |
} |
} |
|
|
void _mulup2_22(a1,a2,ar) |
void _mulup2_22(unsigned int *a1,unsigned int *a2,unsigned int *ar) |
unsigned int *a1,*a2,*ar; |
|
{ |
{ |
unsigned int m[2]; |
unsigned int m[2]; |
|
|
Line 2157 unsigned int *a1,*a2,*ar; |
|
Line 2057 unsigned int *a1,*a2,*ar; |
|
} |
} |
|
|
#if 0 |
#if 0 |
void _mulup2_33(a1,a2,ar) |
void _mulup2_33(unsigned int *a1,unsigned int *a2,unsigned int *ar) |
unsigned int *a1,*a2,*ar; |
|
{ |
{ |
unsigned int m[4]; |
unsigned int m[4]; |
unsigned int c1[2],c2[2]; |
unsigned int c1[2],c2[2]; |
Line 2178 unsigned int *a1,*a2,*ar; |
|
Line 2077 unsigned int *a1,*a2,*ar; |
|
#else |
#else |
/* (ar[5]...ar[0]) = (a1[2]a1[1]a1[0])*(a2[2]a2[1]a2[0]) */ |
/* (ar[5]...ar[0]) = (a1[2]a1[1]a1[0])*(a2[2]a2[1]a2[0]) */ |
|
|
void _mulup2_33(a1,a2,ar) |
void _mulup2_33(unsigned int *a1,unsigned int *a2,unsigned int *ar) |
unsigned int *a1,*a2,*ar; |
|
{ |
{ |
unsigned int m[4]; |
unsigned int m[4]; |
unsigned int c[2]; |
unsigned int c[2]; |
Line 2228 unsigned int *a1,*a2,*ar; |
|
Line 2126 unsigned int *a1,*a2,*ar; |
|
} |
} |
#endif |
#endif |
|
|
void _mulup2_44(a1,a2,ar) |
void _mulup2_44(unsigned int *a1,unsigned int *a2,unsigned int *ar) |
unsigned int *a1,*a2,*ar; |
|
{ |
{ |
unsigned int m[4]; |
unsigned int m[4]; |
unsigned int c1[2],c2[2]; |
unsigned int c1[2],c2[2]; |
Line 2247 unsigned int *a1,*a2,*ar; |
|
Line 2144 unsigned int *a1,*a2,*ar; |
|
ar[2] ^= m[0]; ar[3] ^= m[1]; ar[4] ^= m[2]; ar[5] ^= m[3]; |
ar[2] ^= m[0]; ar[3] ^= m[1]; ar[4] ^= m[2]; ar[5] ^= m[3]; |
} |
} |
|
|
void _mulup2_55(a1,a2,ar) |
void _mulup2_55(unsigned int *a1,unsigned int *a2,unsigned int *ar) |
unsigned int *a1,*a2,*ar; |
|
{ |
{ |
unsigned int m[6]; |
unsigned int m[6]; |
unsigned int c1[3],c2[3]; |
unsigned int c1[3],c2[3]; |
Line 2267 unsigned int *a1,*a2,*ar; |
|
Line 2163 unsigned int *a1,*a2,*ar; |
|
ar[6] ^= m[3]; ar[7] ^= m[4]; ar[8] ^= m[5]; |
ar[6] ^= m[3]; ar[7] ^= m[4]; ar[8] ^= m[5]; |
} |
} |
|
|
void _mulup2_66(a1,a2,ar) |
void _mulup2_66(unsigned int *a1,unsigned int *a2,unsigned int *ar) |
unsigned int *a1,*a2,*ar; |
|
{ |
{ |
unsigned int m[6]; |
unsigned int m[6]; |
unsigned int c1[3],c2[3]; |
unsigned int c1[3],c2[3]; |
Line 2288 unsigned int *a1,*a2,*ar; |
|
Line 2183 unsigned int *a1,*a2,*ar; |
|
} |
} |
|
|
#if 0 |
#if 0 |
void printup2_(f,l) |
void printup2_(unsigned int *f,int l) |
unsigned int *f; |
|
int l; |
|
{ |
{ |
int i; |
int i; |
|
|
|
|
} |
} |
#endif |
#endif |
|
|
void type1_bin_invup2(a,n,inv) |
void type1_bin_invup2(UP2 a,int n,UP2 *inv) |
UP2 a; |
|
int n; |
|
UP2 *inv; |
|
{ |
{ |
int lf,lg,i,j,k,lg2,df,dg,l,w; |
int lf,lg,i,j,k,lg2,df,dg,l,w; |
unsigned int r; |
unsigned int r; |
|
|
} |
} |
} |
} |
|
|
UP2 *compute_tab_gf2n(f) |
UP2 *compute_tab_gf2n(UP2 f) |
UP2 f; |
|
{ |
{ |
GEN_UP2 mod; |
GEN_UP2 mod; |
int m,n,w,i; |
int m,n,w,i; |
|
|
return tab; |
return tab; |
} |
} |
|
|
UP compute_trace_gf2n(tab,c,n) |
UP compute_trace_gf2n(UP2 *tab,GF2N c,int n) |
UP2 *tab; |
|
GF2N c; |
|
int n; |
|
{ |
{ |
GEN_UP2 mod; |
GEN_UP2 mod; |
int w,m,i,j; |
int w,m,i,j; |
|
|
return r; |
return r; |
} |
} |
|
|
void up2toup(f,r) |
void up2toup(UP2 f,UP *r) |
UP2 f; |
|
UP *r; |
|
{ |
{ |
int d,i; |
int d,i; |
UP2 c; |
UP2 c; |
|
|
} |
} |
} |
} |
|
|
void find_root_up2(f,r) |
void find_root_up2(UP2 f,GF2N *r) |
UP2 f; |
|
GF2N *r; |
|
{ |
{ |
int n; |
int n; |
UP2 *tab; |
UP2 *tab; |
UP uf,trace,gcd,quo,rem; |
UP uf,trace,gcd,quo,rem; |
GF2N c; |
GF2N c; |
int i; |
|
|
|
/* computeation of tab : tab[i] = t^(2^i) mod f (i=0,...,n-1) */ |
/* computeation of tab : tab[i] = t^(2^i) mod f (i=0,...,n-1) */ |
n = degup2(f); |
n = degup2(f); |