1/***********************************************************************
2*                                                                      *
3*               This software is part of the ast package               *
4*          Copyright (c) 1996-2010 AT&T Intellectual Property          *
5*                      and is licensed under the                       *
6*                  Common Public License, Version 1.0                  *
7*                    by AT&T Intellectual Property                     *
8*                                                                      *
9*                A copy of the License is available at                 *
10*            http://www.opensource.org/licenses/cpl1.0.txt             *
11*         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*                                                                      *
13*              Information and Software Systems Research               *
14*                            AT&T Research                             *
15*                           Florham Park NJ                            *
16*                                                                      *
17*                 Glenn Fowler <gsf@research.att.com>                  *
18*                                                                      *
19***********************************************************************/
20#pragma prototyped
21
22/*
23 * bsd
24 */
25
26#define bsd_description \
27	"The BSD checksum."
28#define bsd_options	0
29#define bsd_match	"bsd|ucb"
30#define bsd_open	long_open
31#define bsd_init	long_init
32#define bsd_done	short_done
33#define bsd_print	long_print
34#define bsd_data	long_data
35#define bsd_scale	1024
36
37static int
38bsd_block(register Sum_t* p, const void* s, size_t n)
39{
40	register uint32_t	c = ((Integral_t*)p)->sum;
41	register unsigned char*	b = (unsigned char*)s;
42	register unsigned char*	e = b + n;
43
44	while (b < e)
45		c = ((c >> 1) + *b++ + ((c & 01) ? 0x8000 : 0)) & 0xffff;
46	((Integral_t*)p)->sum = c;
47	return 0;
48}
49