| 4432 | } |
| 4433 | |
| 4434 | int bsgs_thirdcheck(Int *start_range,uint32_t a,uint32_t k_index,Int *privatekey) { |
| 4435 | uint64_t j = 0; |
| 4436 | int i = 0,found = 0,r = 0; |
| 4437 | Int base_key,calculatedkey; |
| 4438 | Point base_point,point_aux; |
| 4439 | Point BSGS_Q, BSGS_S,BSGS_Q_AMP; |
| 4440 | char xpoint_raw[32]; |
| 4441 | |
| 4442 | base_key.SetInt32(a); |
| 4443 | base_key.Mult(&BSGS_M2_double); |
| 4444 | base_key.Add(start_range); |
| 4445 | |
| 4446 | base_point = secp->ComputePublicKey(&base_key); |
| 4447 | point_aux = secp->Negation(base_point); |
| 4448 | |
| 4449 | BSGS_S = secp->AddDirect(OriginalPointsBSGS[k_index],point_aux); |
| 4450 | BSGS_Q.Set(BSGS_S); |
| 4451 | |
| 4452 | do { |
| 4453 | BSGS_Q_AMP = secp->AddDirect(BSGS_Q,BSGS_AMP3[i]); |
| 4454 | BSGS_S.Set(BSGS_Q_AMP); |
| 4455 | BSGS_S.x.Get32Bytes((unsigned char *)xpoint_raw); |
| 4456 | r = bloom_check(&bloom_bPx3rd[(uint8_t)xpoint_raw[0]],xpoint_raw,32); |
| 4457 | if(r) { |
| 4458 | r = bsgs_searchbinary(bPtable,xpoint_raw,bsgs_m3,&j); |
| 4459 | if(r) { |
| 4460 | calcualteindex(i,&calculatedkey); |
| 4461 | privatekey->Set(&calculatedkey); |
| 4462 | privatekey->Add((uint64_t)(j+1)); |
| 4463 | privatekey->Add(&base_key); |
| 4464 | point_aux = secp->ComputePublicKey(privatekey); |
| 4465 | if(point_aux.x.IsEqual(&OriginalPointsBSGS[k_index].x)) { |
| 4466 | found = 1; |
| 4467 | } |
| 4468 | else { |
| 4469 | calcualteindex(i,&calculatedkey); |
| 4470 | privatekey->Set(&calculatedkey); |
| 4471 | privatekey->Sub((uint64_t)(j+1)); |
| 4472 | privatekey->Add(&base_key); |
| 4473 | point_aux = secp->ComputePublicKey(privatekey); |
| 4474 | if(point_aux.x.IsEqual(&OriginalPointsBSGS[k_index].x)) { |
| 4475 | found = 1; |
| 4476 | } |
| 4477 | } |
| 4478 | } |
| 4479 | } |
| 4480 | else { |
| 4481 | /* |
| 4482 | For some reason the AddDirect don't return 000000... value when the publickeys are the negated values from each other |
| 4483 | Why JLP? |
| 4484 | This is is an special case |
| 4485 | */ |
| 4486 | if(BSGS_Q.x.IsEqual(&BSGS_AMP3[i].x)) { |
| 4487 | calcualteindex(i,&calculatedkey); |
| 4488 | privatekey->Set(&calculatedkey); |
| 4489 | privatekey->Add(&base_key); |
| 4490 | found = 1; |
| 4491 | } |
no test coverage detected