xref: /titanic_44/usr/src/lib/libsum/common/sum-att.c (revision 7c2fbfb345896881c631598ee3852ce9ce33fb07)
1*7c2fbfb3SApril Chin /***********************************************************************
2*7c2fbfb3SApril Chin *                                                                      *
3*7c2fbfb3SApril Chin *               This software is part of the ast package               *
4*7c2fbfb3SApril Chin *          Copyright (c) 1996-2008 AT&T Intellectual Property          *
5*7c2fbfb3SApril Chin *                      and is licensed under the                       *
6*7c2fbfb3SApril Chin *                  Common Public License, Version 1.0                  *
7*7c2fbfb3SApril Chin *                    by AT&T Intellectual Property                     *
8*7c2fbfb3SApril Chin *                                                                      *
9*7c2fbfb3SApril Chin *                A copy of the License is available at                 *
10*7c2fbfb3SApril Chin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11*7c2fbfb3SApril Chin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*7c2fbfb3SApril Chin *                                                                      *
13*7c2fbfb3SApril Chin *              Information and Software Systems Research               *
14*7c2fbfb3SApril Chin *                            AT&T Research                             *
15*7c2fbfb3SApril Chin *                           Florham Park NJ                            *
16*7c2fbfb3SApril Chin *                                                                      *
17*7c2fbfb3SApril Chin *                 Glenn Fowler <gsf@research.att.com>                  *
18*7c2fbfb3SApril Chin *                                                                      *
19*7c2fbfb3SApril Chin ***********************************************************************/
20*7c2fbfb3SApril Chin #pragma prototyped
21*7c2fbfb3SApril Chin 
22*7c2fbfb3SApril Chin /*
23*7c2fbfb3SApril Chin  * att
24*7c2fbfb3SApril Chin  */
25*7c2fbfb3SApril Chin 
26*7c2fbfb3SApril Chin #define att_description	\
27*7c2fbfb3SApril Chin 	"The system 5 release 4 checksum. This is the default for \bsum\b \
28*7c2fbfb3SApril Chin 	when \bgetconf UNIVERSE\b is \batt\b. This is the only true sum; \
29*7c2fbfb3SApril Chin 	all of the other methods are order dependent."
30*7c2fbfb3SApril Chin #define att_options	0
31*7c2fbfb3SApril Chin #define att_match	"att|sys5|s5|default"
32*7c2fbfb3SApril Chin #define att_open	long_open
33*7c2fbfb3SApril Chin #define att_init	long_init
34*7c2fbfb3SApril Chin #define att_print	long_print
35*7c2fbfb3SApril Chin #define att_data	long_data
36*7c2fbfb3SApril Chin #define att_scale	512
37*7c2fbfb3SApril Chin 
38*7c2fbfb3SApril Chin static int
39*7c2fbfb3SApril Chin att_block(register Sum_t* p, const void* s, size_t n)
40*7c2fbfb3SApril Chin {
41*7c2fbfb3SApril Chin 	register uint32_t	c = ((Integral_t*)p)->sum;
42*7c2fbfb3SApril Chin 	register unsigned char*	b = (unsigned char*)s;
43*7c2fbfb3SApril Chin 	register unsigned char*	e = b + n;
44*7c2fbfb3SApril Chin 
45*7c2fbfb3SApril Chin 	while (b < e)
46*7c2fbfb3SApril Chin 		c += *b++;
47*7c2fbfb3SApril Chin 	((Integral_t*)p)->sum = c;
48*7c2fbfb3SApril Chin 	return 0;
49*7c2fbfb3SApril Chin }
50*7c2fbfb3SApril Chin 
51*7c2fbfb3SApril Chin static int
52*7c2fbfb3SApril Chin att_done(Sum_t* p)
53*7c2fbfb3SApril Chin {
54*7c2fbfb3SApril Chin 	register uint32_t	c = ((Integral_t*)p)->sum;
55*7c2fbfb3SApril Chin 
56*7c2fbfb3SApril Chin 	c = (c & 0xffff) + ((c >> 16) & 0xffff);
57*7c2fbfb3SApril Chin 	c = (c & 0xffff) + (c >> 16);
58*7c2fbfb3SApril Chin 	((Integral_t*)p)->sum = c & 0xffff;
59*7c2fbfb3SApril Chin 	return short_done(p);
60*7c2fbfb3SApril Chin }
61