/* Count the number of differing bytes and bits and return the first differing offset.  */
static int countdiffs(unsigned char *buf, unsigned char *check_buf, unsigned offset, unsigned len, unsigned *bytesp, unsigned *bitsp)
/* Count the number of differing bytes and bits and return the first differing offset.  */
static int countdiffs(unsigned char *buf, unsigned char *check_buf, unsigned offset, unsigned len, unsigned *bytesp, unsigned *bitsp)
{
	unsigned i, bit;
	int first = -1;
	for (i = offset; i < offset + len; i++)
		if (buf[i] != check_buf[i]) {
			first = i;
			break;
		}
	while (i < offset + len) {
		if (buf[i] != check_buf[i]) {
			(*bytesp)++;
			bit = 1;
			while (bit < 256) {
				if ((buf[i] & bit) != (check_buf[i] & bit))
					(*bitsp)++;
				bit <<= 1;
			}
		}
		i++;
	}
	return first;
}