[21914] | 1 | /** @file
|
---|
| 2 | * IPRT - CRCs and Checksums.
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[98103] | 6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[21914] | 7 | *
|
---|
[96407] | 8 | * This file is part of VirtualBox base platform packages, as
|
---|
| 9 | * available from https://www.virtualbox.org.
|
---|
[21914] | 10 | *
|
---|
[96407] | 11 | * This program is free software; you can redistribute it and/or
|
---|
| 12 | * modify it under the terms of the GNU General Public License
|
---|
| 13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 14 | * License.
|
---|
| 15 | *
|
---|
| 16 | * This program is distributed in the hope that it will be useful, but
|
---|
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 19 | * General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
| 22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 23 | *
|
---|
[21914] | 24 | * The contents of this file may alternatively be used under the terms
|
---|
| 25 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[21914] | 28 | * CDDL are applicable instead of those of the GPL.
|
---|
| 29 | *
|
---|
| 30 | * You may elect to license modified versions of this file under the
|
---|
| 31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 32 | *
|
---|
| 33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[21914] | 34 | */
|
---|
| 35 |
|
---|
[76557] | 36 | #ifndef IPRT_INCLUDED_crc_h
|
---|
| 37 | #define IPRT_INCLUDED_crc_h
|
---|
[76507] | 38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 39 | # pragma once
|
---|
| 40 | #endif
|
---|
[21914] | 41 |
|
---|
| 42 | #include <iprt/cdefs.h>
|
---|
| 43 | #include <iprt/types.h>
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | RT_C_DECLS_BEGIN
|
---|
| 47 |
|
---|
| 48 | /** @defgroup grp_rt_crc RTCrc - Checksums and CRCs.
|
---|
| 49 | * @ingroup grp_rt
|
---|
| 50 | * @{
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | /** @defgroup grp_rt_crc32 CRC-32
|
---|
| 55 | * @{ */
|
---|
| 56 | /**
|
---|
| 57 | * Calculate CRC-32 for a memory block.
|
---|
| 58 | *
|
---|
| 59 | * @returns CRC-32 for the memory block.
|
---|
| 60 | * @param pv Pointer to the memory block.
|
---|
| 61 | * @param cb Size of the memory block in bytes.
|
---|
| 62 | */
|
---|
| 63 | RTDECL(uint32_t) RTCrc32(const void *pv, size_t cb);
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * Start a multiblock CRC-32 calculation.
|
---|
| 67 | *
|
---|
| 68 | * @returns Start CRC-32.
|
---|
| 69 | */
|
---|
| 70 | RTDECL(uint32_t) RTCrc32Start(void);
|
---|
| 71 |
|
---|
| 72 | /**
|
---|
| 73 | * Processes a multiblock of a CRC-32 calculation.
|
---|
| 74 | *
|
---|
| 75 | * @returns Intermediate CRC-32 value.
|
---|
| 76 | * @param uCRC32 Current CRC-32 intermediate value.
|
---|
| 77 | * @param pv The data block to process.
|
---|
| 78 | * @param cb The size of the data block in bytes.
|
---|
| 79 | */
|
---|
| 80 | RTDECL(uint32_t) RTCrc32Process(uint32_t uCRC32, const void *pv, size_t cb);
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | * Complete a multiblock CRC-32 calculation.
|
---|
| 84 | *
|
---|
| 85 | * @returns CRC-32 value.
|
---|
| 86 | * @param uCRC32 Current CRC-32 intermediate value.
|
---|
| 87 | */
|
---|
| 88 | RTDECL(uint32_t) RTCrc32Finish(uint32_t uCRC32);
|
---|
| 89 | /** @} */
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | /** @defgroup grp_rt_crc64 CRC-64 Calculation
|
---|
| 93 | * @{ */
|
---|
| 94 | /**
|
---|
| 95 | * Calculate CRC-64 for a memory block.
|
---|
| 96 | *
|
---|
| 97 | * @returns CRC-64 for the memory block.
|
---|
| 98 | * @param pv Pointer to the memory block.
|
---|
| 99 | * @param cb Size of the memory block in bytes.
|
---|
| 100 | */
|
---|
| 101 | RTDECL(uint64_t) RTCrc64(const void *pv, size_t cb);
|
---|
| 102 |
|
---|
| 103 | /**
|
---|
| 104 | * Start a multiblock CRC-64 calculation.
|
---|
| 105 | *
|
---|
| 106 | * @returns Start CRC-64.
|
---|
| 107 | */
|
---|
| 108 | RTDECL(uint64_t) RTCrc64Start(void);
|
---|
| 109 |
|
---|
| 110 | /**
|
---|
| 111 | * Processes a multiblock of a CRC-64 calculation.
|
---|
| 112 | *
|
---|
| 113 | * @returns Intermediate CRC-64 value.
|
---|
| 114 | * @param uCRC64 Current CRC-64 intermediate value.
|
---|
| 115 | * @param pv The data block to process.
|
---|
| 116 | * @param cb The size of the data block in bytes.
|
---|
| 117 | */
|
---|
| 118 | RTDECL(uint64_t) RTCrc64Process(uint64_t uCRC64, const void *pv, size_t cb);
|
---|
| 119 |
|
---|
| 120 | /**
|
---|
| 121 | * Complete a multiblock CRC-64 calculation.
|
---|
| 122 | *
|
---|
| 123 | * @returns CRC-64 value.
|
---|
| 124 | * @param uCRC64 Current CRC-64 intermediate value.
|
---|
| 125 | */
|
---|
| 126 | RTDECL(uint64_t) RTCrc64Finish(uint64_t uCRC64);
|
---|
| 127 | /** @} */
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | /** @defgroup grp_rt_crc_adler32 Adler-32
|
---|
| 131 | * @{ */
|
---|
| 132 | /**
|
---|
| 133 | * Calculate Adler-32 for a memory block.
|
---|
| 134 | *
|
---|
| 135 | * @returns Adler-32 for the memory block.
|
---|
| 136 | * @param pv Pointer to the memory block.
|
---|
| 137 | * @param cb Size of the memory block in bytes.
|
---|
| 138 | */
|
---|
| 139 | RTDECL(uint32_t) RTCrcAdler32(void const *pv, size_t cb);
|
---|
| 140 |
|
---|
| 141 | /**
|
---|
| 142 | * Start a multiblock Adler-32 calculation.
|
---|
| 143 | *
|
---|
| 144 | * @returns Start Adler-32.
|
---|
| 145 | */
|
---|
| 146 | RTDECL(uint32_t) RTCrcAdler32Start(void);
|
---|
| 147 |
|
---|
| 148 | /**
|
---|
| 149 | * Processes a multiblock of a Adler-32 calculation.
|
---|
| 150 | *
|
---|
| 151 | * @returns Intermediate Adler-32 value.
|
---|
| 152 | * @param uCrc Current Adler-32 intermediate value.
|
---|
| 153 | * @param pv The data block to process.
|
---|
| 154 | * @param cb The size of the data block in bytes.
|
---|
| 155 | */
|
---|
| 156 | RTDECL(uint32_t) RTCrcAdler32Process(uint32_t uCrc, void const *pv, size_t cb);
|
---|
| 157 |
|
---|
| 158 | /**
|
---|
| 159 | * Complete a multiblock Adler-32 calculation.
|
---|
| 160 | *
|
---|
| 161 | * @returns Adler-32 value.
|
---|
| 162 | * @param uCrc Current Adler-32 intermediate value.
|
---|
| 163 | */
|
---|
| 164 | RTDECL(uint32_t) RTCrcAdler32Finish(uint32_t uCrc);
|
---|
| 165 |
|
---|
| 166 | /** @} */
|
---|
| 167 |
|
---|
[50526] | 168 |
|
---|
| 169 | /** @defgroup grp_rt_crc32c CRC-32C
|
---|
| 170 | * @{ */
|
---|
| 171 | /**
|
---|
| 172 | * Calculate CRC-32C for a memory block.
|
---|
| 173 | *
|
---|
| 174 | * @returns CRC-32C for the memory block.
|
---|
| 175 | * @param pv Pointer to the memory block.
|
---|
| 176 | * @param cb Size of the memory block in bytes.
|
---|
| 177 | */
|
---|
| 178 | RTDECL(uint32_t) RTCrc32C(const void *pv, size_t cb);
|
---|
| 179 |
|
---|
| 180 | /**
|
---|
| 181 | * Start a multiblock CRC-32 calculation.
|
---|
| 182 | *
|
---|
| 183 | * @returns Start CRC-32.
|
---|
| 184 | */
|
---|
| 185 | RTDECL(uint32_t) RTCrc32CStart(void);
|
---|
| 186 |
|
---|
| 187 | /**
|
---|
| 188 | * Processes a multiblock of a CRC-32C calculation.
|
---|
| 189 | *
|
---|
| 190 | * @returns Intermediate CRC-32C value.
|
---|
| 191 | * @param uCRC32C Current CRC-32C intermediate value.
|
---|
| 192 | * @param pv The data block to process.
|
---|
| 193 | * @param cb The size of the data block in bytes.
|
---|
| 194 | */
|
---|
| 195 | RTDECL(uint32_t) RTCrc32CProcess(uint32_t uCRC32C, const void *pv, size_t cb);
|
---|
| 196 |
|
---|
| 197 | /**
|
---|
| 198 | * Complete a multiblock CRC-32 calculation.
|
---|
| 199 | *
|
---|
| 200 | * @returns CRC-32 value.
|
---|
| 201 | * @param uCRC32 Current CRC-32 intermediate value.
|
---|
| 202 | */
|
---|
| 203 | RTDECL(uint32_t) RTCrc32CFinish(uint32_t uCRC32);
|
---|
| 204 |
|
---|
[21914] | 205 | /** @} */
|
---|
| 206 |
|
---|
[68884] | 207 |
|
---|
| 208 | /** @defgroup grp_rt_crc16ccitt CRC-16-CCITT
|
---|
| 209 | * @{ */
|
---|
| 210 | /**
|
---|
| 211 | * Calculate CRC-16-CCITT for a memory block.
|
---|
| 212 | *
|
---|
| 213 | * @returns CRC-16-CCITT for the memory block.
|
---|
| 214 | * @param pv Pointer to the memory block.
|
---|
| 215 | * @param cb Size of the memory block in bytes.
|
---|
| 216 | */
|
---|
| 217 | RTDECL(uint16_t) RTCrc16Ccitt(const void *pv, size_t cb);
|
---|
| 218 |
|
---|
| 219 | /**
|
---|
| 220 | * Start a multiblock CRC-16-CCITT calculation.
|
---|
| 221 | *
|
---|
| 222 | * @returns Start CRC-16-CCITT.
|
---|
| 223 | */
|
---|
| 224 | RTDECL(uint16_t) RTCrc16CcittStart(void);
|
---|
| 225 |
|
---|
| 226 | /**
|
---|
| 227 | * Processes a multiblock of a CRC-16-CCITT calculation.
|
---|
| 228 | *
|
---|
| 229 | * @returns Intermediate CRC-16-CCITT value.
|
---|
| 230 | * @param uCrc Current CRC-16-CCITT intermediate value.
|
---|
| 231 | * @param pv The data block to process.
|
---|
| 232 | * @param cb The size of the data block in bytes.
|
---|
| 233 | */
|
---|
| 234 | RTDECL(uint16_t) RTCrc16CcittProcess(uint16_t uCrc, const void *pv, size_t cb);
|
---|
| 235 |
|
---|
| 236 | /**
|
---|
| 237 | * Complete a multiblock CRC-16-CCITT calculation.
|
---|
| 238 | *
|
---|
| 239 | * @returns CRC-16-CCITT value.
|
---|
| 240 | * @param uCrc Current CRC-16-CCITT intermediate value.
|
---|
| 241 | */
|
---|
| 242 | RTDECL(uint16_t) RTCrc16CcittFinish(uint16_t uCrc);
|
---|
[50526] | 243 | /** @} */
|
---|
| 244 |
|
---|
[68884] | 245 | /** @} */
|
---|
| 246 |
|
---|
[21914] | 247 | RT_C_DECLS_END
|
---|
| 248 |
|
---|
[76585] | 249 | #endif /* !IPRT_INCLUDED_crc_h */
|
---|
[21914] | 250 |
|
---|