Zepp-Hanzj opened a new pull request, #19246:
URL: https://github.com/apache/nuttx/pull/19246

   ## Summary
   
   Fixes #14532
   
   The existing crc32() uses init=0 with no final XOR, which differs from the 
Linux/zlib standard CRC32 (init=0xFFFFFFFF, final XOR 0xFFFFFFFF). This causes 
interoperability issues when exchanging CRC32 values between NuttX and Linux 
systems (e.g., UART protocols, file integrity checks).
   
   Add two new functions following the crc8/crc16 variant naming convention:
   
   - crc32_ieee(src, len) — full CRC, Linux/zlib compatible
   - crc32_ieeepart(src, len, crcval) — incremental CRC, Linux/zlib compatible
   
   The existing crc32() and crc32part() are unchanged to avoid breaking 
existing callers (bbsram, sbram, etc.).
   
   ## Verification
   
   Built and tested on sim:nsh. Used known Linux zlib CRC32 test vectors.
   
   Build command:
   
     make distclean
     tools/configure.sh sim:nsh
     make -j$(nproc)
   
   Run command:
   
     printf 'hello\npoweroff\n' | timeout 30 ./nuttx 2>/dev/null
   
   Test output:
   
     NuttShell (NSH) NuttX-13.0.0-RC0
     nsh> hello
     === crc32_ieee compatibility test ===
     crc32("hello")      = 0xf032519b (old, init=0)
     crc32_ieee("hello") = 0x3610a686 (expected 0x3610a686)
       PASS
     crc32("123456789")      = 0x2dfd2d88
     crc32_ieee("123456789") = 0xcbf43926 (expected 0xcbf43926)
       PASS
     crc32("")      = 0x00000000
     crc32_ieee("") = 0x00000000 (expected 0x00000000)
       PASS
     crc32_ieeepart incremental("123456789") = 0xcbf43926 (expected 0xcbf43926)
       PASS
     crc32("hello") = 0xf032519b (should be unchanged from before)
       (old crc32 backward compatible - no reference value needed)
     === Results: 5 pass, 0 fail ===
     nsh> poweroff
   
   Test vectors verified against Linux zlib crc32():
     crc32_ieee("hello")     = 0x3610a686 — matches Linux
     crc32_ieee("123456789") = 0xcbf43926 — matches Linux
     crc32_ieee("")           = 0x00000000 — matches Linux
     crc32_ieeepart incremental — matches one-shot crc32_ieee
     crc32("hello")           = 0xf032519b — unchanged, backward compatible


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to