Skip to content

Commit a1aed60

Browse files
committed
rgw_cksum: add 64bit and 32bit crc constructions from crcany
These constructions provide conforming implemenations of Amazon S3 CRC32 (ISO hdlc), CRC32C (iscsi), and CRC64/NVME checksums, in particular, linear combining of adjacent checksums, by Mark Adler. Source: https://github.com/madler/crcany License: approximate BSD with "optional" advertising clause Signed-off-by: Matt Benjamin <[email protected]>
1 parent ff4a415 commit a1aed60

File tree

7 files changed

+1668
-0
lines changed

7 files changed

+1668
-0
lines changed

src/rgw/madler/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (C) 2014-2025 Mark Adler
2+
3+
This software is provided 'as-is', without any express or implied warranty.
4+
In no event will the authors be held liable for any damages arising from the
5+
use of this software.
6+
7+
Permission is granted to anyone to use this software for any purpose,
8+
including commercial applications, and to alter it and redistribute it
9+
freely, subject to the following restrictions:
10+
11+
1. The origin of this software must not be misrepresented; you must not claim
12+
that you wrote the original software. If you use this software in a
13+
product, an acknowledgment in the product documentation would be
14+
appreciated but is not required.
15+
2. Altered source versions must be plainly marked as such, and must not be
16+
misrepresented as being the original software.
17+
3. This notice may not be removed or altered from any source distribution.
18+
19+
Mark Adler
20+

src/rgw/madler/crc32iscsi.c

Lines changed: 463 additions & 0 deletions
Large diffs are not rendered by default.

src/rgw/madler/crc32iscsi.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// The _bit, _byte, and _word routines return the CRC of the len
2+
// bytes at mem, applied to the previous CRC value, crc. If mem is
3+
// NULL, then the other arguments are ignored, and the initial CRC,
4+
// i.e. the CRC of zero bytes, is returned. Those routines will all
5+
// return the same result, differing only in speed and code
6+
// complexity. The _rem routine returns the CRC of the remaining
7+
// bits in the last byte, for when the number of bits in the
8+
// message is not a multiple of eight. The low bits bits of the low
9+
// byte of val are applied to crc. bits must be in 0..8.
10+
11+
#include <stddef.h>
12+
#include <stdint.h>
13+
14+
// Compute the CRC a bit at a time.
15+
uint32_t crc32iscsi_bit(uint32_t crc, void const *mem, size_t len);
16+
17+
// Compute the CRC of the low bits bits in val.
18+
uint32_t crc32iscsi_rem(uint32_t crc, unsigned val, unsigned bits);
19+
20+
// Compute the CRC a byte at a time.
21+
uint32_t crc32iscsi_byte(uint32_t crc, void const *mem, size_t len);
22+
23+
// Compute the CRC a word at a time.
24+
uint32_t crc32iscsi_word(uint32_t crc, void const *mem, size_t len);
25+
26+
// Compute the combination of two CRCs.
27+
uint32_t crc32iscsi_comb(uint32_t crc1, uint32_t crc2, uintmax_t len2);

src/rgw/madler/crc32iso_hdlc.c

Lines changed: 463 additions & 0 deletions
Large diffs are not rendered by default.

src/rgw/madler/crc32iso_hdlc.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// The _bit, _byte, and _word routines return the CRC of the len
2+
// bytes at mem, applied to the previous CRC value, crc. If mem is
3+
// NULL, then the other arguments are ignored, and the initial CRC,
4+
// i.e. the CRC of zero bytes, is returned. Those routines will all
5+
// return the same result, differing only in speed and code
6+
// complexity. The _rem routine returns the CRC of the remaining
7+
// bits in the last byte, for when the number of bits in the
8+
// message is not a multiple of eight. The low bits bits of the low
9+
// byte of val are applied to crc. bits must be in 0..8.
10+
11+
#include <stddef.h>
12+
#include <stdint.h>
13+
14+
// Compute the CRC a bit at a time.
15+
uint32_t crc32iso_hdlc_bit(uint32_t crc, void const *mem, size_t len);
16+
17+
// Compute the CRC of the low bits bits in val.
18+
uint32_t crc32iso_hdlc_rem(uint32_t crc, unsigned val, unsigned bits);
19+
20+
// Compute the CRC a byte at a time.
21+
uint32_t crc32iso_hdlc_byte(uint32_t crc, void const *mem, size_t len);
22+
23+
// Compute the CRC a word at a time.
24+
uint32_t crc32iso_hdlc_word(uint32_t crc, void const *mem, size_t len);
25+
26+
// Compute the combination of two CRCs.
27+
uint32_t crc32iso_hdlc_comb(uint32_t crc1, uint32_t crc2, uintmax_t len2);

src/rgw/madler/crc64nvme.c

Lines changed: 641 additions & 0 deletions
Large diffs are not rendered by default.

src/rgw/madler/crc64nvme.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// The _bit, _byte, and _word routines return the CRC of the len
2+
// bytes at mem, applied to the previous CRC value, crc. If mem is
3+
// NULL, then the other arguments are ignored, and the initial CRC,
4+
// i.e. the CRC of zero bytes, is returned. Those routines will all
5+
// return the same result, differing only in speed and code
6+
// complexity. The _rem routine returns the CRC of the remaining
7+
// bits in the last byte, for when the number of bits in the
8+
// message is not a multiple of eight. The low bits bits of the low
9+
// byte of val are applied to crc. bits must be in 0..8.
10+
11+
#include <stddef.h>
12+
#include <stdint.h>
13+
14+
// Compute the CRC a bit at a time.
15+
uint64_t crc64nvme_bit(uint64_t crc, void const *mem, size_t len);
16+
17+
// Compute the CRC of the low bits bits in val.
18+
uint64_t crc64nvme_rem(uint64_t crc, unsigned val, unsigned bits);
19+
20+
// Compute the CRC a byte at a time.
21+
uint64_t crc64nvme_byte(uint64_t crc, void const *mem, size_t len);
22+
23+
// Compute the CRC a word at a time.
24+
uint64_t crc64nvme_word(uint64_t crc, void const *mem, size_t len);
25+
26+
// Compute the combination of two CRCs.
27+
uint64_t crc64nvme_comb(uint64_t crc1, uint64_t crc2, uintmax_t len2);

0 commit comments

Comments
 (0)