int DecryptC3asClient(unsigned char*Dest,unsigned char*Src,int Len) { if(!ClientDecryptKeysLoaded) if(!LoadKeys(Dec2,ClientDecryptKeys)) return 0; else ClientDecryptKeysLoaded=1; return DecryptC3(Dest,Src,Len,ClientDecryptKeys); }
int EncryptC3asServer(unsigned char*Dest,unsigned char*Src,int Len) { if(!ServerEncryptKeysLoaded) if(!LoadKeys(Enc2,ServerEncryptKeys)) return 0; else ServerEncryptKeysLoaded=1; return EncryptC3(Dest,Src,Len,ServerEncryptKeys); }
INT_PTR __cdecl Service_PGPsetKey(WPARAM wParam, LPARAM lParam) { BOOL del = true; if(bPGPloaded) { if(bPGPkeyrings) { char szKeyID[128]; szKeyID[0]='\0'; PVOID KeyID = pgp_select_keyid(GetForegroundWindow(),szKeyID); if(szKeyID[0]) { DBDeleteContactSetting((HANDLE)wParam,szModuleName,"pgp"); DBCONTACTWRITESETTING cws; memset(&cws,0,sizeof(cws)); cws.szModule = szModuleName; cws.szSetting = "pgp"; cws.value.type = DBVT_BLOB; cws.value.pbVal = (LPBYTE)KeyID; cws.value.cpbVal = pgp_size_keyid(); CallService(MS_DB_CONTACT_WRITESETTING,wParam,(LPARAM)&cws); DBWriteContactSettingByte((HANDLE)wParam,szModuleName,"pgp_mode",0); DBWriteContactSettingString((HANDLE)wParam,szModuleName,"pgp_abbr",szKeyID); del = false; } } else if(bPGPprivkey) { char KeyPath[MAX_PATH]; KeyPath[0]='\0'; if(ShowSelectKeyDlg(0,KeyPath)) { char *publ = LoadKeys(KeyPath,false); if(publ) { DBDeleteContactSetting((HANDLE)wParam,szModuleName,"pgp"); myDBWriteStringEncode((HANDLE)wParam,szModuleName,"pgp",publ); DBWriteContactSettingByte((HANDLE)wParam,szModuleName,"pgp_mode",1); DBWriteContactSettingString((HANDLE)wParam,szModuleName,"pgp_abbr","(binary)"); mir_free(publ); del = false; } } } } if(del) Service_PGPdelKey(wParam,lParam); else { pUinKey ptr = getUinKey((HANDLE)wParam); cpp_delete_context(ptr->cntx); ptr->cntx=0; } ShowStatusIconNotify((HANDLE)wParam); return 1; }
INT_PTR __cdecl Service_PGPsetKey(WPARAM wParam, LPARAM lParam) { BOOL del = true; if (bPGPloaded) { if (bPGPkeyrings) { char szKeyID[128]; szKeyID[0] = '\0'; PVOID KeyID = pgp_select_keyid(GetForegroundWindow(), szKeyID); if (szKeyID[0]) { db_unset(wParam, MODULENAME, "pgp"); db_set_blob(wParam, MODULENAME, "pgp", KeyID, pgp_size_keyid()); db_set_b(wParam, MODULENAME, "pgp_mode", 0); db_set_s(wParam, MODULENAME, "pgp_abbr", szKeyID); del = false; } } else if (bPGPprivkey) { char KeyPath[MAX_PATH]; KeyPath[0] = '\0'; if (ShowSelectKeyDlg(0, KeyPath)) { char *publ = LoadKeys(KeyPath, false); if (publ) { db_unset(wParam, MODULENAME, "pgp"); db_set_s(wParam, MODULENAME, "pgp", publ); db_set_b(wParam, MODULENAME, "pgp_mode", 1); db_set_s(wParam, MODULENAME, "pgp_abbr", "(binary)"); mir_free(publ); del = false; } } } } if (del) Service_PGPdelKey(wParam, lParam); else { pUinKey ptr = getUinKey(wParam); cpp_delete_context(ptr->cntx); ptr->cntx = 0; } ShowStatusIconNotify(wParam); return 1; }
bool Signer::Sign(const char *szIn, szptr& szSign) { DWORD dwCRC[14]; #ifdef _DEBUG printf("\n\rSign - Start !"); #endif if (!LoadKeys()) { puts("!LoadKeys"); return false; } #ifdef _DEBUG printf("\n\rSign - Load Keys"); #endif if(!keys.wEKeyBase || !keys.wNKeyBase) return false; #ifdef _DEBUG char *szInHex = new char [(strlen(szIn)+1)*2+1]; us2sz((const unsigned short *)szIn, (int)(strlen(szIn)+1)/2, szInHex); puts("\n\rInput:\n"); puts(szIn); puts("\nin hex:\n"); puts(szInHex); puts("\n"); delete [] szInHex; #endif if(Keys::CountCrcMD4(dwCRC, szIn, (DWORD)strlen(szIn))) { DWORD dwCrpSize = GetCLenB(sizeof(dwCRC), keys.arwNKey); char *ptrCrpBlock = new char[dwCrpSize]; #ifdef _DEBUG for(int i=4; i<14; i++) dwCRC[i] = 0; #else srand((unsigned)time(NULL)); for(int i=4; i<14; i++) dwCRC[i] = rand(); #endif dwCRC[0] = SwitchIndian(dwCRC[0]); dwCRC[1] = SwitchIndian(dwCRC[1]); dwCRC[2] = SwitchIndian(dwCRC[2]); dwCRC[3] = SwitchIndian(dwCRC[3]); #ifdef _DEBUG for(int h=0; h<sizeof(dwCRC); h++) { printf("packing%d: %x\n", h, ((char*)dwCRC)[h]); } #endif #ifdef _DEBUG printf("\n\rCalling CrpB() - start"); #endif CrpB(ptrCrpBlock, (char *)dwCRC, sizeof(dwCRC), keys.arwEKey, keys.arwNKey); #ifdef _DEBUG printf("\n\rCalling CrpB() - end"); #endif char *charCrpBlock = new char[dwCrpSize*2+1]; us2sz((const unsigned short *)ptrCrpBlock, dwCrpSize/2, charCrpBlock); szSign = charCrpBlock; #ifdef _DEBUG printf("\n\rSign - prepare end"); #endif delete [] charCrpBlock; delete [] ptrCrpBlock; #ifdef _DEBUG printf("\n\rSign - end return true"); #endif return true; } #ifdef _DEBUG printf("\n\rSign - end return false"); #endif return false; }
void CScript_FM1232::CreateEFS( string strDDF /*= ""*/, string strADF /*= "" */ ) { stringstream strsRecords; string strLen,strTmp,strDDFFID,strEFType; S_ADFINFO struADFInfo; transform( strDDF.begin(), strDDF.end(), strDDF.begin(), toupper ); transform( strADF.begin(), strADF.end(), strADF.begin(), toupper ); if ( strDDF == "" ) strDDF = "DDF0"; vector<S_DDFINFO>::const_iterator iterSDDF = m_vecMFStruct.begin(); while ( iterSDDF != m_vecMFStruct.end() )//遍历DDF { strTmp = (*iterSDDF).m_strDDFName;//应用环境简称 transform( strTmp.begin(), strTmp.end(), strTmp.begin(), toupper ); if ( strTmp != strDDF )//不为应用环境简称时继续遍历 { ++iterSDDF; continue; } vector<S_ADFINFO>::const_iterator iterSADF = (*iterSDDF).m_vecADFInfo.begin(); while ( iterSADF!=(*iterSDDF).m_vecADFInfo.end() )//遍历ADF { strTmp = (*iterSADF).m_strFID; transform( strTmp.begin(), strTmp.end(), strTmp.begin(), toupper ); if ( strTmp != strADF )//不为ADF文件标识符的话继续遍历(读取的数据中DF00的FID为"") { ++iterSADF; continue; } if ( strDDF == "DDF0" && strADF == "" )//表示建MF下的所有直属EF文件 { LvTwo_Annotations( "创建MF下的EF文件" ); LvOne_Annotations( "选择MF" ); cInst->Select_File( "MF", (*iterSDDF).m_strFID, (*iterSADF).m_strFID, "", m_bRefreshFlag ); } else if ( strDDF != "DDF0" && strADF == "" )//表示建MF/DDF下的所有直属EF文件 { m_strTemp = "创建 MF-"+(*iterSDDF).m_strDDFName+" 下的EF文件"; LvTwo_Annotations( m_strTemp ); m_strTemp = "选择"+(*iterSDDF).m_strDDFName; LvOne_Annotations( m_strTemp ); cInst->Select_File( "MF", (*iterSDDF).m_strFID, (*iterSADF).m_strFID, "", m_bRefreshFlag ); } else//表示建MF/ADF下的所有直属EF文件 或者 建MF/DDF/ADF下的所有直属EF文件 { if ( (*iterSDDF).m_strFID == "" ) m_strTemp = "创建 MF-"+(*iterSADF).m_strFID+" 下的EF文件"; else m_strTemp = "创建 MF-"+(*iterSDDF).m_strDDFName+"-"+(*iterSADF).m_strFID+" 下的EF文件"; LvTwo_Annotations( m_strTemp ); m_strTemp = "选择"+(*iterSADF).m_strFID; LvOne_Annotations( m_strTemp ); cInst->Select_File( "MF", (*iterSDDF).m_strFID, (*iterSADF).m_strFID, "", m_bRefreshFlag ); //创建安全文件 LvOne_Annotations( "创建安全文件" ); strLen = LoadKeys( (*iterSDDF).m_strDDFName, (*iterSADF).m_strFID, strsRecords );//获取装载密钥的记录和密钥文件空间 cInst->Create_Internal_EF( "SF", strLen, m_bRefreshFlag ); cInfo->Append_Script( strsRecords.str() );//添加所有的装载密钥脚本数据 //外部认证ADF的主控密钥 m_strTemp = "外部认证"+(*iterSADF).m_strFID+"的主控密钥"; LvOne_Annotations( m_strTemp, m_bRefreshFlag ); cParameter->GetADFInfo( (*iterSDDF).m_strFID, (*iterSADF).m_strFID, struADFInfo );//获取ADF信息 cCmd->VAR( struADFInfo.m_strMKvalue, _KEY, m_bRefreshFlag );//将ADF的MK保存到_KEY cInst->Get_Challenge( 8, m_bRefreshFlag ); cCmd->RESP( 0, 8, _VAR10, m_bRefreshFlag ); cCmd->TDES( VAR_Name(_VAR10), VAR_Name(_KEY), _VAR11, m_bRefreshFlag ); cCmd->DES( VAR_Name(_VAR10), VAR_Name(_VAR11), _VAR12, m_bRefreshFlag ); cInst->External_Authenticate( "00", VAR_Name(_VAR12), VAR_Name(_VAR10), 0, m_bRefreshFlag );//MK的密钥标识为00 //引用全局PIN LineFeed(1); } vector<S_EFINFO>::const_iterator iterEF = (*iterSADF).m_vecEFInfo.begin(); while ( iterEF!=(*iterSADF).m_vecEFInfo.end() )//遍历EF,建EF文件并初始化文件 { //文件类型 if ( "1" == (*iterEF).m_strEFType ) strEFType = "定长文件"; if ( "2" == (*iterEF).m_strEFType ) strEFType = "变长文件"; if ( "3" == (*iterEF).m_strEFType ) strEFType = "透明文件"; if ( "4" == (*iterEF).m_strEFType ) strEFType = "循环文件"; if ( "5" == (*iterEF).m_strEFType ) strEFType = "内部文件"; m_strTemp = "建立基本文件"+(*iterEF).m_strSFI+" 读:"+(*iterEF).m_strReadControl+" 写:"+(*iterEF).m_strWriteControl+" 文件类型:"+strEFType; LvOne_Annotations( m_strTemp, m_bRefreshFlag ); cInst->Create_File( "MF", (*iterSDDF).m_strDDFName, (*iterSADF).m_strFID, (*iterEF).m_strSFI, m_bRefreshFlag );//建EF文件 cInst->Select_File( "MF", (*iterSDDF).m_strFID, (*iterSADF).m_strFID, (*iterEF).m_strSFI, m_bRefreshFlag );//选当前建的EF文件 //调用初始化文件接口写记录 InitFile( (*iterSDDF).m_strFID, (*iterSADF).m_strFID, (*iterEF).m_strSFI ); LineFeed(1); ++iterEF; } break; } break; } }
void BundlerApp::ComputeGeometricConstraints(bool overwrite, int new_image_start) { int num_images = GetNumImages(); /* Read information from files if they exist */ const char *filename = "constraints.txt"; if (!overwrite && FileExists(filename)) { ReadGeometricConstraints(filename); return; } else { LoadMatches(); if (num_images < 40000) WriteMatchTable(".prune"); if (!m_skip_fmatrix || !m_skip_homographies || m_keypoint_border_width > 0 || m_keypoint_border_bottom > 0) LoadKeys(false); if (m_keypoint_border_width > 0) { for (int i = 0; i < num_images; i++) { for (int j = i+1; j < num_images; j++) { if (!ImagesMatch(i, j)) continue; RemoveMatchesNearBorder(i, j, m_keypoint_border_width); } } } if (m_keypoint_border_bottom > 0) { for (int i = 0; i < num_images; i++) { for (int j = i+1; j < num_images; j++) { if (!ImagesMatch(i, j)) continue; RemoveMatchesNearBottom(i, j, m_keypoint_border_bottom); } } } if (!m_skip_fmatrix) { ComputeEpipolarGeometry(true, new_image_start); } if (!m_skip_homographies) { ComputeTransforms(false, new_image_start); } MakeMatchListsSymmetric(); if (num_images < 40000) WriteMatchTable(".ransac"); // RemoveAllMatches(); ComputeTracks(new_image_start); // ClearMatches(); RemoveAllMatches(); // SetMatchesFromTracks(); #if 1 /* Set match flags */ int num_tracks = (int) m_track_data.size(); for (int i = 0; i < num_tracks; i++) { TrackData &track = m_track_data[i]; int num_views = (int) track.m_views.size(); for (int j = 0; j < num_views; j++) { int img1 = track.m_views[j].first; assert(img1 >= 0 && img1 < num_images); for (int k = j+1; k < num_views; k++) { int img2 = track.m_views[k].first; assert(img2 >= 0 && img2 < num_images); SetMatch(img1, img2); SetMatch(img2, img1); } } } #endif WriteGeometricConstraints(filename); if (num_images < 40000) WriteMatchTable(".corresp"); } }