📄 computekeym16.nc
字号:
includes PolyOne;
module ComputeKeyM16 { /* used to evaluate key */
provides{
interface ComputeKey;
}
}
implementation {
uint16_t f_poly16(uint16_t *b,uint16_t x){
uint16_t b2,s2=0;
uint32_t s1=0;
uint32_t s;
uint8_t i,j;
uint16_t md0,mdv;
// dbg(DBG_USR1,"c= %d\n",*b);
// dbg(DBG_USR1,"x= %d\n",x);
for(i=T+1;i>0;i--){
j=i-1;
if(s2) s=(uint32_t )x<<16;
else s=s1*x;
md0=s&0xffff;
mdv=s>>16;
if(md0>=mdv) s=md0-mdv;
else s=65536u+1+md0-mdv;
if(b[j]!=0){ /* b[j] is between 1 and 65535 */
s = s+b[j];
// dbg(DBG_USR1,"poly+= %d\n",s);
} else{ /* b[j] is 0 or 65536 */
b2=j>>4; /* j div 16 is the right shift j by 4 bits */
j=j&15; /* j mod 16, is the least 4 bits of j */
b2=b[T+1+b2]>>j; /* get the 9th bit of b[j] */
b2 = b2&1;
if(b2){ /* b[j] is 65536 */
s = s+65536u;
// dbg(DBG_USR1,"poly+= %d\n",s);
}
/* else b[i-1]=0, nothing need to do. */
}
md0=s&0xffff;
mdv=s>>16;
if(md0>=mdv) s=md0-mdv;
else s=65536u+1+md0-mdv;
s1=s&0xffff;
s2=s>>16;
}
return (uint16_t)s1;
}
command void ComputeKey.compute(uint8_t *array, uint16_t ID, uint8_t *key)
{
PolyShare *ptr;
uint16_t *key16;
key16=(uint16_t *)key;
ptr=(PolyShare *)array;
key16[0] = f_poly16(ptr->poly_ceft1, ID);
key16[1] = f_poly16(ptr->poly_ceft2, ID);
key16[2] = f_poly16(ptr->poly_ceft3, ID);
key16[3] = f_poly16(ptr->poly_ceft4, ID);
// dbg(DBG_USR1,"key=%d %d %d %d\n",key16[0],key16[1],key16[2],key16[3]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -