TianoCore EDK2 master
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)
 

Variables

GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT32 mCrcTable [256]
 

Detailed Description

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

Copyright (c) 2007 - 2018, Intel Corporation. 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 150 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 230 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 310 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 70 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 599 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 106 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 186 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 266 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 32 of file CheckSum.c.

Variable Documentation

◆ mCrcTable

Definition at line 325 of file CheckSum.c.