-
Notifications
You must be signed in to change notification settings - Fork 0
/
Crypto.h
73 lines (60 loc) · 1.64 KB
/
Crypto.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _CRYPTO_H_
#define _CRYPTO_H_
#include <iostream>
#include <fstream>
#include <stdint.h>
#include <cstring>
#include <cstdlib>
#include <stdlib.h>
#define XTEA_BLOCK_SIZE 8
#define XTEA_ROUNDS 32
/*
* image string holds the executable
* size holds the size of the executable
*/
typedef struct {
char* image;
//std::streampos size;
unsigned int size;
} DATA;
/*
TODO: Use variadic templates to support different amounts of arguments
and in consequence allow more flexibility for the crypto algorithms ???
struct Crypto : private CryptPolicy {
This constructor takes a variable number of arguments and forwards them to the
base class.
template<typename... Ts> Crypto(Ts&&... ts) : CryptPolicy(std::forward<Ts>(ts)...) {}
};
*/
template <typename CryptPolicy>
class Crypto : private CryptPolicy
{
public:
void doCrypt(DATA *data, uint32_t key[4], int keylen) const;
void doDecrypt(DATA *data, uint32_t key[4], int keylen) const;
};
template <typename CryptPolicy>
void Crypto<CryptPolicy>::doCrypt(DATA *data, uint32_t key[4], int keylen) const
{
// Apply the given policy
CryptPolicy::encrypt(data, key, keylen);
}
template <typename CryptPolicy>
void Crypto<CryptPolicy>::doDecrypt(DATA *data, uint32_t key[4], int keylen) const
{
// Apply the given policy
CryptPolicy::decrypt(data, key, keylen);
}
class CryptPolicyXOR
{
protected:
void encrypt(DATA *data, uint32_t key[4], int keylen) const;
void decrypt(DATA *data, uint32_t key[4], int keylen) const;
};
class CryptPolicyXTEA
{
protected:
void encrypt(DATA *data, uint32_t key[4], int keylen) const;
void decrypt(DATA *data, uint32_t key[4], int keylen) const;
};
#endif // !_CRYPTO_H_