crc32_fold_c.c 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. /* crc32_fold.c -- crc32 folding interface
  2. * Copyright (C) 2021 Nathan Moinvaziri
  3. * For conditions of distribution and use, see copyright notice in zlib.h
  4. */
  5. #include "zbuild.h"
  6. #include "zutil.h"
  7. #include "functable.h"
  8. #include "crc32.h"
  9. Z_INTERNAL uint32_t crc32_fold_reset_c(crc32_fold *crc) {
  10. crc->value = CRC32_INITIAL_VALUE;
  11. return crc->value;
  12. }
  13. Z_INTERNAL void crc32_fold_copy_c(crc32_fold *crc, uint8_t *dst, const uint8_t *src, size_t len) {
  14. crc->value = FUNCTABLE_CALL(crc32)(crc->value, src, len);
  15. memcpy(dst, src, len);
  16. }
  17. Z_INTERNAL void crc32_fold_c(crc32_fold *crc, const uint8_t *src, size_t len, uint32_t init_crc) {
  18. /* Note: while this is basically the same thing as the vanilla CRC function, we still need
  19. * a functable entry for it so that we can generically dispatch to this function with the
  20. * same arguments for the versions that _do_ do a folding CRC but we don't want a copy. The
  21. * init_crc is an unused argument in this context */
  22. Z_UNUSED(init_crc);
  23. crc->value = FUNCTABLE_CALL(crc32)(crc->value, src, len);
  24. }
  25. Z_INTERNAL uint32_t crc32_fold_final_c(crc32_fold *crc) {
  26. return crc->value;
  27. }