Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
spdfrk authored and perexg committed Aug 6, 2014
1 parent 16f99d4 commit 88672fd
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/descrambler/libaesdec/libaesdec.c
Expand Up @@ -2,7 +2,7 @@
* libaesdec.c
*
* Created on: Jun 22, 2014
* Author: root
* Author: spdfrk1
*/

#include <sys/types.h>
Expand All @@ -14,16 +14,18 @@

#include "libaesdec.h"

//-----allocate key structure
struct aes_keys_t {
AES_KEY even;
AES_KEY odd;
};

// Even and Odd cw represent one full 128-bit AES key
//-----even cw represents one full 128-bit AES key
void aes_set_even_control_word(void *keys, const unsigned char *pk) {
AES_set_decrypt_key(pk, 128, &((struct aes_keys_t *) keys)->even);
}

//-----odd cw represents one full 128-bit AES key
void aes_set_odd_control_word(void *keys, const unsigned char *pk) {
AES_set_decrypt_key(pk, 128, &((struct aes_keys_t *) keys)->odd);
}
Expand All @@ -35,8 +37,8 @@ void aes_set_control_words(void *keys, const unsigned char *ev,
AES_set_decrypt_key(od, 128, &((struct aes_keys_t *) keys)->odd);
}

//-----key structure
void *aes_get_key_struct(void) {
//-----allocate key structure
void * aes_get_key_struct(void) {
struct aes_keys_t *keys = (struct aes_keys_t *) malloc(
sizeof(struct aes_keys_t));
if (keys) {
Expand All @@ -46,9 +48,10 @@ void *aes_get_key_struct(void) {
return keys;
}

//-----free key structure
void aes_free_key_struct(void *keys) {
free(keybuffer);
return free(keys);
if (keys)
free(keys);
}

//----- decrypt
Expand All @@ -57,35 +60,32 @@ void aes_decrypt_packet(void *keys, unsigned char *packet) {
unsigned char ev_od = 0;
int xc0, offset, n;
int len;
//int residue;
pkt = packet;
AES_KEY k;

// TODO check all flags
xc0 = pkt[3] & 0xc0;
if (xc0 == 0x00) {//skip clear pkt
//skip clear pkt
if (xc0 == 0x00) {
return;
}
if (xc0 == 0x40) { //skip reserved pkt
//skip reserved pkt
if (xc0 == 0x40) {
return;
}
if (xc0 == 0x80 || xc0 == 0xc0) { // encrypted
ev_od = (xc0 & 0x40) >> 6; // 0 even, 1 odd
pkt[3] &= 0x3f; // consider it decrypted now
if (pkt[3] & 0x20) { // incomplete packet TODO Check this
if (pkt[3] & 0x20) { // incomplete packet
offset = 4 + pkt[4] + 1;
len = 188 - offset;
n = len >> 3;
//residue = len - (n << 3);
if (n == 0) { // decrypted==encrypted!
//DBG(fprintf(stderr,"DECRYPTED MINI!\n"));
return; // this doesn't need more processing
}
}
else {
len = 184;
offset = 4;
//residue = 0;
}
}
else {
Expand All @@ -103,5 +103,4 @@ void aes_decrypt_packet(void *keys, unsigned char *packet) {
for (i = offset; i <= (len - 16); i += 16) {
AES_ecb_encrypt(pkt + i, pkt + i, &k, AES_DECRYPT);
}
return;
}

0 comments on commit 88672fd

Please sign in to comment.