1 /* Licensed under LGPLv2.1+ - see LICENSE file for details */
8 * crc_of_blocks - calculate the crc of the blocks.
9 * @data: pointer to the buffer to CRC
10 * @len: length of the buffer
11 * @blocksize: CRC of each block (final block may be shorter)
12 * @crcbits: the number of bits of crc you want (currently 64 maximum)
13 * @crc: the crcs (array will have (len + blocksize-1)/blocksize entries).
15 * Calculates the CRC of each block, and output the lower @crcbits to
18 void crc_of_blocks(const void *data, size_t len, unsigned int blocksize,
19 unsigned int crcbits, uint64_t crc[]);
22 * crc_context_new - allocate and initialize state for crc_find_block
23 * @blocksize: the size of each block
24 * @crcbits: the bits valid in the CRCs (<= 64)
25 * @crc: array of block crcs (including final block, if any)
26 * @num_crcs: number of block crcs
27 * @tail_size: the size of final partial block, if any (< blocksize).
29 * Returns an allocated pointer to the structure for crc_find_block,
30 * or NULL. Makes a copy of @crc.
32 struct crc_context *crc_context_new(size_t blocksize, unsigned crcbits,
33 const uint64_t crc[], unsigned num_crcs,
37 * crc_read_block - search for block matches in the buffer.
38 * @ctx: struct crc_context from crc_context_new.
39 * @result: unmatched bytecount, or crc which matched.
40 * @buf: pointer to bytes
41 * @buflen: length of buffer
43 * Returns the number of bytes of the buffer which have been digested,
44 * and sets @result either to a negagive number (== -crc_number - 1)
45 * to show that a block matched a crc, or zero or more to represent a
46 * length of unmatched data.
48 * Note that multiple lengths of unmatched data might be returned in a row:
49 * you'll probably want to merge them yourself.
51 size_t crc_read_block(struct crc_context *ctx, long *result,
52 const void *buf, size_t buflen);
55 * crc_read_flush - flush any remaining data from crc_read_block.
56 * @ctx: the context passed to crc_read_block.
58 * Matches the final data. This can be used to create a boundary, or
59 * simply flush the final data. Keep calling it until it returns 0.
61 long crc_read_flush(struct crc_context *ctx);
64 * crc_context_free - free a context returned from crc_context_new.
65 * @ctx: the context returned from crc_context_new, or NULL.
67 void crc_context_free(struct crc_context *ctx);
69 #endif /* CCAN_CRCSYNC_H */