]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/Common/Crc32.c
License header updated to match correct format.
[mirror_edk2.git] / BaseTools / Source / C / Common / Crc32.c
1 /** @file
2 CalcuateCrc32 routine.
3
4 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <stdlib.h>
16 #include "Crc32.h"
17
18 UINT32 mCrcTable[256] = {
19 0x00000000,
20 0x77073096,
21 0xEE0E612C,
22 0x990951BA,
23 0x076DC419,
24 0x706AF48F,
25 0xE963A535,
26 0x9E6495A3,
27 0x0EDB8832,
28 0x79DCB8A4,
29 0xE0D5E91E,
30 0x97D2D988,
31 0x09B64C2B,
32 0x7EB17CBD,
33 0xE7B82D07,
34 0x90BF1D91,
35 0x1DB71064,
36 0x6AB020F2,
37 0xF3B97148,
38 0x84BE41DE,
39 0x1ADAD47D,
40 0x6DDDE4EB,
41 0xF4D4B551,
42 0x83D385C7,
43 0x136C9856,
44 0x646BA8C0,
45 0xFD62F97A,
46 0x8A65C9EC,
47 0x14015C4F,
48 0x63066CD9,
49 0xFA0F3D63,
50 0x8D080DF5,
51 0x3B6E20C8,
52 0x4C69105E,
53 0xD56041E4,
54 0xA2677172,
55 0x3C03E4D1,
56 0x4B04D447,
57 0xD20D85FD,
58 0xA50AB56B,
59 0x35B5A8FA,
60 0x42B2986C,
61 0xDBBBC9D6,
62 0xACBCF940,
63 0x32D86CE3,
64 0x45DF5C75,
65 0xDCD60DCF,
66 0xABD13D59,
67 0x26D930AC,
68 0x51DE003A,
69 0xC8D75180,
70 0xBFD06116,
71 0x21B4F4B5,
72 0x56B3C423,
73 0xCFBA9599,
74 0xB8BDA50F,
75 0x2802B89E,
76 0x5F058808,
77 0xC60CD9B2,
78 0xB10BE924,
79 0x2F6F7C87,
80 0x58684C11,
81 0xC1611DAB,
82 0xB6662D3D,
83 0x76DC4190,
84 0x01DB7106,
85 0x98D220BC,
86 0xEFD5102A,
87 0x71B18589,
88 0x06B6B51F,
89 0x9FBFE4A5,
90 0xE8B8D433,
91 0x7807C9A2,
92 0x0F00F934,
93 0x9609A88E,
94 0xE10E9818,
95 0x7F6A0DBB,
96 0x086D3D2D,
97 0x91646C97,
98 0xE6635C01,
99 0x6B6B51F4,
100 0x1C6C6162,
101 0x856530D8,
102 0xF262004E,
103 0x6C0695ED,
104 0x1B01A57B,
105 0x8208F4C1,
106 0xF50FC457,
107 0x65B0D9C6,
108 0x12B7E950,
109 0x8BBEB8EA,
110 0xFCB9887C,
111 0x62DD1DDF,
112 0x15DA2D49,
113 0x8CD37CF3,
114 0xFBD44C65,
115 0x4DB26158,
116 0x3AB551CE,
117 0xA3BC0074,
118 0xD4BB30E2,
119 0x4ADFA541,
120 0x3DD895D7,
121 0xA4D1C46D,
122 0xD3D6F4FB,
123 0x4369E96A,
124 0x346ED9FC,
125 0xAD678846,
126 0xDA60B8D0,
127 0x44042D73,
128 0x33031DE5,
129 0xAA0A4C5F,
130 0xDD0D7CC9,
131 0x5005713C,
132 0x270241AA,
133 0xBE0B1010,
134 0xC90C2086,
135 0x5768B525,
136 0x206F85B3,
137 0xB966D409,
138 0xCE61E49F,
139 0x5EDEF90E,
140 0x29D9C998,
141 0xB0D09822,
142 0xC7D7A8B4,
143 0x59B33D17,
144 0x2EB40D81,
145 0xB7BD5C3B,
146 0xC0BA6CAD,
147 0xEDB88320,
148 0x9ABFB3B6,
149 0x03B6E20C,
150 0x74B1D29A,
151 0xEAD54739,
152 0x9DD277AF,
153 0x04DB2615,
154 0x73DC1683,
155 0xE3630B12,
156 0x94643B84,
157 0x0D6D6A3E,
158 0x7A6A5AA8,
159 0xE40ECF0B,
160 0x9309FF9D,
161 0x0A00AE27,
162 0x7D079EB1,
163 0xF00F9344,
164 0x8708A3D2,
165 0x1E01F268,
166 0x6906C2FE,
167 0xF762575D,
168 0x806567CB,
169 0x196C3671,
170 0x6E6B06E7,
171 0xFED41B76,
172 0x89D32BE0,
173 0x10DA7A5A,
174 0x67DD4ACC,
175 0xF9B9DF6F,
176 0x8EBEEFF9,
177 0x17B7BE43,
178 0x60B08ED5,
179 0xD6D6A3E8,
180 0xA1D1937E,
181 0x38D8C2C4,
182 0x4FDFF252,
183 0xD1BB67F1,
184 0xA6BC5767,
185 0x3FB506DD,
186 0x48B2364B,
187 0xD80D2BDA,
188 0xAF0A1B4C,
189 0x36034AF6,
190 0x41047A60,
191 0xDF60EFC3,
192 0xA867DF55,
193 0x316E8EEF,
194 0x4669BE79,
195 0xCB61B38C,
196 0xBC66831A,
197 0x256FD2A0,
198 0x5268E236,
199 0xCC0C7795,
200 0xBB0B4703,
201 0x220216B9,
202 0x5505262F,
203 0xC5BA3BBE,
204 0xB2BD0B28,
205 0x2BB45A92,
206 0x5CB36A04,
207 0xC2D7FFA7,
208 0xB5D0CF31,
209 0x2CD99E8B,
210 0x5BDEAE1D,
211 0x9B64C2B0,
212 0xEC63F226,
213 0x756AA39C,
214 0x026D930A,
215 0x9C0906A9,
216 0xEB0E363F,
217 0x72076785,
218 0x05005713,
219 0x95BF4A82,
220 0xE2B87A14,
221 0x7BB12BAE,
222 0x0CB61B38,
223 0x92D28E9B,
224 0xE5D5BE0D,
225 0x7CDCEFB7,
226 0x0BDBDF21,
227 0x86D3D2D4,
228 0xF1D4E242,
229 0x68DDB3F8,
230 0x1FDA836E,
231 0x81BE16CD,
232 0xF6B9265B,
233 0x6FB077E1,
234 0x18B74777,
235 0x88085AE6,
236 0xFF0F6A70,
237 0x66063BCA,
238 0x11010B5C,
239 0x8F659EFF,
240 0xF862AE69,
241 0x616BFFD3,
242 0x166CCF45,
243 0xA00AE278,
244 0xD70DD2EE,
245 0x4E048354,
246 0x3903B3C2,
247 0xA7672661,
248 0xD06016F7,
249 0x4969474D,
250 0x3E6E77DB,
251 0xAED16A4A,
252 0xD9D65ADC,
253 0x40DF0B66,
254 0x37D83BF0,
255 0xA9BCAE53,
256 0xDEBB9EC5,
257 0x47B2CF7F,
258 0x30B5FFE9,
259 0xBDBDF21C,
260 0xCABAC28A,
261 0x53B39330,
262 0x24B4A3A6,
263 0xBAD03605,
264 0xCDD70693,
265 0x54DE5729,
266 0x23D967BF,
267 0xB3667A2E,
268 0xC4614AB8,
269 0x5D681B02,
270 0x2A6F2B94,
271 0xB40BBE37,
272 0xC30C8EA1,
273 0x5A05DF1B,
274 0x2D02EF8D
275 };
276
277 EFI_STATUS
278 CalculateCrc32 (
279 IN UINT8 *Data,
280 IN UINTN DataSize,
281 IN OUT UINT32 *CrcOut
282 )
283 /*++
284
285 Routine Description:
286
287 The CalculateCrc32 routine.
288
289 Arguments:
290
291 Data - The buffer contaning the data to be processed
292 DataSize - The size of data to be processed
293 CrcOut - A pointer to the caller allocated UINT32 that on
294 contains the CRC32 checksum of Data
295
296 Returns:
297
298 EFI_SUCCESS - Calculation is successful.
299 EFI_INVALID_PARAMETER - Data / CrcOut = NULL, or DataSize = 0
300
301 --*/
302 {
303 UINT32 Crc;
304 UINTN Index;
305 UINT8 *Ptr;
306
307 if ((DataSize == 0) || (Data == NULL) || (CrcOut == NULL)) {
308 return EFI_INVALID_PARAMETER;
309 }
310
311 Crc = 0xffffffff;
312 for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {
313 Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr];
314 }
315
316 *CrcOut = Crc ^ 0xffffffff;
317
318 return EFI_SUCCESS;
319 }