aboutsummaryrefslogtreecommitdiff
path: root/src/crypto.hh
blob: 7159a37ebf824ac80a6f67bb334ab9412a8a3e58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef TIBIA_CRYPTO_HH_
#define TIBIA_CRYPTO_HH_ 1

#include "common.hh"

// TODO(fusion): We might want to scrap this implementation and use OpenSSL instead.

struct vlong_flex_unit{
	uint32 n;
	uint32 *a;
	uint32 z;
};

struct vlong_value: vlong_flex_unit {
	uint32 share;
};

struct vlong{
	vlong_value *value;
	int negative;
};

struct vlong_montgomery{
	vlong R;
	vlong R1;
	vlong m;
	vlong n1;
	vlong T;
	vlong k;
	uint32 N;
};

struct TRSAPrivateKey{
	TRSAPrivateKey(void);
	~TRSAPrivateKey(void);
	void init(const char *PrimeP, const char *PrimeQ);
	void decrypt(uint8 *Data); // single 128 bytes block

	// DATA
	// =================
	vlong m_PrimeP;
	vlong m_PrimeQ;
	vlong m_U;
	vlong m_DP;
	vlong m_DQ;
};

struct TXTEASymmetricKey{
	TXTEASymmetricKey(void);
	~TXTEASymmetricKey(void);
	void init(TReadBuffer *Buffer);
	void encrypt(uint8 *Data); // single 8 bytes block
	void decrypt(uint8 *Data); // single 8 bytes block

	// DATA
	// =================
	uint32 m_SymmetricKey[4];
};

#endif //TIBIA_CRYPTO_HH_