xref: /titanic_41/usr/src/lib/libsum/common/sum-att.c (revision 3afe87ebb25691cb6d158edaa34a6fb9b703a691)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1996-2008 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  * att
24  */
25 
26 #define att_description	\
27 	"The system 5 release 4 checksum. This is the default for \bsum\b \
28 	when \bgetconf UNIVERSE\b is \batt\b. This is the only true sum; \
29 	all of the other methods are order dependent."
30 #define att_options	0
31 #define att_match	"att|sys5|s5|default"
32 #define att_open	long_open
33 #define att_init	long_init
34 #define att_print	long_print
35 #define att_data	long_data
36 #define att_scale	512
37 
38 static int
39 att_block(register Sum_t* p, const void* s, size_t n)
40 {
41 	register uint32_t	c = ((Integral_t*)p)->sum;
42 	register unsigned char*	b = (unsigned char*)s;
43 	register unsigned char*	e = b + n;
44 
45 	while (b < e)
46 		c += *b++;
47 	((Integral_t*)p)->sum = c;
48 	return 0;
49 }
50 
51 static int
52 att_done(Sum_t* p)
53 {
54 	register uint32_t	c = ((Integral_t*)p)->sum;
55 
56 	c = (c & 0xffff) + ((c >> 16) & 0xffff);
57 	c = (c & 0xffff) + (c >> 16);
58 	((Integral_t*)p)->sum = c & 0xffff;
59 	return short_done(p);
60 }
61