1
0

SDL_test_crc32.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  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. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * CRC32 functions of SDL test framework.
  20. *
  21. * This code is a part of the SDL test library, not the main SDL library.
  22. */
  23. /*
  24. Implements CRC32 calculations (default output is Perl String::CRC32 compatible).
  25. */
  26. #ifndef SDL_test_crc32_h_
  27. #define SDL_test_crc32_h_
  28. #include <SDL3/SDL_stdinc.h>
  29. #include <SDL3/SDL_begin_code.h>
  30. /* Set up for C function definitions, even when using C++ */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* ------------ Definitions --------- */
  35. /* Definition shared by all CRC routines */
  36. #ifndef CrcUint32
  37. #define CrcUint32 unsigned int
  38. #endif
  39. #ifndef CrcUint8
  40. #define CrcUint8 unsigned char
  41. #endif
  42. #ifdef ORIGINAL_METHOD
  43. #define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */
  44. #else
  45. #define CRC32_POLY 0xEDB88320 /* Perl String::CRC32 compatible */
  46. #endif
  47. /*
  48. * Data structure for CRC32 (checksum) computation
  49. */
  50. typedef struct SDLTest_Crc32Context {
  51. CrcUint32 crc32_table[256]; /* CRC table */
  52. } SDLTest_Crc32Context;
  53. /* ---------- Function Prototypes ------------- */
  54. /*
  55. * Initialize the CRC context
  56. *
  57. * Note: The function initializes the crc table required for all crc calculations.
  58. *
  59. * \param crcContext pointer to context variable
  60. *
  61. * \returns true on success or false on failure; call SDL_GetError()
  62. * for more information.
  63. *
  64. */
  65. bool SDLCALL SDLTest_Crc32Init(SDLTest_Crc32Context *crcContext);
  66. /*
  67. * calculate a crc32 from a data block
  68. *
  69. * \param crcContext pointer to context variable
  70. * \param inBuf input buffer to checksum
  71. * \param inLen length of input buffer
  72. * \param crc32 pointer to Uint32 to store the final CRC into
  73. *
  74. * \returns true on success or false on failure; call SDL_GetError()
  75. * for more information.
  76. *
  77. */
  78. bool SDLCALL SDLTest_Crc32Calc(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
  79. /* Same routine broken down into three steps */
  80. bool SDLCALL SDLTest_Crc32CalcStart(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32);
  81. bool SDLCALL SDLTest_Crc32CalcEnd(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32);
  82. bool SDLCALL SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
  83. /*
  84. * clean up CRC context
  85. *
  86. * \param crcContext pointer to context variable
  87. *
  88. * \returns true on success or false on failure; call SDL_GetError()
  89. * for more information.
  90. *
  91. */
  92. bool SDLCALL SDLTest_Crc32Done(SDLTest_Crc32Context *crcContext);
  93. /* Ends C function definitions when using C++ */
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #include <SDL3/SDL_close_code.h>
  98. #endif /* SDL_test_crc32_h_ */