summaryrefslogtreecommitdiff
path: root/plugins/SecureIM/src/crypt_dll.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-07-08 15:49:18 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-07-08 15:49:18 +0000
commit62ab18a9fda2f19c08ae63a14c7a262ca62f0cce (patch)
tree821876224af8cb3e3f4b9b29ea3237212cde37e7 /plugins/SecureIM/src/crypt_dll.cpp
parent19a5e6f0b9c3232933132dbaa9420aecef497336 (diff)
code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@9732 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SecureIM/src/crypt_dll.cpp')
-rw-r--r--plugins/SecureIM/src/crypt_dll.cpp117
1 files changed, 57 insertions, 60 deletions
diff --git a/plugins/SecureIM/src/crypt_dll.cpp b/plugins/SecureIM/src/crypt_dll.cpp
index 67a03a609c..9390367d93 100644
--- a/plugins/SecureIM/src/crypt_dll.cpp
+++ b/plugins/SecureIM/src/crypt_dll.cpp
@@ -1,24 +1,24 @@
#include "commonheaders.h"
// generate KeyA pair and return public key
-LPSTR InitKeyA(pUinKey ptr,int features)
+LPSTR InitKeyA(pUinKey ptr, int features)
{
Sent_NetLog("InitKeyA: %04x", features);
- if (!ptr->cntx )
- ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0);
+ if (!ptr->cntx)
+ ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact) ? CPP_MODE_BASE64 : 0);
- char *tmp = db_get_sa(ptr->hContact,MODULENAME,"PSK");
+ char *tmp = db_get_sa(ptr->hContact, MODULENAME, "PSK");
if (tmp) {
- cpp_init_keyp(ptr->cntx,tmp); // make pre-shared key from password
+ cpp_init_keyp(ptr->cntx, tmp); // make pre-shared key from password
mir_free(tmp);
}
- LPSTR pub_text = cpp_init_keya(ptr->cntx,features); // calculate public and private key & fill KeyA
+ LPSTR pub_text = cpp_init_keya(ptr->cntx, features); // calculate public and private key & fill KeyA
LPSTR keysig;
- if (features&CPP_FEATURES_NEWPG) {
- if (features&KEY_B_SIG)
+ if (features & CPP_FEATURES_NEWPG) {
+ if (features & KEY_B_SIG)
keysig = (LPSTR)SIG_KEYB;
else
keysig = (LPSTR)SIG_KEYA;
@@ -31,31 +31,31 @@ LPSTR InitKeyA(pUinKey ptr,int features)
int slen = (int)strlen(keysig);
int tlen = (int)strlen(pub_text);
- LPSTR keyToSend = (LPSTR) mir_alloc(slen+tlen+1);
+ LPSTR keyToSend = (LPSTR)mir_alloc(slen + tlen + 1);
- memcpy(keyToSend,keysig,slen);
- memcpy(keyToSend+slen,pub_text,tlen+1);
+ memcpy(keyToSend, keysig, slen);
+ memcpy(keyToSend + slen, pub_text, tlen + 1);
return keyToSend;
}
// store KeyB into context
-int InitKeyB(pUinKey ptr,LPCSTR key)
+int InitKeyB(pUinKey ptr, LPCSTR key)
{
Sent_NetLog("InitKeyB: %s", key);
if (!ptr->cntx)
- ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0);
+ ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact) ? CPP_MODE_BASE64 : 0);
if (!cpp_keyp(ptr->cntx)) {
- char *tmp = db_get_sa(ptr->hContact,MODULENAME,"PSK");
+ char *tmp = db_get_sa(ptr->hContact, MODULENAME, "PSK");
if (tmp) {
- cpp_init_keyp(ptr->cntx,tmp); // make pre-shared key from password
- mir_free(tmp);
+ cpp_init_keyp(ptr->cntx, tmp); // make pre-shared key from password
+ mir_free(tmp);
}
}
- cpp_init_keyb(ptr->cntx,key);
+ cpp_init_keyb(ptr->cntx, key);
ptr->features = cpp_get_features(ptr->cntx);
return cpp_get_error(ptr->cntx);
@@ -63,41 +63,40 @@ int InitKeyB(pUinKey ptr,LPCSTR key)
// store KeyX into context
-void InitKeyX(pUinKey ptr,BYTE *key)
+void InitKeyX(pUinKey ptr, BYTE *key)
{
if (!ptr->cntx)
- ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0);
+ ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact) ? CPP_MODE_BASE64 : 0);
- cpp_set_keyx(ptr->cntx,key);
+ cpp_set_keyx(ptr->cntx, key);
}
// calculate secret key
-BOOL CalculateKeyX(pUinKey ptr,MCONTACT hContact)
+BOOL CalculateKeyX(pUinKey ptr, MCONTACT hContact)
{
int agr = cpp_calc_keyx(ptr->cntx);
if (agr) {
// do this only if key exchanged is ok
// we use a 192bit key
int keysize = cpp_size_keyx();
- PBYTE buffer = (PBYTE) alloca(keysize); // buffer for hash
+ PBYTE buffer = (PBYTE)alloca(keysize); // buffer for hash
// store key
- cpp_get_keyx(ptr->cntx,buffer);
+ cpp_get_keyx(ptr->cntx, buffer);
// store key in database
db_set_blob(hContact, MODULENAME, "offlineKey", buffer, keysize);
// store timeout of key in database (2 days)
- db_set_dw(hContact, MODULENAME, "offlineKeyTimeout", gettime()+(60*60*24*db_get_w(0,MODULENAME,"okt",2)));
+ db_set_dw(hContact, MODULENAME, "offlineKeyTimeout", gettime() + (60 * 60 * 24 * db_get_w(0, MODULENAME, "okt", 2)));
// key exchange is finished
showPopupEC(ptr->hContact);
}
- else {
- // agree value problem
- showPopup(sim002,hContact,g_hPOP[POP_PU_DIS],0);
- }
+ else // agree value problem
+ showPopup(sim002, hContact, g_hPOP[POP_PU_DIS], 0);
+
return agr != 0;
}
@@ -105,14 +104,14 @@ BOOL CalculateKeyX(pUinKey ptr,MCONTACT hContact)
// encrypt message
LPSTR encrypt(pUinKey ptr, LPCSTR szEncMsg)
{
- LPSTR szSig = (LPSTR) (ptr->offlineKey?SIG_ENOF:SIG_ENON);
+ LPSTR szSig = (LPSTR)(ptr->offlineKey ? SIG_ENOF : SIG_ENON);
int slen = (int)strlen(szSig);
int clen = (int)strlen(szEncMsg);
- LPSTR szMsg = (LPSTR) mir_alloc(clen+slen+1);
+ LPSTR szMsg = (LPSTR)mir_alloc(clen + slen + 1);
memcpy(szMsg, szSig, slen);
- memcpy(szMsg+slen, szEncMsg, clen+1);
+ memcpy(szMsg + slen, szEncMsg, clen + 1);
return szMsg;
}
@@ -123,14 +122,14 @@ LPSTR encodeMsg(pUinKey ptr, LPARAM lParam)
{
CCSDATA *pccsd = (CCSDATA *)lParam;
LPSTR szNewMsg = NULL;
- LPSTR szOldMsg = (LPSTR) pccsd->lParam;
+ LPSTR szOldMsg = (LPSTR)pccsd->lParam;
- if (pccsd->wParam & PREF_UTF )
- szNewMsg = encrypt(ptr,cpp_encodeU(ptr->cntx,szOldMsg));
- else if (pccsd->wParam & PREF_UNICODE )
- szNewMsg = encrypt(ptr,cpp_encodeW(ptr->cntx,(LPWSTR)(szOldMsg+strlen(szOldMsg)+1)));
+ if (pccsd->wParam & PREF_UTF)
+ szNewMsg = encrypt(ptr, cpp_encodeU(ptr->cntx, szOldMsg));
+ else if (pccsd->wParam & PREF_UNICODE)
+ szNewMsg = encrypt(ptr, cpp_encodeW(ptr->cntx, (LPWSTR)(szOldMsg + strlen(szOldMsg) + 1)));
else
- szNewMsg = encrypt(ptr,cpp_encodeA(ptr->cntx,szOldMsg));
+ szNewMsg = encrypt(ptr, cpp_encodeA(ptr->cntx, szOldMsg));
pccsd->wParam &= ~PREF_UNICODE;
return szNewMsg;
@@ -144,11 +143,11 @@ LPSTR decodeMsg(pUinKey ptr, LPARAM lParam, LPSTR szEncMsg)
PROTORECVEVENT *ppre = (PROTORECVEVENT *)pccsd->lParam;
LPSTR szNewMsg = NULL;
- LPSTR szOldMsg = (ppre->flags&PREF_UTF)?cpp_decodeU(ptr->cntx,szEncMsg):cpp_decode(ptr->cntx,szEncMsg);
+ LPSTR szOldMsg = (ppre->flags&PREF_UTF) ? cpp_decodeU(ptr->cntx, szEncMsg) : cpp_decode(ptr->cntx, szEncMsg);
if (szOldMsg == NULL) {
ptr->decoded = false;
- switch(cpp_get_error(ptr->cntx)) {
+ switch (cpp_get_error(ptr->cntx)) {
case CPP_ERROR_BAD_LEN:
szNewMsg = mir_strdup(Translate(sim102));
break;
@@ -156,24 +155,24 @@ LPSTR decodeMsg(pUinKey ptr, LPARAM lParam, LPSTR szEncMsg)
szNewMsg = mir_strdup(Translate(sim103));
break;
default:
- ptr->decoded=true;
+ ptr->decoded = true;
szNewMsg = mir_strdup(Translate(sim101));
break;
}
- ppre->flags &= ~(PREF_UNICODE|PREF_UTF);
- pccsd->wParam &= ~(PREF_UNICODE|PREF_UTF);
+ ppre->flags &= ~(PREF_UNICODE | PREF_UTF);
+ pccsd->wParam &= ~(PREF_UNICODE | PREF_UTF);
}
else {
- ptr->decoded=true;
- if (ppre->flags & PREF_UTF) { // если протокол поддерживает utf8 - тогда отправляем в utf8
- int olen = (int)strlen(szOldMsg)+1;
- szNewMsg = (LPSTR) mir_alloc(olen);
- memcpy(szNewMsg,szOldMsg,olen);
+ ptr->decoded = true;
+ if (ppre->flags & PREF_UTF) {
+ int olen = (int)strlen(szOldMsg) + 1;
+ szNewMsg = (LPSTR)mir_alloc(olen);
+ memcpy(szNewMsg, szOldMsg, olen);
}
else {
- int olen = ((int)strlen(szOldMsg)+1)*(sizeof(WCHAR)+1);
- szNewMsg = (LPSTR) mir_alloc(olen);
- memcpy(szNewMsg,szOldMsg,olen);
+ int olen = ((int)strlen(szOldMsg) + 1)*(sizeof(WCHAR) + 1);
+ szNewMsg = (LPSTR)mir_alloc(olen);
+ memcpy(szNewMsg, szOldMsg, olen);
ppre->flags |= PREF_UNICODE;
pccsd->wParam |= PREF_UNICODE;
}
@@ -185,19 +184,19 @@ LPSTR decodeMsg(pUinKey ptr, LPARAM lParam, LPSTR szEncMsg)
BOOL LoadKeyPGP(pUinKey ptr)
{
- int mode = db_get_b(ptr->hContact,MODULENAME,"pgp_mode",255);
+ int mode = db_get_b(ptr->hContact, MODULENAME, "pgp_mode", 255);
if (mode == 0) {
DBVARIANT dbv;
- db_get(ptr->hContact,MODULENAME,"pgp",&dbv);
- BOOL r=(dbv.type == DBVT_BLOB);
- if (r) pgp_set_keyid(ptr->cntx,(PVOID)dbv.pbVal);
+ db_get(ptr->hContact, MODULENAME, "pgp", &dbv);
+ BOOL r = (dbv.type == DBVT_BLOB);
+ if (r) pgp_set_keyid(ptr->cntx, (PVOID)dbv.pbVal);
db_free(&dbv);
return r;
}
if (mode == 1) {
- LPSTR key = db_get_sa(ptr->hContact,MODULENAME,"pgp");
+ LPSTR key = db_get_sa(ptr->hContact, MODULENAME, "pgp");
if (key) {
- pgp_set_key(ptr->cntx,key);
+ pgp_set_key(ptr->cntx, key);
mir_free(key);
return 1;
}
@@ -207,13 +206,11 @@ BOOL LoadKeyPGP(pUinKey ptr)
BOOL LoadKeyGPG(pUinKey ptr)
{
- LPSTR key = db_get_sa(ptr->hContact,MODULENAME,"gpg");
+ LPSTR key = db_get_sa(ptr->hContact, MODULENAME, "gpg");
if (key) {
- gpg_set_keyid(ptr->cntx,key);
+ gpg_set_keyid(ptr->cntx, key);
mir_free(key);
return 2;
}
return 0;
}
-
-// EOF