Skip to content

Commit

Permalink
Fix for uncompressed addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanLucPons committed Apr 9, 2019
1 parent ce4b19c commit f50f6f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
4 changes: 2 additions & 2 deletions SECP256K1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,14 @@ void Secp256K1::GetHash160(int type,bool compressed,

void Secp256K1::GetHash160(int type, bool compressed, Point &pubKey, unsigned char *hash) {

unsigned char shapk[64];

switch (type) {

case P2PKH:
case BECH32:
{
unsigned char publicKeyBytes[128];
unsigned char shapk[64];

if (!compressed) {

Expand Down Expand Up @@ -461,7 +462,6 @@ void Secp256K1::GetHash160(int type, bool compressed, Point &pubKey, unsigned ch

// Redeem Script (1 to 1 P2SH)
unsigned char script[64];
unsigned char shapk[64];

script[0] = 0x00; // OP_0
script[1] = 0x14; // PUSH 20 bytes
Expand Down
21 changes: 8 additions & 13 deletions Vanity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ void VanitySearch::updateFound() {

// ----------------------------------------------------------------------------

static int nbFail = 0;

bool VanitySearch::checkPrivKey(string addr, Int &key, int32_t incr, int endomorphism, bool mode) {

Int k(&key);
Expand All @@ -598,19 +600,12 @@ bool VanitySearch::checkPrivKey(string addr, Int &key, int32_t incr, int endomor
Point p = secp.ComputePublicKey(&k);
string chkAddr = secp.GetAddress(searchType, mode, p);
if (chkAddr != addr) {
if (mode) {
// Compressed address (key may be the opposite one)
k.Neg();
k.Add(&secp.order);
p = secp.ComputePublicKey(&k);
string chkAddr = secp.GetAddress(searchType, mode, p);
if (chkAddr != addr) {
printf("\nWarning, wrong private key generated !\n");
printf(" Addr :%s\n", addr.c_str());
printf(" Check:%s\n", chkAddr.c_str());
return false;
}
} else {
//Key may be the opposite one (negative zero or compressed key)
k.Neg();
k.Add(&secp.order);
p = secp.ComputePublicKey(&k);
string chkAddr = secp.GetAddress(searchType, mode, p);
if (chkAddr != addr) {
printf("\nWarning, wrong private key generated !\n");
printf(" Addr :%s\n", addr.c_str());
printf(" Check:%s\n", chkAddr.c_str());
Expand Down

0 comments on commit f50f6f9

Please sign in to comment.