aschiffler@6713
|
1 |
/*
|
aschiffler@6713
|
2 |
Simple DirectMedia Layer
|
slouken@6885
|
3 |
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
aschiffler@6713
|
4 |
|
aschiffler@6713
|
5 |
This software is provided 'as-is', without any express or implied
|
aschiffler@6713
|
6 |
warranty. In no event will the authors be held liable for any damages
|
aschiffler@6713
|
7 |
arising from the use of this software.
|
aschiffler@6713
|
8 |
|
aschiffler@6713
|
9 |
Permission is granted to anyone to use this software for any purpose,
|
aschiffler@6713
|
10 |
including commercial applications, and to alter it and redistribute it
|
aschiffler@6713
|
11 |
freely, subject to the following restrictions:
|
aschiffler@6713
|
12 |
|
aschiffler@6713
|
13 |
1. The origin of this software must not be misrepresented; you must not
|
aschiffler@6713
|
14 |
claim that you wrote the original software. If you use this software
|
aschiffler@6713
|
15 |
in a product, an acknowledgment in the product documentation would be
|
aschiffler@6713
|
16 |
appreciated but is not required.
|
aschiffler@6713
|
17 |
2. Altered source versions must be plainly marked as such, and must not be
|
aschiffler@6713
|
18 |
misrepresented as being the original software.
|
aschiffler@6713
|
19 |
3. This notice may not be removed or altered from any source distribution.
|
aschiffler@6713
|
20 |
*/
|
aschiffler@6713
|
21 |
|
aschiffler@6713
|
22 |
/**
|
aschiffler@6713
|
23 |
* \file SDL_test_crc32.h
|
aschiffler@6713
|
24 |
*
|
aschiffler@6713
|
25 |
* Include file for SDL test framework.
|
aschiffler@6713
|
26 |
*
|
aschiffler@6713
|
27 |
* This code is a part of the SDL2_test library, not the main SDL library.
|
aschiffler@6713
|
28 |
*/
|
aschiffler@6713
|
29 |
|
aschiffler@6713
|
30 |
/*
|
aschiffler@6713
|
31 |
|
aschiffler@6713
|
32 |
Implements CRC32 calculations (default output is Perl String::CRC32 compatible).
|
aschiffler@6713
|
33 |
|
aschiffler@6713
|
34 |
*/
|
aschiffler@6713
|
35 |
|
aschiffler@6713
|
36 |
#ifndef _SDL_test_crc32_h
|
aschiffler@6713
|
37 |
#define _SDL_test_crc32_h
|
aschiffler@6713
|
38 |
|
aschiffler@6713
|
39 |
#include "begin_code.h"
|
aschiffler@6713
|
40 |
/* Set up for C function definitions, even when using C++ */
|
aschiffler@6713
|
41 |
#ifdef __cplusplus
|
aschiffler@6713
|
42 |
/* *INDENT-OFF* */
|
aschiffler@6713
|
43 |
extern "C" {
|
aschiffler@6713
|
44 |
/* *INDENT-ON* */
|
aschiffler@6713
|
45 |
#endif
|
aschiffler@6713
|
46 |
|
aschiffler@6713
|
47 |
|
aschiffler@6713
|
48 |
/* ------------ Definitions --------- */
|
aschiffler@6713
|
49 |
|
aschiffler@6713
|
50 |
/* Definition shared by all CRC routines */
|
aschiffler@6713
|
51 |
|
aschiffler@6713
|
52 |
#ifndef CrcUint32
|
aschiffler@6713
|
53 |
#define CrcUint32 unsigned int
|
aschiffler@6713
|
54 |
#endif
|
aschiffler@6713
|
55 |
#ifndef CrcUint8
|
aschiffler@6713
|
56 |
#define CrcUint8 unsigned char
|
aschiffler@6713
|
57 |
#endif
|
aschiffler@6713
|
58 |
|
aschiffler@6713
|
59 |
#ifdef ORIGINAL_METHOD
|
aschiffler@6713
|
60 |
#define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */
|
aschiffler@6713
|
61 |
#else
|
aschiffler@6713
|
62 |
#define CRC32_POLY 0xEDB88320 /* Perl String::CRC32 compatible */
|
aschiffler@6713
|
63 |
#endif
|
aschiffler@6713
|
64 |
|
aschiffler@6713
|
65 |
/**
|
aschiffler@6713
|
66 |
* Data structure for CRC32 (checksum) computation
|
aschiffler@6713
|
67 |
*/
|
aschiffler@6713
|
68 |
typedef struct {
|
aschiffler@6713
|
69 |
CrcUint32 crc32_table[256]; /* CRC table */
|
aschiffler@6713
|
70 |
} SDLTest_Crc32Context;
|
aschiffler@6713
|
71 |
|
aschiffler@6713
|
72 |
/* ---------- Function Prototypes ------------- */
|
aschiffler@6713
|
73 |
|
aschiffler@6713
|
74 |
/**
|
aschiffler@6713
|
75 |
* /brief Initialize the CRC context
|
aschiffler@6713
|
76 |
*
|
aschiffler@6713
|
77 |
* Note: The function initializes the crc table required for all crc calculations.
|
aschiffler@6713
|
78 |
*
|
aschiffler@6713
|
79 |
* /param crcContext pointer to context variable
|
aschiffler@6713
|
80 |
*
|
aschiffler@6713
|
81 |
* /returns 0 for OK, -1 on error
|
aschiffler@6713
|
82 |
*
|
aschiffler@6713
|
83 |
*/
|
aschiffler@6713
|
84 |
int SDLTest_Crc32Init(SDLTest_Crc32Context * crcContext);
|
aschiffler@6713
|
85 |
|
aschiffler@6713
|
86 |
|
aschiffler@6713
|
87 |
/**
|
aschiffler@6713
|
88 |
* /brief calculate a crc32 from a data block
|
aschiffler@6713
|
89 |
*
|
aschiffler@6713
|
90 |
* /param crcContext pointer to context variable
|
aschiffler@6713
|
91 |
* /param inBuf input buffer to checksum
|
aschiffler@6713
|
92 |
* /param inLen length of input buffer
|
aschiffler@6713
|
93 |
* /param crc32 pointer to Uint32 to store the final CRC into
|
aschiffler@6713
|
94 |
*
|
aschiffler@6713
|
95 |
* /returns 0 for OK, -1 on error
|
aschiffler@6713
|
96 |
*
|
aschiffler@6713
|
97 |
*/
|
aschiffler@6713
|
98 |
int SDLTest_crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
|
aschiffler@6713
|
99 |
|
aschiffler@6713
|
100 |
/* Same routine broken down into three steps */
|
aschiffler@6713
|
101 |
int SDLTest_Crc32CalcStart(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
|
aschiffler@6713
|
102 |
int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
|
aschiffler@6713
|
103 |
int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
|
aschiffler@6713
|
104 |
|
aschiffler@6713
|
105 |
|
aschiffler@6713
|
106 |
/**
|
aschiffler@6713
|
107 |
* /brief clean up CRC context
|
aschiffler@6713
|
108 |
*
|
aschiffler@6713
|
109 |
* /param crcContext pointer to context variable
|
aschiffler@6713
|
110 |
*
|
aschiffler@6713
|
111 |
* /returns 0 for OK, -1 on error
|
aschiffler@6713
|
112 |
*
|
aschiffler@6713
|
113 |
*/
|
aschiffler@6713
|
114 |
|
aschiffler@6713
|
115 |
int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext);
|
aschiffler@6713
|
116 |
|
aschiffler@6713
|
117 |
|
aschiffler@6713
|
118 |
/* Ends C function definitions when using C++ */
|
aschiffler@6713
|
119 |
#ifdef __cplusplus
|
aschiffler@6713
|
120 |
/* *INDENT-OFF* */
|
aschiffler@6713
|
121 |
}
|
aschiffler@6713
|
122 |
/* *INDENT-ON* */
|
aschiffler@6713
|
123 |
#endif
|
aschiffler@6713
|
124 |
#include "close_code.h"
|
aschiffler@6713
|
125 |
|
aschiffler@6713
|
126 |
#endif /* _SDL_test_crc32_h */
|
aschiffler@6713
|
127 |
|
aschiffler@6713
|
128 |
/* vi: set ts=4 sw=4 expandtab: */
|