blob: 55e936eaa3674c5e99067b0d75e58f39792616ea (
plain) (
blame)
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
|
//
// Copyright (c) 1996 Microsoft Corporation
//
//
// CHKSUM.CPP -- Implementation Checksum()
//
// History:
// 05/24/96 JosephJ Created
//
//
#include "common.h"
//---------------- ::Checksum -----------------------------------
// Compute a 32-bit checksum of the specified bytes
// 0 is retured if pb==NULL or cb==0
DWORD Checksum(const BYTE *pb, UINT cb)
{
const UINT MAXSIZE = 1024;
DWORD dwRet = 0;
//DWORD rgdwBuf[MAXSIZE/sizeof(DWORD)];
if (!pb) goto end;
// TODO: replace by crc32
while(cb--) {dwRet ^= dwRet<<1 ^ *pb++;}
#if (TODO)
// If buffer not dword aligned, we copy it over to a buffer which is,
// and pad it
if (cb & 0x3)
{
if (cb>=MAXSIZE)
{
ASSERT(FALSE);
goto end;
}
CopyMemory(rgdwBuf, pb, cb);
}
#endif (TODO)
end:
return dwRet;
}
//---------------- ::AddToChecksumDW ----------------------------
// Set *pdwChkSum to a new checksum, computed using it's previous value and dw.
void AddToChecksumDW(DWORD *pdwChkSum, DWORD dw)
{
DWORD rgdw[2];
rgdw[0] = *pdwChkSum;
rgdw[1] = dw;
*pdwChkSum = Checksum((const BYTE *) rgdw, sizeof(rgdw));
}
|