Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

ZrtpCrc32.h File Reference

Go to the source code of this file.

Functions

bool zrtpCheckCksum (uint8_t *buffer, uint16_t length, uint32_t crc32)
uint32_t zrtpGenerateCksum (uint8_t *buffer, uint16_t length)
uint32_t zrtpEndCksum (uint32_t crc32)


Function Documentation

bool zrtpCheckCksum uint8_t *  buffer,
uint16_t  length,
uint32_t  crc32
 

Definition at line 140 of file ZrtpCrc32.cxx.

References zrtpEndCksum(), and zrtpGenerateCksum().

Referenced by ZrtpQueue::takeInDataPacket().

00141 {
00142     uint32_t chksum = zrtpGenerateCksum(buffer, length);
00143     chksum = zrtpEndCksum(chksum);
00144     // fprintf(stderr, "Received crc %x, computed crc: %x\n", crc32, chksum);
00145     return (crc32 == chksum);
00146 }

uint32_t zrtpEndCksum uint32_t  crc32  ) 
 

Definition at line 161 of file ZrtpCrc32.cxx.

Referenced by ZrtpQueue::sendDataZRTP(), and zrtpCheckCksum().

00162 {
00163     uint32_t result;
00164     uint8_t byte0, byte1, byte2, byte3;
00165 
00166     result = ~crc32;
00167 
00168     /*  result  now holds the negated polynomial remainder;
00169      *  since the table and algorithm is "reflected" [williams95].
00170      *  That is,  result has the same value as if we mapped the message
00171      *  to a polyomial, computed the host-bit-order polynomial
00172      *  remainder, performed final negation, then did an end-for-end
00173      *  bit-reversal.
00174      *  Note that a 32-bit bit-reversal is identical to four inplace
00175      *  8-bit reversals followed by an end-for-end byteswap.
00176      *  In other words, the bytes of each bit are in the right order,
00177      *  but the bytes have been byteswapped.  So we now do an explicit
00178      *  byteswap.  On a little-endian machine, this byteswap and
00179      *  the final ntohl cancel out and could be elided.
00180      */
00181     byte0 = result & 0xff;
00182     byte1 = (result>>8) & 0xff;
00183     byte2 = (result>>16) & 0xff;
00184     byte3 = (result>>24) & 0xff;
00185 
00186     crc32 = ((byte0 << 24) |
00187              (byte1 << 16) |
00188              (byte2 << 8)  |
00189              byte3);
00190     // fprintf(stderr, "Computed crc32: %x\n", crc32);
00191     return crc32;
00192 }

uint32_t zrtpGenerateCksum uint8_t *  buffer,
uint16_t  length
 

Definition at line 148 of file ZrtpCrc32.cxx.

References CRC32C.

Referenced by ZrtpQueue::sendDataZRTP(), and zrtpCheckCksum().

00149 {
00150     uint32_t crc32 = ~(uint32_t) 0;
00151     uint32_t i;
00152 
00153     // fprintf(stderr, "Buffer %xl, length: %d\n", buffer, length);
00154     /* Calculate the CRC. */
00155     for (i = 0; i < length ; i++)
00156         CRC32C(crc32, buffer[i]);
00157 
00158     return crc32;
00159 }


© sourcejam.com 2005-2008