Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix incomplete packet handling
A calculation error (offset / length) was made which only was a problem for incomplete packets. Also some slight optimization was possible.
  • Loading branch information
spdfrk authored and perexg committed Feb 19, 2016
1 parent ff6bf99 commit a2ebe10
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/descrambler/libaesdec/libaesdec.c
Expand Up @@ -59,7 +59,6 @@ void aes_decrypt_packet(void *keys, unsigned char *packet) {
unsigned char *pkt;
unsigned char ev_od = 0;
int xc0, offset, n;
int len;
pkt = packet;
AES_KEY k;

Expand All @@ -78,15 +77,13 @@ void aes_decrypt_packet(void *keys, unsigned char *packet) {
pkt[3] &= 0x3f; // consider it decrypted now
if (pkt[3] & 0x20) { // incomplete packet
offset = 4 + pkt[4] + 1;
len = 188 - offset;
n = len >> 3;
n = (188 - offset) >> 4;
if (n == 0) { // decrypted==encrypted!
return; // this doesn't need more processing
}
} else {
len = 184;
offset = 4;
}
offset = 4;
}
} else {
return;
}
Expand All @@ -97,9 +94,7 @@ void aes_decrypt_packet(void *keys, unsigned char *packet) {
k = ((struct aes_keys_t *) keys)->odd;
}

// TODO room for improvement?
int i;
for (i = offset; i <= (len - 16); i += 16) {
AES_ecb_encrypt(pkt + i, pkt + i, &k, AES_DECRYPT);
for (; offset <= (188 - 16); offset += 16) {
AES_ecb_encrypt(pkt + offset, pkt + offset, &k, AES_DECRYPT);
}
}

3 comments on commit a2ebe10

@Jalle19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance this fix could get backported to 4.0?

@Trujulu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Far as I know 4.0 is deprecated. You should use 4.2 or higher...

@Jalle19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unfortunate, it's stable and works well, although I had to grab 4.2 to get this patch.

Please sign in to comment.