diff options
Diffstat (limited to 'src/core/stdcrypt/encrypt.cpp')
-rw-r--r-- | src/core/stdcrypt/encrypt.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
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;
}
|