diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-02 15:51:46 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-02 15:51:46 +0000 |
commit | eca1b167120907f6d927de29f449c93bdf381a83 (patch) | |
tree | 0699691346ba01d3963cf5c3ef49138713f37205 /plugins/CryptoPP/cpp_svcs.cpp | |
parent | 1ed8a4ff1ec95b0df08a5bf48bb372c8481e381b (diff) |
- removed __asm piece
git-svn-id: http://svn.miranda-ng.org/main/trunk@717 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CryptoPP/cpp_svcs.cpp')
-rw-r--r-- | plugins/CryptoPP/cpp_svcs.cpp | 107 |
1 files changed, 46 insertions, 61 deletions
diff --git a/plugins/CryptoPP/cpp_svcs.cpp b/plugins/CryptoPP/cpp_svcs.cpp index e03800648d..7e97735540 100644 --- a/plugins/CryptoPP/cpp_svcs.cpp +++ b/plugins/CryptoPP/cpp_svcs.cpp @@ -4,9 +4,9 @@ const unsigned char IV[] = "SIMhell@MIRANDA!"; // encrypt string using KeyX, return encoded string as ASCII or NULL
-LPSTR __cdecl cpp_encrypt(pCNTX ptr, LPCSTR szPlainMsg) {
-
- ptr->error = ERROR_NONE;
+LPSTR __cdecl cpp_encrypt(pCNTX ptr, LPCSTR szPlainMsg)
+{
+ ptr->error = ERROR_NONE;
pSIMDATA p = (pSIMDATA) ptr->pdata;
BYTE dataflag = 0;
@@ -14,19 +14,18 @@ LPSTR __cdecl cpp_encrypt(pCNTX ptr, LPCSTR szPlainMsg) { slen = strlen(szPlainMsg);
LPSTR szMsg;
- if(ptr->features & FEATURES_GZIP) {
+ if (ptr->features & FEATURES_GZIP) {
szMsg = (LPSTR) cpp_gzip((BYTE*)szPlainMsg,slen,clen);
- if(clen>=slen) {
- free(szMsg);
- szMsg = _strdup(szPlainMsg);
+ if (clen>=slen) {
+ free(szMsg);
+ szMsg = _strdup(szPlainMsg);
}
else {
- slen = clen;
- dataflag |= DATA_GZIP;
+ slen = clen;
+ dataflag |= DATA_GZIP;
}
}
- else
- szMsg = _strdup(szPlainMsg);
+ else szMsg = _strdup(szPlainMsg);
string ciphered;
@@ -39,33 +38,31 @@ LPSTR __cdecl cpp_encrypt(pCNTX ptr, LPCSTR szPlainMsg) { free(szMsg);
clen = (int) ciphered.length();
- if(ptr->features & FEATURES_CRC32) {
+ if (ptr->features & FEATURES_CRC32) {
BYTE crc32[CRC32::DIGESTSIZE];
memset(crc32,0,sizeof(crc32));
CRC32().CalculateDigest(crc32, (BYTE*)ciphered.data(), clen);
ciphered.insert(0,(LPSTR)&crc32,CRC32::DIGESTSIZE);
ciphered.insert(0,(LPSTR)&clen,2);
}
- if(ptr->features & FEATURES_GZIP) {
+ if (ptr->features & FEATURES_GZIP)
ciphered.insert(0,(LPSTR)&dataflag,1);
- }
+
clen = (int) ciphered.length();
SAFE_FREE(ptr->tmp);
- if(ptr->features & FEATURES_BASE64) {
+ if (ptr->features & FEATURES_BASE64)
ptr->tmp = base64encode(ciphered.data(),clen);
- }
- else {
+ else
ptr->tmp = base16encode(ciphered.data(),clen);
- }
return ptr->tmp;
}
// decrypt string using KeyX, return decoded string as ASCII or NULL
-LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) {
-
+LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg)
+{
LPSTR ciphered = NULL;
try {
@@ -74,7 +71,7 @@ LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) { int clen = strlen(szEncMsg);
- if(ptr->features & FEATURES_BASE64)
+ if (ptr->features & FEATURES_BASE64)
ciphered = base64decode(szEncMsg,&clen);
else
ciphered = base16decode(szEncMsg,&clen);
@@ -82,21 +79,15 @@ LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) { LPSTR bciphered = ciphered;
BYTE dataflag=0;
- if(ptr->features & FEATURES_GZIP) {
+ if (ptr->features & FEATURES_GZIP) {
dataflag = *ciphered;
bciphered++; clen--; // cut GZIP flag
}
- if(ptr->features & FEATURES_CRC32) {
- int len;
- __asm {
- mov esi,[bciphered];
- xor eax,eax;
- mov ax,word ptr [esi];
- mov [len], eax;
- }
+ if (ptr->features & FEATURES_CRC32) {
+ int len = *( WORD* )bciphered;
bciphered+=2; clen-=2; // cut CRC32 length
- if(clen-CRC32::DIGESTSIZE<len) { // mesage not full
+ if (clen-CRC32::DIGESTSIZE<len) { // mesage not full
#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("cpp_decrypt: error bad_len");
#endif
@@ -110,7 +101,7 @@ LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) { CRC32().CalculateDigest(crc32, (PBYTE)(bciphered+CRC32::DIGESTSIZE), len);
- if(memcmp(crc32,bciphered,CRC32::DIGESTSIZE)) { // message is bad crc
+ if (memcmp(crc32,bciphered,CRC32::DIGESTSIZE)) { // message is bad crc
#if defined(_DEBUG) || defined(NETLIB_LOG)
Sent_NetLog("cpp_decrypt: error bad_crc");
#endif
@@ -133,13 +124,11 @@ LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) { free(ciphered);
SAFE_FREE(ptr->tmp);
- if(dataflag & DATA_GZIP) {
+ if (dataflag & DATA_GZIP) {
ptr->tmp = (LPSTR) cpp_gunzip((PBYTE)unciphered.data(),unciphered.length(),clen);
ptr->tmp[clen] = 0;
}
- else {
- ptr->tmp = (LPSTR) strdup(unciphered.c_str());
- }
+ else ptr->tmp = (LPSTR) strdup(unciphered.c_str());
ptr->error = ERROR_NONE;
return ptr->tmp;
@@ -156,8 +145,8 @@ LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) { // encode message from ANSI into UTF8 if need
-LPSTR __cdecl cpp_encodeA(HANDLE context, LPCSTR msg) {
-
+LPSTR __cdecl cpp_encodeA(HANDLE context, LPCSTR msg)
+{
pCNTX ptr = get_context_on_id(context);
if (!ptr) return NULL;
cpp_alloc_pdata(ptr); pSIMDATA p = (pSIMDATA) ptr->pdata;
@@ -166,7 +155,7 @@ LPSTR __cdecl cpp_encodeA(HANDLE context, LPCSTR msg) { LPSTR szNewMsg = NULL;
LPSTR szOldMsg = (LPSTR) msg;
- if(ptr->features & FEATURES_UTF8) {
+ if (ptr->features & FEATURES_UTF8) {
// ansi message: convert to unicode->utf-8 and encrypt.
int slen = strlen(szOldMsg)+1;
LPWSTR wstring = (LPWSTR) alloca(slen*sizeof(WCHAR));
@@ -184,8 +173,8 @@ LPSTR __cdecl cpp_encodeA(HANDLE context, LPCSTR msg) { // encode message from UTF8
-LPSTR __cdecl cpp_encodeU(HANDLE context, LPCSTR msg) {
-
+LPSTR __cdecl cpp_encodeU(HANDLE context, LPCSTR msg)
+{
pCNTX ptr = get_context_on_id(context);
if (!ptr) return NULL;
cpp_alloc_pdata(ptr); pSIMDATA p = (pSIMDATA) ptr->pdata;
@@ -194,7 +183,7 @@ LPSTR __cdecl cpp_encodeU(HANDLE context, LPCSTR msg) { LPSTR szNewMsg = NULL;
LPSTR szOldMsg = (LPSTR) msg;
- if(ptr->features & FEATURES_UTF8) {
+ if (ptr->features & FEATURES_UTF8) {
// utf8 message: encrypt.
szNewMsg = cpp_encrypt(ptr, szOldMsg);
}
@@ -210,10 +199,9 @@ LPSTR __cdecl cpp_encodeU(HANDLE context, LPCSTR msg) { return szNewMsg;
}
-
// encode message from UNICODE into UTF8 if need
-LPSTR __cdecl cpp_encodeW(HANDLE context, LPWSTR msg) {
-
+LPSTR __cdecl cpp_encodeW(HANDLE context, LPWSTR msg)
+{
pCNTX ptr = get_context_on_id(context);
if (!ptr) return NULL;
cpp_alloc_pdata(ptr); pSIMDATA p = (pSIMDATA) ptr->pdata;
@@ -222,7 +210,7 @@ LPSTR __cdecl cpp_encodeW(HANDLE context, LPWSTR msg) { LPSTR szNewMsg = NULL;
LPSTR szOldMsg = (LPSTR) msg;
- if(ptr->features & FEATURES_UTF8) {
+ if (ptr->features & FEATURES_UTF8) {
// unicode message: convert to utf-8 and encrypt.
szNewMsg = cpp_encrypt(ptr, utf8encode((LPWSTR)szOldMsg));
}
@@ -239,8 +227,8 @@ LPSTR __cdecl cpp_encodeW(HANDLE context, LPWSTR msg) { // decode message from UTF8 if need, return ANSIzUCS2z
-LPSTR __cdecl cpp_decode(HANDLE context, LPCSTR szEncMsg) {
-
+LPSTR __cdecl cpp_decode(HANDLE context, LPCSTR szEncMsg)
+{
pCNTX ptr = get_context_on_id(context);
if (!ptr) return NULL;
cpp_alloc_pdata(ptr); pSIMDATA p = (pSIMDATA) ptr->pdata;
@@ -249,8 +237,8 @@ LPSTR __cdecl cpp_decode(HANDLE context, LPCSTR szEncMsg) { LPSTR szNewMsg = NULL;
LPSTR szOldMsg = cpp_decrypt(ptr, szEncMsg);
- if(szOldMsg) {
- if(ptr->features & FEATURES_UTF8) {
+ if (szOldMsg) {
+ if (ptr->features & FEATURES_UTF8) {
// utf8 message: convert to unicode -> ansii
LPWSTR wstring = utf8decode(szOldMsg);
int wlen = wcslen(wstring)+1;
@@ -273,10 +261,9 @@ LPSTR __cdecl cpp_decode(HANDLE context, LPCSTR szEncMsg) { return szNewMsg;
}
-
// decode message return UTF8z
-LPSTR __cdecl cpp_decodeU(HANDLE context, LPCSTR szEncMsg) {
-
+LPSTR __cdecl cpp_decodeU(HANDLE context, LPCSTR szEncMsg)
+{
pCNTX ptr = get_context_on_id(context);
if (!ptr) return NULL;
cpp_alloc_pdata(ptr); pSIMDATA p = (pSIMDATA) ptr->pdata;
@@ -285,8 +272,8 @@ LPSTR __cdecl cpp_decodeU(HANDLE context, LPCSTR szEncMsg) { LPSTR szNewMsg = NULL;
LPSTR szOldMsg = cpp_decrypt(ptr, szEncMsg);
- if(szOldMsg) {
- if(ptr->features & FEATURES_UTF8) {
+ if (szOldMsg) {
+ if (ptr->features & FEATURES_UTF8) {
// utf8 message: copy
szNewMsg = _strdup(szOldMsg);
}
@@ -303,9 +290,8 @@ LPSTR __cdecl cpp_decodeU(HANDLE context, LPCSTR szEncMsg) { return szNewMsg;
}
-
-int __cdecl cpp_encrypt_file(HANDLE context,LPCSTR file_in,LPCSTR file_out) {
-
+int __cdecl cpp_encrypt_file(HANDLE context,LPCSTR file_in,LPCSTR file_out)
+{
pCNTX ptr = get_context_on_id(context);
if (!ptr) return 0;
cpp_alloc_pdata(ptr); pSIMDATA p = (pSIMDATA) ptr->pdata;
@@ -322,9 +308,8 @@ int __cdecl cpp_encrypt_file(HANDLE context,LPCSTR file_in,LPCSTR file_out) { return 1;
}
-
-int __cdecl cpp_decrypt_file(HANDLE context,LPCSTR file_in,LPCSTR file_out) {
-
+int __cdecl cpp_decrypt_file(HANDLE context,LPCSTR file_in,LPCSTR file_out)
+{
pCNTX ptr = get_context_on_id(context);
if (!ptr) return 0;
cpp_alloc_pdata(ptr); pSIMDATA p = (pSIMDATA) ptr->pdata;
|