int A5IlPair::getRoundOffset(int adv) { std::map<int,int>::iterator it = mRoundOffsets.find(adv); if (it!=mRoundOffsets.end()) { return (*it).second; } assert( (mFreeRound+mNumRounds) <= MAX_RFTABLE_ENTRIES ); Advance* advance = new Advance(adv,mNumRounds); unsigned int *dataPtr = NULL; CALuint pitch = 0; if (calResMap((CALvoid **)&dataPtr, &pitch, *mResRoundFunc, 0) != CAL_RESULT_OK) { assert(!"Error - now I will go and crash myself.\n"); } const uint32_t* aval = advance->getRFtable(); for (int j=0; j < mNumRounds ; j++) { /* Low high order was swapped in old kernel input*/ dataPtr[2*(j+mFreeRound)] = aval[2*j+1]; dataPtr[2*(j+mFreeRound)+1] = aval[2*j+0]; } calResUnmap(*mResRoundFunc); delete advance; mRoundOffsets[adv]=mFreeRound; int ret = mFreeRound; mFreeRound += mNumRounds; return ret; }
/* Try to unmap resource and free it on failure */ CALresult unmapMWMemRes(MWMemRes* mr) { CALresult err; err = calResUnmap(mr->res); if (err != CAL_RESULT_OK) { cal_warn("Failed to unmap resource", err); if (calResFree(mr->res) != CAL_RESULT_OK) warn("Failed to release CAL resource\n"); else mr->res = 0; } return err; }
static bool FillConstantBuffer(CALresource res, u32 runsize, u32 iters, u32 rest, float width, RC5_72UnitWork *rc5_72unitwork, u32 keyIncrement) { u32* constPtr = NULL; CALuint pitch = 0; if(calResMap((CALvoid**)&constPtr, &pitch, res, 0)!=CAL_RESULT_OK) return false; u32 hi,mid,lo; hi=rc5_72unitwork->L0.hi; mid=rc5_72unitwork->L0.mid; lo=rc5_72unitwork->L0.lo; key_incr(&hi,&mid,&lo,keyIncrement*4); //cb0[0] //key_hi,key_mid,key_lo,granularity constPtr[0]=hi; constPtr[1]=mid; constPtr[2]=lo; constPtr[3]=runsize*4; //cb0[1] //plain_lo,plain_hi,cypher_lo,cypher_hi constPtr[4]=rc5_72unitwork->plain.lo; constPtr[5]=rc5_72unitwork->plain.hi; constPtr[6]=rc5_72unitwork->cypher.lo; constPtr[7]=rc5_72unitwork->cypher.hi; //cb0[2] //iters,rest,width constPtr[8]=iters; constPtr[9]=rest; float *f; f=(float*)&constPtr[10]; *f=width; if(calResUnmap(res)!=CAL_RESULT_OK) return false; return true; }
static s32 ReadResultsFromGPU(CALresource res, CALresource globalRes, u32 width, u32 height, RC5_72UnitWork *rc5_72unitwork, u32 *CMC, u32 *iters_done) { u32 *o0, *g0; CALuint pitch = 0; bool found=true; if(globalRes) { CALuint result; if(calResMap((CALvoid**)&g0, &pitch, globalRes, 0)!=CAL_RESULT_OK) return -1; result=g0[0]; g0[0]=0; if(calResUnmap(globalRes)!=CAL_RESULT_OK) return -1; if(result==0) found=false; } if(calResMap((CALvoid**)&o0, &pitch, res, 0)!=CAL_RESULT_OK) { return -1; } u32 last_CMC=0; *iters_done=(o0[0]&0x7e000000)>>25; if(found) for(u32 i=0; i<height; i++) { u32 idx=i*pitch; for(u32 j=0; j<width; j++) { if(o0[idx+j]&0x1ffffff) //partial match { u32 output=o0[idx+j]; u32 CMC_count=(output&0x1ffffff)>>18; u32 CMC_iter=(((output>>2)&0x0000ffff)-1)*width*height; u32 CMC_hit=(CMC_iter+i*width+j)*4+(output&0x00000003); // LogScreen("Partial match found\n"); u32 hi,mid,lo; hi=rc5_72unitwork->L0.hi; mid=rc5_72unitwork->L0.mid; lo=rc5_72unitwork->L0.lo; key_incr(&hi,&mid,&lo,CMC_hit); if(last_CMC<=CMC_hit) { rc5_72unitwork->check.hi=hi; rc5_72unitwork->check.mid=mid; rc5_72unitwork->check.lo=lo; last_CMC=CMC_hit; } rc5_72unitwork->check.count+=CMC_count; if(output&0x80000000) { //full match rc5_72unitwork->L0.hi=hi; rc5_72unitwork->L0.mid=mid; rc5_72unitwork->L0.lo=lo; calResUnmap(res); *CMC=CMC_hit; return 1; } } } }