home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / HPACK78S.ZIP / crc / crc16.h < prev   
C/C++ Source or Header  |  1992-08-27  |  3KB  |  76 lines

  1. /****************************************************************************
  2. *                                                                            *
  3. *                            HPACK Multi-System Archiver                        *
  4. *                            ===========================                        *
  5. *                                                                            *
  6. *                                    CRC16 Macros                            *
  7. *                             CRC16.H  Updated 01/07/91                        *
  8. *                                                                            *
  9. * This program is protected by copyright and as such any use or copying of    *
  10. *  this code for your own purposes directly or indirectly is highly uncool    *
  11. *                      and if you do so there will be....trubble.                *
  12. *                 And remember: We know where your kids go to school.            *
  13. *                                                                            *
  14. *            Copyright 1991  Peter C.Gutmann.  All rights reserved            *
  15. *                                                                            *
  16. ****************************************************************************/
  17.  
  18. #ifndef _CRC16_DEFINED
  19.  
  20. #define _CRC16_DEFINED
  21.  
  22. #include "defs.h"
  23.  
  24. /****************************************************************************
  25. *                                                                            *
  26. *                                    CRC16 Defines                            *
  27. *                                                                            *
  28. ****************************************************************************/
  29.  
  30. /* This macro computes the 16-bit CRC of a byte of data */
  31.  
  32. void updateCRC16( BYTE data );
  33.  
  34. #define updateCRC16(data) crc16 = ( crc16tbl[ ( BYTE ) crc16 ^ ( data ) ] ^ ( crc16 >> 8 ) )
  35.  
  36. extern WORD crc16tbl[], crc16;        /* Defined in CRC16.C */
  37.  
  38. /* To use the above, first initialize the crc16 value to zero:
  39.  
  40.    crc16 = 0;
  41.  
  42.    Then for all data bytes x do:
  43.  
  44.         updateCRC16( x );
  45. */
  46.  
  47. /* The following routine performs a high-speed crc16 calculations on a block
  48.    of data.  Ideally it should be written in assembly language would be much
  49.    faster than the above macro */
  50.  
  51. void crc16buffer( BYTE *buffer, int length );
  52.  
  53. /* Prototype for function in CRC16.C */
  54.  
  55. void initCRC16( void );
  56.  
  57. /****************************************************************************
  58. *                                                                            *
  59. *                            Compressor Checksum Defines                        *
  60. *                                                                            *
  61. ****************************************************************************/
  62.  
  63. /* Defines to handle the data checksum.  The following two checksums were
  64.    chosen to minimize the length of the encoded checksum:  In English,
  65.    the most common digrams are 'e ', ' t', 'th', 'he', the most common
  66.    trigrams are ' th', 'the', 'he ', and the most common tetragrams are
  67.    ' the' and 'the ', thus we use these as the checksum.  For binaries we
  68.    use four consecutive zeroes since these seem to be present in most files */
  69.  
  70. #define CHECKSUM_TEXT    " the"
  71. #define CHECKSUM_BIN    "\0\0\0\0"
  72.  
  73. #define CHECKSUM_LEN    ( sizeof( CHECKSUM_TEXT ) - 1 )    /* -1 for '\0' */
  74.  
  75. #endif /* !_CRC16_DEFINED */
  76.