From: Jaroslav Kysela Date: Thu, 13 Sep 2018 13:10:11 +0000 (+0200) Subject: tvhcsa: optimize offset check for incomplete packet in CSA descramble X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3c34c9c8b625bc8561b0dc2e777432e056b6703;p=thirdparty%2Ftvheadend.git tvhcsa: optimize offset check for incomplete packet in CSA descramble --- diff --git a/src/descrambler/tvhcsa.c b/src/descrambler/tvhcsa.c index 31b906d01..d2c009555 100644 --- a/src/descrambler/tvhcsa.c +++ b/src/descrambler/tvhcsa.c @@ -104,10 +104,9 @@ tvhcsa_csa_cbc_descramble #if ENABLE_DVBCSA uint8_t *pkt; - int ev_od; - int len; - int offset; - int n; + int_fast8_t ev_od; + int_fast16_t len; + int_fast16_t offset; for ( ; tsb < tsb_end; tsb += 188) { @@ -115,26 +114,19 @@ tvhcsa_csa_cbc_descramble memcpy(pkt, tsb, 188); csa->csa_fill++; - do { // handle this packet - if((pkt[3] & 0x80) == 0) // clear or reserved (0x40) + do { // handle this packet + if((pkt[3] & 0x80) == 0) // clear or reserved (0x40) break; ev_od = pkt[3] & 0x40; - pkt[3] &= 0x3f; // consider it decrypted now - if(pkt[3] & 0x20) { // incomplete packet + pkt[3] &= 0x3f; // consider it decrypted now + if(pkt[3] & 0x20) { // incomplete packet offset = 4 + pkt[4] + 1; - if (offset > 187) // invalid offset - break; + if (offset > 188-8) // invalid offset (residue handling?) + break; // no more processing len = 188 - offset; - n = len >> 3; - // FIXME: //residue = len - (n << 3); - if(n == 0) { // decrypted==encrypted! - break; // this doesn't need more processing - } } else { len = 184; offset = 4; - // FIXME: //n = 23; - // FIXME: //residue = 0; } if(ev_od == 0) { csa->csa_tsbbatch_even[csa->csa_fill_even].data = pkt + offset;