Wireshark-dev: Re: [Wireshark-dev] Share CRC32C code between MPA and iSCSI
From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Fri, 04 Apr 2008 02:17:34 -0700
Philip Frey1 wrote:

we have developed a dissector for the MPA (Marker PDU Aligned Framing) protocol which is part of the iWARP stack.
Since we also need to do some CRC32C calculations (same as iSCSI),

...and, it appears, SCTP.

The SCTP dissector has the same CRC table; its CRC routine starts with 0xFFFFFFFF - which, when byte-swapped, is unchanged - and then adds in to the CRC a bunch of bytes and 0's, flips the bits in the result, and then swaps the bytes. Your CRC32 routine doesn't flip the bits, so the right way to combine them might be to:

	export the CRC32 table from crc32c.c, declaring it in crc32.h;

	moving the CRC32C macro from packet-sctp.c to crc32.h;

moving the CRC32C_SWAP macro from crc32c.c to crc32.h (or see whether GLib 1.2.x and 2.x define something equivalent, and use that);

	have calculate_crc32() use the CRC32C macro:

guint32 calculate_crc32(const void *buf, int len, guint32 crc)
{
	const guint8 *p = (const guint8 *)buf;
	crc = CRC32C_SWAP(crc);
	while (len-- > 0) {
		CRC32C(crc, *p++);
	}
	return CRC32C_SWAP(crc);
}

	have sctp_crc32c() use CRC32C_PRELOAD instead of ~0L.

There might be some other merging that could be done.