MCPcopy Create free account
hub / github.com/JeanLucPons/VanitySearch / checkPrivKey

Method checkPrivKey

Vanity.cpp:772–828  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

770// ----------------------------------------------------------------------------
771
772bool VanitySearch::checkPrivKey(string addr, Int &key, int32_t incr, int endomorphism, bool mode) {
773
774 Int k(&key);
775 Point sp = startPubKey;
776
777 if (incr < 0) {
778 k.Add((uint64_t)(-incr));
779 k.Neg();
780 k.Add(&secp->order);
781 if (startPubKeySpecified) sp.y.ModNeg();
782 } else {
783 k.Add((uint64_t)incr);
784 }
785
786 // Endomorphisms
787 switch (endomorphism) {
788 case 1:
789 k.ModMulK1order(&lambda);
790 if(startPubKeySpecified) sp.x.ModMulK1(&beta);
791 break;
792 case 2:
793 k.ModMulK1order(&lambda2);
794 if (startPubKeySpecified) sp.x.ModMulK1(&beta2);
795 break;
796 }
797
798 // Check addresses
799 Point p = secp->ComputePublicKey(&k);
800 if (startPubKeySpecified) p = secp->AddDirect(p, sp);
801
802 string chkAddr = secp->GetAddress(searchType, mode, p);
803 if (chkAddr != addr) {
804
805 //Key may be the opposite one (negative zero or compressed key)
806 k.Neg();
807 k.Add(&secp->order);
808 p = secp->ComputePublicKey(&k);
809 if (startPubKeySpecified) {
810 sp.y.ModNeg();
811 p = secp->AddDirect(p, sp);
812 }
813 string chkAddr = secp->GetAddress(searchType, mode, p);
814 if (chkAddr != addr) {
815 printf("\nWarning, wrong private key generated !\n");
816 printf(" Addr :%s\n", addr.c_str());
817 printf(" Check:%s\n", chkAddr.c_str());
818 printf(" Endo:%d incr:%d comp:%d\n", endomorphism, incr, mode);
819 return false;
820 }
821
822 }
823
824 output(addr, secp->GetPrivAddress(mode ,k), k.GetBase16());
825
826 return true;
827
828}
829

Callers

nothing calls this directly

Calls 10

NegMethod · 0.80
ModNegMethod · 0.80
ModMulK1orderMethod · 0.80
ModMulK1Method · 0.80
ComputePublicKeyMethod · 0.80
AddDirectMethod · 0.80
GetAddressMethod · 0.80
GetPrivAddressMethod · 0.80
GetBase16Method · 0.80
AddMethod · 0.45

Tested by

no test coverage detected