blob: f24da020dbb73d9fb6808b6ac3ab3e971f2e397c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
const CRC_TABLE: [u32; 256] = make_crc_table();
const fn make_crc_table() -> [u32; 256]
{
let mut table = [0u32; 256];
let mut c: u32;
let mut k: i32;
let mut n: u32 = 0;
while n < 256
{
c = n;
k = 0;
while k < 8
{
if c & 1 == 1
{
c = 0xedb88320 ^ (c >> 1);
}
else
{
c = c >> 1;
}
k += 1;
}
table[n as usize] = c;
n += 1;
}
table
}
pub fn update_crc(curr_crc: &mut u32, buff: &[u8]) -> ()
{
for x in buff
{
*curr_crc = CRC_TABLE[((*curr_crc as u8 ^ x) & 0xff) as usize] ^ (*curr_crc >> 8);
}
}
|