summaryrefslogtreecommitdiff
path: root/src/core/stdcrypt/encrypt.cpp
blob: 40e33c9266c3214f3a2272fd0a6fd37379d7263a (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
/*

Miranda NG: the free IM client for Microsoft* Windows*

Copyright (C) 2012-13 Miranda NG project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.

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.
*/

#include "commonheaders.h"

CStdCrypt::CStdCrypt() :
	m_password("Miranda")
{}

void CStdCrypt::destroy()
{
	delete this;
}

size_t CStdCrypt::getKeyLength()
{
	return KEYLENGTH;
}

bool CStdCrypt::getKey(BYTE *pKey, size_t cbKeyLen)
{
	if (cbKeyLen < KEYLENGTH)
		return false;

	memcpy(pKey, m_key, sizeof(m_key));
	if (cbKeyLen > KEYLENGTH)
		memset(pKey + KEYLENGTH, 0, cbKeyLen - KEYLENGTH);
	return true;
}

int CStdCrypt::setKey(const BYTE *pKey, size_t cbKeyLen)
{
	if (cbKeyLen > KEYLENGTH)
		return false;

	memcpy(m_key, pKey, cbKeyLen);
	if (cbKeyLen < KEYLENGTH)
		memset(m_key + cbKeyLen, 0, KEYLENGTH - cbKeyLen);
	return 0;
}

void CStdCrypt::generateKey(void)
{
	LARGE_INTEGER counter;
	QueryPerformanceCounter(&counter);
	srand((UINT)counter.QuadPart);
	for (int i = 0; i < sizeof(m_key); i++)
		m_key[i] = (BYTE)rand();
}

void CStdCrypt::purgeKey(void)
{
	memset(m_key, 0, sizeof(m_key));
}

// sets the master password (in utf-8)
void CStdCrypt::setPassword(const char *pszPassword)
{
	m_password = pszPassword;
}

// result must be freed using mir_free or assigned to mir_ptr<BYTE>
BYTE* CStdCrypt::encodeString(const char *src, size_t *cbResultLen)
{
	return 0;
}

BYTE* CStdCrypt::encodeStringW(const WCHAR* src, size_t *cbResultLen)
{
	return 0;
}

char* CStdCrypt::decodeString(const BYTE *pBuf, size_t bufLen, size_t *cbResultLen)
{
	return 0;
}

WCHAR* CStdCrypt::decodeStringW(const BYTE *pBuf, size_t bufLen, size_t *cbResultLen)
{
	return 0;
}

static MICryptoEngine* __cdecl builder()
{
	return new CStdCrypt();
}

int LoadEncryptionModule(void)
{
	CRYPTO_PROVIDER cp = { sizeof(cp) };
	cp.pszName = "AES (Rjindale)";
	cp.pszDescr = LPGEN("Standard crypto provider");
	cp.pFactory = builder;
	Crypto_RegisterEngine(&cp);
	return 0;
}