1 | /** @file
|
---|
2 | Utility functions to generate checksum based on 2's complement
|
---|
3 | algorithm.
|
---|
4 |
|
---|
5 | Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "BaseLibInternals.h"
|
---|
11 |
|
---|
12 | /**
|
---|
13 | Returns the sum of all elements in a buffer in unit of UINT8.
|
---|
14 | During calculation, the carry bits are dropped.
|
---|
15 |
|
---|
16 | This function calculates the sum of all elements in a buffer
|
---|
17 | in unit of UINT8. The carry bits in result of addition are dropped.
|
---|
18 | The result is returned as UINT8. If Length is Zero, then Zero is
|
---|
19 | returned.
|
---|
20 |
|
---|
21 | If Buffer is NULL, then ASSERT().
|
---|
22 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
23 |
|
---|
24 | @param Buffer The pointer to the buffer to carry out the sum operation.
|
---|
25 | @param Length The size, in bytes, of Buffer.
|
---|
26 |
|
---|
27 | @return Sum The sum of Buffer with carry bits dropped during additions.
|
---|
28 |
|
---|
29 | **/
|
---|
30 | UINT8
|
---|
31 | EFIAPI
|
---|
32 | CalculateSum8 (
|
---|
33 | IN CONST UINT8 *Buffer,
|
---|
34 | IN UINTN Length
|
---|
35 | )
|
---|
36 | {
|
---|
37 | UINT8 Sum;
|
---|
38 | UINTN Count;
|
---|
39 |
|
---|
40 | ASSERT (Buffer != NULL);
|
---|
41 | ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));
|
---|
42 |
|
---|
43 | for (Sum = 0, Count = 0; Count < Length; Count++) {
|
---|
44 | Sum = (UINT8) (Sum + *(Buffer + Count));
|
---|
45 | }
|
---|
46 |
|
---|
47 | return Sum;
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | /**
|
---|
52 | Returns the two's complement checksum of all elements in a buffer
|
---|
53 | of 8-bit values.
|
---|
54 |
|
---|
55 | This function first calculates the sum of the 8-bit values in the
|
---|
56 | buffer specified by Buffer and Length. The carry bits in the result
|
---|
57 | of addition are dropped. Then, the two's complement of the sum is
|
---|
58 | returned. If Length is 0, then 0 is returned.
|
---|
59 |
|
---|
60 | If Buffer is NULL, then ASSERT().
|
---|
61 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
62 |
|
---|
63 | @param Buffer The pointer to the buffer to carry out the checksum operation.
|
---|
64 | @param Length The size, in bytes, of Buffer.
|
---|
65 |
|
---|
66 | @return Checksum The 2's complement checksum of Buffer.
|
---|
67 |
|
---|
68 | **/
|
---|
69 | UINT8
|
---|
70 | EFIAPI
|
---|
71 | CalculateCheckSum8 (
|
---|
72 | IN CONST UINT8 *Buffer,
|
---|
73 | IN UINTN Length
|
---|
74 | )
|
---|
75 | {
|
---|
76 | UINT8 CheckSum;
|
---|
77 |
|
---|
78 | CheckSum = CalculateSum8 (Buffer, Length);
|
---|
79 |
|
---|
80 | //
|
---|
81 | // Return the checksum based on 2's complement.
|
---|
82 | //
|
---|
83 | return (UINT8) (0x100 - CheckSum);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | Returns the sum of all elements in a buffer of 16-bit values. During
|
---|
88 | calculation, the carry bits are dropped.
|
---|
89 |
|
---|
90 | This function calculates the sum of the 16-bit values in the buffer
|
---|
91 | specified by Buffer and Length. The carry bits in result of addition are dropped.
|
---|
92 | The 16-bit result is returned. If Length is 0, then 0 is returned.
|
---|
93 |
|
---|
94 | If Buffer is NULL, then ASSERT().
|
---|
95 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().
|
---|
96 | If Length is not aligned on a 16-bit boundary, then ASSERT().
|
---|
97 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
98 |
|
---|
99 | @param Buffer The pointer to the buffer to carry out the sum operation.
|
---|
100 | @param Length The size, in bytes, of Buffer.
|
---|
101 |
|
---|
102 | @return Sum The sum of Buffer with carry bits dropped during additions.
|
---|
103 |
|
---|
104 | **/
|
---|
105 | UINT16
|
---|
106 | EFIAPI
|
---|
107 | CalculateSum16 (
|
---|
108 | IN CONST UINT16 *Buffer,
|
---|
109 | IN UINTN Length
|
---|
110 | )
|
---|
111 | {
|
---|
112 | UINT16 Sum;
|
---|
113 | UINTN Count;
|
---|
114 | UINTN Total;
|
---|
115 |
|
---|
116 | ASSERT (Buffer != NULL);
|
---|
117 | ASSERT (((UINTN) Buffer & 0x1) == 0);
|
---|
118 | ASSERT ((Length & 0x1) == 0);
|
---|
119 | ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));
|
---|
120 |
|
---|
121 | Total = Length / sizeof (*Buffer);
|
---|
122 | for (Sum = 0, Count = 0; Count < Total; Count++) {
|
---|
123 | Sum = (UINT16) (Sum + *(Buffer + Count));
|
---|
124 | }
|
---|
125 |
|
---|
126 | return Sum;
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | /**
|
---|
131 | Returns the two's complement checksum of all elements in a buffer of
|
---|
132 | 16-bit values.
|
---|
133 |
|
---|
134 | This function first calculates the sum of the 16-bit values in the buffer
|
---|
135 | specified by Buffer and Length. The carry bits in the result of addition
|
---|
136 | are dropped. Then, the two's complement of the sum is returned. If Length
|
---|
137 | is 0, then 0 is returned.
|
---|
138 |
|
---|
139 | If Buffer is NULL, then ASSERT().
|
---|
140 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().
|
---|
141 | If Length is not aligned on a 16-bit boundary, then ASSERT().
|
---|
142 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
143 |
|
---|
144 | @param Buffer The pointer to the buffer to carry out the checksum operation.
|
---|
145 | @param Length The size, in bytes, of Buffer.
|
---|
146 |
|
---|
147 | @return Checksum The 2's complement checksum of Buffer.
|
---|
148 |
|
---|
149 | **/
|
---|
150 | UINT16
|
---|
151 | EFIAPI
|
---|
152 | CalculateCheckSum16 (
|
---|
153 | IN CONST UINT16 *Buffer,
|
---|
154 | IN UINTN Length
|
---|
155 | )
|
---|
156 | {
|
---|
157 | UINT16 CheckSum;
|
---|
158 |
|
---|
159 | CheckSum = CalculateSum16 (Buffer, Length);
|
---|
160 |
|
---|
161 | //
|
---|
162 | // Return the checksum based on 2's complement.
|
---|
163 | //
|
---|
164 | return (UINT16) (0x10000 - CheckSum);
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 | /**
|
---|
169 | Returns the sum of all elements in a buffer of 32-bit values. During
|
---|
170 | calculation, the carry bits are dropped.
|
---|
171 |
|
---|
172 | This function calculates the sum of the 32-bit values in the buffer
|
---|
173 | specified by Buffer and Length. The carry bits in result of addition are dropped.
|
---|
174 | The 32-bit result is returned. If Length is 0, then 0 is returned.
|
---|
175 |
|
---|
176 | If Buffer is NULL, then ASSERT().
|
---|
177 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().
|
---|
178 | If Length is not aligned on a 32-bit boundary, then ASSERT().
|
---|
179 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
180 |
|
---|
181 | @param Buffer The pointer to the buffer to carry out the sum operation.
|
---|
182 | @param Length The size, in bytes, of Buffer.
|
---|
183 |
|
---|
184 | @return Sum The sum of Buffer with carry bits dropped during additions.
|
---|
185 |
|
---|
186 | **/
|
---|
187 | UINT32
|
---|
188 | EFIAPI
|
---|
189 | CalculateSum32 (
|
---|
190 | IN CONST UINT32 *Buffer,
|
---|
191 | IN UINTN Length
|
---|
192 | )
|
---|
193 | {
|
---|
194 | UINT32 Sum;
|
---|
195 | UINTN Count;
|
---|
196 | UINTN Total;
|
---|
197 |
|
---|
198 | ASSERT (Buffer != NULL);
|
---|
199 | ASSERT (((UINTN) Buffer & 0x3) == 0);
|
---|
200 | ASSERT ((Length & 0x3) == 0);
|
---|
201 | ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));
|
---|
202 |
|
---|
203 | Total = Length / sizeof (*Buffer);
|
---|
204 | for (Sum = 0, Count = 0; Count < Total; Count++) {
|
---|
205 | Sum = Sum + *(Buffer + Count);
|
---|
206 | }
|
---|
207 |
|
---|
208 | return Sum;
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 | /**
|
---|
213 | Returns the two's complement checksum of all elements in a buffer of
|
---|
214 | 32-bit values.
|
---|
215 |
|
---|
216 | This function first calculates the sum of the 32-bit values in the buffer
|
---|
217 | specified by Buffer and Length. The carry bits in the result of addition
|
---|
218 | are dropped. Then, the two's complement of the sum is returned. If Length
|
---|
219 | is 0, then 0 is returned.
|
---|
220 |
|
---|
221 | If Buffer is NULL, then ASSERT().
|
---|
222 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().
|
---|
223 | If Length is not aligned on a 32-bit boundary, then ASSERT().
|
---|
224 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
225 |
|
---|
226 | @param Buffer The pointer to the buffer to carry out the checksum operation.
|
---|
227 | @param Length The size, in bytes, of Buffer.
|
---|
228 |
|
---|
229 | @return Checksum The 2's complement checksum of Buffer.
|
---|
230 |
|
---|
231 | **/
|
---|
232 | UINT32
|
---|
233 | EFIAPI
|
---|
234 | CalculateCheckSum32 (
|
---|
235 | IN CONST UINT32 *Buffer,
|
---|
236 | IN UINTN Length
|
---|
237 | )
|
---|
238 | {
|
---|
239 | UINT32 CheckSum;
|
---|
240 |
|
---|
241 | CheckSum = CalculateSum32 (Buffer, Length);
|
---|
242 |
|
---|
243 | //
|
---|
244 | // Return the checksum based on 2's complement.
|
---|
245 | //
|
---|
246 | return (UINT32) ((UINT32)(-1) - CheckSum + 1);
|
---|
247 | }
|
---|
248 |
|
---|
249 |
|
---|
250 | /**
|
---|
251 | Returns the sum of all elements in a buffer of 64-bit values. During
|
---|
252 | calculation, the carry bits are dropped.
|
---|
253 |
|
---|
254 | This function calculates the sum of the 64-bit values in the buffer
|
---|
255 | specified by Buffer and Length. The carry bits in result of addition are dropped.
|
---|
256 | The 64-bit result is returned. If Length is 0, then 0 is returned.
|
---|
257 |
|
---|
258 | If Buffer is NULL, then ASSERT().
|
---|
259 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().
|
---|
260 | If Length is not aligned on a 64-bit boundary, then ASSERT().
|
---|
261 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
262 |
|
---|
263 | @param Buffer The pointer to the buffer to carry out the sum operation.
|
---|
264 | @param Length The size, in bytes, of Buffer.
|
---|
265 |
|
---|
266 | @return Sum The sum of Buffer with carry bits dropped during additions.
|
---|
267 |
|
---|
268 | **/
|
---|
269 | UINT64
|
---|
270 | EFIAPI
|
---|
271 | CalculateSum64 (
|
---|
272 | IN CONST UINT64 *Buffer,
|
---|
273 | IN UINTN Length
|
---|
274 | )
|
---|
275 | {
|
---|
276 | UINT64 Sum;
|
---|
277 | UINTN Count;
|
---|
278 | UINTN Total;
|
---|
279 |
|
---|
280 | ASSERT (Buffer != NULL);
|
---|
281 | ASSERT (((UINTN) Buffer & 0x7) == 0);
|
---|
282 | ASSERT ((Length & 0x7) == 0);
|
---|
283 | ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));
|
---|
284 |
|
---|
285 | Total = Length / sizeof (*Buffer);
|
---|
286 | for (Sum = 0, Count = 0; Count < Total; Count++) {
|
---|
287 | Sum = Sum + *(Buffer + Count);
|
---|
288 | }
|
---|
289 |
|
---|
290 | return Sum;
|
---|
291 | }
|
---|
292 |
|
---|
293 |
|
---|
294 | /**
|
---|
295 | Returns the two's complement checksum of all elements in a buffer of
|
---|
296 | 64-bit values.
|
---|
297 |
|
---|
298 | This function first calculates the sum of the 64-bit values in the buffer
|
---|
299 | specified by Buffer and Length. The carry bits in the result of addition
|
---|
300 | are dropped. Then, the two's complement of the sum is returned. If Length
|
---|
301 | is 0, then 0 is returned.
|
---|
302 |
|
---|
303 | If Buffer is NULL, then ASSERT().
|
---|
304 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().
|
---|
305 | If Length is not aligned on a 64-bit boundary, then ASSERT().
|
---|
306 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
307 |
|
---|
308 | @param Buffer The pointer to the buffer to carry out the checksum operation.
|
---|
309 | @param Length The size, in bytes, of Buffer.
|
---|
310 |
|
---|
311 | @return Checksum The 2's complement checksum of Buffer.
|
---|
312 |
|
---|
313 | **/
|
---|
314 | UINT64
|
---|
315 | EFIAPI
|
---|
316 | CalculateCheckSum64 (
|
---|
317 | IN CONST UINT64 *Buffer,
|
---|
318 | IN UINTN Length
|
---|
319 | )
|
---|
320 | {
|
---|
321 | UINT64 CheckSum;
|
---|
322 |
|
---|
323 | CheckSum = CalculateSum64 (Buffer, Length);
|
---|
324 |
|
---|
325 | //
|
---|
326 | // Return the checksum based on 2's complement.
|
---|
327 | //
|
---|
328 | return (UINT64) ((UINT64)(-1) - CheckSum + 1);
|
---|
329 | }
|
---|
330 |
|
---|
331 | GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT32 mCrcTable[256] = {
|
---|
332 | 0x00000000,
|
---|
333 | 0x77073096,
|
---|
334 | 0xEE0E612C,
|
---|
335 | 0x990951BA,
|
---|
336 | 0x076DC419,
|
---|
337 | 0x706AF48F,
|
---|
338 | 0xE963A535,
|
---|
339 | 0x9E6495A3,
|
---|
340 | 0x0EDB8832,
|
---|
341 | 0x79DCB8A4,
|
---|
342 | 0xE0D5E91E,
|
---|
343 | 0x97D2D988,
|
---|
344 | 0x09B64C2B,
|
---|
345 | 0x7EB17CBD,
|
---|
346 | 0xE7B82D07,
|
---|
347 | 0x90BF1D91,
|
---|
348 | 0x1DB71064,
|
---|
349 | 0x6AB020F2,
|
---|
350 | 0xF3B97148,
|
---|
351 | 0x84BE41DE,
|
---|
352 | 0x1ADAD47D,
|
---|
353 | 0x6DDDE4EB,
|
---|
354 | 0xF4D4B551,
|
---|
355 | 0x83D385C7,
|
---|
356 | 0x136C9856,
|
---|
357 | 0x646BA8C0,
|
---|
358 | 0xFD62F97A,
|
---|
359 | 0x8A65C9EC,
|
---|
360 | 0x14015C4F,
|
---|
361 | 0x63066CD9,
|
---|
362 | 0xFA0F3D63,
|
---|
363 | 0x8D080DF5,
|
---|
364 | 0x3B6E20C8,
|
---|
365 | 0x4C69105E,
|
---|
366 | 0xD56041E4,
|
---|
367 | 0xA2677172,
|
---|
368 | 0x3C03E4D1,
|
---|
369 | 0x4B04D447,
|
---|
370 | 0xD20D85FD,
|
---|
371 | 0xA50AB56B,
|
---|
372 | 0x35B5A8FA,
|
---|
373 | 0x42B2986C,
|
---|
374 | 0xDBBBC9D6,
|
---|
375 | 0xACBCF940,
|
---|
376 | 0x32D86CE3,
|
---|
377 | 0x45DF5C75,
|
---|
378 | 0xDCD60DCF,
|
---|
379 | 0xABD13D59,
|
---|
380 | 0x26D930AC,
|
---|
381 | 0x51DE003A,
|
---|
382 | 0xC8D75180,
|
---|
383 | 0xBFD06116,
|
---|
384 | 0x21B4F4B5,
|
---|
385 | 0x56B3C423,
|
---|
386 | 0xCFBA9599,
|
---|
387 | 0xB8BDA50F,
|
---|
388 | 0x2802B89E,
|
---|
389 | 0x5F058808,
|
---|
390 | 0xC60CD9B2,
|
---|
391 | 0xB10BE924,
|
---|
392 | 0x2F6F7C87,
|
---|
393 | 0x58684C11,
|
---|
394 | 0xC1611DAB,
|
---|
395 | 0xB6662D3D,
|
---|
396 | 0x76DC4190,
|
---|
397 | 0x01DB7106,
|
---|
398 | 0x98D220BC,
|
---|
399 | 0xEFD5102A,
|
---|
400 | 0x71B18589,
|
---|
401 | 0x06B6B51F,
|
---|
402 | 0x9FBFE4A5,
|
---|
403 | 0xE8B8D433,
|
---|
404 | 0x7807C9A2,
|
---|
405 | 0x0F00F934,
|
---|
406 | 0x9609A88E,
|
---|
407 | 0xE10E9818,
|
---|
408 | 0x7F6A0DBB,
|
---|
409 | 0x086D3D2D,
|
---|
410 | 0x91646C97,
|
---|
411 | 0xE6635C01,
|
---|
412 | 0x6B6B51F4,
|
---|
413 | 0x1C6C6162,
|
---|
414 | 0x856530D8,
|
---|
415 | 0xF262004E,
|
---|
416 | 0x6C0695ED,
|
---|
417 | 0x1B01A57B,
|
---|
418 | 0x8208F4C1,
|
---|
419 | 0xF50FC457,
|
---|
420 | 0x65B0D9C6,
|
---|
421 | 0x12B7E950,
|
---|
422 | 0x8BBEB8EA,
|
---|
423 | 0xFCB9887C,
|
---|
424 | 0x62DD1DDF,
|
---|
425 | 0x15DA2D49,
|
---|
426 | 0x8CD37CF3,
|
---|
427 | 0xFBD44C65,
|
---|
428 | 0x4DB26158,
|
---|
429 | 0x3AB551CE,
|
---|
430 | 0xA3BC0074,
|
---|
431 | 0xD4BB30E2,
|
---|
432 | 0x4ADFA541,
|
---|
433 | 0x3DD895D7,
|
---|
434 | 0xA4D1C46D,
|
---|
435 | 0xD3D6F4FB,
|
---|
436 | 0x4369E96A,
|
---|
437 | 0x346ED9FC,
|
---|
438 | 0xAD678846,
|
---|
439 | 0xDA60B8D0,
|
---|
440 | 0x44042D73,
|
---|
441 | 0x33031DE5,
|
---|
442 | 0xAA0A4C5F,
|
---|
443 | 0xDD0D7CC9,
|
---|
444 | 0x5005713C,
|
---|
445 | 0x270241AA,
|
---|
446 | 0xBE0B1010,
|
---|
447 | 0xC90C2086,
|
---|
448 | 0x5768B525,
|
---|
449 | 0x206F85B3,
|
---|
450 | 0xB966D409,
|
---|
451 | 0xCE61E49F,
|
---|
452 | 0x5EDEF90E,
|
---|
453 | 0x29D9C998,
|
---|
454 | 0xB0D09822,
|
---|
455 | 0xC7D7A8B4,
|
---|
456 | 0x59B33D17,
|
---|
457 | 0x2EB40D81,
|
---|
458 | 0xB7BD5C3B,
|
---|
459 | 0xC0BA6CAD,
|
---|
460 | 0xEDB88320,
|
---|
461 | 0x9ABFB3B6,
|
---|
462 | 0x03B6E20C,
|
---|
463 | 0x74B1D29A,
|
---|
464 | 0xEAD54739,
|
---|
465 | 0x9DD277AF,
|
---|
466 | 0x04DB2615,
|
---|
467 | 0x73DC1683,
|
---|
468 | 0xE3630B12,
|
---|
469 | 0x94643B84,
|
---|
470 | 0x0D6D6A3E,
|
---|
471 | 0x7A6A5AA8,
|
---|
472 | 0xE40ECF0B,
|
---|
473 | 0x9309FF9D,
|
---|
474 | 0x0A00AE27,
|
---|
475 | 0x7D079EB1,
|
---|
476 | 0xF00F9344,
|
---|
477 | 0x8708A3D2,
|
---|
478 | 0x1E01F268,
|
---|
479 | 0x6906C2FE,
|
---|
480 | 0xF762575D,
|
---|
481 | 0x806567CB,
|
---|
482 | 0x196C3671,
|
---|
483 | 0x6E6B06E7,
|
---|
484 | 0xFED41B76,
|
---|
485 | 0x89D32BE0,
|
---|
486 | 0x10DA7A5A,
|
---|
487 | 0x67DD4ACC,
|
---|
488 | 0xF9B9DF6F,
|
---|
489 | 0x8EBEEFF9,
|
---|
490 | 0x17B7BE43,
|
---|
491 | 0x60B08ED5,
|
---|
492 | 0xD6D6A3E8,
|
---|
493 | 0xA1D1937E,
|
---|
494 | 0x38D8C2C4,
|
---|
495 | 0x4FDFF252,
|
---|
496 | 0xD1BB67F1,
|
---|
497 | 0xA6BC5767,
|
---|
498 | 0x3FB506DD,
|
---|
499 | 0x48B2364B,
|
---|
500 | 0xD80D2BDA,
|
---|
501 | 0xAF0A1B4C,
|
---|
502 | 0x36034AF6,
|
---|
503 | 0x41047A60,
|
---|
504 | 0xDF60EFC3,
|
---|
505 | 0xA867DF55,
|
---|
506 | 0x316E8EEF,
|
---|
507 | 0x4669BE79,
|
---|
508 | 0xCB61B38C,
|
---|
509 | 0xBC66831A,
|
---|
510 | 0x256FD2A0,
|
---|
511 | 0x5268E236,
|
---|
512 | 0xCC0C7795,
|
---|
513 | 0xBB0B4703,
|
---|
514 | 0x220216B9,
|
---|
515 | 0x5505262F,
|
---|
516 | 0xC5BA3BBE,
|
---|
517 | 0xB2BD0B28,
|
---|
518 | 0x2BB45A92,
|
---|
519 | 0x5CB36A04,
|
---|
520 | 0xC2D7FFA7,
|
---|
521 | 0xB5D0CF31,
|
---|
522 | 0x2CD99E8B,
|
---|
523 | 0x5BDEAE1D,
|
---|
524 | 0x9B64C2B0,
|
---|
525 | 0xEC63F226,
|
---|
526 | 0x756AA39C,
|
---|
527 | 0x026D930A,
|
---|
528 | 0x9C0906A9,
|
---|
529 | 0xEB0E363F,
|
---|
530 | 0x72076785,
|
---|
531 | 0x05005713,
|
---|
532 | 0x95BF4A82,
|
---|
533 | 0xE2B87A14,
|
---|
534 | 0x7BB12BAE,
|
---|
535 | 0x0CB61B38,
|
---|
536 | 0x92D28E9B,
|
---|
537 | 0xE5D5BE0D,
|
---|
538 | 0x7CDCEFB7,
|
---|
539 | 0x0BDBDF21,
|
---|
540 | 0x86D3D2D4,
|
---|
541 | 0xF1D4E242,
|
---|
542 | 0x68DDB3F8,
|
---|
543 | 0x1FDA836E,
|
---|
544 | 0x81BE16CD,
|
---|
545 | 0xF6B9265B,
|
---|
546 | 0x6FB077E1,
|
---|
547 | 0x18B74777,
|
---|
548 | 0x88085AE6,
|
---|
549 | 0xFF0F6A70,
|
---|
550 | 0x66063BCA,
|
---|
551 | 0x11010B5C,
|
---|
552 | 0x8F659EFF,
|
---|
553 | 0xF862AE69,
|
---|
554 | 0x616BFFD3,
|
---|
555 | 0x166CCF45,
|
---|
556 | 0xA00AE278,
|
---|
557 | 0xD70DD2EE,
|
---|
558 | 0x4E048354,
|
---|
559 | 0x3903B3C2,
|
---|
560 | 0xA7672661,
|
---|
561 | 0xD06016F7,
|
---|
562 | 0x4969474D,
|
---|
563 | 0x3E6E77DB,
|
---|
564 | 0xAED16A4A,
|
---|
565 | 0xD9D65ADC,
|
---|
566 | 0x40DF0B66,
|
---|
567 | 0x37D83BF0,
|
---|
568 | 0xA9BCAE53,
|
---|
569 | 0xDEBB9EC5,
|
---|
570 | 0x47B2CF7F,
|
---|
571 | 0x30B5FFE9,
|
---|
572 | 0xBDBDF21C,
|
---|
573 | 0xCABAC28A,
|
---|
574 | 0x53B39330,
|
---|
575 | 0x24B4A3A6,
|
---|
576 | 0xBAD03605,
|
---|
577 | 0xCDD70693,
|
---|
578 | 0x54DE5729,
|
---|
579 | 0x23D967BF,
|
---|
580 | 0xB3667A2E,
|
---|
581 | 0xC4614AB8,
|
---|
582 | 0x5D681B02,
|
---|
583 | 0x2A6F2B94,
|
---|
584 | 0xB40BBE37,
|
---|
585 | 0xC30C8EA1,
|
---|
586 | 0x5A05DF1B,
|
---|
587 | 0x2D02EF8D
|
---|
588 | };
|
---|
589 |
|
---|
590 | /**
|
---|
591 | Computes and returns a 32-bit CRC for a data buffer.
|
---|
592 | CRC32 value bases on ITU-T V.42.
|
---|
593 |
|
---|
594 | If Buffer is NULL, then ASSERT().
|
---|
595 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
596 |
|
---|
597 | @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is to be computed.
|
---|
598 | @param[in] Length The number of bytes in the buffer Data.
|
---|
599 |
|
---|
600 | @retval Crc32 The 32-bit CRC was computed for the data buffer.
|
---|
601 |
|
---|
602 | **/
|
---|
603 | UINT32
|
---|
604 | EFIAPI
|
---|
605 | CalculateCrc32(
|
---|
606 | IN VOID *Buffer,
|
---|
607 | IN UINTN Length
|
---|
608 | )
|
---|
609 | {
|
---|
610 | UINTN Index;
|
---|
611 | UINT32 Crc;
|
---|
612 | UINT8 *Ptr;
|
---|
613 |
|
---|
614 | ASSERT (Buffer != NULL);
|
---|
615 | ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));
|
---|
616 |
|
---|
617 | //
|
---|
618 | // Compute CRC
|
---|
619 | //
|
---|
620 | Crc = 0xffffffff;
|
---|
621 | for (Index = 0, Ptr = Buffer; Index < Length; Index++, Ptr++) {
|
---|
622 | Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr];
|
---|
623 | }
|
---|
624 |
|
---|
625 | return Crc ^ 0xffffffff;
|
---|
626 | }
|
---|