crc.cc 724 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "courgette/crc.h"
  5. #include <stdint.h>
  6. #include <stddef.h>
  7. #ifdef COURGETTE_USE_CRC_LIB
  8. # include "zlib.h"
  9. #else
  10. extern "C" {
  11. #include "third_party/lzma_sdk/C/7zCrc.h"
  12. }
  13. #endif
  14. namespace courgette {
  15. uint32_t CalculateCrc(const uint8_t* buffer, size_t size) {
  16. uint32_t crc;
  17. #ifdef COURGETTE_USE_CRC_LIB
  18. // Calculate Crc by calling CRC method in zlib
  19. crc = crc32(0, buffer, size);
  20. #else
  21. // Calculate Crc by calling CRC method in LZMA SDK
  22. CrcGenerateTable();
  23. crc = CrcCalc(buffer, size);
  24. #endif
  25. return ~crc;
  26. }
  27. } // namespace