Diff for /libaitcrc/src/aitcrc.c between versions 1.2 and 1.2.2.1

version 1.2, 2010/01/20 00:04:45 version 1.2.2.1, 2010/06/13 16:10:16
Line 13  static int crc_Errno; Line 13  static int crc_Errno;
 static char crc_Error[MAX_STR + 1];  static char crc_Error[MAX_STR + 1];
   
 // Adler module  // Adler module
const u_long crc_modAdler = 0xFFF1L;const u_int crc_modAdler = 0xFFF1L;
   
 // All known library CRC types ...  // All known library CRC types ...
 const crcPoly_t crc_Poly[] = {  const crcPoly_t crc_Poly[] = {
        { 1, (u_long) 0x1, "CRC-1-Parity" },         { 1, (u_int) 0x1, "CRC-1-Parity" }, 
        { 4, (u_long) 0x3, "CRC-4-ITU" },         { 4, (u_int) 0x3, "CRC-4-ITU" }, 
        { 5, (u_long) 0x15, "CRC-5-ITU" },         { 5, (u_int) 0x15, "CRC-5-ITU" }, 
        { 6, (u_long) 0x3, "CRC-6-ITU" },         { 6, (u_int) 0x3, "CRC-6-ITU" }, 
        { 7, (u_long) 0x9, "CRC-7-MMC" },         { 7, (u_int) 0x9, "CRC-7-MMC" }, 
        { 8, (u_long) 0x8D, "CRC-8-CCITT" },         { 8, (u_int) 0x8D, "CRC-8-CCITT" }, 
        { 10, (u_long) 0x233, "CRC-10" },         { 10, (u_int) 0x233, "CRC-10" }, 
        { 11, (u_long) 0x385, "CRC-11-FlexRay" },         { 11, (u_int) 0x385, "CRC-11-FlexRay" }, 
        { 12, (u_long) 0x80F, "CRC-12-Telco" },         { 12, (u_int) 0x80F, "CRC-12-Telco" }, 
        { 15, (u_long) 0x4599, "CRC-15-CAN" },         { 15, (u_int) 0x4599, "CRC-15-CAN" }, 
        { 16, (u_long) 0x8005, "CRC-16-IBM" },         { 16, (u_int) 0x8005, "CRC-16-IBM" }, 
        { 24, (u_long) 0x864CFB, "CRC-24-Radix64" },         { 24, (u_int) 0x864CFB, "CRC-24-Radix64" }, 
        { 30, (u_long) 0x2030B9C7, "CRC-30-CDMA" },         { 30, (u_int) 0x2030B9C7, "CRC-30-CDMA" }, 
        { 32, (u_long) 0x04C11DB7, "CRC-32-802.3" }        { 32, (u_int) 0x04C11DB7, "CRC-32-802.3" }
 };  };
   
 // ----------------------------------------------------------  // ----------------------------------------------------------
Line 71  inline void crcSetErr(int eno, char *estr, ...) Line 71  inline void crcSetErr(int eno, char *estr, ...)
  * @crcBits = Number width bits    * @crcBits = Number width bits 
  * return: -1 error, !=-1 reflecting number   * return: -1 error, !=-1 reflecting number
  */   */
inline u_long crcReflect(u_long crcNum, u_char crcBits)inline u_int
 crcReflect(u_int crcNum, u_char crcBits)
 {  {
        register u_long i, j, rev;        register u_int i, j, rev;
   
        for (i = (u_long) 1 << (crcBits - 1), j = 1, rev ^= rev; i; i >>= 1, j <<= 1)        for (i = (u_int) 1 << (crcBits - 1), j = 1, rev ^= rev; i; i >>= 1, j <<= 1)
                 if (crcNum & i)                  if (crcNum & i)
                         rev |= j;                          rev |= j;
   
Line 93  inline u_long crcReflect(u_long crcNum, u_char crcBits Line 94  inline u_long crcReflect(u_long crcNum, u_char crcBits
  * @xorCRC = Last xor CRC value   * @xorCRC = Last xor CRC value
  * return: -1 error, !=-1 CRC checksum   * return: -1 error, !=-1 CRC checksum
  */   */
inline u_long crcCalc(u_char * __restrict psBuf, u_int bufLen, u_char crcBits, u_char RevOpts, u_long initCRC, u_long xorCRC)inline u_int
 crcCalc(u_char * __restrict psBuf, u_int bufLen, u_char crcBits, u_char RevOpts, u_int initCRC, u_int xorCRC)
 {  {
        const u_long bits = sizeof(long) * 8 - crcBits;        const u_int bits = sizeof(int) * 8 - crcBits;
        u_long poly, crchibit, crc;        u_int poly, crchibit, crc;
        register u_long i, j, b, ch;        register u_int i, j, b, ch;
   
         if (!psBuf) {          if (!psBuf) {
                 crc_Errno = 1;                  crc_Errno = 1;
Line 155  inline u_long crcCalc(u_char * __restrict psBuf, u_int Line 157  inline u_long crcCalc(u_char * __restrict psBuf, u_int
         }          }
         poly <<= bits;          poly <<= bits;
   
        crchibit = (u_long) 1 << (crcBits - 1);        crchibit = (u_int) 1 << (crcBits - 1);
         crchibit <<= bits;          crchibit <<= bits;
         crc = initCRC << bits;          crc = initCRC << bits;
   
         for (i = 0; i < bufLen; i++) {          for (i = 0; i < bufLen; i++) {
                ch = (u_long) *psBuf++;                ch = (u_int) *psBuf++;
                 if (RevOpts & REVOPTS_REVERTBYTE)                  if (RevOpts & REVOPTS_REVERTBYTE)
                         ch = crcReflect(ch, 8);                          ch = crcReflect(ch, 8);
   
Line 176  inline u_long crcCalc(u_char * __restrict psBuf, u_int Line 178  inline u_long crcCalc(u_char * __restrict psBuf, u_int
         }          }
   
         if (RevOpts & REVOPTS_REVERTCRC)          if (RevOpts & REVOPTS_REVERTCRC)
                crc = crcReflect(crc, sizeof(long) * 8);                crc = crcReflect(crc, sizeof(int) * 8);
         crc ^= xorCRC << bits;          crc ^= xorCRC << bits;
         crc &= (((crchibit - 1) << 1) | 1);          crc &= (((crchibit - 1) << 1) | 1);
         if (!(RevOpts & REVOPTS_REVERTCRC))          if (!(RevOpts & REVOPTS_REVERTCRC))
Line 194  inline u_long crcCalc(u_char * __restrict psBuf, u_int Line 196  inline u_long crcCalc(u_char * __restrict psBuf, u_int
  * @bufLen = Length of data   * @bufLen = Length of data
  * return: -1 error, !=-1 Checksum   * return: -1 error, !=-1 Checksum
  */   */
inline u_short crcIP(u_short * __restrict nBuf, int bufLen)inline u_short
 crcIP(u_short * __restrict nBuf, int bufLen)
 {  {
        register u_long sum;        register u_int sum;
   
         if (!nBuf) {          if (!nBuf) {
                 crc_Errno = 1;                  crc_Errno = 1;
Line 215  inline u_short crcIP(u_short * __restrict nBuf, int bu Line 218  inline u_short crcIP(u_short * __restrict nBuf, int bu
 }  }
   
 /*  /*
 * crcFletcher() Fletcher-16 Checksum computing * crcFletcher16() Fletcher-16 Checksum computing
  * @nBuf = Data for calculation   * @nBuf = Data for calculation
  * @bufLen = Length of data   * @bufLen = Length of data
  * return: -1 error, !=-1 Checksum   * return: -1 error, !=-1 Checksum
  */   */
inline u_long crcFletcher(u_short * __restrict nBuf, int bufLen)inline u_short
 crcFletcher16(u_short * __restrict nBuf, int bufLen)
 {  {
        register u_long s1, s2, clen;        register u_short s1, s2;
         register u_int clen;
   
         if (!nBuf) {          if (!nBuf) {
                 crc_Errno = 1;                  crc_Errno = 1;
                   strlcpy(crc_Error, "crcFletcher16(): Invalid parameters!", MAX_STR + 1);
                   return -1;
           }
   
           s1 = s2 = 0xFF;
           while (bufLen) {
                   clen = bufLen > MAX_FLETCHER16_DIGEST ? MAX_FLETCHER16_DIGEST : bufLen;
                   bufLen -= clen;
   
                   do {
                           s1 += (u_short) *nBuf++;
                           s2 += s1;
                   } while (--clen);
   
                   s1 = (s1 >> 8) + (s1 & 0xFF);
                   s2 = (s2 >> 8) + (s2 & 0xFF);
           }
   
           crc_Errno ^= crc_Errno;
           return (s2 << 8) | s1;
   }
   
   /*
    * crcFletcher() Fletcher-32 Checksum computing
    * @nBuf = Data for calculation
    * @bufLen = Length of data
    * return: -1 error, !=-1 Checksum
    */
   inline u_int
   crcFletcher(u_short * __restrict nBuf, int bufLen)
   {
           register u_int s1, s2, clen;
   
           if (!nBuf) {
                   crc_Errno = 1;
                 strlcpy(crc_Error, "crcFletcher(): Invalid parameters!", MAX_STR + 1);                  strlcpy(crc_Error, "crcFletcher(): Invalid parameters!", MAX_STR + 1);
                 return -1;                  return -1;
         }          }
Line 236  inline u_long crcFletcher(u_short * __restrict nBuf, i Line 276  inline u_long crcFletcher(u_short * __restrict nBuf, i
                 bufLen -= clen;                  bufLen -= clen;
   
                 do {                  do {
                        s1 += (u_long) *nBuf++;                        s1 += (u_int) *nBuf++;
                         s2 += s1;                          s2 += s1;
                 } while (--clen);                  } while (--clen);
   
Line 254  inline u_long crcFletcher(u_short * __restrict nBuf, i Line 294  inline u_long crcFletcher(u_short * __restrict nBuf, i
  * @bufLen = Length of data   * @bufLen = Length of data
  * return: -1 error, !=-1 Checksum   * return: -1 error, !=-1 Checksum
  */   */
inline u_long crcAdler(u_char * __restrict psBuf, int bufLen)inline u_int
 crcAdler(u_char * __restrict psBuf, int bufLen)
 {  {
        register u_long s1, s2, clen;        register u_int s1, s2, clen;
   
         if (!psBuf) {          if (!psBuf) {
                 crc_Errno = 1;                  crc_Errno = 1;
Line 271  inline u_long crcAdler(u_char * __restrict psBuf, int  Line 312  inline u_long crcAdler(u_char * __restrict psBuf, int 
                 bufLen -= clen;                  bufLen -= clen;
   
                 do {                  do {
                        s1 += (u_long) *psBuf++;                        s1 += (u_int) *psBuf++;
                         s2 += s1;                          s2 += s1;
                 } while (--clen);                  } while (--clen);
   

Removed from v.1.2  
changed lines
  Added in v.1.2.2.1


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>