Debian Codegraph @

ext/zlib-ng/crc32_fold.c

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