summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-11-13 12:47:58 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-11-13 12:47:58 +0000
commit268d637031d98cd88ef29dbac4a7c862f678cfc0 (patch)
treec6eceaf3a603af8158c3bed4541c4d1144569ef7
parent0c2319086294bc02e08db82c507a3f6fc50af9fb (diff)
initial version of stdcrypt, without encryption
git-svn-id: http://svn.miranda-ng.org/main/trunk@6888 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--include/m_crypto.h32
-rw-r--r--src/core/stdcrypt/commonheaders.h3
-rw-r--r--src/core/stdcrypt/encrypt.cpp83
-rw-r--r--src/core/stdcrypt/stdcrypt.h50
-rw-r--r--src/core/stdcrypt/stdcrypt_10.vcxproj1
-rw-r--r--src/core/stdcrypt/stdcrypt_10.vcxproj.filters3
-rw-r--r--src/core/stdcrypt/stdcrypt_11.vcxproj1
-rw-r--r--src/core/stdcrypt/stdcrypt_11.vcxproj.filters3
-rw-r--r--src/core/stdcrypt/stdcrypt_12.vcxproj1
-rw-r--r--src/core/stdcrypt/stdcrypt_12.vcxproj.filters3
10 files changed, 166 insertions, 14 deletions
diff --git a/include/m_crypto.h b/include/m_crypto.h
index a6679d9e6e..9cd971b5bd 100644
--- a/include/m_crypto.h
+++ b/include/m_crypto.h
@@ -26,34 +26,38 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_core.h>
-typedef struct tagCRYPTOENGINE
+struct MICryptoEngine
{
DWORD dwVersion;
+ STDMETHOD_(void, destroy)(void) PURE;
+
// get/set the instance key
- void (__cdecl *pfnGetKey)(const BYTE *pKey, size_t cbKeyLen);
- BOOL (__cdecl *pfnSetKey)(const BYTE **pKey, size_t *cbKeyLen);
+ STDMETHOD_(size_t, getKeyLength)(void) PURE;
+ STDMETHOD_(bool, getKey)(BYTE *pKey, size_t cbKeyLen) PURE;
+ STDMETHOD_(int, setKey)(const BYTE *pKey, size_t cbKeyLen) PURE;
- void(__cdecl *pfnGenerateKey)(void); // creates a new key inside
- void(__cdecl *pfnPurgeKey)(void); // purges a key from memory
+ STDMETHOD_(void, generateKey)(void)PURE; // creates a new key inside
+ STDMETHOD_(void, purgeKey)(void)PURE; // purges a key from memory
// sets the master password (in utf-8)
- void(__cdecl *pfnSetPassword)(const char *pszPassword);
+ STDMETHOD_(void, setPassword)(const char *pszPassword) PURE;
- BYTE* (__cdecl *pfnEncodeString)( const char *src, size_t *cbResultLen);
- BYTE* (__cdecl *pfnEncodeStringW)(const WCHAR* src, size_t *cbResultLen);
+ // result must be freed using mir_free or assigned to mir_ptr<BYTE>
+ STDMETHOD_(BYTE*, encodeString)(const char *src, size_t *cbResultLen) PURE;
+ STDMETHOD_(BYTE*, encodeStringW)(const WCHAR* src, size_t *cbResultLen) PURE;
- char* (__cdecl *pfnDecodeString)(const BYTE *pBuf, size_t bufLen, size_t *cbResultLen);
- WCHAR* (__cdecl *pfnDecodeStringW)(const BYTE *pBuf, size_t bufLen, size_t *cbResultLen);
-}
-CRYPTO_ENGINE;
+ // result must be freed using mir_free or assigned to ptrA/ptrT
+ STDMETHOD_(char*, decodeString)(const BYTE *pBuf, size_t bufLen, size_t *cbResultLen) PURE;
+ STDMETHOD_(WCHAR*, decodeStringW)(const BYTE *pBuf, size_t bufLen, size_t *cbResultLen) PURE;
+};
//registers a crypto provider v0.94+
//wParam = (int)hLangpack
//lParam = (CRYPTO_PROVIDER*)
//returns HANDLE on success or NULL on failure
-typedef CRYPTO_ENGINE* (__cdecl *pfnCryptoProviderFactory)(void);
+typedef MICryptoEngine* (__cdecl *pfnCryptoProviderFactory)(void);
#define CPF_UNICODE 1
@@ -77,7 +81,7 @@ typedef struct tagCRYPTOPROVIDER
pfnCryptoProviderFactory pFactory;
}
-CRYPTO_PROVIDER;
+ CRYPTO_PROVIDER;
#define MS_CRYPTO_REGISTER_ENGINE "SRCrypto/RegisterEngine"
diff --git a/src/core/stdcrypt/commonheaders.h b/src/core/stdcrypt/commonheaders.h
index a16eb54b8e..f89df739dd 100644
--- a/src/core/stdcrypt/commonheaders.h
+++ b/src/core/stdcrypt/commonheaders.h
@@ -65,6 +65,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <m_icolib.h>
#include <m_modernopt.h>
#include <m_timezones.h>
+#include <m_string.h>
#include <m_crypto.h>
#include "version.h"
@@ -72,4 +73,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../../resource.h"
#include "../stdplug.h"
+#include "stdcrypt.h"
+
extern HINSTANCE hInst;
diff --git a/src/core/stdcrypt/encrypt.cpp b/src/core/stdcrypt/encrypt.cpp
index fc72e74abc..40e33c9266 100644
--- a/src/core/stdcrypt/encrypt.cpp
+++ b/src/core/stdcrypt/encrypt.cpp
@@ -23,11 +23,94 @@ 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;
}
diff --git a/src/core/stdcrypt/stdcrypt.h b/src/core/stdcrypt/stdcrypt.h
new file mode 100644
index 0000000000..4d5b0710ca
--- /dev/null
+++ b/src/core/stdcrypt/stdcrypt.h
@@ -0,0 +1,50 @@
+/*
+
+Standard encryption plugin for Myranda NG
+Copyright (C) 2012-13 George Hazan
+
+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.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#define KEYLENGTH (256/8)
+
+struct CStdCrypt : public MICryptoEngine, public MZeroedObject
+{
+ CStdCrypt();
+
+ BYTE m_key[KEYLENGTH];
+ CMStringA m_password;
+
+ STDMETHODIMP_(void) destroy();
+
+ // get/set the instance key
+ STDMETHODIMP_(size_t) getKeyLength(void);
+ STDMETHODIMP_(bool) getKey(BYTE *pKey, size_t cbKeyLen);
+ STDMETHODIMP_(int) setKey(const BYTE *pKey, size_t cbKeyLen);
+
+ STDMETHODIMP_(void) generateKey(void); // creates a new key inside
+ STDMETHODIMP_(void) purgeKey(void); // purges a key from memory
+
+ // sets the master password (in utf-8)
+ STDMETHODIMP_(void) setPassword(const char *pszPassword);
+
+ // result must be freed using mir_free or assigned to mir_ptr<BYTE>
+ STDMETHODIMP_(BYTE*) encodeString(const char *src, size_t *cbResultLen);
+ STDMETHODIMP_(BYTE*) encodeStringW(const WCHAR* src, size_t *cbResultLen);
+
+ // result must be freed using mir_free or assigned to ptrA/ptrT
+ STDMETHODIMP_(char*) decodeString(const BYTE *pBuf, size_t bufLen, size_t *cbResultLen);
+ STDMETHODIMP_(WCHAR*) decodeStringW(const BYTE *pBuf, size_t bufLen, size_t *cbResultLen);
+};
diff --git a/src/core/stdcrypt/stdcrypt_10.vcxproj b/src/core/stdcrypt/stdcrypt_10.vcxproj
index a8fb8b5b1a..d48b79c832 100644
--- a/src/core/stdcrypt/stdcrypt_10.vcxproj
+++ b/src/core/stdcrypt/stdcrypt_10.vcxproj
@@ -212,6 +212,7 @@
<ClInclude Include="..\..\..\include\m_crypto.h" />
<ClInclude Include="..\stdplug.h" />
<ClInclude Include="commonheaders.h" />
+ <ClInclude Include="stdcrypt.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
diff --git a/src/core/stdcrypt/stdcrypt_10.vcxproj.filters b/src/core/stdcrypt/stdcrypt_10.vcxproj.filters
index f4466c28bd..3130117a02 100644
--- a/src/core/stdcrypt/stdcrypt_10.vcxproj.filters
+++ b/src/core/stdcrypt/stdcrypt_10.vcxproj.filters
@@ -35,6 +35,9 @@
<ClInclude Include="..\..\..\include\m_crypto.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="stdcrypt.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="version.rc">
diff --git a/src/core/stdcrypt/stdcrypt_11.vcxproj b/src/core/stdcrypt/stdcrypt_11.vcxproj
index 890a10e365..16d8244f14 100644
--- a/src/core/stdcrypt/stdcrypt_11.vcxproj
+++ b/src/core/stdcrypt/stdcrypt_11.vcxproj
@@ -215,6 +215,7 @@
<ClInclude Include="..\..\..\include\m_crypto.h" />
<ClInclude Include="..\stdplug.h" />
<ClInclude Include="commonheaders.h" />
+ <ClInclude Include="stdcrypt.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
diff --git a/src/core/stdcrypt/stdcrypt_11.vcxproj.filters b/src/core/stdcrypt/stdcrypt_11.vcxproj.filters
index f4466c28bd..3130117a02 100644
--- a/src/core/stdcrypt/stdcrypt_11.vcxproj.filters
+++ b/src/core/stdcrypt/stdcrypt_11.vcxproj.filters
@@ -35,6 +35,9 @@
<ClInclude Include="..\..\..\include\m_crypto.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="stdcrypt.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="version.rc">
diff --git a/src/core/stdcrypt/stdcrypt_12.vcxproj b/src/core/stdcrypt/stdcrypt_12.vcxproj
index 2d7f5c5881..efedd20ed0 100644
--- a/src/core/stdcrypt/stdcrypt_12.vcxproj
+++ b/src/core/stdcrypt/stdcrypt_12.vcxproj
@@ -215,6 +215,7 @@
<ClInclude Include="..\..\..\include\m_crypto.h" />
<ClInclude Include="..\stdplug.h" />
<ClInclude Include="commonheaders.h" />
+ <ClInclude Include="stdcrypt.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
diff --git a/src/core/stdcrypt/stdcrypt_12.vcxproj.filters b/src/core/stdcrypt/stdcrypt_12.vcxproj.filters
index f4466c28bd..3130117a02 100644
--- a/src/core/stdcrypt/stdcrypt_12.vcxproj.filters
+++ b/src/core/stdcrypt/stdcrypt_12.vcxproj.filters
@@ -35,6 +35,9 @@
<ClInclude Include="..\..\..\include\m_crypto.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="stdcrypt.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="version.rc">