summaryrefslogtreecommitdiff
path: root/plugins/Dbx_tree/encryption/Cipher.h
blob: 76d07e61a0633b7febbf6ad17bbfc8a3d596be4c (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*

dbx_tree: tree database driver for Miranda IM

Copyright 2007-2010 Michael "Protogenes" Kunz,

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#pragma once

#ifdef _MSC_VER
#include "../stdint.h"
#else
#include <stdint.h>
#endif

#include <wchar.h>

#pragma pack(push, 1)

#ifdef __INTERFACE_ONLY__
#define __INTERFACE_VIRTUAL__
#else
#define __INTERFACE_VIRTUAL__ virtual
#endif

class CCipher
{
public:
	typedef struct TCipherInterface
	{
		CCipher * self;
		uint32_t Size;
		void           (__cdecl CCipher::*Destroy)();

		const wchar_t* (__cdecl CCipher::*Name)();
		const wchar_t* (__cdecl CCipher::*Description)();
		const uint32_t (__cdecl CCipher::*BlockSizeBytes)();
		const bool     (__cdecl CCipher::*IsStreamCipher)();

		void           (__cdecl CCipher::*SetKey)(void* Key, uint32_t KeyLength);
		void           (__cdecl CCipher::*Encrypt)(void* Data, uint32_t Size, uint32_t Nonce, uint32_t StartByte);
		void           (__cdecl CCipher::*Decrypt)(void* Data, uint32_t Size, uint32_t Nonce, uint32_t StartByte);

	} TCipherInterface;
	TCipherInterface * m_Interface;

#ifndef __INTERFACE_ONLY__
	virtual void __cdecl Destroy()
	{
		delete this;
	}

	CCipher() 
	{
		m_Interface = new TCipherInterface;
		m_Interface->Size = sizeof(TCipherInterface);
		m_Interface->self = this;
		m_Interface->Destroy        = &CCipher::Destroy;
		m_Interface->Name           = &CCipher::Name;
		m_Interface->Description    = &CCipher::Description;
		m_Interface->BlockSizeBytes = &CCipher::BlockSizeBytes;
		m_Interface->IsStreamCipher = &CCipher::IsStreamCipher;
		m_Interface->SetKey         = &CCipher::SetKey;
		m_Interface->Encrypt        = &CCipher::Encrypt;
		m_Interface->Decrypt        = &CCipher::Decrypt;
	};
#endif

#ifdef __INTERFACE_ONLY__
	CCipher(TCipherInterface * Interface)
	{
		m_Interface = Interface;
	};
#endif

	__INTERFACE_VIRTUAL__ ~CCipher()
#ifdef __INTERFACE_ONLY__
	{
		(m_Interface->self->*(m_Interface->Destroy))();
	}	
#else
	{	}	
#endif
	;

	__INTERFACE_VIRTUAL__ const wchar_t* __cdecl Name()
#ifdef __INTERFACE_ONLY__
	{
		return (m_Interface->self->*(m_Interface->Name))();
	}
#else
	= 0
#endif
		;

	__INTERFACE_VIRTUAL__ const wchar_t* __cdecl Description()
#ifdef __INTERFACE_ONLY__
	{
		return (m_Interface->self->*(m_Interface->Description))();
	}
#else
	= 0
#endif
		;

	__INTERFACE_VIRTUAL__ const uint32_t __cdecl BlockSizeBytes()
#ifdef __INTERFACE_ONLY__
	{
		return (m_Interface->self->*(m_Interface->BlockSizeBytes))();
	}
#else
		= 0
#endif
		;

	__INTERFACE_VIRTUAL__ const bool __cdecl IsStreamCipher()
#ifdef __INTERFACE_ONLY__
	{
		return (m_Interface->self->*(m_Interface->IsStreamCipher))();
	}
#else
		= 0
#endif
		;

	__INTERFACE_VIRTUAL__ void __cdecl SetKey(void* Key, uint32_t KeyLength)
#ifdef __INTERFACE_ONLY__
	{
		return (m_Interface->self->*(m_Interface->SetKey))(Key, KeyLength);
	}
#else
		= 0
#endif
		;
	__INTERFACE_VIRTUAL__ void __cdecl Encrypt(void* Data, uint32_t Size, uint32_t Nonce, uint32_t StartByte)
#ifdef __INTERFACE_ONLY__
	{
		return (m_Interface->self->*(m_Interface->Encrypt))(Data, Size, Nonce, StartByte);
	}
#else
		= 0
#endif
		;
	__INTERFACE_VIRTUAL__ void __cdecl Decrypt(void* Data, uint32_t Size, uint32_t Nonce, uint32_t StartByte)
#ifdef __INTERFACE_ONLY__
	{
		return (m_Interface->self->*(m_Interface->Decrypt))(Data, Size, Nonce, StartByte);
	}
#else
		= 0
#endif
		;

};

typedef struct TCipherInfo
{
	uint32_t cbSize;
	const uint32_t ID;
	const wchar_t* Name;
	const wchar_t* Description;
	CCipher::TCipherInterface * (__cdecl *Create)();
} TCipherInfo;

#pragma pack(pop)