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