encrypt: Simplify initialization code

This avoids destructors being even needed.
This commit is contained in:
Emmanuel Gil Peyrot 2020-11-18 22:38:36 +01:00
parent 7de7d6c1c5
commit 87cb2f648f
2 changed files with 9 additions and 29 deletions

View File

@ -55,7 +55,7 @@
#endif
//TODO - do we need these here?
_KEY2 key2;
static _KEY2 key2;
//http://home.utah.edu/~nahaj/factoring/isqrt.c.html
static u64 isqrt (u64 x) {

View File

@ -20,28 +20,12 @@
#include "types.h"
#include <string.h>
struct _KEY1
struct _KEY1 final
{
_KEY1(const u8 *inKeyBufPtr)
{
if (keyBuf) delete[] keyBuf;
keyBuf = new u32 [0x412];
memset(keyBuf, 0x00, 0x412 * sizeof(u32));
memset(&keyCode[0], 0, sizeof(keyCode));
this->keyBufPtr = inKeyBufPtr;
}
_KEY1(const u8 *inKeyBufPtr) : keyBufPtr(inKeyBufPtr) {}
~_KEY1()
{
if (keyBuf)
{
delete[] keyBuf;
keyBuf = NULL;
}
}
u32 *keyBuf;
u32 keyCode[3];
u32 keyBuf[0x412] = {};
u32 keyCode[3] = {};
const u8 *keyBufPtr;
void init(u32 idcode, u8 level, u8 modulo);
@ -50,23 +34,19 @@ struct _KEY1
void encrypt(u32 *ptr);
};
struct _KEY2
struct _KEY2 final
{
private:
u64 seed0;
u64 seed1;
u64 seed0 = 0x58C56DE0E8ULL;
u64 seed1 = 0x5C879B9B05ULL;
u64 x;
u64 y;
u64 bitsReverse39(u64 key);
public:
_KEY2() : seed0(0x58C56DE0E8ULL),
seed1(0x5C879B9B05ULL)
{}
void applySeed(u8 PROCNUM);
u8 apply(u8 data);
};
#endif
#endif