From owner-FreeBSD-tech-jp@jp.FreeBSD.org Sat Mar  1 00:35:45 2003
Received: (from daemon@localhost)
	by castle.jp.FreeBSD.org (8.11.6+3.4W/8.11.3) id h1SFZjv26732;
	Sat, 1 Mar 2003 00:35:45 +0900 (JST)
	(envelope-from owner-FreeBSD-tech-jp@jp.FreeBSD.org)
Received: from mps3.plala.or.jp (mpsb-nat18.plala.or.jp [202.212.115.65])
	by castle.jp.FreeBSD.org (8.11.6+3.4W/8.11.3) with ESMTP/inet id h1SFZji26727
	for <FreeBSD-tech-jp@jp.FreeBSD.org>; Sat, 1 Mar 2003 00:35:45 +0900 (JST)
	(envelope-from s-hrgsh@lapis.plala.or.jp)
Received: from sv ([218.47.144.233]) by mps3.plala.or.jp with SMTP
          id <20030228153539.JMBV7809.mps3.plala.or.jp@sv>
          for <FreeBSD-tech-jp@jp.FreeBSD.org>;
          Sat, 1 Mar 2003 00:35:39 +0900
From: Seishi Hiragushi <s-hrgsh@lapis.plala.or.jp>
To: FreeBSD-tech-jp@jp.FreeBSD.org
Message-Id: <20030301003539.2749814e.s-hrgsh@lapis.plala.or.jp>
In-Reply-To: <20030204223708.STBL21276.pop03.dreamnet.ne.jp@chino.localhost>
References: <20030204223708.STBL21276.pop03.dreamnet.ne.jp@chino.localhost>
X-Mailer: Sylpheed version 0.8.10 (GTK+ 1.2.10; i386-portbld-freebsd4.7)
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-JP
Content-Transfer-Encoding: 7bit
Reply-To: FreeBSD-tech-jp@jp.FreeBSD.org
Precedence: list
Date: Sat, 1 Mar 2003 00:35:39 +0900
X-Sequence: FreeBSD-tech-jp 3330
Subject: [FreeBSD-tech-jp 3330] Re: CRC32
Errors-To: owner-FreeBSD-tech-jp@jp.FreeBSD.org
Sender: owner-FreeBSD-tech-jp@jp.FreeBSD.org
X-Originator: s-hrgsh@lapis.plala.or.jp
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+030107

On Wed, 5 Feb 2003 07:37:10 +0900
chi@bd.mbn.or.jp (Chiharu Shibata) wrote:

> $B$3$l$r:8Aw$j$K$D$$$F$b!"(B4bit$BC10L$G$N%F!<%V%k;2>H$G7W;;$9$k$3$H$O$G$-$J$$(B
> $B$G$7$g$&$+!)$H$$$&$N$,:#2s$N<ALd$K$J$j$^$9!#(B


$B0J2<$N$h$&$J%3!<%I$G7W;;$G$-$k$h$&$G$9!#(B
bit$BNs$N=g$r5U$K$7$J$$$H$$$1$J$$$N$,?I$$$H$3$m!#(B

unsigned long crc_l(int n, unsigned char c[])
{
 unsigned int d;
 unsigned long crc = ~0;

 static const unsigned char cnv[]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};

 static const unsigned long crctab[] = {
 0x00000000UL, 0x04c11db7UL, 0x09823b6eUL, 0x0d4326d9UL,
 0x130476dcUL, 0x17c56b6bUL, 0x1a864db2UL, 0x1e475005UL,
 0x2608edb8UL, 0x22c9f00fUL, 0x2f8ad6d6UL, 0x2b4bcb61UL,
 0x350c9b64UL, 0x31cd86d3UL, 0x3c8ea00aUL, 0x384fbdbdUL,
 };

 while (--n>=0) {
        d = *c++;
        crc ^= (unsigned long)cnv[d & 0xF] << 28;
        crc = (crc << 4) ^ crctab[crc >> 28];
        crc ^= (unsigned long)cnv[d >> 4] << 28;
        crc = (crc << 4) ^ crctab[crc >> 28];
 }
 return crc;
}

