Rev 4505 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4505 | Rev 4558 | ||
---|---|---|---|
Line 40... | Line 40... | ||
40 | 40 | ||
41 | #define CRC_DIVIDER_BE 0x04C11DB7 |
41 | #define CRC_DIVIDER_BE 0x04C11DB7 |
42 | 42 | ||
43 | #define CRC_DIVIDER_LE 0xEDB88320 |
43 | #define CRC_DIVIDER_LE 0xEDB88320 |
44 | 44 | ||
45 | uint32_t compute_crc32_le( uint32_t seed, uint8_t * data, int length ){ |
45 | uint32_t compute_crc32_le( uint32_t seed, uint8_t * data, size_t length ){ |
46 | int index; |
46 | int index; |
47 | 47 | ||
48 | while( length >= 8 ){ |
48 | while( length >= 8 ){ |
49 | seed ^= ( * data ); |
49 | seed ^= ( * data ); |
50 | for( index = 0; index < 8; ++ index ){ |
50 | for( index = 0; index < 8; ++ index ){ |
Line 69... | Line 69... | ||
69 | length -= 8; |
69 | length -= 8; |
70 | } |
70 | } |
71 | return seed; |
71 | return seed; |
72 | } |
72 | } |
73 | 73 | ||
74 | uint32_t compute_crc32_be( uint32_t seed, uint8_t * data, int length ){ |
74 | uint32_t compute_crc32_be( uint32_t seed, uint8_t * data, size_t length ){ |
75 | int index; |
75 | int index; |
76 | 76 | ||
77 | while( length >= 8 ){ |
77 | while( length >= 8 ){ |
78 | seed ^= ( * data ) << 24; |
78 | seed ^= ( * data ) << 24; |
79 | for( index = 0; index < 8; ++ index ){ |
79 | for( index = 0; index < 8; ++ index ){ |
Line 98... | Line 98... | ||
98 | length -= 8; |
98 | length -= 8; |
99 | } |
99 | } |
100 | return seed; |
100 | return seed; |
101 | } |
101 | } |
102 | 102 | ||
103 | uint32_t compute_checksum( uint32_t seed, uint8_t * data, int length ){ |
103 | uint32_t compute_checksum( uint32_t seed, uint8_t * data, size_t length ){ |
104 | int index; |
104 | size_t index; |
105 | 105 | ||
106 | // sum all the 16 bit fields |
106 | // sum all the 16 bit fields |
107 | for( index = 0; index < length - 1; index += 2 ){ |
107 | for( index = 0; index + 1 < length; index += 2 ){ |
108 | seed += ( data[ index ] << 8 ) + data[ index + 1 ]; |
108 | seed += ( data[ index ] << 8 ) + data[ index + 1 ]; |
109 | } |
109 | } |
110 | 110 | ||
111 | // last odd byte with zero padding |
111 | // last odd byte with zero padding |
112 | if( index == length - 1 ){ |
112 | if( index + 1 == length ){ |
113 | seed += data[ index ] << 8; |
113 | seed += data[ index ] << 8; |
114 | } |
114 | } |
115 | 115 | ||
116 | return seed; |
116 | return seed; |
117 | } |
117 | } |