diff options
author | George Hazan <george.hazan@gmail.com> | 2013-06-16 14:52:30 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-06-16 14:52:30 +0000 |
commit | 061047f67b695296a39a65df4a24916def1f67d5 (patch) | |
tree | 1b8b26385c66a0605e1a2688b23d68ea4558b32a /plugins/CryptoPP/src | |
parent | 16883b99a9de3b600bb7cc0bd42317249e74f2df (diff) |
custom (and also buggy) base64 processing code replaced with the core functions
git-svn-id: http://svn.miranda-ng.org/main/trunk@4987 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CryptoPP/src')
-rw-r--r-- | plugins/CryptoPP/src/base16.cpp | 4 | ||||
-rw-r--r-- | plugins/CryptoPP/src/base16.h | 2 | ||||
-rw-r--r-- | plugins/CryptoPP/src/base64.cpp | 99 | ||||
-rw-r--r-- | plugins/CryptoPP/src/base64.h | 58 | ||||
-rw-r--r-- | plugins/CryptoPP/src/commonheaders.h | 5 | ||||
-rw-r--r-- | plugins/CryptoPP/src/cpp_keys.cpp | 6 | ||||
-rw-r--r-- | plugins/CryptoPP/src/cpp_svcs.cpp | 25 | ||||
-rw-r--r-- | plugins/CryptoPP/src/version.h | 2 |
8 files changed, 36 insertions, 165 deletions
diff --git a/plugins/CryptoPP/src/base16.cpp b/plugins/CryptoPP/src/base16.cpp index ace113ff76..700cec8502 100644 --- a/plugins/CryptoPP/src/base16.cpp +++ b/plugins/CryptoPP/src/base16.cpp @@ -18,7 +18,7 @@ char *base16encode(const char *inBuffer, int count) { }
-char *base16decode(const char *inBuffer, size_t *count) {
+char *base16decode(const char *inBuffer, unsigned int *count) {
char *outBuffer = (char *) malloc(*count);
BYTE *outBufferPtr = (BYTE *) outBuffer;
@@ -56,7 +56,7 @@ char *base16decode(const char *inBuffer, size_t *count) { char *base16decode(const char *inBuffer)
{
- size_t count = strlen(inBuffer);
+ unsigned count = (unsigned)strlen(inBuffer);
return base16decode(inBuffer, &count);
}
diff --git a/plugins/CryptoPP/src/base16.h b/plugins/CryptoPP/src/base16.h index 2a2c18c42a..871bca3fbd 100644 --- a/plugins/CryptoPP/src/base16.h +++ b/plugins/CryptoPP/src/base16.h @@ -44,7 +44,7 @@ static const byte asciiToBin16[] = static const byte binToAscii16[] = "0123456789ABCDEF";
char *base16encode(const char *, const int);
-char *base16decode(const char *, size_t *);
+char *base16decode(const char *, unsigned*);
char *base16decode(const char *);
#define encode16(data) binToAscii16[data]
diff --git a/plugins/CryptoPP/src/base64.cpp b/plugins/CryptoPP/src/base64.cpp index 92f23ba64b..8daa2bd598 100644 --- a/plugins/CryptoPP/src/base64.cpp +++ b/plugins/CryptoPP/src/base64.cpp @@ -1,97 +1,22 @@ #include "commonheaders.h"
-
-string base64encode(const string buf)
+string base64encode(const string& buf)
{
- string out;
- char *base64 = base64encode(buf.data(), buf.length());
- out.assign(base64);
- free(base64);
- return out;
-}
-
-
-char *base64encode(const char *inBuffer, const size_t count) {
-
- int srcIndex = 0, destIndex = 0, remainder = count % 3;
- char *outBuffer = (char *) malloc(count*2+1);
- BYTE *inBufferPtr = (BYTE *) inBuffer;
-
- while(srcIndex < count) {
- outBuffer[destIndex++] = encode64(inBufferPtr[srcIndex] >> 2);
- outBuffer[destIndex++] = encode64(((inBufferPtr[srcIndex] << 4) & 0x30) | ((inBufferPtr[srcIndex + 1] >> 4) & 0x0F));
- srcIndex++;
- outBuffer[destIndex++] = encode64(((inBufferPtr[srcIndex] << 2) & 0x3C) | ((inBufferPtr[srcIndex + 1] >> 6) & 0x03));
- srcIndex++;
- outBuffer[destIndex++] = encode64(inBufferPtr[srcIndex++] & 0x3F);
- }
-
- if (remainder == 2) {
- outBuffer[destIndex - 1] = BPAD;
- outBuffer[destIndex - 2] = encode64((inBufferPtr[srcIndex - 2] << 2) & 0x3C);
- }
- else if (remainder == 1) {
- outBuffer[destIndex - 2] = outBuffer[destIndex - 1] = BPAD;
- outBuffer[destIndex - 3] = encode64((inBufferPtr[srcIndex - 3] << 4) & 0x30);
- }
- destIndex -= (3 - remainder) % 3;
- outBuffer[destIndex] = '\0';
-
- return outBuffer;
+ return (char*)ptrA( mir_base64_encode((PBYTE)buf.data(), (unsigned)buf.length()));
}
-
-string base64decode(const string buf) {
- string out;
- size_t len = buf.length();
- char *plain = base64decode(buf.data(), &len);
- out.assign(plain,len);
- free(plain);
- return out;
-}
-
-
-string base64decode(const char *buf) {
- string out;
- size_t len = strlen(buf);
- char *plain = base64decode(buf, &len);
- out.assign(plain,len);
- free(plain);
- return out;
+string base64decode(const string& buf)
+{
+ unsigned len;
+ char *plain = (char*)mir_base64_decode(buf.data(), &len);
+ return (plain == NULL) ? string() : string(plain, len);
}
-
-char *base64decode(const char *inBuffer, size_t *count) {
-
- int srcIndex = 0, destIndex = 0;
- char *outBuffer = (char *) malloc(*count);
-
- while(srcIndex < *count) {
- BYTE c0, c1, c2 = 0, c3 = 0;
- const size_t delta = *count - srcIndex;
- c0 = decode64(inBuffer[srcIndex++]);
- c1 = decode64(inBuffer[srcIndex++]);
- if (delta > 2) {
- c2 = decode64(inBuffer[srcIndex++]);
- if (delta > 3)
- c3 = decode64(inBuffer[srcIndex++]);
- }
- if ((c0 | c1 | c2 | c3) == BERR) {
- free(outBuffer);
- return(NULL);
- }
- outBuffer[destIndex++] = (c0 << 2) | (c1 >> 4);
- if (delta > 2) {
- outBuffer[destIndex++] = (c1 << 4) | (c2 >> 2);
- if (delta > 3 )
- outBuffer[destIndex++] = (c2 << 6) | (c3);
- }
- }
- outBuffer[destIndex] = '\0';
- *count = destIndex;
-
- return outBuffer;
+string base64decode(const char *buf)
+{
+ unsigned len;
+ char *plain = (char*)mir_base64_decode(buf, &len);
+ return (plain == NULL) ? string() : string(plain, len);
}
-
// EOF
diff --git a/plugins/CryptoPP/src/base64.h b/plugins/CryptoPP/src/base64.h deleted file mode 100644 index 8be9cbc4fa..0000000000 --- a/plugins/CryptoPP/src/base64.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __BASE_64__
-#define __BASE_64__
-
-#define BPAD '=' /* Padding for odd-sized output */
-#define BERR 0xFF /* Illegal char marker */
-#define BEOF 0x7F /* EOF marker (padding char or EOL) */
-
-typedef unsigned char byte;
-
-static const byte asciiToBin64[] =
- { BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BEOF, BERR, BERR, BEOF, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, 0x3E, BERR, BERR, BERR, 0x3F,
- 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
- 0x3C, 0x3D, BERR, BERR, BERR, BEOF, BERR, BERR,
- BERR, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
- 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
- 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
- 0x17, 0x18, 0x19, BERR, BERR, BERR, BERR, BERR,
- BERR, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
- 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
- 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
- 0x31, 0x32, 0x33, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR,
- BERR, BERR, BERR, BERR, BERR, BERR, BERR, BERR
- };
-
-static const byte binToAscii64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-char *base64encode(const char *, const size_t);
-char *base64decode(const char *, size_t *);
-
-string base64encode(const string);
-string base64decode(const string);
-
-string base64decode(const char *);
-
-#define encode64(data) binToAscii64[data]
-#define decode64(data) asciiToBin64[data]
-
-#endif
diff --git a/plugins/CryptoPP/src/commonheaders.h b/plugins/CryptoPP/src/commonheaders.h index b59445c548..863a839cc9 100644 --- a/plugins/CryptoPP/src/commonheaders.h +++ b/plugins/CryptoPP/src/commonheaders.h @@ -60,7 +60,6 @@ #include "mmi.h"
#include "utf8.h"
#include "base16.h"
-#include "base64.h"
#include "gettime.h"
#include "cpp_rsam.h"
#include "cpp_rsau.h"
@@ -82,6 +81,10 @@ extern CRITICAL_SECTION localQueueMutex; void ExtractFile(char*,int,int);
size_t rtrim(LPCSTR);
+std::string base64encode(const std::string&);
+std::string base64decode(const std::string&);
+std::string base64decode(const char *);
+
#if defined(_DEBUG) || defined(NETLIB_LOG)
extern HANDLE hNetlibUser;
void InitNetlib();
diff --git a/plugins/CryptoPP/src/cpp_keys.cpp b/plugins/CryptoPP/src/cpp_keys.cpp index b216eb6a2f..c1b2d9efb5 100644 --- a/plugins/CryptoPP/src/cpp_keys.cpp +++ b/plugins/CryptoPP/src/cpp_keys.cpp @@ -59,7 +59,7 @@ LPSTR __cdecl cpp_init_keya(HANDLE context, int features) { SAFE_FREE(ptr->tmp);
if (ptr->mode & MODE_BASE64 || features & FEATURES_NEWPG)
- ptr->tmp = base64encode((LPSTR)&publ1,KEYSIZE+2);
+ ptr->tmp = mir_base64_encode(publ1,KEYSIZE+2);
else
ptr->tmp = base16encode((LPSTR)&publ1,KEYSIZE+2);
@@ -73,14 +73,14 @@ int __cdecl cpp_init_keyb(HANDLE context, LPCSTR key) { pCNTX ptr = get_context_on_id(context); if (!ptr) return 0;
pSIMDATA p = (pSIMDATA) cpp_alloc_pdata(ptr);
- size_t clen = rtrim(key);
+ unsigned clen = (unsigned)rtrim(key);
ptr->features = 0;
LPSTR pub_binary;
if ((clen==KEYSIZE*2) || (clen==(KEYSIZE+2)*2))
pub_binary = base16decode(key,&clen);
else
- pub_binary = base64decode(key,&clen);
+ pub_binary = (LPSTR)mir_base64_decode(key,&clen);
if ( !pub_binary || (clen!=KEYSIZE && clen!=KEYSIZE+2) ) {
#if defined(_DEBUG) || defined(NETLIB_LOG)
diff --git a/plugins/CryptoPP/src/cpp_svcs.cpp b/plugins/CryptoPP/src/cpp_svcs.cpp index e2a1dd9053..990ab22f29 100644 --- a/plugins/CryptoPP/src/cpp_svcs.cpp +++ b/plugins/CryptoPP/src/cpp_svcs.cpp @@ -10,10 +10,11 @@ LPSTR __cdecl cpp_encrypt(pCNTX ptr, LPCSTR szPlainMsg) pSIMDATA p = (pSIMDATA) ptr->pdata;
BYTE dataflag = 0;
- size_t clen, slen = strlen(szPlainMsg);
+ size_t slen = strlen(szPlainMsg);
LPSTR szMsg;
if (ptr->features & FEATURES_GZIP) {
+ size_t clen;
szMsg = (LPSTR) cpp_gzip((BYTE*)szPlainMsg,slen,clen);
if (clen>=slen) {
free(szMsg);
@@ -36,7 +37,7 @@ LPSTR __cdecl cpp_encrypt(pCNTX ptr, LPCSTR szPlainMsg) free(szMsg);
- clen = (int) ciphered.length();
+ unsigned clen = (unsigned)ciphered.length();
if (ptr->features & FEATURES_CRC32) {
BYTE crc32[CRC32::DIGESTSIZE];
memset(crc32,0,sizeof(crc32));
@@ -46,14 +47,13 @@ LPSTR __cdecl cpp_encrypt(pCNTX ptr, LPCSTR szPlainMsg) }
if (ptr->features & FEATURES_GZIP)
ciphered.insert(0,(LPSTR)&dataflag,1);
-
- clen = (int) ciphered.length();
-
SAFE_FREE(ptr->tmp);
+
+ clen = (unsigned)ciphered.length();
if (ptr->features & FEATURES_BASE64)
- ptr->tmp = base64encode(ciphered.data(),clen);
+ ptr->tmp = mir_base64_encode((PBYTE)ciphered.data(), clen);
else
- ptr->tmp = base16encode(ciphered.data(),clen);
+ ptr->tmp = base16encode(ciphered.data(), clen);
return ptr->tmp;
}
@@ -68,10 +68,10 @@ LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) ptr->error = ERROR_SEH;
pSIMDATA p = (pSIMDATA) ptr->pdata;
- size_t clen = strlen(szEncMsg);
+ unsigned clen = (unsigned)strlen(szEncMsg);
if (ptr->features & FEATURES_BASE64)
- ciphered = base64decode(szEncMsg,&clen);
+ ciphered = (LPSTR)mir_base64_decode(szEncMsg,&clen);
else
ciphered = base16decode(szEncMsg,&clen);
@@ -86,7 +86,7 @@ LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) 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
@@ -124,8 +124,9 @@ LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) SAFE_FREE(ptr->tmp);
if (dataflag & DATA_GZIP) {
- ptr->tmp = (LPSTR) cpp_gunzip((PBYTE)unciphered.data(),unciphered.length(),clen);
- ptr->tmp[clen] = 0;
+ size_t clen2 = clen;
+ ptr->tmp = (LPSTR) cpp_gunzip((PBYTE)unciphered.data(),unciphered.length(),clen2);
+ ptr->tmp[clen2] = 0;
}
else ptr->tmp = (LPSTR) _strdup(unciphered.c_str());
diff --git a/plugins/CryptoPP/src/version.h b/plugins/CryptoPP/src/version.h index 8d7c950b88..c8062071eb 100644 --- a/plugins/CryptoPP/src/version.h +++ b/plugins/CryptoPP/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 1
#define __MINOR_VERSION 0
#define __RELEASE_NUM 4
-#define __BUILD_NUM 5
+#define __BUILD_NUM 6
#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
#define __TOSTRING(x) #x
|