XPlor/libs/encryption/encryption.h

54 lines
2.0 KiB
C
Raw Permalink Normal View History

2025-04-04 20:34:24 -04:00
#ifndef ENCRYPTION_H
#define ENCRYPTION_H
2025-02-08 19:58:54 -05:00
#include <QDataStream>
2025-03-01 20:38:52 -05:00
#include <QFile>
2025-04-04 20:34:24 -04:00
#include <QDebug>
#include <QCryptographicHash>
2025-02-08 19:58:54 -05:00
2025-04-04 20:34:24 -04:00
class Encryption {
public:
2025-02-08 19:58:54 -05:00
static const int VECTOR_SIZE = 16; // 16 32-bit words
static const int NUM_OF_BLOCKS_PER_CHUNK = 8192;
//--------------------------------------------------------------------
// Helper functions (assuming littleendian order)
2025-04-04 20:39:36 -04:00
static void Convert32BitTo8Bit(quint32 value, quint8* array);
2025-02-08 19:58:54 -05:00
2025-04-04 20:39:36 -04:00
static quint32 ConvertArrayTo32Bit(const QByteArray &array);
2025-02-08 19:58:54 -05:00
2025-04-04 20:39:36 -04:00
static quint32 Rotate(quint32 value, quint32 numBits);
2025-02-08 19:58:54 -05:00
// Build the IV table from a 0x20byte feed. The table is 0xFB0 bytes.
2025-04-04 20:39:36 -04:00
static QByteArray InitIVTable(const QByteArray &feed);
2025-02-08 19:58:54 -05:00
// "unk" function as in the C# code.
2025-04-04 20:39:36 -04:00
static int unk(quint64 arg1, quint8 arg2);
2025-02-08 19:58:54 -05:00
// Compute the IV for a given section index using the IV table.
2025-04-04 20:39:36 -04:00
static QByteArray GetIV(const QByteArray &table, int index);
2025-02-08 19:58:54 -05:00
// Update the IV table given the section's SHA1 hash.
2025-04-04 20:39:36 -04:00
static void UpdateIVTable(QByteArray &table, int index, const QByteArray &sectionHash);
2025-02-08 19:58:54 -05:00
2025-04-04 20:39:36 -04:00
static quint32 ToUInt32(const QByteArray &data, int offset);
2025-02-08 19:58:54 -05:00
//--------------------------------------------------------------------
// Salsa20 decryption for one section.
// This function resets the counter for each section.
2025-04-04 20:39:36 -04:00
static QByteArray salsa20DecryptSection(const QByteArray &sectionData, const QByteArray &key, const QByteArray &iv, int blockSize = 64);
2025-03-01 20:38:52 -05:00
2025-04-04 20:39:36 -04:00
static void fillIVTable(QByteArray fastFileData, QByteArray& ivTable, quint32 ivTableLength);
2025-03-01 20:38:52 -05:00
2025-04-04 20:39:36 -04:00
static void fillIV(int index, QByteArray& ivPtr, const QByteArray& ivTable, const QVector<quint32>& ivCounter);
2025-03-01 20:38:52 -05:00
2025-04-04 20:39:36 -04:00
static void generateNewIV(int index, const QByteArray& hash, QByteArray& ivTable, QVector<quint32>& ivCounter);
2025-03-01 20:38:52 -05:00
static QByteArray decryptFastFile_BO2(const QByteArray& fastFileData);
static QByteArray decryptFastFile_BO3(const QByteArray& fastFileData);
2025-02-08 19:58:54 -05:00
};
2025-04-04 20:34:24 -04:00
#endif // ENCRYPTION_H