]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvhcsa: optimize offset check for incomplete packet in CSA descramble
authorJaroslav Kysela <perex@perex.cz>
Thu, 13 Sep 2018 13:10:11 +0000 (15:10 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 13 Sep 2018 13:10:11 +0000 (15:10 +0200)
src/descrambler/tvhcsa.c

index 31b906d01f076a42778392c73dbf7d2b42288b42..d2c00955559bd3ac28450a90a2575071cd3ce4a3 100644 (file)
@@ -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;