alder_lake_bios/Insyde/InsydeModulePkg/Universal/Irsi/IrsiRegistrationRuntimeDxe/Crc32.c

74 lines
1.5 KiB
C

/** @file
Helper functions for calculating CRC32 checksum
;******************************************************************************
;* Copyright (c) 2012, Insyde Software Corp. All Rights Reserved.
;*
;* You may not reproduce, distribute, publish, display, perform, modify, adapt,
;* transmit, broadcast, present, recite, release, license or otherwise exploit
;* any part of this publication in any form, by any means, without the prior
;* written permission of Insyde Software Corporation.
;*
;******************************************************************************
*/
UINT32 mCrcTable[256];
/**
This internal function reverses bits for 32bit data.
@param Value The data to be reversed.
@return Data reversed.
**/
UINT32
ReverseBits (
UINT32 Value
)
{
UINTN Index;
UINT32 NewValue;
NewValue = 0;
for (Index = 0; Index < 32; Index++) {
if ((Value & (1 << Index)) != 0) {
NewValue = NewValue | (1 << (31 - Index));
}
}
return NewValue;
}
/**
Initialize CRC32 table.
@param none
@retval none
**/
VOID
InitializeCrc32Table (
VOID
)
{
UINTN TableEntry;
UINTN Index;
UINT32 Value;
for (TableEntry = 0; TableEntry < 256; TableEntry++) {
Value = ReverseBits ((UINT32) TableEntry);
for (Index = 0; Index < 8; Index++) {
if ((Value & 0x80000000) != 0) {
Value = (Value << 1) ^ 0x04c11db7;
} else {
Value = Value << 1;
}
}
mCrcTable[TableEntry] = ReverseBits (Value);
}
}