Hi everyone,
I am trying to make a multiplication function in Binary Field with GF2m, f(x)=x^1279 + x^319 + x^127 + x^63 + 1.
Unfortunately, It does not work properly. I don't know why. Could you please show me if I miss something in my code.
Code:
In my f initialization:
f[19]=f[19]|(1ULL <<63); //set 1279th bit to 1
f[4]=f[4]| (1ULL << 63); // set 319th bit to 1
f[1]=f[1]| (1ULL << 63); //set 127th bit to 1
f[0]=f[0]| (1ULL << 63); // set 63rd bit to 1
f[0]=f[0]|1ULL; //set 1st bit to 1
in my shiftleft:
unsigned char a,b=0;
int i;
b=x[19]& (1ULL<<63);
for (i=19;i>=0;i--){
a=x[i] & (1ULL<<63) ;
x[i]=x[i]<<1ULL;
if (i!=19) if(b) x[i]|=1;
b=a;
}
in my ff_mul:
copy b to b1
if (a[0] & 1) //if the lowest bit of a is 1
for (i=0;i<20;i++) c[i]=b1[i];
for (i=1;i<1279;i++){
k=(b1[19] & (1ULL<<63)); //get the highest bit of b1
shiftleft(b1); //shiftleft b1 by 1
if(k)
for(j=0;j<20;j++) b1[j]^=f[j]; // f=x^1279 + x^319 + x^127 + x^63 + 1
if(a[i / 64] >> (i % 64) & 1) //if the lowest bit of a is 1
for(j=0;j<20;j++) c[j]^=b1[j];
Actually, when I checked each function separately, I saw they are true. However, it still fail when I combine them. Thank you so much.