TianoCore EDK2 master
Loading...
Searching...
No Matches
CheckSum.c File Reference
#include "BaseLibInternals.h"

Go to the source code of this file.

Functions

UINT8 EFIAPI CalculateSum8 (IN CONST UINT8 *Buffer, IN UINTN Length)
 
UINT8 EFIAPI CalculateCheckSum8 (IN CONST UINT8 *Buffer, IN UINTN Length)
 
UINT16 EFIAPI CalculateSum16 (IN CONST UINT16 *Buffer, IN UINTN Length)
 
UINT16 EFIAPI CalculateCheckSum16 (IN CONST UINT16 *Buffer, IN UINTN Length)
 
UINT32 EFIAPI CalculateSum32 (IN CONST UINT32 *Buffer, IN UINTN Length)
 
UINT32 EFIAPI CalculateCheckSum32 (IN CONST UINT32 *Buffer, IN UINTN Length)
 
UINT64 EFIAPI CalculateSum64 (IN CONST UINT64 *Buffer, IN UINTN Length)
 
UINT64 EFIAPI CalculateCheckSum64 (IN CONST UINT64 *Buffer, IN UINTN Length)
 
UINT32 EFIAPI CalculateCrc32 (IN VOID *Buffer, IN UINTN Length)
 
UINT16 EFIAPI CalculateCrc16Ansi (IN CONST VOID *Buffer, IN UINTN Length, IN UINT16 InitialValue)
 
UINT32 EFIAPI CalculateCrc32c (IN CONST VOID *Buffer, IN UINTN Length, IN UINT32 InitialValue)
 
UINT16 EFIAPI CalculateCrc16CcittF (IN CONST VOID *Buffer, IN UINTN Length, IN UINT16 InitialValue)
 

Variables

GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT32 mCrcTable [256]
 
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT16 mCrc16LookupTable [256]
 
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT32 mCrc32cLookupTable [256]
 
GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT16 mCrc16CcittFLookupTable [256]
 

Detailed Description

Utility functions to generate checksum based on 2's complement algorithm.

Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
Copyright (c) 2022, Pedro Falcato. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CheckSum.c.

Function Documentation

◆ CalculateCheckSum16()

UINT16 EFIAPI CalculateCheckSum16 ( IN CONST UINT16 *  Buffer,
IN UINTN  Length 
)

Returns the two's complement checksum of all elements in a buffer of 16-bit values.

This function first calculates the sum of the 16-bit values in the buffer specified by Buffer and Length. The carry bits in the result of addition are dropped. Then, the two's complement of the sum is returned. If Length is 0, then 0 is returned.

If Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). If Length is not aligned on a 16-bit boundary, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
BufferThe pointer to the buffer to carry out the checksum operation.
LengthThe size, in bytes, of Buffer.
Returns
Checksum The 2's complement checksum of Buffer.

Definition at line 151 of file CheckSum.c.

◆ CalculateCheckSum32()

UINT32 EFIAPI CalculateCheckSum32 ( IN CONST UINT32 *  Buffer,
IN UINTN  Length 
)

Returns the two's complement checksum of all elements in a buffer of 32-bit values.

This function first calculates the sum of the 32-bit values in the buffer specified by Buffer and Length. The carry bits in the result of addition are dropped. Then, the two's complement of the sum is returned. If Length is 0, then 0 is returned.

If Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). If Length is not aligned on a 32-bit boundary, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
BufferThe pointer to the buffer to carry out the checksum operation.
LengthThe size, in bytes, of Buffer.
Returns
Checksum The 2's complement checksum of Buffer.

Definition at line 231 of file CheckSum.c.

◆ CalculateCheckSum64()

UINT64 EFIAPI CalculateCheckSum64 ( IN CONST UINT64 *  Buffer,
IN UINTN  Length 
)

Returns the two's complement checksum of all elements in a buffer of 64-bit values.

This function first calculates the sum of the 64-bit values in the buffer specified by Buffer and Length. The carry bits in the result of addition are dropped. Then, the two's complement of the sum is returned. If Length is 0, then 0 is returned.

If Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). If Length is not aligned on a 64-bit boundary, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
BufferThe pointer to the buffer to carry out the checksum operation.
LengthThe size, in bytes, of Buffer.
Returns
Checksum The 2's complement checksum of Buffer.

Definition at line 311 of file CheckSum.c.

◆ CalculateCheckSum8()

UINT8 EFIAPI CalculateCheckSum8 ( IN CONST UINT8 *  Buffer,
IN UINTN  Length 
)

Returns the two's complement checksum of all elements in a buffer of 8-bit values.

This function first calculates the sum of the 8-bit values in the buffer specified by Buffer and Length. The carry bits in the result of addition are dropped. Then, the two's complement of the sum is returned. If Length is 0, then 0 is returned.

If Buffer is NULL, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
BufferThe pointer to the buffer to carry out the checksum operation.
LengthThe size, in bytes, of Buffer.
Returns
Checksum The 2's complement checksum of Buffer.

Definition at line 71 of file CheckSum.c.

◆ CalculateCrc16Ansi()

UINT16 EFIAPI CalculateCrc16Ansi ( IN CONST VOID *  Buffer,
IN UINTN  Length,
IN UINT16  InitialValue 
)

Calculates the CRC16-ANSI checksum of the given buffer.

Parameters
[in]BufferPointer to the buffer.
[in]LengthLength of the buffer, in bytes.
[in]InitialValueInitial value of the CRC.
Returns
The CRC16-ANSI checksum.

Definition at line 670 of file CheckSum.c.

◆ CalculateCrc16CcittF()

UINT16 EFIAPI CalculateCrc16CcittF ( IN CONST VOID *  Buffer,
IN UINTN  Length,
IN UINT16  InitialValue 
)

Calculates the CRC16-CCITT-FALSE checksum of the given buffer.

Parameters
[in]BufferPointer to the buffer.
[in]LengthLength of the buffer, in bytes.
[in]InitialValueInitial value of the CRC.
Returns
The CRC16-CCITT-FALSE checksum.

Definition at line 813 of file CheckSum.c.

◆ CalculateCrc32()

UINT32 EFIAPI CalculateCrc32 ( IN VOID *  Buffer,
IN UINTN  Length 
)

Computes and returns a 32-bit CRC for a data buffer. CRC32 value bases on ITU-T V.42.

If Buffer is NULL, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
[in]BufferA pointer to the buffer on which the 32-bit CRC is to be computed.
[in]LengthThe number of bytes in the buffer Data.
Return values
Crc32The 32-bit CRC was computed for the data buffer.

Definition at line 600 of file CheckSum.c.

◆ CalculateCrc32c()

UINT32 EFIAPI CalculateCrc32c ( IN CONST VOID *  Buffer,
IN UINTN  Length,
IN UINT32  InitialValue 
)

Calculates the CRC32c checksum of the given buffer.

Parameters
[in]BufferPointer to the buffer.
[in]LengthLength of the buffer, in bytes.
[in]InitialValueInitial value of the CRC.
Returns
The CRC32c checksum.

Definition at line 747 of file CheckSum.c.

◆ CalculateSum16()

UINT16 EFIAPI CalculateSum16 ( IN CONST UINT16 *  Buffer,
IN UINTN  Length 
)

Returns the sum of all elements in a buffer of 16-bit values. During calculation, the carry bits are dropped.

This function calculates the sum of the 16-bit values in the buffer specified by Buffer and Length. The carry bits in result of addition are dropped. The 16-bit result is returned. If Length is 0, then 0 is returned.

If Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). If Length is not aligned on a 16-bit boundary, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
BufferThe pointer to the buffer to carry out the sum operation.
LengthThe size, in bytes, of Buffer.
Returns
Sum The sum of Buffer with carry bits dropped during additions.

Definition at line 107 of file CheckSum.c.

◆ CalculateSum32()

UINT32 EFIAPI CalculateSum32 ( IN CONST UINT32 *  Buffer,
IN UINTN  Length 
)

Returns the sum of all elements in a buffer of 32-bit values. During calculation, the carry bits are dropped.

This function calculates the sum of the 32-bit values in the buffer specified by Buffer and Length. The carry bits in result of addition are dropped. The 32-bit result is returned. If Length is 0, then 0 is returned.

If Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). If Length is not aligned on a 32-bit boundary, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
BufferThe pointer to the buffer to carry out the sum operation.
LengthThe size, in bytes, of Buffer.
Returns
Sum The sum of Buffer with carry bits dropped during additions.

Definition at line 187 of file CheckSum.c.

◆ CalculateSum64()

UINT64 EFIAPI CalculateSum64 ( IN CONST UINT64 *  Buffer,
IN UINTN  Length 
)

Returns the sum of all elements in a buffer of 64-bit values. During calculation, the carry bits are dropped.

This function calculates the sum of the 64-bit values in the buffer specified by Buffer and Length. The carry bits in result of addition are dropped. The 64-bit result is returned. If Length is 0, then 0 is returned.

If Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). If Length is not aligned on a 64-bit boundary, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
BufferThe pointer to the buffer to carry out the sum operation.
LengthThe size, in bytes, of Buffer.
Returns
Sum The sum of Buffer with carry bits dropped during additions.

Definition at line 267 of file CheckSum.c.

◆ CalculateSum8()

UINT8 EFIAPI CalculateSum8 ( IN CONST UINT8 *  Buffer,
IN UINTN  Length 
)

Returns the sum of all elements in a buffer in unit of UINT8. During calculation, the carry bits are dropped.

This function calculates the sum of all elements in a buffer in unit of UINT8. The carry bits in result of addition are dropped. The result is returned as UINT8. If Length is Zero, then Zero is returned.

If Buffer is NULL, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

Parameters
BufferThe pointer to the buffer to carry out the sum operation.
LengthThe size, in bytes, of Buffer.
Returns
Sum The sum of Buffer with carry bits dropped during additions.

Definition at line 33 of file CheckSum.c.

Variable Documentation

◆ mCrc16CcittFLookupTable

GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT16 mCrc16CcittFLookupTable[256]

Definition at line 767 of file CheckSum.c.

◆ mCrc16LookupTable

GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT16 mCrc16LookupTable[256]

Definition at line 623 of file CheckSum.c.

◆ mCrc32cLookupTable

GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT32 mCrc32cLookupTable[256]

Definition at line 690 of file CheckSum.c.

◆ mCrcTable

GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT32 mCrcTable[256]

Definition at line 326 of file CheckSum.c.