xref: /csrg-svn/sys/ufs/lfs/lfs_cksum.c (revision 63375)
151185Sbostic /*-
2*63375Sbostic  * Copyright (c) 1991, 1993
3*63375Sbostic  *	The Regents of the University of California.  All rights reserved.
451185Sbostic  *
551185Sbostic  * %sccs.include.redist.c%
651185Sbostic  *
7*63375Sbostic  *	@(#)lfs_cksum.c	8.1 (Berkeley) 06/11/93
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
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;
2953353Sbostic 		++(u_short *)str;
3053353Sbostic 	}
3151185Sbostic 	return (sum);
3251185Sbostic }
33