1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1996-2011 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
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 
37 static int
bsd_block(register Sum_t * p,const void * s,size_t n)38 bsd_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