2018-07-17 14:05:22 +02:00
|
|
|
#include "decrypt.h"
|
2018-07-24 18:10:07 +02:00
|
|
|
#include "utils/decryptUtilities.h"
|
|
|
|
|
|
|
|
struct DECRYPTION_DATA {
|
|
|
|
uint32_t key0;
|
|
|
|
uint32_t key1;
|
|
|
|
uint32_t key2;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DECRYPTION_DATA decryptor;
|
|
|
|
|
|
|
|
void initDecryptor(uint32_t key0, uint32_t key1, uint32_t key2) {
|
|
|
|
decryptor.key0 = key0;
|
|
|
|
decryptor.key1 = key1;
|
|
|
|
decryptor.key2 = key2;
|
|
|
|
}
|
2018-07-17 14:05:22 +02:00
|
|
|
|
|
|
|
/** Decrypts the given input in-place. The input buffer will be modified. */
|
2018-08-07 15:22:07 +02:00
|
|
|
void decrypt(uint8_t* chunk, unsigned long length) {
|
2018-07-24 18:10:07 +02:00
|
|
|
for (unsigned long i = 0; i < length; i += 1) {
|
2018-10-07 20:05:08 +02:00
|
|
|
uint8_t curChar = chunk[i];
|
2018-10-07 19:55:40 +02:00
|
|
|
curChar = curChar ^ decryptByte((uint16_t)((uint16_t)(decryptor.key2 & (uint16_t)0xFFFF) | (uint16_t)2));
|
|
|
|
updateKeys(&(decryptor.key0), &(decryptor.key1), &(decryptor.key2), curChar);
|
2018-10-07 20:05:08 +02:00
|
|
|
chunk[i] = curChar;
|
2018-07-24 18:10:07 +02:00
|
|
|
}
|
2018-07-17 14:05:22 +02:00
|
|
|
}
|