Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
CRC.cpp
1/*
2Copyright (C) 2016,2018,2025 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#include <cassert>
17#include "aeongames/CRC.hpp"
18
19namespace AeonGames
20{
27 uint32_t crc32i ( const char* message, size_t size, uint32_t previous_crc )
28 {
29 assert ( message != nullptr );
30 // Un-finalize the previous CRC to continue computing
31 uint32_t remainder = reflect32<16> ( previous_crc ) ^ 0xFFFFFFFF;
32 uint32_t data;
33 /*
34 * Divide the message by the polynomial, a byte at a time.
35 */
36 for ( size_t byte = 0; byte < size; ++byte )
37 {
38 data = reflect32<4> ( static_cast<uint8_t> ( message[byte] ) ) ^ ( remainder >> ( 32 - 8 ) );
39 remainder = crc_table32[data] ^ ( remainder << 8 );
40 }
41 /*
42 * The final remainder is the CRC.
43 */
44 return reflect32<16> ( remainder ) ^ 0xFFFFFFFF;
45 }
46
53 uint64_t crc64i ( const char* message, size_t size, uint64_t previous_crc )
54 {
55 assert ( message != nullptr );
56 // Un-finalize the previous CRC to continue computing
57 uint64_t remainder = reflect64<32> ( previous_crc ) ^ 0xFFFFFFFFFFFFFFFF;
58 uint64_t data;
59 /*
60 * Divide the message by the polynomial, a byte at a time.
61 */
62 for ( size_t byte = 0; byte < size; ++byte )
63 {
64 data = reflect64<4> ( static_cast<uint8_t> ( message[byte] ) ) ^ ( remainder >> ( 64 - 8 ) );
65 remainder = crc_table64[data] ^ ( remainder << 8 );
66 }
67 /*
68 * The final remainder is the CRC.
69 */
70 return reflect64<32> ( remainder ) ^ 0xFFFFFFFFFFFFFFFF;
71 }
72}
<- This is here just for the literals
Definition AABB.hpp:31
uint32_t crc32i(const char *message, size_t size, uint32_t previous_crc)
Compute the CRC32 of a given message, continuing from a previous CRC value.
Definition CRC.cpp:27
uint64_t crc64i(const char *message, size_t size, uint64_t previous_crc)
Compute the CRC64 of a given message, continuing from a previous CRC value.
Definition CRC.cpp:53