Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Checksum.h File Reference


Detailed Description

Utility functions to compute and verify a 16-bits ISO checksum.

The checksum algorithms are as specified in appendix A.2 of the Packet Utilization Standard (issue of Jan. 30-th 2003). A checksum is computed by calling function doChecksum. It is verified by calling function verifyChecksum. The checksum is computed or verified over items that are treated as of type unsigned char. A checksum result is expressed as an unsigned short where the leftmost byte of the result (CK1) is the least significant byte of the return value of doChecksum and the rightmost byte (CK2) is the most significant byte.

The variable where the inermediate quantities C0 and C1 are accumulated is defined to be of type int. There is no check against an overflow in this variable. This essentially puts a limit on the maximum length of the data stream over which the checksum is computed.

The functions defined in this module do not conform to project-specific coding rule PR3.3. They take as argument an array holding the items over which the checksum is to be computer/verified. The alternative design is where the items are passed one by one and intermediate results are stored internally to the module. This alternative would have complied with PR3.3 but would also have been significantly slower for large chunks of data.

Definition in file Checksum.h.

Go to the source code of this file.

Functions

unsigned short doChecksum (unsigned char *item, unsigned int n)
 Compute the checksum.

bool verifyChecksum (unsigned char *item, unsigned int n, unsigned short checksum)
 Verify the checksum.


Function Documentation

unsigned short doChecksum unsigned char *  item,
unsigned int  n
 

Compute the checksum.

The first argument is treated as an array of size n that holds the items over which the checksum is to be computed. The return value of the function is the checksum value.

Parameters:
item the array holding the items that must be checksummed
n the number of items in the array
Returns:
the value of the checksum
Version:
1.0
Author:
A. Pasetti

Definition at line 15 of file Checksum.cpp.

bool verifyChecksum unsigned char *  item,
unsigned int  n,
unsigned short  checksum
 

Verify the checksum.

The first argument is treated as an array of size n that holds the items over which the checksum is to be verified. Argument checksum holds the expected checksum value. The return value of the function indicates whether the checksum is verified (return value of true) or not (return value of false).

Parameters:
item the array holding the items that must be checksum verified
n the number of items in the array
checksum the value of the checksum
Returns:
the flag indicating whether the check sum is verified
Version:
1.0
Author:
A. Pasetti

Definition at line 39 of file Checksum.cpp.

Copyright 2003 P&P Software GmbH - All Rights Reserved