// store KeyX into context void InitKeyX(pUinKey ptr,BYTE *key) { if (!ptr->cntx) ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0); cpp_set_keyx(ptr->cntx,key); }
// создает RSA контекст void createRSAcntx(pUinKey ptr) { if (!ptr->cntx) { ptr->cntx = cpp_create_context(CPP_MODE_RSA); ptr->keyLoaded = 0; } }
// пересоздает RSA контекст void resetRSAcntx(pUinKey ptr) { if( ptr->cntx ) { cpp_delete_context(ptr->cntx); ptr->cntx = cpp_create_context(CPP_MODE_RSA); ptr->keyLoaded = 0; } }
int __cdecl pgp_init() { if (!hPGPPRIV) { // create context for private pgp keys hPGPPRIV = (HANDLE)cpp_create_context(MODE_PGP | MODE_PRIV_KEY); pCNTX tmp = (pCNTX)hPGPPRIV; tmp->pdata = (PBYTE)malloc(sizeof(PGPDATA)); memset(tmp->pdata, 0, sizeof(PGPDATA)); } hpgpsdk = g_hInst; return 0; }
int __cdecl pgp_init() { int r; if( !hPGPPRIV ) { // create context for private pgp keys hPGPPRIV = (HANDLE) cpp_create_context(MODE_PGP|MODE_PRIV_KEY); pCNTX tmp = (pCNTX) hPGPPRIV; tmp->pdata = (PBYTE) malloc(sizeof(PGPDATA)); memset(tmp->pdata,0,sizeof(PGPDATA)); } if( r = load_pgp_sdk(666,6) ) return r; if( r = load_pgp_sdk(666,8) ) return r; hpgpsdk = 0; return 0; }
// store KeyB into context 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); if (!cpp_keyp(ptr->cntx)) { 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_keyb(ptr->cntx,key); ptr->features = cpp_get_features(ptr->cntx); return cpp_get_error(ptr->cntx); }
// store KeyB into context int InitKeyB(pUinKey ptr,LPCSTR key) { #if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("InitKeyB: %s", key); #endif if(!ptr->cntx) ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0); if(!cpp_keyp(ptr->cntx)) { char *tmp = myDBGetString(ptr->hContact,szModuleName,"PSK"); if(tmp) { cpp_init_keyp(ptr->cntx,tmp); // make pre-shared key from password mir_free(tmp); } } cpp_init_keyb(ptr->cntx,key); ptr->features = cpp_get_features(ptr->cntx); return cpp_get_error(ptr->cntx); }
// generate KeyA pair and return public key LPSTR InitKeyA(pUinKey ptr,int features) { #if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("InitKeyA: %04x", features); #endif if( !ptr->cntx ) ptr->cntx = cpp_create_context(isProtoSmallPackets(ptr->hContact)?CPP_MODE_BASE64:0); char *tmp = myDBGetString(ptr->hContact,szModuleName,"PSK"); if(tmp) { 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 keysig; if(features&CPP_FEATURES_NEWPG) { if(features&KEY_B_SIG) keysig = (LPSTR)SIG_KEYB; else keysig = (LPSTR)SIG_KEYA; } else if(isProtoSmallPackets(ptr->hContact)) keysig = (LPSTR)SIG_KEY4; else keysig = (LPSTR)SIG_KEY3; int slen = strlen(keysig); int tlen = strlen(pub_text); LPSTR keyToSend = (LPSTR) mir_alloc(slen+tlen+1); memcpy(keyToSend,keysig,slen); memcpy(keyToSend+slen,pub_text,tlen+1); return keyToSend; }