THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
\r
- Module Name: CheckSum.c\r
-\r
**/\r
\r
+\r
+#include <BaseLibInternals.h>\r
+\r
+\r
/**\r
Calculate the sum of all elements in a buffer in unit of UINT8. \r
During calculation, the carry bits are dropped.\r
If Buffer is NULL, then ASSERT().\r
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
\r
- @param Buffer Pointer to the buffer to carry out the sum operation.\r
- @param Length The size, in bytes, of Buffer .\r
+ @param Buffer Pointer to the buffer to carry out the sum operation.\r
+ @param Length The size, in bytes, of Buffer .\r
\r
@return Sum The sum of Buffer with carry bits dropped during additions.\r
\r
ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));\r
\r
for (Sum = 0, Count = 0; Count < Length; Count++) {\r
- Sum = Sum + *(Buffer + Count);\r
+ Sum = (UINT8) (Sum + *(Buffer + Count));\r
}\r
\r
return Sum;\r
If Buffer is NULL, then ASSERT().\r
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
\r
-\r
- @param Buffer Pointer to the buffer to carry out the checksum operation.\r
- @param Length The size, in bytes, of Buffer.\r
+ @param Buffer Pointer to the buffer to carry out the checksum operation.\r
+ @param Length The size, in bytes, of Buffer.\r
\r
@return Checksum The 2's complement checksum of Buffer.\r
\r
If Length is not aligned on a 16-bit boundary, then ASSERT().\r
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
\r
- @param Buffer Pointer to the buffer to carry out the sum operation.\r
- @param Length The size, in bytes, of Buffer.\r
+ @param Buffer Pointer to the buffer to carry out the sum operation.\r
+ @param Length The size, in bytes, of Buffer.\r
\r
@return Sum The sum of Buffer with carry bits dropped during additions.\r
\r
{\r
UINT16 Sum;\r
UINTN Count;\r
+ UINTN Total;\r
\r
ASSERT (Buffer != NULL);\r
ASSERT (((UINTN) Buffer & 0x1) == 0);\r
ASSERT ((Length & 0x1) == 0);\r
ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));\r
\r
-\r
- for (Sum = 0, Count = 0; Count < Length; Count++) {\r
- Sum = Sum + *(Buffer + Count);\r
+ Total = Length / sizeof (*Buffer);\r
+ for (Sum = 0, Count = 0; Count < Total; Count++) {\r
+ Sum = (UINT16) (Sum + *(Buffer + Count));\r
}\r
\r
return Sum;\r
If Length is not aligned on a 16-bit boundary, then ASSERT().\r
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
\r
- @param Buffer Pointer to the buffer to carry out the checksum operation.\r
- @param Length The size, in bytes, of Buffer.\r
+ @param Buffer Pointer to the buffer to carry out the checksum operation.\r
+ @param Length The size, in bytes, of Buffer.\r
\r
@return Checksum The 2's complement checksum of Buffer.\r
\r
If Length is not aligned on a 32-bit boundary, then ASSERT().\r
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
\r
- @param Buffer Pointer to the buffer to carry out the sum operation.\r
- @param Length The size, in bytes, of Buffer.\r
+ @param Buffer Pointer to the buffer to carry out the sum operation.\r
+ @param Length The size, in bytes, of Buffer.\r
\r
@return Sum The sum of Buffer with carry bits dropped during additions.\r
\r
{\r
UINT32 Sum;\r
UINTN Count;\r
+ UINTN Total;\r
\r
ASSERT (Buffer != NULL);\r
ASSERT (((UINTN) Buffer & 0x3) == 0);\r
ASSERT ((Length & 0x3) == 0);\r
ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));\r
\r
-\r
- for (Sum = 0, Count = 0; Count < Length; Count++) {\r
+ Total = Length / sizeof (*Buffer);\r
+ for (Sum = 0, Count = 0; Count < Total; Count++) {\r
Sum = Sum + *(Buffer + Count);\r
}\r
\r
If Length is not aligned on a 32-bit boundary, then ASSERT().\r
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
\r
- @param Buffer Pointer to the buffer to carry out the checksum operation.\r
- @param Length The size, in bytes, of Buffer.\r
+ @param Buffer Pointer to the buffer to carry out the checksum operation.\r
+ @param Length The size, in bytes, of Buffer.\r
\r
@return Checksum The 2's complement checksum of Buffer.\r
\r
If Length is not aligned on a 64-bit boundary, then ASSERT().\r
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
\r
- @param Buffer Pointer to the buffer to carry out the sum operation.\r
- @param Length The size, in bytes, of Buffer.\r
+ @param Buffer Pointer to the buffer to carry out the sum operation.\r
+ @param Length The size, in bytes, of Buffer.\r
\r
@return Sum The sum of Buffer with carry bits dropped during additions.\r
\r
{\r
UINT64 Sum;\r
UINTN Count;\r
+ UINTN Total;\r
\r
ASSERT (Buffer != NULL);\r
ASSERT (((UINTN) Buffer & 0x7) == 0);\r
ASSERT ((Length & 0x7) == 0);\r
ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));\r
\r
- for (Sum = 0, Count = 0; Count < Length; Count++) {\r
+ Total = Length / sizeof (*Buffer);\r
+ for (Sum = 0, Count = 0; Count < Total; Count++) {\r
Sum = Sum + *(Buffer + Count);\r
}\r
\r
If Length is not aligned on a 64-bit boundary, then ASSERT().\r
If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
\r
- @param Buffer Pointer to the buffer to carry out the checksum operation.\r
- @param Length The size, in bytes, of Buffer.\r
+ @param Buffer Pointer to the buffer to carry out the checksum operation.\r
+ @param Length The size, in bytes, of Buffer.\r
\r
@return Checksum The 2's complement checksum of Buffer.\r
\r