Source code of Windows XP (NT5)
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.

45 lines
1.1 KiB

  1. /*++
  2. Copyright (c) 1998-1999, Microsoft Corporation
  3. Module Name:
  4. crc-32.cpp
  5. Abstract:
  6. --*/
  7. #include <windows.h>
  8. #include "crc-32.h"
  9. DWORD CRC_32(LPBYTE pb, DWORD cb)
  10. {
  11. // CRC-32 algorithm used in PKZip, AUTODIN II, Ethernet, and FDDI
  12. // but xor out (xorot) has been changed from 0xFFFFFFFF to 0 so
  13. // we can store the CRC at the end of the block and expect 0 to be
  14. // the value of the CRC of the resulting block (including the stored
  15. // CRC).
  16. cm_t cmt = {
  17. 32, // cm_width Parameter: Width in bits [8,32].
  18. 0x04C11DB7, // cm_poly Parameter: The algorithm's polynomial.
  19. 0xFFFFFFFF, // cm_init Parameter: Initial register value.
  20. TRUE, // cm_refin Parameter: Reflect input bytes?
  21. TRUE, // cm_refot Parameter: Reflect output CRC?
  22. 0, // cm_xorot Parameter: XOR this to output CRC.
  23. 0 // cm_reg Context: Context during execution.
  24. };
  25. // Documented test case for CRC-32:
  26. // Checking "123456789" should return 0xCBF43926
  27. cm_ini(&cmt);
  28. cm_blk(&cmt, pb, cb);
  29. return cm_crc(&cmt);
  30. }