home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / bsrc_260.arj / SRC.ZIP / aglcrc.c next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  7.3 KB  |  189 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                This module was adapted by Michael Buenter                */
  13. /*               Based on original source file by Arjen Lentz               */
  14. /*                  Hydra CRC calculations for BinkleyTerm                  */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44.  
  45. /*============================================================ Rev. 17 Jan 1993
  46.   Routines for table driven CRC-16 & CRC-32, including building tables
  47.   Refer to CRC.DOC for information and documentation.
  48.   This file in portable C is 100% interchangable with the CRC.ASM (80x86 ASM).
  49.   -----------------------------------------------------------------------------
  50.  
  51.           Information collected and edited by Arjen G. Lentz
  52.         Sourcecode in C and 80x86 ASM written by Arjen G. Lentz
  53.         COPYRIGHT (C) 1992-1993; ALL RIGHTS RESERVED
  54.  
  55.  
  56.   CONTACT ADDRESS
  57.  
  58.   LENTZ SOFTWARE-DEVELOPMENT   Arjen Lentz @
  59.   Langegracht 7B      AINEX-BBS +31-33-633916
  60.   3811 BT  Amersfoort      FidoNet 2:283/512
  61.   The Netherlands      arjen_lentz@f512.n283.z2.fidonet.org
  62.  
  63.  
  64.   DISCLAIMER
  65.  
  66.   This information is provided "as is" and comes with no warranties of any
  67.   kind, either expressed or implied. It's intended to be used by programmers
  68.   and developers. In no event shall the author be liable to you or anyone
  69.   else for any damages, including any lost profits, lost savings or other
  70.   incidental or consequential damages arising out of the use or inability
  71.   to use this information.
  72.  
  73.  
  74.   LICENCE
  75.  
  76.   This package may be freely distributed provided the files remain together,
  77.   in their original unmodified form.
  78.   All files, executables and sourcecode remain the copyrighted property of
  79.   Arjen G. Lentz and LENTZ SOFTWARE-DEVELOPMENT.
  80.   Licence for any use granted, provided this notice & CRC.DOC are included.
  81.   For executable applications, credit should be given in the appropriate
  82.   place in the program and documentation.
  83.   These notices must be retained in any copies of any part of this
  84.   documentation and/or software.
  85.  
  86.   Any use of, or operation on (including copying/distributing) any of
  87.   the above mentioned files implies full and unconditional acceptance of
  88.   this license and disclaimer.
  89.  
  90. =============================================================================*/
  91.  
  92. #include "includes.h"
  93. #include "aglcrc.h"
  94.  
  95. /* ------------------------------------------------------------------------- */
  96. void 
  97. crc16init (word FAR * crctab, word poly)
  98. {
  99.     register int i, j;
  100.     register word crc;
  101.  
  102.     for (i = 0; i <= 255; i++)
  103.     {
  104.         crc = i;
  105.         for (j = 8; j > 0; j--)
  106.         {
  107.             if (crc & 1)
  108.                 crc = (crc >> 1) ^ poly;
  109.             else
  110.                 crc >>= 1;
  111.         }
  112.         crctab[i] = crc;
  113.     }
  114. }                                /*crc16init()*/
  115.  
  116. /* ------------------------------------------------------------------------- */
  117. word 
  118. crc16block (word FAR * crctab, word crc, byte FAR * buf, word len)
  119. {
  120.     while (len--)
  121.         crc = crc16upd (crctab, crc, *buf++);
  122.  
  123.     return (crc);
  124. }                                /*crc16block()*/
  125.  
  126. /* ------------------------------------------------------------------------- */
  127. void 
  128. crc16rinit (word FAR * crctab, word poly)
  129. {
  130.     register int i, j;
  131.     register word crc;
  132.  
  133.     for (i = 0; i <= 255; i++)
  134.     {
  135.         crc = i << 8;
  136.         for (j = 8; j > 0; j--)
  137.         {
  138.             if (crc & 0x8000)
  139.                 crc = (crc << 1) ^ poly;
  140.             else
  141.                 crc <<= 1;
  142.         }
  143.         crctab[i] = crc;
  144.     }
  145. }                                /*crc16rinit()*/
  146.  
  147. /* ------------------------------------------------------------------------- */
  148. word 
  149. crc16rblock (word FAR * crctab, word crc, byte FAR * buf, word len)
  150. {
  151.     while (len--)
  152.         crc = crc16rupd (crctab, crc, *buf++);
  153.  
  154.     return (crc);
  155. }                                /*crc16rblock()*/
  156.  
  157. /* ------------------------------------------------------------------------- */
  158. void 
  159. crc32init (ULONG FAR * crctab, ULONG poly)
  160. {
  161.     register int i, j;
  162.     register ULONG crc;
  163.  
  164.     for (i = 0; i <= 255; i++)
  165.     {
  166.         crc = i;
  167.         for (j = 8; j > 0; j--)
  168.         {
  169.             if (crc & 1)
  170.                 crc = (crc >> 1) ^ poly;
  171.             else
  172.                 crc >>= 1;
  173.         }
  174.         crctab[i] = crc;
  175.     }
  176. }                                /*crc32init()*/
  177.  
  178. /* ------------------------------------------------------------------------- */
  179. ULONG 
  180. crc32block (ULONG FAR * crctab, ULONG crc, byte FAR * buf, word len)
  181. {
  182.     while (len--)
  183.         crc = crc32upd (crctab, crc, *buf++);
  184.  
  185.     return (crc);
  186. }                                /*crc32block()*/
  187.  
  188. /* end of crc.c ------------------------------------------------------------ */
  189.