/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/20#include "SDL_internal.h"2122/* Public domain CRC implementation adapted from:23http://home.thep.lu.se/~bjorn/crc/crc32_simple.c2425This algorithm is compatible with the 32-bit CRC described here:26https://www.lammertbies.nl/comm/info/crc-calculation27*/28/* NOTE: DO NOT CHANGE THIS ALGORITHM29There is code that relies on this in the joystick code30*/3132static Uint32 crc32_for_byte(Uint32 r)33{34int i;35for (i = 0; i < 8; ++i) {36r = (r & 1 ? 0 : (Uint32)0xEDB88320L) ^ r >> 1;37}38return r ^ (Uint32)0xFF000000L;39}4041Uint32 SDL_crc32(Uint32 crc, const void *data, size_t len)42{43// As an optimization we can precalculate a 256 entry table for each byte44size_t i;45for (i = 0; i < len; ++i) {46crc = crc32_for_byte((Uint8)crc ^ ((const Uint8 *)data)[i]) ^ crc >> 8;47}48return crc;49}505152