summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-08-15 14:21:16 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-08-15 14:21:16 +0000
commit21c56b9074fbfdacba112a51ae3b54edfa243e59 (patch)
tree9880c23569b1012e2ae78b43a45b661a0742d616 /protocols
parent7651a0799879e5af9a6831551c1c73f6e4890143 (diff)
custom base64 & sha1 libs removed from MRA
git-svn-id: http://svn.miranda-ng.org/main/trunk@5702 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/MRA/Mra_11.vcxproj20
-rw-r--r--protocols/MRA/Mra_11.vcxproj.filters63
-rw-r--r--protocols/MRA/src/Mra.h3
-rw-r--r--protocols/MRA/src/MraOfflineMsg.cpp151
-rw-r--r--protocols/MRA/src/MraProto.h2
-rw-r--r--protocols/MRA/src/MraSendCommand.cpp48
-rw-r--r--protocols/MRA/src/Mra_functions.cpp89
-rw-r--r--protocols/MRA/src/Mra_proto.cpp25
-rw-r--r--protocols/MRA/src/Sdk/Base64.h380
-rw-r--r--protocols/MRA/src/Sdk/SHA1.h530
10 files changed, 210 insertions, 1101 deletions
diff --git a/protocols/MRA/Mra_11.vcxproj b/protocols/MRA/Mra_11.vcxproj
index b7762bd93e..a036582ea4 100644
--- a/protocols/MRA/Mra_11.vcxproj
+++ b/protocols/MRA/Mra_11.vcxproj
@@ -190,6 +190,7 @@
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="src\MraUtils.cpp" />
<ClCompile Include="src\stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
@@ -234,6 +235,25 @@
<ClInclude Include="src\MraSendQueue.h" />
<ClInclude Include="src\proto.h" />
<ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\Sdk\BuffToLowerCase.h" />
+ <ClInclude Include="src\Sdk\DebugFunctions.h" />
+ <ClInclude Include="src\Sdk\FIFOMT.h" />
+ <ClInclude Include="src\Sdk\InterlockedFunctions.h" />
+ <ClInclude Include="src\Sdk\InternetTime.h" />
+ <ClInclude Include="src\Sdk\ListMT.h" />
+ <ClInclude Include="src\Sdk\MemoryCompare.h" />
+ <ClInclude Include="src\Sdk\MemoryFind.h" />
+ <ClInclude Include="src\Sdk\MemoryFindByte.h" />
+ <ClInclude Include="src\Sdk\MemoryReplace.h" />
+ <ClInclude Include="src\Sdk\RC4.h" />
+ <ClInclude Include="src\Sdk\SHA1.h" />
+ <ClInclude Include="src\Sdk\SocketFunctions.h" />
+ <ClInclude Include="src\Sdk\StrHexToNum.h" />
+ <ClInclude Include="src\Sdk\StrToNum.h" />
+ <ClInclude Include="src\Sdk\SystemHeaders.h" />
+ <ClInclude Include="src\Sdk\timefuncs.h" />
+ <ClInclude Include="src\Sdk\zconf.h" />
+ <ClInclude Include="src\Sdk\zlib.h" />
<ClInclude Include="src\version.h" />
</ItemGroup>
<ItemGroup>
diff --git a/protocols/MRA/Mra_11.vcxproj.filters b/protocols/MRA/Mra_11.vcxproj.filters
index ed7f4006e4..9df9c95b3a 100644
--- a/protocols/MRA/Mra_11.vcxproj.filters
+++ b/protocols/MRA/Mra_11.vcxproj.filters
@@ -13,6 +13,9 @@
<UniqueIdentifier>{482639cd-fb25-4cfb-9e55-4a299271787c}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
+ <Filter Include="Header Files\SDK">
+ <UniqueIdentifier>{09f251ef-6cd8-48b3-a275-f10b210f5459}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Mra.cpp">
@@ -78,6 +81,9 @@
<ClCompile Include="src\stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\MraUtils.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Mra.h">
@@ -140,6 +146,63 @@
<ClInclude Include="src\version.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="src\Sdk\BuffToLowerCase.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\DebugFunctions.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\FIFOMT.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\InterlockedFunctions.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\InternetTime.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\ListMT.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\MemoryCompare.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\MemoryFind.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\MemoryFindByte.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\MemoryReplace.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\RC4.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\SHA1.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\SocketFunctions.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\StrHexToNum.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\StrToNum.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\SystemHeaders.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\timefuncs.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\zconf.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Sdk\zlib.h">
+ <Filter>Header Files\SDK</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\resource.rc">
diff --git a/protocols/MRA/src/Mra.h b/protocols/MRA/src/Mra.h
index da0a7f76be..4cd92193bf 100644
--- a/protocols/MRA/src/Mra.h
+++ b/protocols/MRA/src/Mra.h
@@ -75,7 +75,6 @@
#include <StrToNum.h>
#include <StrToNum.h>
#include <StrHexToNum.h>
-#include <Base64.h>
#include <InternetTime.h>
#include <ListMT.h>
#include <FIFOMT.h>
@@ -264,4 +263,6 @@ DWORD GetMraXStatusIDFromMraUriStatus (LPSTR lpszStatusUri, size_t dwStatusUriS
INT_PTR CALLBACK DlgProcAccount(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
+#define LPS2ANSI(var, p, size) char *var = (char*)alloca(size+1); memcpy(var, p, size); var[size]=0;
+
#endif // !defined(AFX_MRA_H__F58D13FF_F6F2_476C_B8F0_7B9E9357CF48__INCLUDED_)
diff --git a/protocols/MRA/src/MraOfflineMsg.cpp b/protocols/MRA/src/MraOfflineMsg.cpp
index 38d9d7869f..829bca6b27 100644
--- a/protocols/MRA/src/MraOfflineMsg.cpp
+++ b/protocols/MRA/src/MraOfflineMsg.cpp
@@ -15,17 +15,12 @@ DWORD MraOfflineMessageGetHeaderValue (LPSTR lpszHeader, LPSTR lpszHeaderLow, s
DWORD MraOfflineMessageGetHeaderValueLow (LPSTR lpszHeaderLow, size_t dwHeaderSize, LPSTR lpszValueName, size_t dwValueNameSize, LPSTR *plpszValue, size_t *pdwValueSize);
DWORD MraOfflineMessageConvertTime (INTERNET_TIME *pitTime);
-
-
-
DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MRA_LPS *plpsEMail, MRA_LPS *plpsText, MRA_LPS *plpsRTFText, MRA_LPS *plpsMultiChatData, LPBYTE *plpbBuff)
{// Сообщение
DWORD dwRetErrorCode = ERROR_INVALID_HANDLE;
-
if (plpsMsg)
- if (plpsMsg->lpszData && plpsMsg->dwSize)
- {
+ if (plpsMsg->lpszData && plpsMsg->dwSize) {
LPSTR lpszHeader, lpszHeaderLow, lpszBody, lpszContentTypeLow, lpszTemp;
size_t dwHeaderSize, dwBodySize, dwContentTypeSize, dwTempSize;
DWORD dwMultichatType;
@@ -34,153 +29,121 @@ DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MR
DebugPrintCRLFA(plpsMsg->lpszData);
#endif
- if (MraOfflineMessageGetMIMEHeadAndBody(plpsMsg->lpszData, plpsMsg->dwSize, &lpszHeader, &dwHeaderSize, &lpszBody, &dwBodySize) == NO_ERROR)
- {
+ if (MraOfflineMessageGetMIMEHeadAndBody(plpsMsg->lpszData, plpsMsg->dwSize, &lpszHeader, &dwHeaderSize, &lpszBody, &dwBodySize) == NO_ERROR) {
lpszHeaderLow = (LPSTR)mir_calloc(dwHeaderSize);
if (lpszHeaderLow) BuffToLowerCase(lpszHeaderLow, lpszHeader, dwHeaderSize);
if (pdwTime)
- if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "date", 4, &lpszTemp, &dwTempSize) == NO_ERROR)
- {
+ if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "date", 4, &lpszTemp, &dwTempSize) == NO_ERROR) {
INTERNET_TIME itTime;
InternetTimeGetTime(lpszTemp, dwTempSize, &itTime);
(*pdwTime) = MraOfflineMessageConvertTime(&itTime);
- }else {
- (*pdwTime) = 0;
}
+ else (*pdwTime) = 0;
if (pdwFlags)
if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "x-mrim-flags", 12, &lpszTemp, &dwTempSize) == NO_ERROR)
- {
(*pdwFlags) = StrHexToUNum32(lpszTemp, dwTempSize);
- }else {
+ else
(*pdwFlags) = 0;
- }
if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "x-mrim-multichat-type", 21, &lpszTemp, &dwTempSize) == NO_ERROR)
- {
dwMultichatType = StrHexToUNum32(lpszTemp, dwTempSize);
- }else {
+ else
dwMultichatType = 0;
- }
-
if (plpsEMail)
- if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "from", 4, &plpsEMail->lpszData, &plpsEMail->dwSize) != NO_ERROR)
- {
+ if (MraOfflineMessageGetHeaderValue(lpszHeader, lpszHeaderLow, dwHeaderSize, "from", 4, &plpsEMail->lpszData, &plpsEMail->dwSize) != NO_ERROR) {
plpsEMail->lpszData = NULL;
plpsEMail->dwSize = 0;
}
-
- if (plpsText)
- {
+ if (plpsText) {
plpsText->lpszData = NULL;
plpsText->dwSize = 0;
}
- if (plpsRTFText)
- {
+ if (plpsRTFText) {
plpsRTFText->lpszData = NULL;
plpsRTFText->dwSize = 0;
}
- if (plpsMultiChatData)
- {
+ if (plpsMultiChatData) {
plpsMultiChatData->lpszData = NULL;
plpsMultiChatData->dwSize = 0;
}
if (plpbBuff) (*plpbBuff) = NULL;
if (plpsText || plpsRTFText)
- if (MraOfflineMessageGetHeaderValueLow(lpszHeaderLow, dwHeaderSize, "content-type", 12, &lpszContentTypeLow, &dwContentTypeSize) == NO_ERROR)
- {
-
- if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "multipart/alternative", 21))
- {// Content-Type: multipart/alternative; boundary = 1217508709J3777283291217508709T31197726
+ if (MraOfflineMessageGetHeaderValueLow(lpszHeaderLow, dwHeaderSize, "content-type", 12, &lpszContentTypeLow, &dwContentTypeSize) == NO_ERROR) {
+ if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "multipart/alternative", 21)) {
+ // Content-Type: multipart/alternative; boundary = 1217508709J3777283291217508709T31197726
LPSTR lpszBoundary, lpszMIMEPart, lpszCurMIMEPos, lpszMIMEHeader, lpszMIMEHeaderLow, lpszMIMEBody, lpszMIMEContentType;
size_t i, dwBoundarySize, dwMIMEPartSize, dwMIMEHeaderSize, dwMIMEBodySize, dwMIMEContentTypeSize;
lpszBoundary = (LPSTR)MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "boundary=", 9);
- if (lpszBoundary)
- {
+ if (lpszBoundary) {
dwBoundarySize = ((dwContentTypeSize-(lpszBoundary-lpszContentTypeLow))-9);
lpszBoundary = (lpszHeader+((lpszBoundary+9)-lpszHeaderLow));
i = 0;
lpszCurMIMEPos = lpszBody;
- while (MraOfflineMessageGetNextMIMEPart(lpszBody, dwBodySize, lpszBoundary, dwBoundarySize, &lpszCurMIMEPos, &lpszMIMEPart, &dwMIMEPartSize) == NO_ERROR)
- {
- if (MraOfflineMessageGetMIMEHeadAndBody(lpszMIMEPart, dwMIMEPartSize, &lpszMIMEHeader, &dwMIMEHeaderSize, &lpszMIMEBody, &dwMIMEBodySize) == NO_ERROR)
- {
+ while (MraOfflineMessageGetNextMIMEPart(lpszBody, dwBodySize, lpszBoundary, dwBoundarySize, &lpszCurMIMEPos, &lpszMIMEPart, &dwMIMEPartSize) == NO_ERROR) {
+ if (MraOfflineMessageGetMIMEHeadAndBody(lpszMIMEPart, dwMIMEPartSize, &lpszMIMEHeader, &dwMIMEHeaderSize, &lpszMIMEBody, &dwMIMEBodySize) == NO_ERROR) {
lpszMIMEHeaderLow = (LPSTR)mir_calloc(dwMIMEHeaderSize);
- if (lpszMIMEHeaderLow)
- {
+ if (lpszMIMEHeaderLow) {
BuffToLowerCase(lpszMIMEHeaderLow, lpszMIMEHeader, dwMIMEHeaderSize);
- if (MraOfflineMessageGetHeaderValueLow(lpszMIMEHeaderLow, dwMIMEHeaderSize, "content-type", 12, &lpszMIMEContentType, &dwMIMEContentTypeSize) == NO_ERROR)
- {
- if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "text/plain", 10))
- {// this is simple text part: text/plain
- if (plpsText)
- {
- if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "utf-16le", 8))
- {// charset = UTF-16LE// предполагаем что оно в base64
- if (plpbBuff)
- {// буффер для декодирования текста можно выделять
- LPWSTR lpwszText;
- size_t dwTextSize;
-
- lpwszText = (LPWSTR)mir_calloc(dwMIMEBodySize);
- if (lpwszText)
- {
- BASE64DecodeFormated(lpszMIMEBody, dwMIMEBodySize, lpwszText, dwMIMEBodySize, &dwTextSize);
+ if (MraOfflineMessageGetHeaderValueLow(lpszMIMEHeaderLow, dwMIMEHeaderSize, "content-type", 12, &lpszMIMEContentType, &dwMIMEContentTypeSize) == NO_ERROR) {
+ if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "text/plain", 10)) {
+ // this is simple text part: text/plain
+ if (plpsText) {
+ if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "utf-16le", 8)) {
+ // charset = UTF-16LE// предполагаем что оно в base64
+ if (plpbBuff) {
+ // буффер для декодирования текста можно выделять
+ LPS2ANSI(szMime, lpszMIMEBody, dwMIMEBodySize);
+ unsigned dwTextSize;
+ LPWSTR lpwszText = (LPWSTR)mir_base64_decode(szMime, &dwTextSize);
+ if (lpwszText) {
plpsText->lpwszData = lpwszText;
plpsText->dwSize = dwTextSize;
- if (pdwFlags)
- {
+ if (pdwFlags) {
(*pdwFlags) |= MESSAGE_FLAG_v1p16; // set unocode flag if not exist
(*pdwFlags) &= ~MESSAGE_FLAG_CP1251; // reset ansi flag if exist
}
- (*plpbBuff) = (LPBYTE)lpwszText;
+ *plpbBuff = (LPBYTE)lpwszText;
dwRetErrorCode = NO_ERROR;
}
}
- }else
- if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "cp-1251", 7))
- {// charset = CP-1251
+ }
+ else if ( MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "cp-1251", 7)) {
+ // charset = CP-1251
plpsText->lpszData = lpszMIMEBody;
plpsText->dwSize = dwMIMEBodySize;
- if (pdwFlags)
- {
+ if (pdwFlags) {
(*pdwFlags) &= ~MESSAGE_FLAG_v1p16; // reset unocode flag if exist
(*pdwFlags) |= MESSAGE_FLAG_CP1251; // set ansi flag
}
dwRetErrorCode = NO_ERROR;
- }else {
- DebugBreak();
}
+ else DebugBreak();
}
- }else
- if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "application/x-mrim-rtf", 22))
- {
- if (plpsRTFText)
- {
+ }
+ else if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "application/x-mrim-rtf", 22)) {
+ if (plpsRTFText) {
plpsRTFText->lpszData = lpszMIMEBody;
plpsRTFText->dwSize = dwMIMEBodySize;
if (pdwFlags) (*pdwFlags) |= MESSAGE_FLAG_RTF; // set RTF flag if not exist
dwRetErrorCode = NO_ERROR;
}
- }else
- if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "application/x-mrim+xml", 22))
- {
- if (plpsMultiChatData)
- {
+ }
+ else if (MemoryFind(0, lpszMIMEContentType, dwMIMEContentTypeSize, "application/x-mrim+xml", 22)) {
+ if (plpsMultiChatData) {
plpsMultiChatData->lpszData = lpszMIMEBody;
plpsMultiChatData->dwSize = dwMIMEBodySize;
if (pdwFlags) (*pdwFlags) |= MESSAGE_FLAG_MULTICHAT; // set MESSAGE_FLAG_MULTICHAT flag if not exist
dwRetErrorCode = NO_ERROR;
}
- }else {
- DebugBreak();
}
+ else DebugBreak();
}
mir_free(lpszMIMEHeaderLow);
}
@@ -189,23 +152,19 @@ DWORD MraOfflineMessageGet(MRA_LPS *plpsMsg, DWORD *pdwTime, DWORD *pdwFlags, MR
}
DebugBreakIf((i>3 || i == 0));
- }else {// boundary not found
- DebugBreak();
}
- }else
- if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "text/plain", 10))
- {// Content-Type: text/plain; charset = CP-1251
- if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "utf-16le", 8))
- {// charset = UTF-16LE// предполагаем что оно в base64
- if (plpbBuff)
- {// буффер для декодирования текста можно выделять
- LPWSTR lpwszText;
- size_t dwTextSize;
-
- lpwszText = (LPWSTR)mir_calloc(dwBodySize);
- if (lpwszText)
- {
- BASE64DecodeFormated(lpszBody, dwBodySize, lpwszText, dwBodySize, &dwTextSize);
+ else DebugBreak(); // boundary not found
+ }
+ else if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "text/plain", 10)) {
+ // Content-Type: text/plain; charset = CP-1251
+ if (MemoryFind(0, lpszContentTypeLow, dwContentTypeSize, "utf-16le", 8)) {
+ // charset = UTF-16LE// предполагаем что оно в base64
+ if (plpbBuff) {
+ // буфер для декодирования текста можно выделять
+ LPS2ANSI(szMime, lpszBody, dwBodySize);
+ unsigned dwTextSize;
+ LPWSTR lpwszText = (LPWSTR)mir_base64_decode(szMime, &dwTextSize);
+ if (lpwszText) {
plpsText->lpwszData = lpwszText;
plpsText->dwSize = dwTextSize;
if (pdwFlags)
diff --git a/protocols/MRA/src/MraProto.h b/protocols/MRA/src/MraProto.h
index 3506aa51bf..341398d368 100644
--- a/protocols/MRA/src/MraProto.h
+++ b/protocols/MRA/src/MraProto.h
@@ -272,8 +272,6 @@ struct CMraProto : public PROTO<CMraProto>
BOOL SetPassDB(LPSTR lpszBuff, size_t dwBuffSize);
BOOL GetPassDB(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSize);
- BOOL GetPassDB_v1(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSize);
- BOOL GetPassDB_v2(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSize);
BOOL MraRequestXStatusDetails(DWORD dwXStatus);
BOOL MraSendReplyBlogStatus(HANDLE hContact);
diff --git a/protocols/MRA/src/MraSendCommand.cpp b/protocols/MRA/src/MraSendCommand.cpp
index 55ffd86bba..fb4a9e711a 100644
--- a/protocols/MRA/src/MraSendCommand.cpp
+++ b/protocols/MRA/src/MraSendCommand.cpp
@@ -80,23 +80,18 @@ DWORD CMraProto::MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType,
// pack auth message
if (dwFlags & MESSAGE_FLAG_AUTHORIZE) {
- LPBYTE lpbAuthMsgBuff;
- size_t dwMessageConvertedBuffSize = (((((dwMessageSize*sizeof(WCHAR))+1024)+2)/3)*4);
-
- lpszMessageConverted = (LPSTR)mir_calloc(dwMessageConvertedBuffSize);
- lpbAuthMsgBuff = (LPBYTE)mir_calloc(((dwMessageSize*sizeof(WCHAR))+1024));
- if (lpszMessageConverted && lpbAuthMsgBuff) {
+ LPBYTE lpbAuthMsgBuff = (LPBYTE)mir_calloc(((dwMessageSize*sizeof(WCHAR))+1024));
+ if (lpbAuthMsgBuff) {
lpbDataCurrent = lpbAuthMsgBuff;
SetUL(&lpbDataCurrent, 2);
SetLPSW(&lpbDataCurrent, NULL, 0);//***deb possible nick here
SetLPSW(&lpbDataCurrent, lpwszMessage, dwMessageSize);
- BASE64EncodeUnSafe(lpbAuthMsgBuff, (lpbDataCurrent-lpbAuthMsgBuff), lpszMessageConverted, dwMessageConvertedBuffSize, &dwMessageConvertedSize);
- }
- else {
- mir_free(lpszMessageConverted);
- lpszMessageConverted = (LPSTR)lpwszMessage;
+ lpszMessageConverted = mir_base64_encode(lpbAuthMsgBuff, (lpbDataCurrent-lpbAuthMsgBuff));
+ dwMessageConvertedSize = strlen(lpszMessageConverted);
}
+ else lpszMessageConverted = (LPSTR)lpwszMessage;
+
mir_free(lpbAuthMsgBuff);
}
// messages with Flash
@@ -104,9 +99,8 @@ DWORD CMraProto::MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType,
size_t dwRFTBuffSize = (((dwMessageSize*sizeof(WCHAR))*4)+8192), dwRTFDataSize;
dwFlags |= MESSAGE_FLAG_RTF;
- lpszMessageRTF = (LPSTR)mir_calloc(dwRFTBuffSize);
ptrA lpbRTFData((char*)mir_calloc(dwRFTBuffSize));
- if (lpszMessageRTF && lpbRTFData) {
+ if (lpbRTFData) {
DWORD dwBackColour = getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR);
lpbDataCurrent = (LPBYTE)lpszMessageRTF;
@@ -119,8 +113,10 @@ DWORD CMraProto::MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType,
SetLPSW(&lpbDataCurrent, lpwszMessage, dwMessageSize);// сам мульт UNICODE
dwRTFDataSize = dwRFTBuffSize;
- if ( compress2((LPBYTE)(LPSTR)lpbRTFData, (DWORD*)&dwRTFDataSize, (LPBYTE)lpszMessageRTF, (lpbDataCurrent-(LPBYTE)lpszMessageRTF), Z_BEST_COMPRESSION) == Z_OK)
- BASE64EncodeUnSafe(lpbRTFData, dwRTFDataSize, lpszMessageRTF, dwRFTBuffSize, &dwMessageRTFSize);
+ if ( compress2((LPBYTE)(LPSTR)lpbRTFData, (DWORD*)&dwRTFDataSize, (LPBYTE)lpszMessageRTF, (lpbDataCurrent-(LPBYTE)lpszMessageRTF), Z_BEST_COMPRESSION) == Z_OK) {
+ lpszMessageRTF = mir_base64_encode((LPBYTE)(char*)lpbRTFData, dwRTFDataSize);
+ dwMessageRTFSize = lstrlenA(lpszMessageRTF);
+ }
}
}
// standart message
@@ -129,9 +125,8 @@ DWORD CMraProto::MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType,
if (dwFlags & MESSAGE_FLAG_RTF) { // add RFT part
size_t dwRFTBuffSize = (((dwMessageSize*sizeof(WCHAR))*16)+8192), dwRTFDataSize;
- lpszMessageRTF = (LPSTR)mir_calloc(dwRFTBuffSize);
ptrA lpbRTFData((char*)mir_calloc(dwRFTBuffSize));
- if (lpszMessageRTF && lpbRTFData) {
+ if (lpbRTFData) {
if ( !MraConvertToRTFW(lpwszMessage, dwMessageSize, (LPSTR)lpbRTFData, dwRFTBuffSize, &dwRTFDataSize)) {
DWORD dwBackColour = getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR);
lpbDataCurrent = (LPBYTE)lpszMessageRTF;
@@ -141,8 +136,10 @@ DWORD CMraProto::MraMessageW(BOOL bAddToQueue, HANDLE hContact, DWORD dwAckType,
SetLPS(&lpbDataCurrent, (LPSTR)&dwBackColour, sizeof(DWORD));
dwRTFDataSize = dwRFTBuffSize;
- if ( compress2((LPBYTE)(LPSTR)lpbRTFData, (DWORD*)&dwRTFDataSize, (LPBYTE)lpszMessageRTF, (lpbDataCurrent-(LPBYTE)lpszMessageRTF), Z_BEST_COMPRESSION) == Z_OK)
- BASE64EncodeUnSafe(lpbRTFData, dwRTFDataSize, lpszMessageRTF, dwRFTBuffSize, &dwMessageRTFSize);
+ if ( compress2((LPBYTE)(LPSTR)lpbRTFData, (DWORD*)&dwRTFDataSize, (LPBYTE)lpszMessageRTF, (lpbDataCurrent-(LPBYTE)lpszMessageRTF), Z_BEST_COMPRESSION) == Z_OK) {
+ lpszMessageRTF = mir_base64_encode((LPBYTE)(char*)lpbRTFData, dwRTFDataSize);
+ dwMessageRTFSize = lstrlenA(lpszMessageRTF);
+ }
}
}
}
@@ -236,22 +233,23 @@ DWORD CMraProto::MraAddContactW(HANDLE hContact, DWORD dwContactFlag, DWORD dwGr
SetLPS(&lpbDataCurrent, lpszPhones, dwPhonesSize);
// pack auth message
- LPBYTE lpbAuthMsgBuff, lpbAuthMessageConverted, lpbAuthDataCurrent;
+ LPBYTE lpbAuthMsgBuff, lpbAuthDataCurrent;
+ LPSTR lpszAuthMessageConverted;
size_t dwAuthMessageConvertedBuffSize = (((((dwAuthMessageSize*sizeof(WCHAR))+1024)+2)/3)*4), dwAuthMessageConvertedSize = 0;
- lpbAuthMessageConverted = (LPBYTE)mir_calloc(dwAuthMessageConvertedBuffSize);
lpbAuthMsgBuff = (LPBYTE)mir_calloc(((dwAuthMessageSize*sizeof(WCHAR))+1024));
- if (lpbAuthMessageConverted && lpbAuthMsgBuff) {
+ if (lpbAuthMsgBuff) {
lpbAuthDataCurrent = lpbAuthMsgBuff;
SetUL(&lpbAuthDataCurrent, 2);
SetLPSW(&lpbAuthDataCurrent, NULL, 0);//***deb possible nick here
SetLPSW(&lpbAuthDataCurrent, lpwszAuthMessage, dwAuthMessageSize);
- BASE64EncodeUnSafe(lpbAuthMsgBuff, (lpbAuthDataCurrent-lpbAuthMsgBuff), lpbAuthMessageConverted, dwAuthMessageConvertedBuffSize, &dwAuthMessageConvertedSize);
+ lpszAuthMessageConverted = mir_base64_encode(lpbAuthMsgBuff, (lpbAuthDataCurrent-lpbAuthMsgBuff));
+ dwAuthMessageConvertedSize = lstrlenA(lpszAuthMessageConverted);
}
- SetLPS(&lpbDataCurrent, (LPSTR)lpbAuthMessageConverted, dwAuthMessageConvertedSize);
+ SetLPS(&lpbDataCurrent, (LPSTR)lpszAuthMessageConverted, dwAuthMessageConvertedSize);
mir_free(lpbAuthMsgBuff);
- mir_free(lpbAuthMessageConverted);
+ mir_free(lpszAuthMessageConverted);
SetUL(&lpbDataCurrent, dwActions);
diff --git a/protocols/MRA/src/Mra_functions.cpp b/protocols/MRA/src/Mra_functions.cpp
index c8eaa7b6df..114de07da0 100644
--- a/protocols/MRA/src/Mra_functions.cpp
+++ b/protocols/MRA/src/Mra_functions.cpp
@@ -1524,7 +1524,7 @@ DWORD MemFillRandom(LPVOID lpBuff, size_t dwBuffSize)
BOOL CMraProto::SetPassDB(LPSTR lpszBuff, size_t dwBuffSize)
{
BOOL bRet = FALSE;
- BYTE btRandomData[256], btCryptedPass[256] = {0}, bthmacSHA1[SHA1HashSize] = {0};
+ BYTE btRandomData[256], btCryptedPass[256] = {0}, bthmacSHA1[MIR_SHA1_HASH_SIZE] = {0};
char szEMail[MAX_EMAIL_LEN] = {0};
size_t dwEMailSize;
@@ -1539,18 +1539,17 @@ BOOL CMraProto::SetPassDB(LPSTR lpszBuff, size_t dwBuffSize)
SHA1GetDigest(lpszBuff, dwBuffSize, &btCryptedPass[1]);
- //BASE64EncodeUnSafe(lpszBuff, dwBuffSize, &btCryptedPass[(1+SHA1HashSize)], (sizeof(btCryptedPass)-1), &dwBuffSize);
- memmove(&btCryptedPass[(1+SHA1HashSize)], lpszBuff, dwBuffSize);
+ //BASE64EncodeUnSafe(lpszBuff, dwBuffSize, &btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], (sizeof(btCryptedPass)-1), &dwBuffSize);
+ memmove(&btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], lpszBuff, dwBuffSize);
btCryptedPass[0] = (BYTE)dwBuffSize;
//memmove(&btCryptedPass[1], lpszBuff, dwBuffSize);
hmac_sha1(btRandomData, sizeof(btRandomData), (BYTE*)szEMail, dwEMailSize, bthmacSHA1);
- RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, SHA1HashSize);
+ RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, sizeof(btRandomData));
CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass));
- RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, SHA1HashSize);
-
+ RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
setDword("pCryptVer", MRA_PASS_CRYPT_VER);
mraWriteContactSettingBlob(NULL, "pCryptData", btRandomData, sizeof(btRandomData));
@@ -1563,50 +1562,22 @@ return(bRet);
}
-BOOL CMraProto::GetPassDB_v1(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSize)
+BOOL CMraProto::GetPassDB(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSize)
{
- BYTE btRandomData[256] = {0}, btCryptedPass[256] = {0}, bthmacSHA1[SHA1HashSize] = {0};
- char szEMail[MAX_EMAIL_LEN] = {0};
- size_t dwRandomDataSize, dwCryptedPass, dwEMailSize, dwPassSize;
-
- if (getDword("pCryptVer", 0) == 1)
- if (mraGetContactSettingBlob(NULL, "pCryptData", btRandomData, sizeof(btRandomData), &dwRandomDataSize))
- if (dwRandomDataSize == sizeof(btRandomData))
- if (mraGetContactSettingBlob(NULL, "pCryptPass", btCryptedPass, sizeof(btCryptedPass), &dwCryptedPass))
- if (dwCryptedPass == sizeof(btCryptedPass))
- if (mraGetStaticStringA(NULL, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
- hmac_sha1(btRandomData, sizeof(btRandomData), (BYTE*)szEMail, dwEMailSize, bthmacSHA1);
-
- RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, SHA1HashSize);
- CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass));
- RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, dwRandomDataSize);
- RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, SHA1HashSize);
-
- dwPassSize = (*btCryptedPass);
- BASE64DecodeUnSafe(&btCryptedPass[(1+SHA1HashSize)], dwPassSize, &btCryptedPass[(1+SHA1HashSize)], (sizeof(btCryptedPass)-1), &dwPassSize);
- SHA1GetDigest(&btCryptedPass[(1+SHA1HashSize)], dwPassSize, btRandomData);
- if (MemoryCompare(&btCryptedPass[1], SHA1HashSize, btRandomData, SHA1HashSize) == CMEM_EQUAL)
- if (dwBuffSize >= dwPassSize) {
- memmove(lpszBuff, &btCryptedPass[(1+SHA1HashSize)], dwPassSize);
- *(lpszBuff + dwPassSize) = 0;
-
- if (pdwBuffSize)
- *pdwBuffSize = dwPassSize;
- return TRUE;
- }
+ switch (getDword("pCryptVer", 0)) {
+ case 1:
+ MessageBox(NULL, TranslateT("Your password expired. Please reenter password in the Options dialog"), TranslateT("Error"), MB_OK);
+ return FALSE;
+ case 2:
+ break;
+ default:
+ return FALSE;
}
- return FALSE;
-}
-
-
-BOOL CMraProto::GetPassDB_v2(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSize)
-{
- BYTE btRandomData[256] = {0}, btCryptedPass[256] = {0}, bthmacSHA1[SHA1HashSize] = {0};
+ BYTE btRandomData[256] = {0}, btCryptedPass[256] = {0}, bthmacSHA1[MIR_SHA1_HASH_SIZE] = {0};
char szEMail[MAX_EMAIL_LEN] = {0};
size_t dwRandomDataSize, dwCryptedPass, dwEMailSize, dwPassSize;
- if (getDword("pCryptVer", 0) == 2)
if (mraGetContactSettingBlob(NULL, "pCryptData", btRandomData, sizeof(btRandomData), &dwRandomDataSize))
if (dwRandomDataSize == sizeof(btRandomData))
if (mraGetContactSettingBlob(NULL, "pCryptPass", btCryptedPass, sizeof(btCryptedPass), &dwCryptedPass))
@@ -1614,17 +1585,16 @@ BOOL CMraProto::GetPassDB_v2(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffS
if (mraGetStaticStringA(NULL, "e-mail", szEMail, SIZEOF(szEMail), &dwEMailSize)) {
hmac_sha1(btRandomData, sizeof(btRandomData), (BYTE*)szEMail, dwEMailSize, bthmacSHA1);
- RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, SHA1HashSize);
+ RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass));
RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, dwRandomDataSize);
- RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, SHA1HashSize);
+ RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE);
dwPassSize = ((*btCryptedPass)&0xff);
- SHA1GetDigest(&btCryptedPass[(1+SHA1HashSize)], dwPassSize, btRandomData);
- if (MemoryCompare(&btCryptedPass[1], SHA1HashSize, btRandomData, SHA1HashSize) == CMEM_EQUAL)
- if (dwBuffSize >= dwPassSize)
- {
- memmove(lpszBuff, &btCryptedPass[(1+SHA1HashSize)], dwPassSize);
+ SHA1GetDigest(&btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], dwPassSize, btRandomData);
+ if (MemoryCompare(&btCryptedPass[1], MIR_SHA1_HASH_SIZE, btRandomData, MIR_SHA1_HASH_SIZE) == CMEM_EQUAL)
+ if (dwBuffSize >= dwPassSize) {
+ memmove(lpszBuff, &btCryptedPass[(1+MIR_SHA1_HASH_SIZE)], dwPassSize);
(*(lpszBuff+dwPassSize)) = 0;
if (pdwBuffSize) (*pdwBuffSize) = dwPassSize;
@@ -1635,23 +1605,6 @@ BOOL CMraProto::GetPassDB_v2(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffS
return FALSE;
}
-BOOL CMraProto::GetPassDB(LPSTR lpszBuff, size_t dwBuffSize, size_t *pdwBuffSize)
-{
- #if /*defined (_DEBUG) ||*/ defined (REL_DEB)
- mraGetStaticStringA(NULL, "Pass", lpszBuff, dwBuffSize, pdwBuffSize);
- return TRUE;
- #else
- switch (getDword("pCryptVer", 0)) {
- case 1:
- return GetPassDB_v1(lpszBuff, dwBuffSize, pdwBuffSize);
- case 2:
- return GetPassDB_v2(lpszBuff, dwBuffSize, pdwBuffSize);
- default:
- return FALSE;
- }
- #endif
-}
-
DWORD ReplaceInBuff(LPVOID lpInBuff, size_t dwInBuffSize, size_t dwReplaceItemsCount, LPVOID *plpInReplaceItems, size_t *pdwInReplaceItemsCounts, LPVOID *plpOutReplaceItems, size_t *pdwOutReplaceItemsCounts, LPVOID lpOutBuff, size_t dwOutBuffSize, size_t *pdwOutBuffSize)
{
DWORD dwRetErrorCode = NO_ERROR;
diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp
index a733c433bf..08f933154d 100644
--- a/protocols/MRA/src/Mra_proto.cpp
+++ b/protocols/MRA/src/Mra_proto.cpp
@@ -1759,14 +1759,14 @@ DWORD CMraProto::MraRecvCommand_Message(DWORD dwTime, DWORD dwFlags, MRA_LPS *pl
// pre processing - extracting/decoding
if (dwFlags & MESSAGE_FLAG_AUTHORIZE) { // extract auth message из обычного текста
- size_t dwAuthPartsCount, dwAuthBuffSize = (plpsText->dwSize+32), dwAuthDataSize;
- LPBYTE lpbAuthData, lpbDataCurrent;
+ size_t dwAuthPartsCount, dwAuthBuffSize = (plpsText->dwSize+32);
+ LPBYTE lpbDataCurrent;
MRA_LPS lpsAuthFrom, lpsAuthMessage;
- lpbAuthData = (LPBYTE)mir_calloc(dwAuthBuffSize);
+ LPS2ANSI(szText, plpsText->lpszData, plpsText->dwSize);
+ unsigned dwAuthDataSize;
+ LPBYTE lpbAuthData = (LPBYTE)mir_base64_decode(szText, &dwAuthDataSize);
if (lpbAuthData) {
- BASE64DecodeFormated(plpsText->lpszData, plpsText->dwSize, lpbAuthData, dwAuthBuffSize, &dwAuthDataSize);
-
lpbDataCurrent = lpbAuthData;
dwAuthPartsCount = GetUL(&lpbDataCurrent);
if ( !GetLPS(lpbAuthData, dwAuthDataSize, &lpbDataCurrent, &lpsAuthFrom))
@@ -1809,14 +1809,15 @@ DWORD CMraProto::MraRecvCommand_Message(DWORD dwTime, DWORD dwFlags, MRA_LPS *pl
else {
if ((dwFlags & MESSAGE_FLAG_RTF) && plpsRFTText) //MESSAGE_FLAG_FLASH there
if (plpsRFTText->lpszData && plpsRFTText->dwSize) { // decode RTF
- size_t dwRTFPartsCount, dwCompressedSize, dwRFTBuffSize = ((plpsRFTText->dwSize*16)+8192), dwRTFDataSize;
- LPBYTE lpbRTFData, lpbCompressed, lpbDataCurrent;
+ size_t dwRTFPartsCount, dwRFTBuffSize = ((plpsRFTText->dwSize*16)+8192), dwRTFDataSize;
+ LPBYTE lpbDataCurrent;
MRA_LPS lpsRTFString, lpsBackColour, lpsString;
- lpbRTFData = (LPBYTE)mir_calloc(dwRFTBuffSize);
- lpbCompressed = (LPBYTE)mir_calloc((plpsRFTText->dwSize+32));
- if (lpbRTFData && lpbCompressed) {
- BASE64DecodeFormated(plpsRFTText->lpszData, plpsRFTText->dwSize, lpbCompressed, (plpsRFTText->dwSize+32), &dwCompressedSize);
+ mir_ptr<BYTE> lpbRTFData((LPBYTE)mir_calloc(dwRFTBuffSize));
+ if (lpbRTFData) {
+ LPS2ANSI(szRtf, plpsRFTText->lpszData, plpsRFTText->dwSize);
+ unsigned dwCompressedSize;
+ mir_ptr<BYTE> lpbCompressed((LPBYTE)mir_base64_decode(szRtf, &dwCompressedSize));
dwRTFDataSize = dwRFTBuffSize;
if ( uncompress(lpbRTFData, (DWORD*)&dwRTFDataSize, lpbCompressed, dwCompressedSize) == Z_OK) {
lpbDataCurrent = lpbRTFData;
@@ -1867,8 +1868,6 @@ DWORD CMraProto::MraRecvCommand_Message(DWORD dwTime, DWORD dwFlags, MRA_LPS *pl
DebugBreak();
}
}
- mir_free(lpbCompressed);
- mir_free(lpbRTFData);
}
}
}
diff --git a/protocols/MRA/src/Sdk/Base64.h b/protocols/MRA/src/Sdk/Base64.h
deleted file mode 100644
index d3cce03e9a..0000000000
--- a/protocols/MRA/src/Sdk/Base64.h
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * Copyright (c) 2003 Rozhuk Ivan <rozhuk.im@gmail.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-
-#if !defined(AFX_BASE64__H__INCLUDED_)
-#define AFX_BASE64__H__INCLUDED_
-
-
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-
-
-//typedef unsigned char BYTE;
-//
-// BASE64 coding:
-// 214 46 138
-// 11010100 00101110 10001010
-// ! ! !
-// ---------->>> convert 3 8bit to 4 6bit
-// 110101 000010 111010 001010
-// 53 2 58 10
-// this numbers is offset in array coding below...
-//
- //01234567890123456789012345
-static BYTE *pbtCodingTableBASE64=(BYTE*)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; //52...63
-static BYTE btDeCodingTableBASE64[256]={64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63,52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,64,0,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,64,64,64,64,64,64,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,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64};
-
-
-
-
-__inline void BASE64CopyUnSafe(LPCVOID lpcSource,LPCVOID lpcDestination,size_t dwSize,size_t *pdwCopyedSize)
-{// копируем только б64 символы
- LPBYTE lpbSource,lpbDestination;
-
- lpbSource=(LPBYTE)lpcSource;
- lpbDestination=(LPBYTE)lpcDestination;
- while(dwSize--)
- {
- if ((*lpbSource)>32 && (*lpbSource)<128) (*lpbDestination++)=(*lpbSource);
- lpbSource++;
- }
- if (pdwCopyedSize) (*pdwCopyedSize)=((size_t)lpbDestination-(size_t)lpcDestination);
-}
-
-
-
-__inline DWORD BASE64EncodeUnSafe(LPCVOID lpcSource,size_t dwSourceSize,LPCVOID lpcDestination,size_t dwDestinationSize,size_t *pdwEncodedSize)
-{// BASE64 кодирование
- DWORD dwRetErrorCode;
- size_t dwEncodedSize=((dwSourceSize*4+11)/12*4+1);//(((dwSourceSize+2)/3)*4);
-
- if ((dwDestinationSize<dwEncodedSize))
- {// выходной буффер слишком мал
- dwRetErrorCode=ERROR_INSUFFICIENT_BUFFER;
- }else{// размер выходного буффера достаточен
- dwEncodedSize=0;
- if(lpcSource && lpcDestination && dwSourceSize)
- {
-#ifdef _WIN64
- LPBYTE lpbtSource=(LPBYTE)lpcSource,lpbtDestination=(LPBYTE)lpcDestination;
- size_t i;
-
- for (i=0;i<dwSourceSize;i+=3)
- {
- *(lpbtDestination++)=pbtCodingTableBASE64[(*lpbtSource)>>2]; // c1
- *(lpbtDestination++)=pbtCodingTableBASE64[(((*lpbtSource)<<4)&060) | ((lpbtSource[1]>>4)&017)]; // c2
- *(lpbtDestination++)=pbtCodingTableBASE64[((lpbtSource[1]<<2)&074) | ((lpbtSource[2]>>6)&03)]; // c3
- *(lpbtDestination++)=pbtCodingTableBASE64[lpbtSource[2] & 077]; // c4
- lpbtSource+=3;
- }
-
- // If dwSourceSize was not a multiple of 3, then we have encoded too many characters. Adjust appropriately.
- if(i==(dwSourceSize+1))
- {// There were only 2 bytes in that last group
- lpbtDestination[-1]='=';
- }else
- if(i==(dwSourceSize+2))
- {// There was only 1 byte in that last group
- lpbtDestination[-1]='=';
- lpbtDestination[-2]='=';
- }
-
- (*lpbtDestination)=0;
- dwEncodedSize=(lpbtDestination-((LPBYTE)lpcDestination));
-
-#else
- __asm{
- push ebx // сохраняем регистр
- push edi // сохраняем регистр
- push esi // сохраняем регистр
-
- mov ebx,pbtCodingTableBASE64// ebx = адрес таблицы перекодировки
- mov ecx,dwSourceSize // ecx = длинна входного буффера
- mov edi,lpcDestination // edi = адрес выходного буффера
- mov esi,lpcSource // esi = указатель на входной буффер
- cld
- jmp short read_loop_cmp
-
- //////////Code function///////////////////////////////////////////
- // функция кодировки
- // eax - входящий буффер, используется только 3 байта //in buff, 3 byte used
- // eax - выходящий буффер, используется 4 байта //out buff, 4 byte used
- code_func:
- // третья версия функции разложения,
- // меняем местами два крайних байта
- bswap eax
- rol eax,6
- shl al,2
- ror eax,10
- shr ax,2
- shr al,2
- xlat
- rol eax,8
- xlat
- rol eax,8
- xlat
- rol eax,8
- xlat
- rol eax,8
- bswap eax// 188-235
- ret
- //////////////////////////////////////////////////////////////////
-
- /////////////Read & converting cycle//////////////////////////////
- read_loop:
- lodsd // читаем 4 байта
- dec esi // используем только 3
- and eax,0x00FFFFFF
- //====================================================
- // третья версия функции разложения,
- // меняем местами два крайних байта
- bswap eax
- rol eax,6
- shl al,2
- ror eax,10
- shr ax,2
- shr al,2
- xlat
- rol eax,8
- xlat
- rol eax,8
- xlat
- rol eax,8
- xlat
- rol eax,8
- bswap eax
- //====================================================
- stosd
- sub ecx,3
-
- read_loop_cmp:
- cmp ecx,3 // проверяем, чтобы длинна была как минимум 4 байта
- jg short read_loop // если длинна 3 и более байт, то продолжаем дальше
-
- /////////////////////////////////////////////////////////////////
- xor eax,eax // обнуляем регистр
- cmp ecx,3 // сравниваем длинну с 3
- je short tree_byte_tail// если длинна 3 байта, то переходим к функции обрабатывающей остаток такой длинны
- cmp ecx,2 // сравниваем длинну с 2
- je short two_byte_tail // если длинна 2 байта, то переходим к функции обрабатывающей остаток такой длинны
- // иначе, длинна остатка равна 1
- //////////tail 1 byte////////////////////////////////////////////
- mov al,byte ptr [esi] // читаем 1 байт
- call code_func // преобразуем
- and eax,0x0000FFFF // обнуляем последние два байта
- or eax,0x3D3D0000 // записываем в последние два байта 61("=")
- jmp short end_tail_handler //
-
- //////////tail 2 byte////////////////////////////////////////////
- two_byte_tail:
- mov ax,word ptr [esi] // читаем 2 байта
- call code_func // преобразуем
- and eax,0x00FFFFFF // обнуляем последний байт
- or eax,0x3D000000 // записываем в последний байт 61("=")
- jmp short end_tail_handler //
-
- //////////tail 3 byte////////////////////////////////////////////
- tree_byte_tail:
- lodsw
- ror eax,16
- mov al,byte ptr [esi] // читаем 1 байт
- rol eax,16
- call code_func // преобразуем
-
- end_tail_handler:
- stosd // записываем 4 байта, уже закодированных
-
- sub edi,lpcDestination // вычисляем колличество байт, записанных в выходной буффер
- mov dwEncodedSize,edi // записываем колличество байт в возвращаемую переменную
- pop esi // восстанавливаем содержимое регистра
- pop edi // восстанавливаем содержимое регистра
- pop ebx // восстанавливаем содержимое регистра
- }
-#endif
- dwRetErrorCode=NO_ERROR;
- }else{
- dwRetErrorCode=ERROR_INVALID_HANDLE;
- }
- }
- if (pdwEncodedSize) (*pdwEncodedSize)=dwEncodedSize;
-
-return(dwRetErrorCode);
-}
-
-
-__inline DWORD BASE64Encode(LPCVOID lpcSource,size_t dwSourceSize,LPCVOID lpcDestination,size_t dwDestinationSize,size_t *pdwEncodedSize)
-{// BASE64 кодирование
- DWORD dwRetErrorCode;
-
- __try
- {
- dwRetErrorCode=BASE64EncodeUnSafe(lpcSource,dwSourceSize,lpcDestination,dwDestinationSize,pdwEncodedSize);
- }__except(EXCEPTION_EXECUTE_HANDLER){
- dwRetErrorCode=ERROR_INVALID_ADDRESS;
- }
-return(dwRetErrorCode);
-}
-
-
-
-__inline DWORD BASE64DecodeUnSafe(LPCVOID lpcSource,size_t dwSourceSize,LPCVOID lpcDestination,size_t dwDestinationSize,size_t *pdwDecodedSize)
-{// BASE64 декодирование
- DWORD dwRetErrorCode;
- size_t dwDecodedSize=((dwSourceSize>>2)*3);// ((dwSourceSize/4)*3);
-
- if ((dwDestinationSize<dwDecodedSize))
- {// выходной буффер слишком мал
- dwRetErrorCode=ERROR_INSUFFICIENT_BUFFER;
- }else{// размер выходного буффера достаточен
- dwDecodedSize=0;
- if(lpcSource && lpcDestination)
- {// буффера в порядке
- if (dwSourceSize>3)
- {
-#ifdef _WIN64
- LPBYTE lpbtSource=(LPBYTE)lpcSource,lpbtDestination=(LPBYTE)lpcDestination;
-
- for(size_t i=0;i<dwSourceSize;i+=4)
- {
- *(lpbtDestination++)=(unsigned char) (btDeCodingTableBASE64[(*lpbtSource)] << 2 | btDeCodingTableBASE64[lpbtSource[1]] >> 4);
- *(lpbtDestination++)=(unsigned char) (btDeCodingTableBASE64[lpbtSource[1]] << 4 | btDeCodingTableBASE64[lpbtSource[2]] >> 2);
- *(lpbtDestination++)=(unsigned char) (btDeCodingTableBASE64[lpbtSource[2]] << 6 | btDeCodingTableBASE64[lpbtSource[3]]);
- lpbtSource+=4;
- }
-
- dwDecodedSize=(lpbtDestination-((LPBYTE)lpcDestination));
- if ((*((BYTE*)lpcSource+(dwSourceSize-1)))=='=') dwDecodedSize--;
- if ((*((BYTE*)lpcSource+(dwSourceSize-2)))=='=') dwDecodedSize--;
-
-
-#else
- __asm{
- push ebx // сохраняем регистр
- push edi // сохраняем регистр
- push esi // сохраняем регистр
-
- mov ebx,offset btDeCodingTableBASE64// ebx = адрес таблицы перекодировки
- mov ecx,dwSourceSize // ecx = длинна входного буффера
- mov edi,lpcDestination // edi = адрес выходного буффера
- mov esi,lpcSource // esi = указатель на входной буффер
- cld
-
- read_loop:
- lodsd // читаем 4 байта
- //===============bit conversion====================================
- // eax - входящий буффер, используется только 4 байта //in buff, 4 byte used
- // eax - выходящий буффер, используется только 3 байта //out buff, 3 byte used
- // третья версия функции сложения бит
- bswap eax
-
- ror eax,8
- xlat
-
- ror eax,8
- xlat
-
- ror eax,8
- xlat
-
- ror eax,8
- xlat
-
- shl al,2
- shl ax,2
- rol eax,10
- shr al,2
- ror eax,6
- bswap eax
- mov edx,eax
- //234-250
- //===============================================================
- stosd
- dec edi
- sub ecx,4
- cmp ecx,3
- jg short read_loop
-
- sub edi,lpcDestination // вычисляем колличество байт, записанных в выходной буффер
- mov dwDecodedSize,edi // записываем колличество байт в возвращаемую переменную
- pop esi // восстанавливаем содержимое регистра
- pop edi // восстанавливаем содержимое регистра
- pop ebx // восстанавливаем содержимое регистра
- }
-
- if ((*((BYTE*)lpcSource+(dwSourceSize-1)))=='=') dwDecodedSize--;
- if ((*((BYTE*)lpcSource+(dwSourceSize-2)))=='=') dwDecodedSize--;
-#endif
- dwRetErrorCode=NO_ERROR;
- }else{// во входном буффере слишком мало данных
- dwRetErrorCode=ERROR_INSUFFICIENT_BUFFER;
- }
- }else{
- dwRetErrorCode=ERROR_INVALID_HANDLE;
- }
- }
-
- if (pdwDecodedSize) (*pdwDecodedSize)=dwDecodedSize;
-return(dwRetErrorCode);
-}
-
-
-__inline DWORD BASE64Decode(LPCVOID lpcSource,size_t dwSourceSize,LPCVOID lpcDestination,size_t dwDestinationSize,size_t *pdwDecodedSize)
-{// BASE64 декодирование
- DWORD dwRetErrorCode;
-
- __try
- {
- dwRetErrorCode=BASE64DecodeUnSafe(lpcSource,dwSourceSize,lpcDestination,dwDestinationSize,pdwDecodedSize);
- }__except(EXCEPTION_EXECUTE_HANDLER){
- dwRetErrorCode=ERROR_INVALID_ADDRESS;
- }
-return(dwRetErrorCode);
-}
-
-
-__inline DWORD BASE64DecodeFormated(LPCVOID lpcSource,size_t dwSourceSize,LPCVOID lpcDestination,size_t dwDestinationSize,size_t *pdwDecodedSize)
-{// BASE64 декодирование и игнорирование форматирования
- DWORD dwRetErrorCode;
-
- if (dwSourceSize<=dwDestinationSize)
- {
- BASE64CopyUnSafe(lpcSource,lpcDestination,dwSourceSize,&dwSourceSize);
- dwRetErrorCode=BASE64DecodeUnSafe(lpcDestination,dwSourceSize,lpcDestination,dwDestinationSize,pdwDecodedSize);
- }else{// во входном буффере слишком мало данных
- dwRetErrorCode=ERROR_INSUFFICIENT_BUFFER;
- }
-
-return(dwRetErrorCode);
-}
-
-
-
-#endif // !defined(AFX_BASE64__H__INCLUDED_)
diff --git a/protocols/MRA/src/Sdk/SHA1.h b/protocols/MRA/src/Sdk/SHA1.h
index f7d4643d32..61f6c58399 100644
--- a/protocols/MRA/src/Sdk/SHA1.h
+++ b/protocols/MRA/src/Sdk/SHA1.h
@@ -25,7 +25,6 @@
*
*/
-
#if !defined(AFX__SHA1_H__INCLUDED_)
#define AFX__SHA1_H__INCLUDED_
@@ -33,92 +32,20 @@
#pragma once
#endif // _MSC_VER > 1000
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+//////////////////////////////RFC 2104//////////////////////////////
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+void hmac_sha1(BYTE *text,size_t text_len,BYTE *key,size_t key_len,BYTE *digest);
-// see
-// RFC 3174 - SHA1
-// RFC 2104 - HMAC
-// RFC 2617 - CvtHex
-
-
-
-#define SHA1HashSize 20
-#define SHA1HashHexSize 40
-
-/* This structure will hold context information for the SHA-1 hashing operation */
-typedef struct SHA1Context
-{
- DWORD Intermediate_Hash[SHA1HashSize/4];/* Message Digest */
- ULARGE_INTEGER Length; /* Message length in bits */
- BYTE Message_Block[64]; /* 512-bit message blocks */
- BOOL Computed; /* Is the digest computed? */
-} SHA1Context;
-
-
-#ifdef UNICODE
- #define SHA1HMACGetString SHA1HMACGetStringW
- #define SHA1GetStringDigest SHA1GetStringDigestW
- #define SHA1CvtString SHA1CvtStringW
-#else
- #define SHA1HMACGetString SHA1HMACGetStringA
- #define SHA1GetStringDigest SHA1GetStringDigestA
- #define SHA1CvtString SHA1CvtStringA
-#endif
-
-
-#ifndef SHA1_MAX_SPEED
- #ifdef SecureZeroMemory
- #define SHA1SecureZeroMemory SecureZeroMemory
- #else
- #define SHA1SecureZeroMemory bzero
- #endif
-#else
- #define SHA1SecureZeroMemory
-#endif
-
-
-/*
- * Description:
- * This file implements the Secure Hashing Algorithm 1 as
- * defined in FIPS PUB 180-1 published April 17, 1995.
- *
- * The SHA-1, produces a 160-bit message digest for a given
- * data stream. It should take about 2**n steps to find a
- * message with the same digest as a given message and
- * 2**(n/2) to find any two messages with the same digest,
- * when n is the digest size in bits. Therefore, this
- * algorithm can serve as a means of providing a
- * "fingerprint" for a message.
- *
- * Portability Issues:
- * SHA-1 is defined in terms of 32-bit "words". This code
- * uses <stdint.h> (included via "sha1.h" to define 32 and 8
- * bit unsigned integer types. If your C compiler does not
- * support 32 bit unsigned integers, this code is not
- * appropriate.
- *
- * Caveats:
- * SHA-1 is designed to work with messages less than 2^64 bits
- * long. Although SHA-1 allows a message digest to be generated
- * for messages of any number of bits less than 2^64, this
- * implementation only works with messages with a length that is
- * a multiple of the size of an 8-bit character.
- *
- */
-
-
-
-/* Define the SHA1 circular left shift macro */
-#define SHA1CircularShift(bits,word) (((word) << (bits)) | ((word) >> (32-(bits))))
-
-/* Local Function Prototyptes */
-//void SHA1PadMessage(SHA1Context *);
-//void SHA1ProcessMessageBlock(SHA1Context *);
-
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
__inline DWORD BSWAP(DWORD dwIn)
{
-return((((dwIn<<8) & 0x00ff0000) | (dwIn<<24) | ((dwIn>>8) & 0x0000ff00) | (dwIn>>24)));
+ return((((dwIn<<8) & 0x00ff0000) | (dwIn<<24) | ((dwIn>>8) & 0x0000ff00) | (dwIn>>24)));
}
__inline void CopyMemoryReverseDWORD(LPCVOID lpcDestination,LPCVOID lpcSource,size_t dwSize)
@@ -152,445 +79,16 @@ __inline void CopyMemoryReverseDWORD(LPCVOID lpcDestination,LPCVOID lpcSource,si
#endif
}
-
-
-/*
-* SHA1ProcessMessageBlock
-*
-* Description:
-* This function will process the next 512 bits of the message
-* stored in the Message_Block array.
-*
-* Parameters:
-* None.
-*
-* Returns:
-* Nothing.
-*
-* Comments:
-* Many of the variable names in this code, especially the
-* single character names, were used because those were the
-* names used in the publication.
-*
-*
-*/
-__inline void SHA1ProcessMessageBlock(SHA1Context *context,BYTE *Message_Block)
-{
- /* Constants defined in SHA-1 */
- const DWORD K[]={0x5A827999,0x6ED9EBA1,0x8F1BBCDC,0xCA62C1D6};
- DWORD t; /* Loop counter */
- DWORD temp; /* Temporary word value */
- DWORD W[80]; /* Word sequence */
- DWORD A=context->Intermediate_Hash[0],/* Word buffers */
- B=context->Intermediate_Hash[1],
- C=context->Intermediate_Hash[2],
- D=context->Intermediate_Hash[3],
- E=context->Intermediate_Hash[4];
-
- /* Initialize the first 16 words in the array W */
- CopyMemoryReverseDWORD(W,Message_Block,64);
-
- for(t=16;t<80;t++)
- {
- W[t]=SHA1CircularShift(1,W[t-3]^W[t-8]^W[t-14]^W[t-16]);
- }
-
- for(t=0;t<20;t++)
- {
- temp=SHA1CircularShift(5,A) + ((B&C) | ((~B)&D)) + E + W[t] + K[0];
- E=D;
- D=C;
- C=SHA1CircularShift(30,B);
- B=A;
- A=temp;
- }
-
- for(t=20;t<40;t++)
- {
- temp=SHA1CircularShift(5,A) + (B^C^D) + E + W[t] + K[1];
- E=D;
- D=C;
- C=SHA1CircularShift(30,B);
- B=A;
- A=temp;
- }
-
- for(t=40;t<60;t++)
- {
- temp=SHA1CircularShift(5,A) + ((B&C) | (B&D) | (C&D)) + E + W[t] + K[2];
- E=D;
- D=C;
- C=SHA1CircularShift(30,B);
- B=A;
- A=temp;
- }
-
- for(t=60;t<80;t++)
- {
- temp=SHA1CircularShift(5,A) + (B^C^D) + E + W[t] + K[3];
- E=D;
- D=C;
- C=SHA1CircularShift(30,B);
- B=A;
- A=temp;
- }
-
- context->Intermediate_Hash[0]+=A;
- context->Intermediate_Hash[1]+=B;
- context->Intermediate_Hash[2]+=C;
- context->Intermediate_Hash[3]+=D;
- context->Intermediate_Hash[4]+=E;
-
- /* Zeroize sensitive information.*/
- SHA1SecureZeroMemory(W,sizeof(W));
-}
-
-
-/*
-* SHA1PadMessage
-*
-* Description:
-* According to the standard, the message must be padded to an even
-* 512 bits. The first padding bit must be a '1'. The last 64
-* bits represent the length of the original message. All bits in
-* between should be 0. This function will pad the message
-* according to those rules by filling the Message_Block array
-* accordingly. It will also call the ProcessMessageBlock function
-* provided appropriately. When it returns, it can be assumed that
-* the message digest has been computed.
-*
-* Parameters:
-* context: [in/out]
-* The context to pad
-* ProcessMessageBlock: [in]
-* The appropriate SHA*ProcessMessageBlock function
-* Returns:
-* Nothing.
-*
-*/
-__inline void SHA1PadMessage(SHA1Context *context)
-{
- /*
- * Check to see if the current message block is too small to hold
- * the initial padding bits and length. If so, we will pad the
- * block, process it, and then continue padding into a second
- * block.
- */
- size_t Message_Block_Index=(size_t)((context->Length.LowPart>>3) & 0x3F);
- context->Message_Block[Message_Block_Index++]=0x80;
- if (Message_Block_Index>56)
- {
- memset(&context->Message_Block[Message_Block_Index], 0, (64-Message_Block_Index));
- SHA1ProcessMessageBlock(context,context->Message_Block);
- memset(&context->Message_Block, 0, 56);
- }else{
- memset(&context->Message_Block[Message_Block_Index], 0, (56-Message_Block_Index));
- }
-
- /* Store the message length as the last 8 octets */
- context->Message_Block[56]=(BYTE)(context->Length.HighPart>>24);
- context->Message_Block[57]=(BYTE)(context->Length.HighPart>>16);
- context->Message_Block[58]=(BYTE)(context->Length.HighPart>>8);
- context->Message_Block[59]=(BYTE)(context->Length.HighPart);
- context->Message_Block[60]=(BYTE)(context->Length.LowPart>>24);
- context->Message_Block[61]=(BYTE)(context->Length.LowPart>>16);
- context->Message_Block[62]=(BYTE)(context->Length.LowPart>>8);
- context->Message_Block[63]=(BYTE)(context->Length.LowPart);
-
- SHA1ProcessMessageBlock(context,context->Message_Block);
-}
-
-
-
-/*
-* SHA1Reset
-*
-* Description:
-* This function will initialize the SHA1Context in preparation
-* for computing a new SHA1 message digest.
-*
-* Parameters:
-* context: [in/out]
-* The context to reset.
-*
-* Returns:
-* sha Error Code.
-*
-*/
-__inline DWORD SHA1Reset(SHA1Context *context)
-{
- context->Intermediate_Hash[0]=0x67452301;
- context->Intermediate_Hash[1]=0xEFCDAB89;
- context->Intermediate_Hash[2]=0x98BADCFE;
- context->Intermediate_Hash[3]=0x10325476;
- context->Intermediate_Hash[4]=0xC3D2E1F0;
- context->Length.QuadPart=0;
- context->Computed=FALSE;
-
-return(NO_ERROR);
-}
-
-/*
-* SHA1Result
-*
-* Description:
-* This function will return the 160-bit message digest into the
-* Message_Digest array provided by the caller.
-* NOTE: The first octet of hash is stored in the 0th element,
-* the last octet of hash in the 19th element.
-*
-* Parameters:
-* context: [in/out]
-* The context to use to calculate the SHA-1 hash.
-* Message_Digest: [out]
-* Where the digest is returned.
-*
-* Returns:
-* sha Error Code.
-*
-*/
-__inline DWORD SHA1Result(SHA1Context *context,BYTE *Message_Digest)
-{
- if (context->Computed==FALSE)
- {
- SHA1PadMessage(context);
- SHA1SecureZeroMemory(context->Message_Block,64);/* message may be sensitive, clear it out */
- context->Length.QuadPart=0; /* and clear length */
- context->Computed=TRUE;
- }
-
- CopyMemoryReverseDWORD(Message_Digest,context->Intermediate_Hash,SHA1HashSize);
-
-return(NO_ERROR);
-}
-
-/*
-* SHA1Input
-*
-* Description:
-* This function accepts an array of octets as the next portion
-* of the message.
-*
-* Parameters:
-* context: [in/out]
-* The SHA context to update
-* message_array: [in]
-* An array of characters representing the next portion of
-* the message.
-* length: [in]
-* The length of the message in message_array
-*
-* Returns:
-* sha Error Code.
-*
-*/
-__inline DWORD SHA1Input(SHA1Context *context,const BYTE *message_array,size_t length)
-{
- if (context->Computed==TRUE) return(ERROR_INVALID_HANDLE_STATE);
-
- if ((context->Length.QuadPart+(length<<3))>=(length<<3))
- {
- size_t i,Message_Block_Index,partLen;
- /* Compute number of bytes mod 64 */
- Message_Block_Index=(size_t)((context->Length.LowPart>>3) & 0x3F);
- /* Update number of bits */
- context->Length.QuadPart+=(((ULONGLONG)length)<<3);
- partLen=(64-Message_Block_Index);
- /* Transform as many times as possible.*/
- if (length>=partLen)
- {
- memmove(&context->Message_Block[Message_Block_Index],message_array,partLen);
- SHA1ProcessMessageBlock(context,context->Message_Block);
- for (i=partLen;(i+63)<length;i+=64) SHA1ProcessMessageBlock(context,(BYTE*)&message_array[i]);
- Message_Block_Index=0;
- }else{
- i=0;
- }
- /* Buffer remaining input */
- memmove(&context->Message_Block[Message_Block_Index],&message_array[i],(length-i));
- }else{
- return(RPC_S_STRING_TOO_LONG);/* Message is too long */
- }
-return(NO_ERROR);
-}
-////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////
-//////////////////////////////RFC 2104//////////////////////////////
-////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////
-__inline void hmac_sha1(BYTE *text,size_t text_len,BYTE *key,size_t key_len,BYTE *digest)
-{
-//BYTE* text; /* pointer to data stream */
-//int text_len; /* length of data stream */
-//BYTE* key; /* pointer to authentication key */
-//int key_len; /* length of authentication key */
-//HASH digest; /* caller digest to be filled in */
- SHA1Context context;
- BYTE k_ipad[65]; /* inner padding - key XORd with ipad */
- BYTE k_opad[65]; /* outer padding - key XORd with opad */
- BYTE tk[SHA1HashSize];
- /* if key is longer than 64 bytes reset it to key=SHA1(key) */
- if (key_len>64)
- {
- SHA1Context tctx;
-
- SHA1Reset(&tctx);
- SHA1Input(&tctx,key,key_len);
- SHA1Result(&tctx,(BYTE*)&tk);
-
- key=tk;
- key_len=SHA1HashSize;
- }
-
- /*
- * the HMAC_SHA1 transform looks like:
- *
- * SHA1(K XOR opad, SHA1(K XOR ipad, text))
- *
- * where K is an n byte key
- * ipad is the byte 0x36 repeated 64 times
- * opad is the byte 0x5c repeated 64 times
- * and text is the data being protected
- */
-
- /* start out by storing key in pads */
- memmove(&k_ipad,key,key_len);
- memmove(&k_opad,key,key_len);
- memset(&k_ipad[key_len], 0, (sizeof(k_ipad)-key_len));
- memset(&k_opad[key_len], 0 , (sizeof(k_opad)-key_len));
-
- /* XOR key with ipad and opad values */
- for (size_t i=0;i<(64/sizeof(ULONGLONG));i++)
- {
- ((ULONGLONG*)k_ipad)[i]^=0x3636363636363636;
- ((ULONGLONG*)k_opad)[i]^=0x5C5C5C5C5C5C5C5C;
- }
- /* perform inner SHA1 */
- SHA1Reset(&context); /* init context for 1st pass */
- SHA1Input(&context,k_ipad,64); /* start with inner pad */
- SHA1Input(&context,text,text_len); /* then text of datagram */
- SHA1Result(&context,digest); /* finish up 1st pass */
- /* perform outer SHA1 */
- SHA1Reset(&context); /* init context for 2nd pass */
- SHA1Input(&context,k_opad,64); /* start with outer pad */
- SHA1Input(&context,(BYTE*)digest,SHA1HashSize); /* then results of 1st hash */
- SHA1Result(&context,digest); /* finish up 2nd pass */
-
- SHA1SecureZeroMemory(k_ipad,sizeof(k_ipad));
- SHA1SecureZeroMemory(k_opad,sizeof(k_opad));
- SHA1SecureZeroMemory(tk,sizeof(tk));
-}
-////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////
-//////////////////////////////RFC 2617//////////////////////////////
-////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////
-__inline void SHA1CvtHex(BYTE *Bin,BYTE *Hex)
-{
- BYTE j;
-
- for (size_t i=0;i<SHA1HashSize;i++)
- {
- j=(Bin[i]>>4)&0xf;
- if(j<=9)
- {
- Hex[(i*2)]=(j+'0');
- }else{
- Hex[(i*2)]=(j+'a'-10);
- }
-
- j=Bin[i]&0xf;
- if(j<=9)
- {
- Hex[(i*2+1)]=(j+'0');
- }else{
- Hex[(i*2+1)]=(j+'a'-10);
- }
- };
- Hex[SHA1HashHexSize]=0;
-};
-
-////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////
-__inline void SHA1CvtStringA(BYTE *digest,LPSTR lpszDigest)
-{
- SHA1CvtHex(digest,(BYTE*)lpszDigest);
-};
-
-
-__inline void SHA1CvtStringW(BYTE *digest,LPWSTR lpszDigest)
-{
- size_t i,p=0;
- for (i=0;i<SHA1HashSize;i++,p+=2)
- {
- wsprintfW((LPWSTR)(lpszDigest+p),L"%02x",digest[i]);
- }
- lpszDigest[SHA1HashHexSize]=0;
-};
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////
-__inline void SHA1HMACGetDigest(LPVOID lpBuff,size_t dwBuffSize,LPVOID lpKey,size_t dwKeySize,BYTE *digest)
-{
- hmac_sha1((BYTE*)lpBuff,dwBuffSize,(BYTE*)lpKey,dwKeySize,digest);
-}
-
-
-__inline void SHA1HMACGetStringA(LPSTR lpszBuff,size_t dwBuffSize,LPSTR lpszKey,size_t dwKeySize,LPSTR lpszDigest)
-{
- BYTE digest[SHA1HashSize];
- hmac_sha1((BYTE*)lpszBuff,dwBuffSize,(BYTE*)lpszKey,dwKeySize,digest);
- SHA1CvtHex(digest,(BYTE*)lpszDigest);
-}
-
-
-__inline void SHA1HMACGetStringW(LPWSTR lpszBuff,size_t dwBuffSize,LPWSTR lpszKey,size_t dwKeySize,LPWSTR lpszDigest)
-{
- BYTE digest[SHA1HashSize];
- hmac_sha1((BYTE*)lpszBuff,dwBuffSize,(BYTE*)lpszKey,dwKeySize,digest);
- SHA1CvtStringW(digest,lpszDigest);
-}
-
-
__inline void SHA1GetDigest(LPVOID lpBuff,size_t dwBuffSize,BYTE *digest)
{
- SHA1Context sha;
+ mir_sha1_ctx sha;
- SHA1Reset(&sha);
- SHA1Input(&sha,(BYTE*)lpBuff,dwBuffSize);
- SHA1Result(&sha,digest);
+ mir_sha1_init(&sha);
+ mir_sha1_append(&sha,(BYTE*)lpBuff,dwBuffSize);
+ mir_sha1_finish(&sha,digest);
}
-
-__inline void SHA1GetStringDigestA(LPSTR lpszBuff,size_t dwBuffSize,LPSTR lpszDigest)
-{
- SHA1Context sha;
- BYTE digest[SHA1HashSize];
-
- SHA1Reset(&sha);
- SHA1Input(&sha,(BYTE*)lpszBuff,dwBuffSize);
- SHA1Result(&sha,digest);
-
- SHA1CvtHex(digest,(BYTE*)lpszDigest);
-}
-
-
-__inline void SHA1GetStringDigestW(LPWSTR lpszBuff,size_t dwBuffSize,LPWSTR lpszDigest)
-{
- SHA1Context sha;
- BYTE digest[SHA1HashSize];
-
- SHA1Reset(&sha);
- SHA1Input(&sha,(BYTE*)lpszBuff,dwBuffSize);
- SHA1Result(&sha,digest);
-
- SHA1CvtStringW(digest,lpszDigest);
-}
-
-
-
-
-#endif //AFX__SHA1_H__INCLUDED_ \ No newline at end of file
+#endif //AFX__SHA1_H__INCLUDED_