Commit 8f24ef7a authored by Adrien Dorsaz's avatar Adrien Dorsaz

Applies emokit technique to retrive encryption key and decrypt datas.

parent 48c6c838
......@@ -24,6 +24,11 @@
#include <utils/Rijndael.h>
#include <QDebug>
#define EMOKIT_MAX_STR 255
#define EMOKIT_KEYSIZE 16 // 16 bytes == 128 bits
#define EMOKIT_CONSUMER 0
#define EMOKIT_RESEARCH 1
class Sbs2EmotivDecryptor : public QObject
{
Q_OBJECT
......@@ -35,11 +40,13 @@ public:
private:
char* serialNumber;
char* key;
CRijndael* oRijndael;
void initialize();
char buffer[16];
char buffer2[16];
int currentPacket;
void emokit_get_crypto_key(int dev_type);
signals:
......
#include "sbs2emotivdecryptor.h"
#include <stdint.h>
Sbs2EmotivDecryptor::Sbs2EmotivDecryptor(QObject *parent) :
QObject(parent)
{
oRijndael = 0;
oRijndael = new CRijndael();
serialNumber = new char[16];
currentPacket = 0;
key = new char[EMOKIT_KEYSIZE];
}
void Sbs2EmotivDecryptor::setSerialNumber(char *serialNumber_)
......@@ -28,47 +29,72 @@ void Sbs2EmotivDecryptor::setSerialNumber(QString serialNumber_)
initialize();
}
void Sbs2EmotivDecryptor::initialize() {}
void Sbs2EmotivDecryptor::decrypt(char cipher[32], char plain[32])
{
void Sbs2EmotivDecryptor::initialize() {
//emokit_get_crypto_key(dev_type);
qDebug() << "SN is : ";
for(int i=0;i<16;i++){
qDebug() << serialNumber[i];
}
emokit_get_crypto_key(EMOKIT_RESEARCH); // need to be checked directly with original emokit application
qDebug() << "Key is : ";
for(int i=0;i<16;i++){
qDebug() << key[i];
}
//libmcrypt initialization
/*s->td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, NULL, MCRYPT_ECB, NULL);
s->blocksize = mcrypt_enc_get_block_size(s->td); //should return a 16bits blocksize
plain[0] = currentPacket;
plain[1] = qrand()%RAND_MAX*10;
plain[2] = qrand()%RAND_MAX*10;
plain[3] = qrand()%RAND_MAX*10;
plain[4] = qrand()%RAND_MAX*10;
plain[5] = qrand()%RAND_MAX*10;
plain[6] = qrand()%RAND_MAX*10;
plain[7] = qrand()%RAND_MAX*10;
plain[8] = qrand()%RAND_MAX*10;
plain[9] = qrand()%RAND_MAX*10;
plain[10] = qrand()%RAND_MAX*10;
plain[11] = qrand()%RAND_MAX*10;
plain[12] = qrand()%RAND_MAX*10;
plain[13] = qrand()%RAND_MAX*10;
plain[14] = qrand()%RAND_MAX*10;
plain[15] = qrand()%RAND_MAX*10;
plain[16] = qrand()%RAND_MAX*10;
plain[17] = qrand()%RAND_MAX*10;
plain[18] = qrand()%RAND_MAX*10;
plain[19] = qrand()%RAND_MAX*10;
plain[20] = qrand()%RAND_MAX*10;
plain[21] = qrand()%RAND_MAX*10;
plain[22] = qrand()%RAND_MAX*10;
plain[23] = qrand()%RAND_MAX*10;
plain[24] = qrand()%RAND_MAX*10;
plain[25] = qrand()%RAND_MAX*10;
plain[26] = qrand()%RAND_MAX*10;
plain[27] = qrand()%RAND_MAX*10;
plain[28] = qrand()%RAND_MAX*10;
plain[29] = qrand()%RAND_MAX*10;
plain[30] = qrand()%RAND_MAX*10;
plain[31] = qrand()%RAND_MAX*10;
s->block_buffer = (unsigned char *)malloc(s->blocksize);
mcrypt_generic_init(s->td, s->key, EMOKIT_KEYSIZE, NULL);*/
oRijndael->MakeKey(reinterpret_cast<const char *>(key), CRijndael::sm_chain0, 16, 16);
}
void Sbs2EmotivDecryptor::decrypt(char cipher[32], char plain[32])
{
/*
As found in emokit, the key to decrypt datas is made from the serial number.
And then we'll use the Rijndael tool to decrypt datas using this key.
*/
oRijndael->Decrypt(cipher, plain, 32, CRijndael::ECB);
currentPacket = (currentPacket+1)%129;
}
void Sbs2EmotivDecryptor::emokit_get_crypto_key(int dev_type) {
unsigned char type = (unsigned char) dev_type;
unsigned int l = 16;
type &= 0xF;
type = (type == 0);
key[0] = (uint8_t)serialNumber[l-1];
key[1] = '\0';
key[2] = (uint8_t)serialNumber[l-2];
if(type) {
key[3] = 'H';
key[4] = (uint8_t)serialNumber[l-1];
key[5] = '\0';
key[6] = (uint8_t)serialNumber[l-2];
key[7] = 'T';
key[8] = (uint8_t)serialNumber[l-3];
key[9] = '\x10';
key[10] = (uint8_t)serialNumber[l-4];
key[11] = 'B';
}
else {
key[3] = 'T';
key[4] = (uint8_t)serialNumber[l-3];
key[5] = '\x10';
key[6] = (uint8_t)serialNumber[l-4];
key[7] = 'B';
key[8] = (uint8_t)serialNumber[l-1];
key[9] = '\0';
key[10] = (uint8_t)serialNumber[l-2];
key[11] = 'H';
}
key[12] = (uint8_t)serialNumber[l-3];
key[13] = '\0';
key[14] = (uint8_t)serialNumber[l-4];
key[15] = 'P';
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment