SDL_test_crc32.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 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_begin_code.h>
  29. /* Set up for C function definitions, even when using C++ */
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* ------------ Definitions --------- */
  34. /* Definition shared by all CRC routines */
  35. #ifndef CrcUint32
  36. #define CrcUint32 unsigned int
  37. #endif
  38. #ifndef CrcUint8
  39. #define CrcUint8 unsigned char
  40. #endif
  41. #ifdef ORIGINAL_METHOD
  42. #define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */
  43. #else
  44. #define CRC32_POLY 0xEDB88320 /* Perl String::CRC32 compatible */
  45. #endif
  46. /*
  47. * Data structure for CRC32 (checksum) computation
  48. */
  49. typedef struct SDLTest_Crc32Context {
  50. CrcUint32 crc32_table[256]; /* CRC table */
  51. } SDLTest_Crc32Context;
  52. /* ---------- Function Prototypes ------------- */
  53. /*
  54. * Initialize the CRC context
  55. *
  56. * Note: The function initializes the crc table required for all crc calculations.
  57. *
  58. * \param crcContext pointer to context variable
  59. *
  60. * \returns 0 for OK, -1 on error
  61. *
  62. */
  63. int SDLCALL SDLTest_Crc32Init(SDLTest_Crc32Context *crcContext);
  64. /*
  65. * calculate a crc32 from a data block
  66. *
  67. * \param crcContext pointer to context variable
  68. * \param inBuf input buffer to checksum
  69. * \param inLen length of input buffer
  70. * \param crc32 pointer to Uint32 to store the final CRC into
  71. *
  72. * \returns 0 for OK, -1 on error
  73. *
  74. */
  75. int SDLCALL SDLTest_Crc32Calc(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
  76. /* Same routine broken down into three steps */
  77. int SDLCALL SDLTest_Crc32CalcStart(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32);
  78. int SDLCALL SDLTest_Crc32CalcEnd(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32);
  79. int SDLCALL SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
  80. /*
  81. * clean up CRC context
  82. *
  83. * \param crcContext pointer to context variable
  84. *
  85. * \returns 0 for OK, -1 on error
  86. *
  87. */
  88. int SDLCALL SDLTest_Crc32Done(SDLTest_Crc32Context *crcContext);
  89. /* Ends C function definitions when using C++ */
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #include <SDL3/SDL_close_code.h>
  94. #endif /* SDL_test_crc32_h_ */