crc32.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* crc32.c -- compute the CRC-32 of a data stream
  2. * Copyright (C) 1995-2022 Mark Adler
  3. * For conditions of distribution and use, see copyright notice in zlib.h
  4. *
  5. * This interleaved implementation of a CRC makes use of pipelined multiple
  6. * arithmetic-logic units, commonly found in modern CPU cores. It is due to
  7. * Kadatch and Jenkins (2010). See doc/crc-doc.1.0.pdf in this distribution.
  8. */
  9. #include "zbuild.h"
  10. #include "functable.h"
  11. #include "crc32_braid_tbl.h"
  12. /* ========================================================================= */
  13. const uint32_t * Z_EXPORT PREFIX(get_crc_table)(void) {
  14. return (const uint32_t *)crc_table;
  15. }
  16. #ifdef ZLIB_COMPAT
  17. unsigned long Z_EXPORT PREFIX(crc32_z)(unsigned long crc, const unsigned char *buf, size_t len) {
  18. if (buf == NULL) return 0;
  19. return (unsigned long)FUNCTABLE_CALL(crc32)((uint32_t)crc, buf, len);
  20. }
  21. #else
  22. uint32_t Z_EXPORT PREFIX(crc32_z)(uint32_t crc, const unsigned char *buf, size_t len) {
  23. if (buf == NULL) return 0;
  24. return FUNCTABLE_CALL(crc32)(crc, buf, len);
  25. }
  26. #endif
  27. #ifdef ZLIB_COMPAT
  28. unsigned long Z_EXPORT PREFIX(crc32)(unsigned long crc, const unsigned char *buf, unsigned int len) {
  29. return (unsigned long)PREFIX(crc32_z)((uint32_t)crc, buf, len);
  30. }
  31. #else
  32. uint32_t Z_EXPORT PREFIX(crc32)(uint32_t crc, const unsigned char *buf, uint32_t len) {
  33. return PREFIX(crc32_z)(crc, buf, len);
  34. }
  35. #endif