fix(crc32): use correct init value for ESP-IDF ROM CRC32
esp_rom_crc32_le(0xFFFFFFFF, ...) inverts the input (~0xFFFFFFFF = 0), so the effective init is 0x00000000, not 0xFFFFFFFF (standard zlib). This caused all NVS page/entry CRC checks to fail silently.
This commit is contained in:
parent
92dd27ed9b
commit
1076aa3848
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Pre-computed CRC32 lookup table using reflected polynomial 0xEDB88320.
|
* Pre-computed CRC32 lookup table using reflected polynomial 0xEDB88320.
|
||||||
* Compatible with zlib.crc32() used by ESP-IDF.
|
* Compatible with esp_rom_crc32_le(0xFFFFFFFF, ...) used by ESP-IDF NVS/OTA.
|
||||||
*/
|
*/
|
||||||
const CRC32_TABLE: Uint32Array = (() => {
|
const CRC32_TABLE: Uint32Array = (() => {
|
||||||
const table = new Uint32Array(256);
|
const table = new Uint32Array(256);
|
||||||
|
|
@ -16,7 +16,7 @@ const CRC32_TABLE: Uint32Array = (() => {
|
||||||
|
|
||||||
/** Compute CRC32 of a Uint8Array. Returns unsigned 32-bit integer. */
|
/** Compute CRC32 of a Uint8Array. Returns unsigned 32-bit integer. */
|
||||||
export function crc32(data: Uint8Array): number {
|
export function crc32(data: Uint8Array): number {
|
||||||
let crc = 0xFFFFFFFF;
|
let crc = 0x00000000;
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
crc = (crc >>> 8) ^ CRC32_TABLE[(crc ^ data[i]) & 0xFF];
|
crc = (crc >>> 8) ^ CRC32_TABLE[(crc ^ data[i]) & 0xFF];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue