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