]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Runtime/RuntimeDxe/Crc32.c
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 CalculateCrc32 Boot Services as defined in DXE CIS.
20 This Boot Services is in the Runtime Driver because this service is
21 also required by SetVirtualAddressMap() when the EFI System Table and
22 EFI Runtime Services Table are converted from physical address to
23 virtual addresses. This requires that the 32-bit CRC be recomputed.
31 UINT32 mCrcTable
[256];
35 RuntimeDriverCalculateCrc32 (
44 Calculate CRC32 for target data
48 Data - The target data.
49 DataSize - The target data size.
50 CrcOut - The CRC32 for target data.
54 EFI_SUCCESS - The CRC32 for target data is calculated successfully.
55 EFI_INVALID_PARAMETER - Some parameter is not valid, so the CRC32 is not
64 if (Data
== NULL
|| DataSize
== 0 || CrcOut
== NULL
) {
65 return EFI_INVALID_PARAMETER
;
69 for (Index
= 0, Ptr
= Data
; Index
< DataSize
; Index
++, Ptr
++) {
70 Crc
= (Crc
>> 8) ^ mCrcTable
[(UINT8
) Crc
^ *Ptr
];
73 *CrcOut
= Crc
^ 0xffffffff;
86 Reverse bits for 32bit data.
90 Value - the data to be reversed.
102 for (Index
= 0; Index
< 32; Index
++) {
103 if (Value
& (1 << Index
)) {
104 NewValue
= NewValue
| (1 << (31 - Index
));
112 RuntimeDriverInitializeCrc32Table (
119 Initialize CRC32 table.
135 for (TableEntry
= 0; TableEntry
< 256; TableEntry
++) {
136 Value
= ReverseBits ((UINT32
) TableEntry
);
137 for (Index
= 0; Index
< 8; Index
++) {
138 if (Value
& 0x80000000) {
139 Value
= (Value
<< 1) ^ 0x04c11db7;
145 mCrcTable
[TableEntry
] = ReverseBits (Value
);