| 1 |
/* We don't find this case because in "crc32_generic_shift" function |
| 2 |
loop's iteration number isn't a constant (i < 8 * (int)(len & 3)). */ |
| 3 |
|
| 4 |
#include <stddef.h> |
| 5 |
typedef unsigned int u32; |
| 6 |
#define __attribute_const__ __attribute__((__const__)) |
| 7 |
static u32 __attribute_const__ gf2_multiply (u32 x, u32 y, u32 modulus) |
| 8 |
{ |
| 9 |
u32 product = x & 1 ? y : 0; |
| 10 |
int i; |
| 11 |
|
| 12 |
for (i = 0; i < 31; i++) |
| 13 |
{ |
| 14 |
product = (product >> 1) ^ (product & 1 ? modulus : 0); |
| 15 |
x >>= 1; |
| 16 |
product ^= x & 1 ? y : 0; |
| 17 |
} |
| 18 |
return product; |
| 19 |
} |
| 20 |
|
| 21 |
u32 __attribute_const__ crc32_generic_shift(u32 crc, size_t len, |
| 22 |
u32 polynomial) |
| 23 |
{ |
| 24 |
u32 power = polynomial; /* CRC of x^32 */ |
| 25 |
int i; |
| 26 |
|
| 27 |
/* Shift up to 32 bits in the simple linear way */ |
| 28 |
for (i = 0; i < 8 * (int)(len & 3); i++) |
| 29 |
crc = (crc >> 1) ^ (crc & 1 ? polynomial : 0); |
| 30 |
|
| 31 |
len >>= 2; |
| 32 |
if (!len) |
| 33 |
return crc; |
| 34 |
|
| 35 |
for (;;) { |
| 36 |
/* "power" is x^(2^i), modulo the polynomial */ |
| 37 |
if (len & 1) |
| 38 |
crc = gf2_multiply(crc, power, polynomial); |
| 39 |
|
| 40 |
len >>= 1; |
| 41 |
if (!len) |
| 42 |
break; |
| 43 |
|
| 44 |
/* Square power, advancing to x^(2^(i+1)) */ |
| 45 |
power = gf2_multiply(power, power, polynomial); |
| 46 |
} |
| 47 |
|
| 48 |
return crc; |
| 49 |
} |