CRC算法及工作原理
return (accum);
}
/* 函数mk-crctbl利用函数crchware建立内存中的CRC数值表 */
unsigned short *mk-crctbl(poly,crcfn);
unsigned short poly;/* CRC除数--CRC生成多项式 */
R>unsigned short (*crcfn)();/* 指向CRC函数(例如crchware)的指针 */
{
/* unsigned short */malloc(); */
unsigned short *crctp;
int i;
if((crctp=(unsigned short*)malloc(256*sizeof(unsigned)))==0)
return 0;
for(i=0;i256;i++)
crctp=(*crcfn)(i,poly,0);
return crctp;
}
/* 函数mk-crctbl的使用范例 */
if((crctblp=mk-crctbl(CRCCCITT,crchware))==NIL)
{
puts(insuff memory for CRC lookup table.n);
return 1; */
/* 函数crcupdate用以用查表法计算CRC值并更新CRC累加器值 */
void crcupdate(data,accum,crctab)
unsigned short data;/* 输入的数据 */
unsigned short *accum;/* 指向CRC累加器的指针 */
unsigned short *crctab;/* 指向内存中CRC表的指针 */
{
static short comb-val;
comb-val=(*accum>>8)^data;
*accum=(*accum8)^crctab[comb-val];
}
评论