CRC算法及工作原理
return (accum);
}
/* 函數(shù)mk-crctbl利用函數(shù)crchware建立內(nèi)存中的CRC數(shù)值表 */
unsigned short *mk-crctbl(poly,crcfn);
unsigned short poly;/* CRC除數(shù)--CRC生成多項(xiàng)式 */
R>unsigned short (*crcfn)();/* 指向CRC函數(shù)(例如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;
}
/* 函數(shù)mk-crctbl的使用范例 */
if((crctblp=mk-crctbl(CRCCCITT,crchware))==NIL)
{
puts(insuff memory for CRC lookup table.n);
return 1; */
/* 函數(shù)crcupdate用以用查表法計(jì)算CRC值并更新CRC累加器值 */
void crcupdate(data,accum,crctab)
unsigned short data;/* 輸入的數(shù)據(jù) */
unsigned short *accum;/* 指向CRC累加器的指針 */
unsigned short *crctab;/* 指向內(nèi)存中CRC表的指針 */
{
static short comb-val;
comb-val=(*accum>>8)^data;
*accum=(*accum8)^crctab[comb-val];
}
評論