File: cksum.cn

package info (click to toggle)
xdelta 0.14-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 684 kB
  • ctags: 682
  • sloc: ansic: 5,668; sh: 1,740; makefile: 62
file content (79 lines) | stat: -rw-r--r-- 2,501 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* -*-Mode: C;-*-
 * XDELTA - RCS replacement and delta generator
 * Copyright (C) 1997  Josh MacDonald
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: cksum.cn 1.3 Sun, 12 Oct 1997 20:29:34 -0700 jmacd $
 */

void
NAME (const TYPE *buf,
      const gint  len,
      Checksum   *cksum)
{
  gint i = 0;

  cksum->high = 0;
  cksum->low = 0;

  if (len > 16)
    {
      const gint len_minus_16 = len - 16;

      for (; i < len_minus_16; i+=16)
	{
	  cksum->high += 16*(CHEW(buf[i+0]) + cksum->low) +
	                 15* CHEW(buf[i+1]) +
	                 14* CHEW(buf[i+2]) +
	                 13* CHEW(buf[i+3]) +
	                 12* CHEW(buf[i+4]) +
	                 11* CHEW(buf[i+5]) +
	                 10* CHEW(buf[i+6]) +
	                 9*  CHEW(buf[i+7]) +
	                 8*  CHEW(buf[i+8]) +
	                 7*  CHEW(buf[i+9]) +
	                 6*  CHEW(buf[i+10]) +
	                 5*  CHEW(buf[i+11]) +
	                 4*  CHEW(buf[i+12]) +
	                 3*  CHEW(buf[i+13]) +
	                 2*  CHEW(buf[i+14]) +
	                 1*  CHEW(buf[i+15]);

	  cksum->low  +=     CHEW(buf[i+0]) +
	                     CHEW(buf[i+1]) +
	                     CHEW(buf[i+2]) +
	                     CHEW(buf[i+3]) +
	                     CHEW(buf[i+4]) +
	                     CHEW(buf[i+5]) +
	                     CHEW(buf[i+6]) +
	                     CHEW(buf[i+7]) +
	                     CHEW(buf[i+8]) +
	                     CHEW(buf[i+9]) +
	                     CHEW(buf[i+10]) +
	                     CHEW(buf[i+11]) +
	                     CHEW(buf[i+12]) +
	                     CHEW(buf[i+13]) +
	                     CHEW(buf[i+14]) +
	                     CHEW(buf[i+15]);
	}
    }

  for (; i < len; i += 1)
    {
      cksum->low  += CHEW(buf[i]);
      cksum->high += cksum->low;
    }
}