예제 #1
0
파일: bcmutils.c 프로젝트: ANFS/ANFS-kernel
u16 hndcrc16(u8 *pdata,	/* pointer to array of data to process */
	uint nbytes,	/* number of input data bytes to process */
	u16 crc	/* either CRC16_INIT_VALUE or previous return value */
    ) {
	while (nbytes-- > 0)
		CRC_INNER_LOOP(16, crc, *pdata++);
	return crc;
}
예제 #2
0
파일: bcmutils.c 프로젝트: cilynx/dd-wrt
uint32
hndcrc32(
    uint8 *pdata,  /* pointer to array of data to process */
    uint   nbytes, /* number of input data bytes to process */
    uint32 crc     /* either CRC32_INIT_VALUE or previous return value */
)
{
	uint8 *pend;
#ifdef __mips__
	uint8 tmp[4];
	ulong *tptr = (ulong *)tmp;

	/* in case the beginning of the buffer isn't aligned */
	pend = (uint8 *)((uint)(pdata + 3) & 0xfffffffc);
	nbytes -= (pend - pdata);
	while (pdata < pend)
		CRC_INNER_LOOP(32, crc, *pdata++);

	/* handle bulk of data as 32-bit words */
	pend = pdata + (nbytes & 0xfffffffc);
	while (pdata < pend) {
		*tptr = *(ulong *)pdata;
		pdata += sizeof(ulong *);
		CRC_INNER_LOOP(32, crc, tmp[0]);
		CRC_INNER_LOOP(32, crc, tmp[1]);
		CRC_INNER_LOOP(32, crc, tmp[2]);
		CRC_INNER_LOOP(32, crc, tmp[3]);
	}

	/* 1-3 bytes at end of buffer */
	pend = pdata + (nbytes & 0x03);
	while (pdata < pend)
		CRC_INNER_LOOP(32, crc, *pdata++);
#else
	pend = pdata + nbytes;
	while (pdata < pend)
		CRC_INNER_LOOP(32, crc, *pdata++);
#endif /* __mips__ */

	return crc;
}