crc32.c (65668) | crc32.c (76259) |
---|---|
1/* 2 * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or 3 * code or tables extracted from it, as desired without restriction. 4 * 5 * First, the polynomial itself and its table of feedback terms. The 6 * polynomial is 7 * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 8 * --- 17 unchanged lines hidden (view full) --- 26 * The feedback terms table consists of 256, 32-bit entries. Notes 27 * 28 * The table can be generated at runtime if desired; code to do so 29 * is shown later. It might not be obvious, but the feedback 30 * terms simply represent the results of eight shift/xor opera 31 * tions for all combinations of data and CRC register values 32 * 33 * The values must be right-shifted by eight bits by the "updcrc | 1/* 2 * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or 3 * code or tables extracted from it, as desired without restriction. 4 * 5 * First, the polynomial itself and its table of feedback terms. The 6 * polynomial is 7 * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 8 * --- 17 unchanged lines hidden (view full) --- 26 * The feedback terms table consists of 256, 32-bit entries. Notes 27 * 28 * The table can be generated at runtime if desired; code to do so 29 * is shown later. It might not be obvious, but the feedback 30 * terms simply represent the results of eight shift/xor opera 31 * tions for all combinations of data and CRC register values 32 * 33 * The values must be right-shifted by eight bits by the "updcrc |
34 * logic; the shift must be unsigned (bring in zeroes). On some | 34 * logic; the shift must be u_(bring in zeroes). On some |
35 * hardware you could probably optimize the shift in assembler by 36 * using byte-swap instructions 37 * polynomial $edb88320 38 */ 39 40 41#include "includes.h" | 35 * hardware you could probably optimize the shift in assembler by 36 * using byte-swap instructions 37 * polynomial $edb88320 38 */ 39 40 41#include "includes.h" |
42RCSID("$OpenBSD: crc32.c,v 1.7 2000/09/07 20:27:51 deraadt Exp $"); | 42RCSID("$OpenBSD: crc32.c,v 1.8 2000/12/19 23:17:56 markus Exp $"); |
43 44#include "crc32.h" 45 | 43 44#include "crc32.h" 45 |
46static unsigned int crc32_tab[] = { | 46static u_int crc32_tab[] = { |
47 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 48 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 49 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 50 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 51 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, 52 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 53 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 54 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, --- 40 unchanged lines hidden (view full) --- 95 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 96 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, 97 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 98 0x2d02ef8dL 99}; 100 101/* Return a 32-bit CRC of the contents of the buffer. */ 102 | 47 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 48 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 49 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 50 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 51 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, 52 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 53 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 54 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, --- 40 unchanged lines hidden (view full) --- 95 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 96 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, 97 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 98 0x2d02ef8dL 99}; 100 101/* Return a 32-bit CRC of the contents of the buffer. */ 102 |
103unsigned int 104ssh_crc32(const unsigned char *s, unsigned int len) | 103u_int 104ssh_crc32(const u_char *s, u_int len) |
105{ | 105{ |
106 unsigned int i; 107 unsigned int crc32val; | 106 u_int i; 107 u_int crc32val; |
108 109 crc32val = 0; 110 for (i = 0; i < len; i ++) { 111 crc32val = crc32_tab[(crc32val ^ s[i]) & 0xff] ^ (crc32val >> 8); 112 } 113 return crc32val; 114} | 108 109 crc32val = 0; 110 for (i = 0; i < len; i ++) { 111 crc32val = crc32_tab[(crc32val ^ s[i]) & 0xff] ^ (crc32val >> 8); 112 } 113 return crc32val; 114} |