151185Sbostic /*- 251185Sbostic * Copyright (c) 1991 The Regents of the University of California. 351185Sbostic * All rights reserved. 451185Sbostic * 551185Sbostic * %sccs.include.redist.c% 651185Sbostic * 7*54261Sbostic * @(#)lfs_cksum.c 7.5 (Berkeley) 06/22/92 851185Sbostic */ 951185Sbostic 10*54261Sbostic #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