Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2 KiB

  1. //
  2. // MODULE: CRCCOMPUTE.CPP
  3. //
  4. // PURPOSE: CRC Calculator
  5. //
  6. // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint
  7. //
  8. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  9. //
  10. // AUTHOR: Roman Mach (based on existing CRC designs)
  11. //
  12. // ORIGINAL DATE: 8/7/97
  13. //
  14. // NOTES:
  15. // 1.
  16. //
  17. // Version Date By Comments
  18. //--------------------------------------------------------------------
  19. // V0.2 8/7/97 RM Local Version for Memphis
  20. // V0.3 04/09/98 JM/OK+ Local Version for NT5
  21. //
  22. #include "stdafx.h"
  23. #include "crc.h"
  24. void CCRC::BuildCrcTable()
  25. {
  26. DWORD dwX;
  27. int y;
  28. DWORD dwAccum;
  29. for (dwX = 0; dwX < 256; dwX++)
  30. {
  31. dwAccum = dwX << 24;
  32. for (y = 0; y < 8; y++)
  33. {
  34. if (dwAccum & 0x80000000)
  35. dwAccum = (dwAccum << 1) ^ POLYNOMIAL;
  36. else
  37. dwAccum <<= 1;
  38. }
  39. dwCrcTable[dwX] = dwAccum;
  40. }
  41. return;
  42. }
  43. DWORD CCRC::ComputeCRC(LPCSTR sznBuffer, DWORD dwBufSize, DWORD dwAccum)
  44. {
  45. DWORD dwX;
  46. DWORD dwY;
  47. // DWORD dwAccum = 0xFFFFFFFF;
  48. for (dwX = 0; dwX < dwBufSize; dwX++)
  49. {
  50. dwY = ((dwAccum >> 24) ^ *sznBuffer++) & 0xFF;
  51. dwAccum = (dwAccum << 8) ^ dwCrcTable[dwY];
  52. }
  53. return dwAccum;
  54. }