xref: /csrg-svn/sys/ufs/lfs/lfs_cksum.c (revision 67808)
151185Sbostic /*-
263375Sbostic  * Copyright (c) 1991, 1993
363375Sbostic  *	The Regents of the University of California.  All rights reserved.
451185Sbostic  *
551185Sbostic  * %sccs.include.redist.c%
651185Sbostic  *
7*67808Smckusick  *	@(#)lfs_cksum.c	8.2 (Berkeley) 10/09/94
851185Sbostic  */
951185Sbostic 
1054261Sbostic #include <sys/types.h>
1151185Sbostic 
1251185Sbostic /*
1351215Sbostic  * Simple, general purpose, fast checksum.  Data must be short-aligned.
1451215Sbostic  * Returns a u_long in case we ever want to do something more rigorous.
1551487Sbostic  *
1651487Sbostic  * XXX
1751487Sbostic  * Use the TCP/IP checksum instead.
1851185Sbostic  */
1951185Sbostic u_long
cksum(str,len)2051185Sbostic cksum(str, len)
2151185Sbostic 	register void *str;
2251185Sbostic 	register size_t len;
2351185Sbostic {
2451185Sbostic 	register u_long sum;
2551185Sbostic 
2651185Sbostic 	len &= ~(sizeof(u_short) - 1);
2753353Sbostic 	for (sum = 0; len; len -= sizeof(u_short)) {
2853353Sbostic 		sum ^= *(u_short *)str;
29*67808Smckusick 		str = (void *)((u_short *)str + 1);
3053353Sbostic 	}
3151185Sbostic 	return (sum);
3251185Sbostic }
33