mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-29 19:17:41 +00:00
* Keyman for Windows 10.0 Open Source * Squashed 'windows/src/ext/jedi/jedi/' content from commit f444ad2 git-subtree-dir: windows/src/ext/jedi/jedi git-subtree-split: f444ad2da4693851e523f1ea6bd541f701904c24 * Squashed 'windows/src/ext/jedi/jcl/' content from commit d63d3c9fd git-subtree-dir: windows/src/ext/jedi/jcl git-subtree-split: d63d3c9fd9ff84efdd8159084ec6a60313644243 * Squashed 'windows/src/ext/jedi/jvcl/' content from commit bee19f3b4 git-subtree-dir: windows/src/ext/jedi/jvcl git-subtree-split: bee19f3b46909fde2fa92c06cd2706f41d99f6c3 * Add required .res files * Add required .res files * Add docbook files (forced) * Add required libxslt * Add required jedi files * Add installation files * Tweak .gitignore for open * CI * Remove KMW from Developer source (#122) * Remove KMW from Developer source (copies during build) * Remove KMW from Developer source (copies during build) * Remove KMW from Developer source (copies during build) * Fixup release build and copy license, readme from kmw during build * Remove obsolete build help documentation * Keyman Engine 10 on Windows regression for shift states (#129) * Improve #128 -- cleaner debug messages * Fixes #127, shift state now resets correctly; and more work for #128 * Fixes #130 (#131)
71 lines
1.4 KiB
C++
71 lines
1.4 KiB
C++
|
|
#define STRICT
|
|
#include <windows.h>
|
|
|
|
/*
|
|
* Instead of performing a straightforward calculation of the 32 bit
|
|
* CRC using a series of logical operations, this program uses the
|
|
* faster table lookup method. This routine is called once when the
|
|
* program starts up to build the table which will be used later
|
|
* when calculating the CRC values.
|
|
*/
|
|
|
|
#define CRC32_POLYNOMIAL 0xEDB88320L
|
|
|
|
unsigned long CRCTable[256];
|
|
|
|
static void BuildCRCTable(void)
|
|
{
|
|
static BOOL TableBuilt = FALSE;
|
|
int i;
|
|
int j;
|
|
unsigned long crc;
|
|
|
|
if(!TableBuilt)
|
|
{
|
|
for(i = 0; i <= 255; i++)
|
|
{
|
|
crc = i;
|
|
|
|
for(j = 8; j > 0; j--)
|
|
if(crc & 1) crc = (crc >> 1) ^ CRC32_POLYNOMIAL; else crc >>= 1;
|
|
|
|
CRCTable[i] = crc;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* This routine calculates the CRC for a block of data using the
|
|
* table lookup method. It accepts an original value for the crc,
|
|
* and returns the updated value.
|
|
*/
|
|
|
|
static unsigned long CalculateBufferCRC(unsigned long count, BYTE *p)
|
|
{
|
|
unsigned long temp1;
|
|
unsigned long temp2;
|
|
unsigned long crc = 0xFFFFFFFFL;
|
|
|
|
while (count-- != 0)
|
|
{
|
|
temp1 = ( crc >> 8 ) & 0x00FFFFFFL;
|
|
temp2 = CRCTable[((int) crc ^ *p++) & 0xff];
|
|
crc = temp1 ^ temp2;
|
|
}
|
|
|
|
return crc;
|
|
}
|
|
|
|
|
|
BOOL VerifyChecksum(LPBYTE buf, LPDWORD CheckSum, DWORD sz)
|
|
{
|
|
DWORD tempcs;
|
|
|
|
tempcs = *CheckSum;
|
|
*CheckSum = 0;
|
|
|
|
BuildCRCTable();
|
|
return tempcs == CalculateBufferCRC(sz, buf);
|
|
}
|