/* * MIRACL C++ Implementation file GF2m12x.cpp * * AUTHOR : M. Scott * * PURPOSE : Implementation of class GF2m12x (12-th extension over 2^m) * uses irreducible polynomial x^12+x^FA+x^FB+x^FC+1 * * WARNING: This class has been cobbled together for a specific use with * the MIRACL library. It is not complete, and may not work in other * applications * */ #include "gf2m12x.h" using namespace std; void GF2m12x::get(GF2m* a) {for (int i=0;i=1;i--) { if (!x[i].iszero()) return i; } return 0; } GF2m12x& GF2m12x::powq() { GF2m t[2*FM],m; int i,j,r=(get_mip()->M)%FM; if (r==0) return *this; for (j=0;j=FM;i--) { // reduce mod x^FM+x^FA+x^FB+x^FC+1 m=t[i]; if (m.iszero()) continue; t[i]=0; t[i-FM]+=m; t[i-(FM-FA)]+=m; #ifdef FB t[i-(FM-FB)]+=m; t[i-(FM-FC)]+=m; #endif } for (i=0;i=FM;i--) { // reduce mod x^FM+x^FA+x^FB+x^FC+1 m=t[i]; if (m.iszero()) continue; t[i]=0; t[i-FM]+=m; t[i-(FM-FA)]+=m; #ifdef FB t[i-(FM-FB)]+=m; t[i-(FM-FC)]+=m; #endif } for (i=0;i=FM;i--) { m=t[i]; t[i]=0; t[i-FM]+=m; t[i-(FM-FA)]+=m; #ifdef FB t[i-(FM-FB)]+=m; t[i-(FM-FC)]+=m; #endif } for (i=0;i=j-1) F[i]+=gamma*G[i-j+1]; if (i>=j) F[i]+=beta*G[i-j]; } for (i=0;i<=degB || i<=degC+j;i++) { B[i]*=alpha; if (i>=j-1) B[i]+=gamma*C[i-j+1]; if (i>=j) B[i]+=beta*C[i-j]; } while (degF>=0 && F[degF]==0) degF--; if (degF==degG) { alpha=F[degF]; for (i=0;i<=degF;i++) { F[i]*=G[degF]; F[i]+=alpha*G[i]; } for (i=0;i<=FM-degF;i++) { B[i]*=G[degF]; B[i]+=alpha*C[i]; } while (degF>=0 && F[degF]==0) degF--; } degB=FM-1; while (degB>=0 && B[degB]==0) degB--; } alpha=(GF2m)1/F[0]; for (i=0;i<=degB;i++) x[i]=alpha*B[i]; return; } GF2m12x& GF2m12x::operator/=(const GF2m12x& a) { GF2m12x b=a; b.invert(); *this *= b; return *this; } GF2m12x operator+(const GF2m12x& a,const GF2m12x& b) { GF2m12x r=a; r+=b; return r;} GF2m12x operator+(const GF2m12x& a,const GF2m& b) { GF2m12x r=a; r+=b; return r;} GF2m12x operator+(const GF2m& a,const GF2m12x& b) { GF2m12x r=b; r+=a; return r;} GF2m12x operator*(const GF2m12x& a,const GF2m12x& b) { GF2m12x r=a; if (&a!=&b) r*=b; else r*=r; return r; } GF2m12x operator/(const GF2m12x& a,const GF2m12x& b) { GF2m12x r=a; r/=b; return r; } GF2m12x operator*(const GF2m12x& a,const GF2m& b) { GF2m12x r=a; r*=b; return r;} GF2m12x operator*(const GF2m& a,const GF2m12x& b) { GF2m12x r=b; r*=a; return r;} GF2m12x randx12(void) { int m=get_mip()->M; GF2m12x r; for (int i=0;i1) for (i=nb-2;i>=0;) { n=window(k,i,&nbw,&nzs,5); for (j=0;j0) u*=t[n/2]; i-=nbw; if (nzs) { for (j=0;j