158099996Sbostic /*- 2b6149518Sbostic * Copyright (c) 1991, 1993 3b6149518Sbostic * The Regents of the University of California. All rights reserved. 458099996Sbostic * 558099996Sbostic * %sccs.include.redist.c% 658099996Sbostic * 7*1b726accSmckusick * @(#)lfs_cksum.c 8.2 (Berkeley) 10/09/94 858099996Sbostic */ 958099996Sbostic 10bc286c81Sbostic #include <sys/types.h> 1158099996Sbostic 1258099996Sbostic /* 1368bfaaa9Sbostic * Simple, general purpose, fast checksum. Data must be short-aligned. 1468bfaaa9Sbostic * Returns a u_long in case we ever want to do something more rigorous. 15860e5d38Sbostic * 16860e5d38Sbostic * XXX 17860e5d38Sbostic * Use the TCP/IP checksum instead. 1858099996Sbostic */ 1958099996Sbostic u_long cksum(str,len)2058099996Sbosticcksum(str, len) 2158099996Sbostic register void *str; 2258099996Sbostic register size_t len; 2358099996Sbostic { 2458099996Sbostic register u_long sum; 2558099996Sbostic 2658099996Sbostic len &= ~(sizeof(u_short) - 1); 270c815f7bSbostic for (sum = 0; len; len -= sizeof(u_short)) { 280c815f7bSbostic sum ^= *(u_short *)str; 29*1b726accSmckusick str = (void *)((u_short *)str + 1); 300c815f7bSbostic } 3158099996Sbostic return (sum); 3258099996Sbostic } 33