ok.. I know it sounds annoying to ask questions like this, BUT I really don't understand the code [advance_reg(int*)] below. In the comments of the code, it says that "/the register steps according to the primitive polynomial(64,4,3,1,0);/", I just didn't get it. Any one please give me a hint about this code please? For example, why it defines the adv_64 arrays like that? I understand the first for block shifted the number 27 times, one bit each time. But why? what is the math behind this? Further, why perform the second for block? What does these all connect with the polynomial(64,4,3,1,0)?
static int bitcnt( int x)
{
unsigned i=0,y;
for (y=(unsigned)x; y; y &= (y-1) )
i++;
return(i);
}
static void advance_reg(int *reg_fill)
{
const int mask = 0x1b;
int adv_64[4][2];
int i,new_fill[2];
unsigned temp;
adv_64[0][0] = 0xb0000000;
adv_64[0][1] = 0x1b;
adv_64[1][0] = 0x60000000;
adv_64[1][1] = 0x2d;
adv_64[2][0] = 0xc0000000;
adv_64[2][1] = 0x5a;
adv_64[3][0] = 0x80000000;
adv_64[3][1] = 0xaf;
new_fill[1] = new_fill[0] = 0;
temp = mask<<27;
for (i=27;i>=0;i--)
{
new_fill[0] = (new_fill[0]<<1) | (1&bitcnt(reg_fill[0]&temp));
new_fill[1] = (new_fill[1]<<1) | (1&bitcnt(reg_fill[1]&temp));
temp >>= 1;
}
for (i=28;i<32;i++)
{
temp = bitcnt(reg_fill[0]&(mask<<i));
temp ^= bitcnt(reg_fill[1]&(mask>>(32-i)));
new_fill[0] |= (1&temp)<<i;
temp = bitcnt(reg_fill[0]&adv_64[i-28][0]);
temp ^= bitcnt(reg_fill[1]&adv_64[i-28][1]);
new_fill[1] |= (1&temp)<<i;
}
reg_fill[0] = new_fill[0];
reg_fill[1] = new_fill[1];
}