| 4304 | } |
| 4305 | |
| 4306 | int bsgs_thirdcheck(Int *start_range,uint32_t a,uint32_t k_index,Int *privatekey) { |
| 4307 | uint64_t j = 0; |
| 4308 | int i = 0,found = 0,r = 0; |
| 4309 | Int base_key,calculatedkey; |
| 4310 | Point base_point,point_aux; |
| 4311 | Point BSGS_Q, BSGS_S,BSGS_Q_AMP; |
| 4312 | char xpoint_raw[32]; |
| 4313 | |
| 4314 | base_key.SetInt32(a); |
| 4315 | base_key.Mult(&BSGS_M2_double); |
| 4316 | base_key.Add(start_range); |
| 4317 | |
| 4318 | base_point = secp->ComputePublicKey(&base_key); |
| 4319 | point_aux = secp->Negation(base_point); |
| 4320 | |
| 4321 | BSGS_S = secp->AddDirect(OriginalPointsBSGS[k_index],point_aux); |
| 4322 | BSGS_Q.Set(BSGS_S); |
| 4323 | |
| 4324 | do { |
| 4325 | BSGS_Q_AMP = secp->AddDirect(BSGS_Q,BSGS_AMP3[i]); |
| 4326 | BSGS_S.Set(BSGS_Q_AMP); |
| 4327 | BSGS_S.x.Get32Bytes((unsigned char *)xpoint_raw); |
| 4328 | r = bloom_check(&bloom_bPx3rd[(uint8_t)xpoint_raw[0]],xpoint_raw,32); |
| 4329 | if(r) { |
| 4330 | r = bsgs_searchbinary(bPtable,xpoint_raw,bsgs_m3,&j); |
| 4331 | if(r) { |
| 4332 | calcualteindex(i,&calculatedkey); |
| 4333 | privatekey->Set(&calculatedkey); |
| 4334 | privatekey->Add((uint64_t)(j+1)); |
| 4335 | privatekey->Add(&base_key); |
| 4336 | point_aux = secp->ComputePublicKey(privatekey); |
| 4337 | if(point_aux.x.IsEqual(&OriginalPointsBSGS[k_index].x)) { |
| 4338 | found = 1; |
| 4339 | } |
| 4340 | else { |
| 4341 | calcualteindex(i,&calculatedkey); |
| 4342 | privatekey->Set(&calculatedkey); |
| 4343 | privatekey->Sub((uint64_t)(j+1)); |
| 4344 | privatekey->Add(&base_key); |
| 4345 | point_aux = secp->ComputePublicKey(privatekey); |
| 4346 | if(point_aux.x.IsEqual(&OriginalPointsBSGS[k_index].x)) { |
| 4347 | found = 1; |
| 4348 | } |
| 4349 | } |
| 4350 | } |
| 4351 | } |
| 4352 | else { |
| 4353 | /* |
| 4354 | For some reason the AddDirect don't return 000000... value when the publickeys are the negated values from each other |
| 4355 | Why JLP? |
| 4356 | This is is an special case |
| 4357 | */ |
| 4358 | if(BSGS_Q.x.IsEqual(&BSGS_AMP3[i].x)) { |
| 4359 | calcualteindex(i,&calculatedkey); |
| 4360 | privatekey->Set(&calculatedkey); |
| 4361 | privatekey->Add(&base_key); |
| 4362 | found = 1; |
| 4363 | } |
no test coverage detected