summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-08-15 14:29:13 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-08-15 14:29:13 +0000
commit9a245d98a67b303dcbe22664296f18ab327e95b6 (patch)
treedb2a4391286af5b68733a0a1ec518163f4f042fc /protocols
parent21c56b9074fbfdacba112a51ae3b54edfa243e59 (diff)
missing file added
git-svn-id: http://svn.miranda-ng.org/main/trunk@5703 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/MRA/Mra_10.vcxproj1
-rw-r--r--protocols/MRA/Mra_10.vcxproj.filters3
-rw-r--r--protocols/MRA/src/MraUtils.cpp60
3 files changed, 64 insertions, 0 deletions
diff --git a/protocols/MRA/Mra_10.vcxproj b/protocols/MRA/Mra_10.vcxproj
index ec5727dd76..11bacd5c3a 100644
--- a/protocols/MRA/Mra_10.vcxproj
+++ b/protocols/MRA/Mra_10.vcxproj
@@ -187,6 +187,7 @@
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="src\MraUtils.cpp" />
<ClCompile Include="src\stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
diff --git a/protocols/MRA/Mra_10.vcxproj.filters b/protocols/MRA/Mra_10.vcxproj.filters
index ed7f4006e4..e674ed722d 100644
--- a/protocols/MRA/Mra_10.vcxproj.filters
+++ b/protocols/MRA/Mra_10.vcxproj.filters
@@ -78,6 +78,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">
diff --git a/protocols/MRA/src/MraUtils.cpp b/protocols/MRA/src/MraUtils.cpp
new file mode 100644
index 0000000000..d35255d4a9
--- /dev/null
+++ b/protocols/MRA/src/MraUtils.cpp
@@ -0,0 +1,60 @@
+#include "Mra.h"
+#include "MraSendQueue.h"
+
+void hmac_sha1(BYTE *text,size_t text_len,BYTE *key,size_t key_len,BYTE *digest)
+{
+ mir_sha1_ctx context;
+ BYTE k_ipad[65]; /* inner padding - key XORd with ipad */
+ BYTE k_opad[65]; /* outer padding - key XORd with opad */
+ BYTE tk[MIR_SHA1_HASH_SIZE];
+ /* if key is longer than 64 bytes reset it to key=SHA1(key) */
+ if (key_len>64)
+ {
+ mir_sha1_ctx tctx;
+
+ mir_sha1_init(&tctx);
+ mir_sha1_append(&tctx,key,key_len);
+ mir_sha1_finish(&tctx,(BYTE*)&tk);
+
+ key=tk;
+ key_len=MIR_SHA1_HASH_SIZE;
+ }
+
+ /*
+ * 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 */
+ mir_sha1_init(&context); /* init context for 1st pass */
+ mir_sha1_append(&context,k_ipad,64); /* start with inner pad */
+ mir_sha1_append(&context,text,text_len); /* then text of datagram */
+ mir_sha1_finish(&context,digest); /* finish up 1st pass */
+ /* perform outer SHA1 */
+ mir_sha1_init(&context); /* init context for 2nd pass */
+ mir_sha1_append(&context,k_opad,64); /* start with outer pad */
+ mir_sha1_append(&context,(BYTE*)digest,MIR_SHA1_HASH_SIZE); /* then results of 1st hash */
+ mir_sha1_finish(&context,digest); /* finish up 2nd pass */
+
+ bzero(k_ipad,sizeof(k_ipad));
+ bzero(k_opad,sizeof(k_opad));
+ bzero(tk,sizeof(tk));
+}