opencv
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 "functable.h"7
8#include "crc32_fold.h"9
10#include <limits.h>11
12Z_INTERNAL uint32_t crc32_fold_reset_c(crc32_fold *crc) {13crc->value = CRC32_INITIAL_VALUE;14return crc->value;15}
16
17Z_INTERNAL void crc32_fold_copy_c(crc32_fold *crc, uint8_t *dst, const uint8_t *src, size_t len) {18crc->value = functable.crc32(crc->value, src, len);19memcpy(dst, src, len);20}
21
22Z_INTERNAL void crc32_fold_c(crc32_fold *crc, const uint8_t *src, size_t len, uint32_t init_crc) {23/* Note: while this is basically the same thing as the vanilla CRC function, we still need24* a functable entry for it so that we can generically dispatch to this function with the
25* same arguments for the versions that _do_ do a folding CRC but we don't want a copy. The
26* init_crc is an unused argument in this context */
27Z_UNUSED(init_crc);28crc->value = functable.crc32(crc->value, src, len);29}
30
31Z_INTERNAL uint32_t crc32_fold_final_c(crc32_fold *crc) {32return crc->value;33}
34