From ad0b79eec5db37fd7b751f7d8878c80020cc3042 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 8 Sep 2021 11:50:53 +0700 Subject: [PATCH] Add comments to the udp crc --- crates/core/src/bcudp/crc.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/core/src/bcudp/crc.rs b/crates/core/src/bcudp/crc.rs index 760df61..e50e5a1 100644 --- a/crates/core/src/bcudp/crc.rs +++ b/crates/core/src/bcudp/crc.rs @@ -1,7 +1,20 @@ use crc32fast::Hasher; pub(crate) fn calc_crc(payload: &[u8]) -> u32 { + // Bc uses a non standard crc. + // + // It uses the polynomial 0x04c11db7 + // It uses the inital value or 0x00000000 + // It uses the xorout of 0x00000000 + // + // The crc32fast has an odd behavior were it bitwise negates + // the initial value before the loop. In order to have + // an effective initial value of 0x00000000 we need to provide + // the value 0xffffffff let mut hasher = Hasher::new_with_initial(0xffffffff); hasher.update(payload); + // crc32fast uses the algorithm CRC-32/ISO-HDLC + // This has an xorout of 0xffffffff + // we must undo this xorout hasher.finalize() ^ 0xffffffff_u32 }