diff --git a/src/dvb/dvb_tables.c b/src/dvb/dvb_tables.c index 51deca6c..ef75e3ab 100644 --- a/src/dvb/dvb_tables.c +++ b/src/dvb/dvb_tables.c @@ -202,7 +202,7 @@ dvb_proc_table(th_dvb_mux_instance_t *tdmi, th_dvb_table_t *tdt, uint8_t *sec, /* It seems some hardware (or is it the dvb API?) does not honour the DMX_CHECK_CRC flag, so we check it again */ - if(chkcrc && crc32(sec, r)) + if(chkcrc && crc32(sec, r, 0xffffffff)) return; r -= 3; diff --git a/src/psi.c b/src/psi.c index 4619d1da..2496e766 100644 --- a/src/psi.c +++ b/src/psi.c @@ -63,7 +63,7 @@ psi_section_reassemble0(psi_section_t *ps, const uint8_t *data, excess = ps->ps_offset - tsize; - if(crc && crc32(ps->ps_data, tsize)) + if(crc && crc32(ps->ps_data, tsize, 0xffffffff)) return -1; cb(ps->ps_data, tsize - (crc ? 4 : 0), opaque); @@ -163,14 +163,14 @@ psi_append_crc32(uint8_t *buf, int offset, int maxlen) if(offset + 4 > maxlen) return -1; - crc = crc32(buf, offset); + crc = crc32(buf, offset, 0xffffffff); buf[offset + 0] = crc >> 24; buf[offset + 1] = crc >> 16; buf[offset + 2] = crc >> 8; buf[offset + 3] = crc; - assert(crc32(buf, offset + 4) == 0); + assert(crc32(buf, offset + 4, 0xffffffff) == 0); return offset + 4; } diff --git a/src/tvhead.h b/src/tvhead.h index a60d962f..632203e6 100644 --- a/src/tvhead.h +++ b/src/tvhead.h @@ -839,6 +839,6 @@ int tvh_socket(int domain, int type, int protocol); void hexdump(const char *pfx, const uint8_t *data, int len); -uint32_t crc32(uint8_t *data, size_t datalen); +uint32_t crc32(uint8_t *data, size_t datalen, uint32_t crc); #endif /* TV_HEAD_H */ diff --git a/src/utils.c b/src/utils.c index 91a29dc6..2b69a901 100644 --- a/src/utils.c +++ b/src/utils.c @@ -51,10 +51,8 @@ static uint32_t crc_tab[256] = { }; uint32_t -crc32(uint8_t *data, size_t datalen) +crc32(uint8_t *data, size_t datalen, uint32_t crc) { - uint32_t crc = 0xffffffff; - while(datalen--) crc = (crc << 8) ^ crc_tab[((crc >> 24) ^ *data++) & 0xff];