summaryrefslogtreecommitdiff
path: root/docs/common/lib_crypto/RollingChecksum.txt
blob: d871b3f205c264d4f6314cd52c701b29a3f3c590 (plain)
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
CLASS RollingChecksum

Implementing the rsync rolling checksum algorithm. Read it's description first:

http://samba.anu.edu.au/rsync/tech_report/node3.html


SUBTITLE Construction and initial checksum calculation

The constructor takes a pointer to a block of data and a size, and calculates the checksum of this block. It can now be "rolled forward" to find the checksum of the block of the same size, one byte forward, with minimal calculation.


FUNCTION RollingChecksum::GetChecksum()

Returns the checksum for the current block.


FUNCTION RollingChecksum::RollForward()

This function takes the byte at the start of the current block, and the last byte of the block it's rolling forward to, and moves the checksum on.

If the block is

	char *pBlock = <something>;

with size s, then it should be called with

	RollForward(pBlock[0], pBlock[s])

and now GetChecksum will return the checksum of the block (pBlock+1) of size s.


FUNCTION RollingChecksum::RollForwardSeveral()

Similar to RollForward(), but is more efficient for skipping several bytes at once.  Takes pointers to the data buffer rather than the actual data values.