void CDataGenerationThread::threadProc() { #ifdef WIN32 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE); #else #endif const DataGenerationThreadParameters *Parameters = (const DataGenerationThreadParameters *)Params; CChainWalkContext cwc; // Make a pointer to the beginning of the data block uint64 *ptrCurrent = (uint64*)zBuffer; // Make a pointer to the end of the data block. uint64 *ptrEnd = (uint64*)(zBuffer + DATA_CHUNK_SIZE); uint64 nSeed = Parameters->nChainStart; while(m_nChainsCalculated < Parameters->nChainCount && bTerminateThreadFlag != 1) { *ptrCurrent = nSeed; cwc.SetIndex(nSeed++); // Increase the pointer location ptrCurrent++; int nPos; for (nPos = 0; nPos < Parameters->nRainbowChainLen - 1; nPos++) { cwc.IndexToPlain(); cwc.PlainToHash(); cwc.HashToIndex(nPos); } *ptrCurrent = cwc.GetIndex(); // Increase the pointer location ptrCurrent++; // We counted another chain m_nChainsCalculated++; // The data buffer is full.. Let's swap buffers if(ptrCurrent >= ptrEnd) { // The old buffer isn't emptied yet. So we have to wait before writing our data while(bDataReady == 1 && bTerminateThreadFlag != 1) { Sleep(1); } // Copy the data over memcpy(zDataChunk, zBuffer, DATA_CHUNK_SIZE); // Mark the buffer as full bDataReady = 1; // Reset the data pointer ptrCurrent = (uint64*)zBuffer; } } bTerminateThreadFlag = 1; }
int main(int argc, char* argv[]) { if (argc != 3) { Logo(); printf("usage: rtdump rainbow_table_pathname rainbow_chain_index\n"); return 0; } string sPathName = argv[1]; int nRainbowChainIndex = atoi(argv[2]); int nRainbowChainLen, nRainbowChainCount; if (!CChainWalkContext::SetupWithPathName(sPathName, nRainbowChainLen, nRainbowChainCount)) return 0; if (nRainbowChainIndex < 0 || nRainbowChainIndex > nRainbowChainCount - 1) { printf("valid rainbow chain index range: 0 - %d\n", nRainbowChainCount - 1); return 0; } // Open file FILE* file = fopen(sPathName.c_str(), "rb"); if (file == NULL) { printf("failed to open %s\n", sPathName.c_str()); return 0; } // Dump if (GetFileLen(file) != nRainbowChainCount * 16) printf("rainbow table size check fail\n"); else { // Read required chain RainbowChain chain; fseek(file, nRainbowChainIndex * 16, SEEK_SET); fread(&chain, 1, 16, file); // Dump required chain CChainWalkContext cwc; cwc.SetIndex(chain.nIndexS); int nPos; for (nPos = 0; nPos < nRainbowChainLen - 1; nPos++) { cwc.IndexToPlain(); cwc.PlainToHash(); printf("#%-4d %s %s %s\n", nPos, uint64tohexstr(cwc.GetIndex()).c_str(), cwc.GetPlainBinary().c_str(), cwc.GetHash().c_str()); cwc.HashToIndex(nPos); } printf("#%-4d %s\n", nPos, uint64tohexstr(cwc.GetIndex()).c_str()); if (cwc.GetIndex() != chain.nIndexE) printf("\nwarning: rainbow chain integrity check fail!\n"); } // Close file fclose(file); return 0; }
int main(int argc, char **argv) { int retval; double fd; char output_path[512]; //, chkpt_path[512]; //FILE* state; retval = boinc_init(); if (retval) { fprintf(stderr, "boinc_init returned %d\n", retval); exit(retval); } // get size of input file (used to compute fraction done) // //file_size(input_path, fsize); // See if there's a valid checkpoint file. // If so seek input file and truncate output file // if(argc < 10) { fprintf(stderr, "Not enough parameters"); return -1; } std::string sHashRoutineName, sCharsetName, sSalt, sCheckPoints; uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen; uint64 nChainStart; sHashRoutineName = argv[1]; sCharsetName = argv[2]; nPlainLenMin = atoi(argv[3]); nPlainLenMax = atoi(argv[4]); nRainbowTableIndex = atoi(argv[5]); nRainbowChainLen = atoi(argv[6]); nRainbowChainCount = atoi(argv[7]); #ifdef _WIN32 nChainStart = _atoi64(argv[8]); #else nChainStart = atoll(argv[8]); #endif sCheckPoints = argv[9]; std::vector<uint32> vCPPositions; char *cp = strtok((char *)sCheckPoints.c_str(), ","); while(cp != NULL) { vCPPositions.push_back(atoi(cp)); cp = strtok(NULL, ","); } if(argc == 11) { sSalt = argv[10]; } //std::cout << "Starting ChainGenerator" << std::endl; // Setup CChainWalkContext //std::cout << "ChainGenerator started." << std::endl; if (!CChainWalkContext::SetHashRoutine(sHashRoutineName)) { fprintf(stderr, "hash routine %s not supported\n", sHashRoutineName.c_str()); return 1; } //std::cout << "Hash routine validated" << std::endl; if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax)) { std::cerr << "charset " << sCharsetName << " not supported" << std::endl; return 2; } //std::cout << "Plain charset validated" << std::endl; if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex)) { std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl; return 3; } //std::cout << "Rainbowtable index validated" << std::endl; if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall") { // Convert username to unicode const char *szSalt = sSalt.c_str(); int salt_length = strlen(szSalt); unsigned char cur_salt[256]; for (int i=0; i<salt_length; i++) { cur_salt[i*2] = szSalt[i]; cur_salt[i*2+1] = 0x00; } CChainWalkContext::SetSalt(cur_salt, salt_length*2); } else if(sHashRoutineName == "halflmchall") { // The salt is hardcoded into the hash routine // CChainWalkContext::SetSalt((unsigned char*)&salt, 8); } else if(sHashRoutineName == "oracle") { CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length()); } //std::cout << "Opening chain file" << std::endl; // Open file boinc_resolve_filename("result", output_path, sizeof(output_path)); fclose(boinc_fopen(output_path, "a")); FILE *outfile = boinc_fopen(output_path, "r+b"); if (outfile == NULL) { std::cerr << "failed to create " << output_path << std::endl; return 4; } // Check existing chains unsigned int nDataLen = (unsigned int)GetFileLen(outfile); // Round to boundary nDataLen = nDataLen / 10 * 10; if (nDataLen == nRainbowChainCount * 10) { std::cerr << "precomputation of this rainbow table already finished" << std::endl; fclose(outfile); return 0; } nChainStart += (nDataLen / 10); fseek(outfile, nDataLen, SEEK_SET); //XXX size_t isn't 32/64 clean size_t nReturn; CChainWalkContext cwc; uint64 nIndex[2]; //time_t tStart = time(NULL); // std::cout << "Starting to generate chains" << std::endl; for(uint32 nCurrentCalculatedChains = nDataLen / 10; nCurrentCalculatedChains < nRainbowChainCount; nCurrentCalculatedChains++) { uint32 cpcheck = 0; unsigned short checkpoint = 0; fd = (double)nCurrentCalculatedChains / (double)nRainbowChainCount; boinc_fraction_done(fd); cwc.SetIndex(nChainStart++); // use a given index now! nIndex[0] = cwc.GetIndex(); for (uint32 nPos = 0; nPos < nRainbowChainLen - 1; nPos++) { // std::cout << "IndexToPlain()" << std::endl; cwc.IndexToPlain(); // std::cout << "PlainToHash()" << std::endl; cwc.PlainToHash(); // std::cout << "HashToIndex()" << std::endl; cwc.HashToIndex(nPos); if(cpcheck < vCPPositions.size() && nPos == vCPPositions[cpcheck]) { checkpoint |= (1 << cpcheck) & (unsigned short)cwc.GetIndex() << cpcheck; cpcheck++; } } //std::cout << "GetIndex()" << std::endl; nIndex[1] = cwc.GetIndex(); // Write chain to disk if ((nReturn = fwrite(&nIndex[1], 1, 8, outfile)) != 8) { std::cerr << "disk write fail" << std::endl; fclose(outfile); return 9; } if((nReturn = fwrite(&checkpoint, 1, 2, outfile)) != 2) { std::cerr << "disk write fail" << std::endl; fclose(outfile); return 9; } } //std::cout << "Generation completed" << std::endl; fclose(outfile); boinc_fraction_done(1); boinc_finish(0); }
void rcrackiThread::CheckAlarmO() { uint32_t i; if(cudaDevId < 0) { for (i = 0; i < t_pChainsFoundO.size(); i++) { RainbowChainO* t_pChain = t_pChainsFoundO[i]; int t_nGuessedPos = t_nGuessedPoss[i]; CChainWalkContext cwc; uint64_t nIndexS = t_pChain->nIndexS; cwc.SetIndex(nIndexS); int nPos; for (nPos = 0; nPos < t_nGuessedPos; nPos++) { cwc.IndexToPlain(); cwc.PlainToHash(); cwc.HashToIndex(nPos); } cwc.IndexToPlain(); cwc.PlainToHash(); if (cwc.CheckHash(t_pHash)) { t_Hash = cwc.GetHash(); t_Plain = cwc.GetPlain(); t_Binary = cwc.GetBinary(); foundHash = true; break; } else { foundHash = false; t_nChainWalkStepDueToFalseAlarm += t_nGuessedPos + 1; t_nFalseAlarm++; } } } #if GPU else { uint64_t *calcBuff = new uint64_t[2*cudaBuffCount]; CudaCWCExtender ex(&t_cwc); rcuda::RCudaTask cuTask; int nGuessedPos, nMaxGuessedPos; int ii, calcSize; size_t chainSize; ex.Init(); chainSize = t_pChainsFoundO.size(); foundHash = false; for(i = 0; !foundHash && i < chainSize; ) { calcSize = std::min<int>(i + cudaBuffCount, chainSize); nMaxGuessedPos = 0; for(ii = i; ii < calcSize; ii++) { calcBuff[(ii<<1)] = t_pChainsFoundO[ii]->nIndexS; nGuessedPos = t_nGuessedPoss[ii]; calcBuff[(ii<<1)+1] = (unsigned int)nGuessedPos; nMaxGuessedPos = (nMaxGuessedPos>=nGuessedPos? nMaxGuessedPos : nGuessedPos); } calcSize -= i; cuTask.hash = ex.GetHash(); cuTask.startIdx = i; cuTask.idxCount = calcSize; cuTask.dimVec = ex.GetPlainDimVec(); cuTask.dimVecSize = ex.GetPlainDimVecSize()/2; cuTask.charSet = ex.GetCharSet(); cuTask.charSetSize = ex.GetCharSetSize(); cuTask.reduceOffset = ex.GetReduceOffset(); cuTask.plainSpaceTotal = ex.GetPlainSpaceTotal(); cuTask.rainbowChainLen = nMaxGuessedPos; cuTask.kernChainSize = cudaChainSize; cuTask.targetHash = t_pHash; calcSize = rcuda::CheckAlarmOnCUDA(&cuTask, calcBuff); if(calcSize > 0 && calcSize == cuTask.idxCount) { for(ii = 0; ii < calcSize; ii++) { if(calcBuff[(ii<<1)|1] >= (1ull<<63)) { CChainWalkContext cwc; cwc.SetIndex(calcBuff[ii<<1]); cwc.IndexToPlain(); cwc.PlainToHash(); t_Hash = cwc.GetHash(); t_Plain = cwc.GetPlain(); t_Binary = cwc.GetBinary(); foundHash = true; break; } else { t_nChainWalkStepDueToFalseAlarm += calcBuff[(ii<<1)|1] + 1; t_nFalseAlarm++; } } i += calcSize; } else { printf("CheckAlarmO() on CUDA failed!\n"); exit(101); } } delete [] calcBuff; } #endif }