Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added candy #283

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c68e662
Read CHANGELOG.md to see the updates
albertobsd Apr 28, 2023
765f23d
Fixed README.md
albertobsd Apr 28, 2023
63aa8fb
some fixes, check CHANGELOG.md
albertobsd Apr 30, 2023
e5d093f
Update keyhunt.cpp
seega May 4, 2023
65987aa
Update Random.cpp
seega May 4, 2023
f08dff0
Merge pull request #208 from seega/main
albertobsd May 4, 2023
d3d9ef6
cygwin fix v2
seega May 6, 2023
ec56e1f
cygwin fix
seega May 6, 2023
0253114
Revert "cygwin fix"
seega May 6, 2023
6a25033
Update Random.cpp
seega May 6, 2023
1cce3bb
Merge pull request #210 from seega/main
albertobsd May 7, 2023
d29ea17
added option -6 to skip checksums, check CHANGELOG.md
albertobsd May 7, 2023
8d54417
Update keyhunt.cpp
seega May 7, 2023
dfb710b
Merge pull request #212 from seega/main
albertobsd May 7, 2023
8a51838
Added warning for BSGS and Endomorphism, they don't work together
albertobsd May 8, 2023
5a8d6c0
Update README.md
mysterek1337 May 12, 2023
84330e6
Merge pull request #213 from mysterek1337/main
albertobsd May 12, 2023
a278e8c
added keyhunt_legacy.cpp legacy version, check README.md
albertobsd May 16, 2023
98b20ef
removed unused flags in the Makefile
albertobsd May 16, 2023
dddd177
fixed some bugs for legacy version
albertobsd May 17, 2023
3cd3376
Small editions of unused variables
albertobsd May 17, 2023
f92555a
endomorphism for eth
albertobsd May 18, 2023
88934c8
endomorphism for eth in legacy version
albertobsd May 18, 2023
d345a3c
Speed x2 for BSGS mode main
albertobsd May 19, 2023
2b3c218
Double BSGS speed for legacy version
albertobsd May 20, 2023
e3c6762
BSGS Server (Only linux)
albertobsd May 30, 2023
a19a745
Solving some BSGS Server issues
albertobsd Jun 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed some bugs for legacy version
  • Loading branch information
albertobsd committed May 17, 2023
commit dddd177162cd2fe43ebe0357e99cbf12b7e8321b
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ legacy:
gcc -march=native -mtune=native -Wno-unused-result -Ofast -ftree-vectorize -c base58/base58.c -o base58.o
gcc -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c xxhash/xxhash.c -o xxhash.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c util.c -o util.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c hashing.c -o hashing.o -lcrypto
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c gmp256k1/Int.cpp -o Int.o -lgmp
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c gmp256k1/Point.cpp -o Point.o -lgmp
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c gmp256k1/GMP256K1.cpp -o GMP256K1.o -lgmp
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c gmp256k1/IntMod.cpp -o IntMod.o -lgmp
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -flto -c gmp256k1/Random.cpp -o Random.o -lgmp
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -flto -c gmp256k1/IntGroup.cpp -o IntGroup.o -lgmp
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -o keyhunt keyhunt_legacy.cpp base58.o bloom.o oldbloom.o xxhash.o util.o Int.o Point.o GMP256K1.o IntMod.o IntGroup.o Random.o hashing.o -lm -lpthread -lcrypto -lgmp
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c sha3/sha3.c -o sha3.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c sha3/keccak.c -o keccak.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c hashing.c -o hashing.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c gmp256k1/Int.cpp -o Int.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c gmp256k1/Point.cpp -o Point.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c gmp256k1/GMP256K1.cpp -o GMP256K1.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c gmp256k1/IntMod.cpp -o IntMod.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -flto -c gmp256k1/Random.cpp -o Random.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -flto -c gmp256k1/IntGroup.cpp -o IntGroup.o
g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -o keyhunt keyhunt_legacy.cpp base58.o bloom.o oldbloom.o xxhash.o util.o Int.o Point.o GMP256K1.o IntMod.o IntGroup.o Random.o hashing.o sha3.o keccak.o -lm -lpthread -lcrypto -lgmp
rm -r *.o
75 changes: 61 additions & 14 deletions gmp256k1/GMP256K1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Secp256K1::~Secp256K1() {

Point Secp256K1::Negation(Point &p) {
Point Q;
Q.Clear();
//Q.Clear();
Q.x.Set(&p.x);
Q.y.Set(&this->P);
Q.y.Sub(&p.y);
Expand Down Expand Up @@ -562,33 +562,80 @@ void Secp256K1::GetHash160(int type, bool compressed, Point &pubKey, unsigned ch
void Secp256K1::GetHash160(int type,bool compressed,
Point &k0,Point &k1,Point &k2,Point &k3,
uint8_t *h0,uint8_t *h1,uint8_t *h2,uint8_t *h3) {
GetHash160(type,compressed,k0,h0);
GetHash160(type,compressed,k1,h1);
GetHash160(type,compressed,k2,h2);
GetHash160(type,compressed,k3,h3);

switch (type) {
case P2PKH:
case BECH32:
unsigned char digests[4][65];

if (!compressed) {
// Full public key
digests[0][0] = 0x4;
digests[1][0] = 0x4;
digests[2][0] = 0x4;
digests[3][0] = 0x4;
k0.x.Get32Bytes(digests[0] + 1);
k0.y.Get32Bytes(digests[0] + 33);
k1.x.Get32Bytes(digests[1] + 1);
k1.y.Get32Bytes(digests[1] + 33);
k2.x.Get32Bytes(digests[2] + 1);
k2.y.Get32Bytes(digests[2] + 33);
k3.x.Get32Bytes(digests[3] + 1);
k3.y.Get32Bytes(digests[3] + 33);

sha256_4(65, digests[0], digests[1],digests[2],digests[3],digests[0], digests[1],digests[2],digests[3]);
} else {
// Compressed public key
digests[0][0] = (unsigned char) k0.y.IsEven() ? 0x2 : 0x3;
digests[1][0] = (unsigned char) k1.y.IsEven() ? 0x2 : 0x3;
digests[2][0] = (unsigned char) k2.y.IsEven() ? 0x2 : 0x3;
digests[3][0] = (unsigned char) k3.y.IsEven() ? 0x2 : 0x3;
k0.x.Get32Bytes(digests[0] + 1);
k1.x.Get32Bytes(digests[1] + 1);
k2.x.Get32Bytes(digests[2] + 1);
k3.x.Get32Bytes(digests[3] + 1);
sha256_4(33, digests[0], digests[1],digests[2],digests[3],digests[0], digests[1],digests[2],digests[3]);
}
rmd160_4(32, digests[0], digests[1],digests[2],digests[3],h0,h1,h2,h3);

break;
case P2SH:
printf("Unsoported P2SH\n");
exit(0);
/*
// Redeem Script (1 to 1 P2SH)
unsigned char script[64];
script[0] = 0x00; // OP_0
script[1] = 0x14; // PUSH 20 bytes
GetHash160(P2PKH, compressed, pubKey, script + 2);
sha256(script, 22, shapk);
rmd160(shapk,32,hash);
*/
break;
}
}


void Secp256K1::GetHash160_fromX(int type,unsigned char prefix,
Int *k0,Int *k1,Int *k2,Int *k3,
uint8_t *h0,uint8_t *h1,uint8_t *h2,uint8_t *h3) {
unsigned char digests[4][33];
int i;
//int i;
switch (type) {
case P2PKH:

k0->Get32Bytes((unsigned char*)(digests[0] + 1));
k1->Get32Bytes((unsigned char*)(digests[1] + 1));
k2->Get32Bytes((unsigned char*)(digests[2] + 1));
k3->Get32Bytes((unsigned char*)(digests[3] + 1));
for(i = 0; i < 4; i++) {
digests[i][0] = prefix;
sha256(digests[i],33,digests[i]);
}
rmd160(digests[0],32,h0);
rmd160(digests[1],32,h1);
rmd160(digests[2],32,h2);
rmd160(digests[3],32,h3);
digests[0][0] = prefix;
digests[1][0] = prefix;
digests[2][0] = prefix;
digests[3][0] = prefix;

sha256_4(33, digests[0], digests[1],digests[2],digests[3],digests[0], digests[1],digests[2],digests[3]);
rmd160_4(32, digests[0], digests[1],digests[2],digests[3],h0,h1,h2,h3);

break;

case P2SH:
Expand Down
11 changes: 4 additions & 7 deletions gmp256k1/Int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ bool Int::IsOdd() {
}

int Int::GetSize() {
/*
gmp_printf("GetSize of %Zi\n",num);
fflush(stdout);
*/
int r = mpz_sizeinbase(num,2);
if(r % 8 == 0)
return (int)(r/8);
Expand Down Expand Up @@ -281,13 +285,6 @@ char* Int::GetBase16() {
return mpz_get_str(NULL,16,num);
}

/*
char* Int::GetBaseN(int n,const char *charset);
char* Int::GetBlockStr();
char* Int::GetC64Str(int nbDigit);
*/


void Int::SetInt64(uint64_t value) {
char my_str_value[U64STRINGSIZE]; // 30 digits + null terminator
snprintf(my_str_value, U64STRINGSIZE, "%lu", value);
Expand Down
34 changes: 5 additions & 29 deletions gmp256k1/Point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include <stdio.h>

Point::Point() {
mpz_set_ui(x.num,0);
mpz_set_ui(y.num,0);
mpz_set_ui(z.num,0);

}

Expand Down Expand Up @@ -87,22 +90,7 @@ void Point::Reduce() {
i.ModInv();
x.ModMul(&x,&i);
y.ModMul(&y,&i);
z.SetInt32(1);
/*
Yes, exactly. The Reduce function you mentioned converts the point from projective coordinates back to affine coordinates.

In elliptic curve computations, it's often more efficient to work with projective coordinates because they allow addition and doubling operations to be performed without needing to do division operations, which are computationally expensive.

However, at the end of your computation, or at certain intermediate stages, you might need to convert the point back to affine coordinates. That's what this Reduce function is doing.

Here's what each line in Reduce is doing:

Int i(&z); creates an integer i from the z coordinate of the point.
i.ModInv(); computes the modular inverse of i, effectively performing a division operation. Note that this operation is only valid if i is not zero.
x.ModMul(&x,&i); and y.ModMul(&y,&i); multiply the x and y coordinates by the modular inverse of z, effectively dividing them by z. This converts the x and y coordinates from projective back to affine coordinates.
z.SetInt32(1); sets the z coordinate to 1, completing the conversion to affine coordinates.
In the end, Reduce leaves the point in the form (X/Z, Y/Z, 1), which is equivalent to (X, Y) in affine coordinates.
*/
z.SetInt32(1);
}

bool Point::equals(Point &p) {
Expand All @@ -120,19 +108,7 @@ Point& Point::operator=(const Point& other) {
mpz_set(x.num,other.x.num);
mpz_set(y.num,other.y.num);
mpz_set(z.num,other.z.num);
/*
ptrs[0] = x.GetBase16();
ptrs[1] = y.GetBase16();
ptrs[2] = z.GetBase16();
printf("Point\n");
printf("X: %s\n",ptrs[0]);
printf("Y: %s\n",ptrs[1]);
printf("Z: %s\n",ptrs[2]);
printf("End Point\n");
for(int i = 0; i<3; i++) {
free(ptrs[i]);
}
*/

// Return the current object
return *this;
}
Expand Down
Loading