X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/01c034ad857128c51482a563befb374e38ebe668..32874aeac8dacbca26663777b39a79efc5d8dc4b:/sshcrc.c diff --git a/sshcrc.c b/sshcrc.c index 63050b95..fb0db0ca 100644 --- a/sshcrc.c +++ b/sshcrc.c @@ -89,7 +89,7 @@ #define POLY (0xEDB88320L) #ifdef GENPROGRAM -#define INITFUNC /* the gen program needs the init func :-) */ +#define INITFUNC /* the gen program needs the init func :-) */ #endif #ifdef INITFUNC @@ -100,21 +100,22 @@ */ static unsigned long crc32_table[256]; -void crc32_init(void) { +void crc32_init(void) +{ unsigned long crcword; int i; - + for (i = 0; i < 256; i++) { - unsigned long newbyte, x32term; - int j; - crcword = 0; - newbyte = i; - for (j = 0; j < 8; j++) { - x32term = (crcword ^ newbyte) & 1; - crcword = (crcword >> 1) ^ (x32term * POLY); - newbyte >>= 1; - } - crc32_table[i] = crcword; + unsigned long newbyte, x32term; + int j; + crcword = 0; + newbyte = i; + for (j = 0; j < 8; j++) { + x32term = (crcword ^ newbyte) & 1; + crcword = (crcword >> 1) ^ (x32term * POLY); + newbyte >>= 1; + } + crc32_table[i] = crcword; } } @@ -193,29 +194,31 @@ static const unsigned long crc32_table[256] = { #endif #ifdef GENPROGRAM -int main(void) { +int main(void) +{ unsigned long crcword; int i; crc32_init(); for (i = 0; i < 256; i++) { - printf("%s0x%08XL%s", - (i % 4 == 0 ? " " : " "), - crc32_table[i], - (i % 4 == 3 ? (i == 255 ? "\n" : ",\n") : ",")); + printf("%s0x%08XL%s", + (i % 4 == 0 ? " " : " "), + crc32_table[i], + (i % 4 == 3 ? (i == 255 ? "\n" : ",\n") : ",")); } return 0; } #endif -unsigned long crc32(const void *buf, size_t len) { +unsigned long crc32(const void *buf, size_t len) +{ unsigned long crcword = 0L; const unsigned char *p = (const unsigned char *) buf; while (len--) { - unsigned long newbyte = *p++; - newbyte ^= crcword & 0xFFL; - crcword = (crcword >> 8) ^ crc32_table[newbyte]; + unsigned long newbyte = *p++; + newbyte ^= crcword & 0xFFL; + crcword = (crcword >> 8) ^ crc32_table[newbyte]; } return crcword; }