From 0da18210b5d38bd6685501d1dad13abeacc863b2 Mon Sep 17 00:00:00 2001 From: jmr2704 Date: Fri, 4 Oct 2024 05:55:57 -0300 Subject: [PATCH 1/2] feat: Compiling on Mac OS and Windows, removed warnings when compiling, --- Makefile | 70 ++++- base58/base58.c | 391 ++++++++++++------------ gmp256k1/Random.cpp | 6 +- hash/ripemd160.cpp | 11 +- hash/ripemd160_sse.cpp | 19 +- hash/sha256.cpp | 14 +- hash/sha256_sse.cpp | 10 +- keyhunt.cpp | 662 +++++++++++++++++++++------------------- rmd160/rmd160.h | 23 +- secp256k1/Int.cpp | 110 +++---- secp256k1/IntMod.cpp | 39 ++- secp256k1/Random.cpp | 12 +- secp256k1/SECP256K1.cpp | 4 +- sha3/keccak.c | 71 +++-- sha3/sha3.h | 57 ++-- util.c | 28 +- util.h | 24 +- 17 files changed, 842 insertions(+), 709 deletions(-) diff --git a/Makefile b/Makefile index b5524e4..fe2ccfb 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,15 @@ default: + # Compile C++ With g++ g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -flto -c oldbloom/bloom.cpp -o oldbloom.o g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -flto -c bloom/bloom.cpp -o bloom.o + # Compile C with gcc gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-unused-parameter -Ofast -ftree-vectorize -c base58/base58.c -o base58.o gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c rmd160/rmd160.c -o rmd160.o - g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c sha3/sha3.c -o sha3.o - g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c sha3/keccak.c -o keccak.o + gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c sha3/sha3.c -o sha3.o + gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c sha3/keccak.c -o keccak.o gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c xxhash/xxhash.c -o xxhash.o - g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c util.c -o util.o + gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c util.c -o util.o + # Compile C++ With g++ g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/Int.cpp -o Int.o g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/Point.cpp -o Point.o g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/SECP256K1.cpp -o SECP256K1.o @@ -17,35 +20,48 @@ default: g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/sha256.o -ftree-vectorize -flto -c hash/sha256.cpp g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/ripemd160_sse.o -ftree-vectorize -flto -c hash/ripemd160_sse.cpp g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/sha256_sse.o -ftree-vectorize -flto -c hash/sha256_sse.cpp - g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -o keyhunt keyhunt.cpp base58.o rmd160.o hash/ripemd160.o hash/ripemd160_sse.o hash/sha256.o hash/sha256_sse.o bloom.o oldbloom.o xxhash.o util.o Int.o Point.o SECP256K1.o IntMod.o Random.o IntGroup.o sha3.o keccak.o -lm -lpthread + g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -o cacahave keyhunt.cpp base58.o rmd160.o hash/ripemd160.o hash/ripemd160_sse.o hash/sha256.o hash/sha256_sse.o bloom.o oldbloom.o xxhash.o util.o Int.o Point.o SECP256K1.o IntMod.o Random.o IntGroup.o sha3.o keccak.o -lm -lpthread rm -r *.o + clean: - rm keyhunt + rm -f keyhunt keyhunt.exe legacy: + # Compile C++ With g++ g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -flto -c oldbloom/bloom.cpp -o oldbloom.o g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -flto -c bloom/bloom.cpp -o bloom.o + + # Compile .c with gcc 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 + gcc -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c sha3/sha3.c -o sha3.o + gcc -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c sha3/keccak.c -o keccak.o + gcc -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -c hashing.c -o hashing.o + + # Compile C++ With g++ 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 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 + + g++ -march=native -mtune=native -Wall -Wextra -Ofast -ftree-vectorize -o cacahaveLegacy 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 bsgsd: + # Compile C++ With g++ g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -flto -c oldbloom/bloom.cpp -o oldbloom.o g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -flto -c bloom/bloom.cpp -o bloom.o + + # Compile .c with gcc gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-unused-parameter -Ofast -ftree-vectorize -c base58/base58.c -o base58.o gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c rmd160/rmd160.c -o rmd160.o - g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c sha3/sha3.c -o sha3.o - g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c sha3/keccak.c -o keccak.o + gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c sha3/sha3.c -o sha3.o + gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c sha3/keccak.c -o keccak.o gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c xxhash/xxhash.c -o xxhash.o + + # Compile C++ With g++ g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c util.c -o util.o g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/Int.cpp -o Int.o g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/Point.cpp -o Point.o @@ -57,5 +73,33 @@ bsgsd: g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/sha256.o -ftree-vectorize -flto -c hash/sha256.cpp g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/ripemd160_sse.o -ftree-vectorize -flto -c hash/ripemd160_sse.cpp g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/sha256_sse.o -ftree-vectorize -flto -c hash/sha256_sse.cpp - g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -o bsgsd bsgsd.cpp base58.o rmd160.o hash/ripemd160.o hash/ripemd160_sse.o hash/sha256.o hash/sha256_sse.o bloom.o oldbloom.o xxhash.o util.o Int.o Point.o SECP256K1.o IntMod.o Random.o IntGroup.o sha3.o keccak.o -lm -lpthread - rm -r *.o + + g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -o bsgsd bsgsd.cpp base58.o rmd160.o hash/ripemd160.o hash/ripemd160_sse.o hash/sha256.o hash/sha256_sse.o bloom.o oldbloom.o xxhash.o util.o Int.o Point.o SECP256K1.o IntMod.o Random.o IntGroup.o sha3.o keccak.o -lm -lpthread + + rm -f *.o + +windows: + # Compile C++ with MinGW + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c oldbloom/bloom.cpp -o oldbloom.o + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c bloom/bloom.cpp -o bloom.o + # Compile C with MinGW + x86_64-w64-mingw32-gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-unused-parameter -Ofast -ftree-vectorize -c base58/base58.c -o base58.o + x86_64-w64-mingw32-gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c rmd160/rmd160.c -o rmd160.o + x86_64-w64-mingw32-gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c sha3/sha3.c -o sha3.o + x86_64-w64-mingw32-gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c sha3/keccak.c -o keccak.o + x86_64-w64-mingw32-gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c xxhash/xxhash.c -o xxhash.o + x86_64-w64-mingw32-gcc -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Ofast -ftree-vectorize -c util.c -o util.o + # Compile C++ with MinGW + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/Int.cpp -o Int.o + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/Point.cpp -o Point.o + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/SECP256K1.cpp -o SECP256K1.o + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/IntMod.cpp -o IntMod.o + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/Random.cpp -o Random.o + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -c secp256k1/IntGroup.cpp -o IntGroup.o + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/ripemd160.o -ftree-vectorize -c hash/ripemd160.cpp + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/sha256.o -ftree-vectorize -c hash/sha256.cpp + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/ripemd160_sse.o -ftree-vectorize -c hash/ripemd160_sse.cpp + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -o hash/sha256_sse.o -ftree-vectorize -c hash/sha256_sse.cpp + # Compile .exe + x86_64-w64-mingw32-g++ -m64 -march=native -mtune=native -mssse3 -Wall -Wextra -Wno-deprecated-copy -Ofast -ftree-vectorize -o cacahave.exe rmd160.o hash/ripemd160.o hash/ripemd160_sse.o base58.o hash/sha256.o hash/sha256_sse.o bloom.o oldbloom.o xxhash.o util.o Int.o Point.o SECP256K1.o IntMod.o Random.o IntGroup.o sha3.o keccak.o keyhunt.cpp -lm -lpthread + rm -f *.o diff --git a/base58/base58.c b/base58/base58.c index 1dcc4ff..6bec9a0 100644 --- a/base58/base58.c +++ b/base58/base58.c @@ -21,14 +21,14 @@ bool (*b58_sha256_impl)(void *, const void *, size_t) = NULL; static const int8_t b58digits_map[] = { - -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1, - -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1, - 22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1, - -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46, - 47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1, + -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1, + 22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1, + -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46, + 47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1, }; typedef uint64_t b58_maxint_t; @@ -38,215 +38,212 @@ static const b58_almostmaxint_t b58_almostmaxint_mask = ((((b58_maxint_t)1) << b bool b58tobin(void *bin, size_t *binszp, const char *b58, size_t b58sz) { - size_t binsz = *binszp; - const unsigned char *b58u = (void*)b58; - unsigned char *binu = bin; - size_t outisz = (binsz + sizeof(b58_almostmaxint_t) - 1) / sizeof(b58_almostmaxint_t); - b58_almostmaxint_t outi[outisz]; - b58_maxint_t t; - b58_almostmaxint_t c; - size_t i, j; - uint8_t bytesleft = binsz % sizeof(b58_almostmaxint_t); - b58_almostmaxint_t zeromask = bytesleft ? (b58_almostmaxint_mask << (bytesleft * 8)) : 0; - unsigned zerocount = 0; - - if (!b58sz) - b58sz = strlen(b58); - - for (i = 0; i < outisz; ++i) { - outi[i] = 0; - } - - // Leading zeros, just count - for (i = 0; i < b58sz && b58u[i] == '1'; ++i) - ++zerocount; - - for ( ; i < b58sz; ++i) - { - if (b58u[i] & 0x80) - // High-bit set on invalid digit - return false; - if (b58digits_map[b58u[i]] == -1) - // Invalid base58 digit - return false; - c = (unsigned)b58digits_map[b58u[i]]; - for (j = outisz; j--; ) - { - t = ((b58_maxint_t)outi[j]) * 58 + c; - c = t >> b58_almostmaxint_bits; - outi[j] = t & b58_almostmaxint_mask; - } - if (c) - // Output number too big (carry to the next int32) - return false; - if (outi[0] & zeromask) - // Output number too big (last int32 filled too far) - return false; - } - - j = 0; - if (bytesleft) { - for (i = bytesleft; i > 0; --i) { - *(binu++) = (outi[0] >> (8 * (i - 1))) & 0xff; - } - ++j; - } - - for (; j < outisz; ++j) - { - for (i = sizeof(*outi); i > 0; --i) { - *(binu++) = (outi[j] >> (8 * (i - 1))) & 0xff; - } - } - - // Count canonical base58 byte count - binu = bin; - for (i = 0; i < binsz; ++i) - { - if (binu[i]) - break; - --*binszp; - } - *binszp += zerocount; - - return true; + size_t binsz = *binszp; + const unsigned char *b58u = (void*)b58; + unsigned char *binu = bin; + size_t outisz = (binsz + sizeof(b58_almostmaxint_t) - 1) / sizeof(b58_almostmaxint_t); + b58_almostmaxint_t outi[outisz]; + b58_maxint_t t; + b58_almostmaxint_t c; + size_t i, j; + uint8_t bytesleft = binsz % sizeof(b58_almostmaxint_t); + b58_almostmaxint_t zeromask = bytesleft ? (b58_almostmaxint_mask << (bytesleft * 8)) : 0; + unsigned zerocount = 0; + + memset(outi, 0, sizeof(outi)); + + if (!b58sz) + b58sz = strlen(b58); + + // Leading zeros, just count + for (i = 0; i < b58sz && b58u[i] == '1'; ++i) + ++zerocount; + + for ( ; i < b58sz; ++i) + { + if (b58u[i] & 0x80) + // High-bit set on invalid digit + return false; + if (b58digits_map[b58u[i]] == -1) + // Invalid base58 digit + return false; + c = (unsigned)b58digits_map[b58u[i]]; + for (j = outisz; j--; ) + { + t = ((b58_maxint_t)outi[j]) * 58 + c; + c = t >> b58_almostmaxint_bits; + outi[j] = t & b58_almostmaxint_mask; + } + if (c) + // Output number too big (carry to the next int32) + return false; + if (outi[0] & zeromask) + // Output number too big (last int32 filled too far) + return false; + } + + j = 0; + if (bytesleft) { + for (i = bytesleft; i > 0; --i) { + *(binu++) = (outi[0] >> (8 * (i - 1))) & 0xff; + } + ++j; + } + + for (; j < outisz; ++j) + { + for (i = sizeof(*outi); i > 0; --i) { + *(binu++) = (outi[j] >> (8 * (i - 1))) & 0xff; + } + } + + // Count canonical base58 byte count + binu = bin; + for (i = 0; i < binsz; ++i) + { + if (binu[i]) + break; + --*binszp; + } + *binszp += zerocount; + + return true; } static bool my_dblsha256(void *hash, const void *data, size_t datasz) { - uint8_t buf[0x20]; - return b58_sha256_impl(buf, data, datasz) && b58_sha256_impl(hash, buf, sizeof(buf)); + uint8_t buf[0x20]; + return b58_sha256_impl(buf, data, datasz) && b58_sha256_impl(hash, buf, sizeof(buf)); } int b58check(const void *bin, size_t binsz, const char *base58str, size_t b58sz) { - unsigned char buf[32]; - const uint8_t *binc = bin; - unsigned i; - if (binsz < 4) - return -4; - if (!my_dblsha256(buf, bin, binsz - 4)) - return -2; - if (memcmp(&binc[binsz - 4], buf, 4)) - return -1; - - // Check number of zeros is correct AFTER verifying checksum (to avoid possibility of accessing base58str beyond the end) - for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i) - {} // Just finding the end of zeros, nothing to do in loop - if (binc[i] == '\0' || base58str[i] == '1') - return -3; - - return binc[0]; + unsigned char buf[32]; + const uint8_t *binc = bin; + unsigned i; + if (binsz < 4) + return -4; + if (!my_dblsha256(buf, bin, binsz - 4)) + return -2; + if (memcmp(&binc[binsz - 4], buf, 4)) + return -1; + + // Check number of zeros is correct AFTER verifying checksum (to avoid possibility of accessing base58str beyond the end) + for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i) + {} // Just finding the end of zeros, nothing to do in loop + if (binc[i] == '\0' || base58str[i] == '1') + return -3; + + return binc[0]; } static const char b58digits_ordered[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz) { - const uint8_t *bin = data; - int carry; - size_t i, j, high, zcount = 0; - size_t size; - - while (zcount < binsz && !bin[zcount]) - ++zcount; - - size = (binsz - zcount) * 138 / 100 + 1; - uint8_t buf[size]; - memset(buf, 0, size); - - for (i = zcount, high = size - 1; i < binsz; ++i, high = j) - { - for (carry = bin[i], j = size - 1; (j > high) || carry; --j) - { - carry += 256 * buf[j]; - buf[j] = carry % 58; - carry /= 58; - if (!j) { - // Otherwise j wraps to maxint which is > high - break; - } - } - } - - for (j = 0; j < size && !buf[j]; ++j); - - if (*b58sz <= zcount + size - j) - { - *b58sz = zcount + size - j + 1; - return false; - } - - if (zcount) - memset(b58, '1', zcount); - for (i = zcount; j < size; ++i, ++j) - b58[i] = b58digits_ordered[buf[j]]; - b58[i] = '\0'; - *b58sz = i + 1; - - return true; + const uint8_t *bin = data; + int carry; + size_t i, j, high, zcount = 0; + size_t size; + + while (zcount < binsz && !bin[zcount]) + ++zcount; + + size = (binsz - zcount) * 138 / 100 + 1; + uint8_t buf[size]; + memset(buf, 0, size); + + for (i = zcount, high = size - 1; i < binsz; ++i, high = j) + { + for (carry = bin[i], j = size - 1; (j > high) || carry; --j) + { + carry += 256 * buf[j]; + buf[j] = carry % 58; + carry /= 58; + if (!j) { + // Otherwise j wraps to maxint which is > high + break; + } + } + } + + for (j = 0; j < size && !buf[j]; ++j); + + if (*b58sz <= zcount + size - j) + { + *b58sz = zcount + size - j + 1; + return false; + } + + if (zcount) + memset(b58, '1', zcount); + for (i = zcount; j < size; ++i, ++j) + b58[i] = b58digits_ordered[buf[j]]; + b58[i] = '\0'; + *b58sz = i + 1; + + return true; } -bool b58enc_custom(char *b58, size_t *b58sz, const void *data, size_t binsz,char *buffer) +bool b58enc_custom(char *b58, size_t *b58sz, const void *data, size_t binsz, char *buffer) { - const uint8_t *bin = data; - int carry; - size_t i, j, high, zcount = 0; - size_t size; - - while (zcount < binsz && !bin[zcount]) - ++zcount; - - size = (binsz - zcount) * 138 / 100 + 1; - uint8_t buf[size]; - memset(buf, 0, size); - - for (i = zcount, high = size - 1; i < binsz; ++i, high = j) - { - for (carry = bin[i], j = size - 1; (j > high) || carry; --j) - { - carry += 256 * buf[j]; - buf[j] = carry % 58; - carry /= 58; - if (!j) { - // Otherwise j wraps to maxint which is > high - break; - } - } - } - - for (j = 0; j < size && !buf[j]; ++j); - - if (*b58sz <= zcount + size - j) - { - *b58sz = zcount + size - j + 1; - return false; - } - - if (zcount) - memset(b58, buffer[0], zcount); - for (i = zcount; j < size; ++i, ++j) - b58[i] = buffer[buf[j]]; - b58[i] = '\0'; - *b58sz = i + 1; - - return true; + const uint8_t *bin = data; + int carry; + size_t i, j, high, zcount = 0; + size_t size; + + while (zcount < binsz && !bin[zcount]) + ++zcount; + + size = (binsz - zcount) * 138 / 100 + 1; + uint8_t buf[size]; + memset(buf, 0, size); + + for (i = zcount, high = size - 1; i < binsz; ++i, high = j) + { + for (carry = bin[i], j = size - 1; (j > high) || carry; --j) + { + carry += 256 * buf[j]; + buf[j] = carry % 58; + carry /= 58; + if (!j) { + // Otherwise j wraps to maxint which is > high + break; + } + } + } + + for (j = 0; j < size && !buf[j]; ++j); + + if (*b58sz <= zcount + size - j) + { + *b58sz = zcount + size - j + 1; + return false; + } + + if (zcount) + memset(b58, buffer[0], zcount); + for (i = zcount; j < size; ++i, ++j) + b58[i] = buffer[buf[j]]; + b58[i] = '\0'; + *b58sz = i + 1; + + return true; } - bool b58check_enc(char *b58c, size_t *b58c_sz, uint8_t ver, const void *data, size_t datasz) { - uint8_t buf[1 + datasz + 0x20]; - uint8_t *hash = &buf[1 + datasz]; - - buf[0] = ver; - memcpy(&buf[1], data, datasz); - if (!my_dblsha256(hash, buf, datasz + 1)) - { - *b58c_sz = 0; - return false; - } - - return b58enc(b58c, b58c_sz, buf, 1 + datasz + 4); + uint8_t buf[1 + datasz + 0x20]; + uint8_t *hash = &buf[1 + datasz]; + + buf[0] = ver; + memcpy(&buf[1], data, datasz); + if (!my_dblsha256(hash, buf, datasz + 1)) + { + *b58c_sz = 0; + return false; + } + + return b58enc(b58c, b58c_sz, buf, 1 + datasz + 4); } diff --git a/gmp256k1/Random.cpp b/gmp256k1/Random.cpp index 9160714..75f40d5 100644 --- a/gmp256k1/Random.cpp +++ b/gmp256k1/Random.cpp @@ -12,7 +12,11 @@ #include #include #include - #include + #ifdef __unix__ || __unix + #include + #else + #include + #endif #if defined(GRND_NONBLOCK) #define USE_GETRANDOM #endif diff --git a/hash/ripemd160.cpp b/hash/ripemd160.cpp index 8584d8f..a860625 100644 --- a/hash/ripemd160.cpp +++ b/hash/ripemd160.cpp @@ -311,11 +311,12 @@ void ripemd160(unsigned char *input,int length,unsigned char *digest) { } std::string ripemd160_hex(unsigned char *digest) { + char buf[2 * 20 + 1]; + buf[2 * 20] = '\0'; - char buf[2 * 20 + 1]; - buf[2 * 20] = 0; - for (int i = 0; i < 20; i++) - sprintf(buf + i * 2, "%02x", (int)digest[i]); - return std::string(buf); + for (int i = 0; i < 20; i++) { + snprintf(buf + i * 2, sizeof(buf) - i * 2, "%02x", (int)digest[i]); + } + return std::string(buf); } diff --git a/hash/ripemd160_sse.cpp b/hash/ripemd160_sse.cpp index 20ff459..27675a3 100644 --- a/hash/ripemd160_sse.cpp +++ b/hash/ripemd160_sse.cpp @@ -22,7 +22,7 @@ // Internal SSE RIPEMD-160 implementation. namespace ripemd160sse { -#ifdef WIN64 +#ifdef _MSC_VER static const __declspec(align(16)) uint32_t _init[] = { #else static const uint32_t _init[] __attribute__ ((aligned (16))) = { @@ -44,12 +44,12 @@ namespace ripemd160sse { #ifdef WIN64 -#define not(x) _mm_andnot_si128(x, _mm_cmpeq_epi32(_mm_setzero_si128(), _mm_setzero_si128())) +#define bitwise_not(x) _mm_andnot_si128(x, _mm_cmpeq_epi32(_mm_setzero_si128(), _mm_setzero_si128())) #define f1(x,y,z) _mm_xor_si128(x, _mm_xor_si128(y, z)) #define f2(x,y,z) _mm_or_si128(_mm_and_si128(x,y),_mm_andnot_si128(x,z)) -#define f3(x,y,z) _mm_xor_si128(_mm_or_si128(x,not(y)),z) +#define f3(x,y,z) _mm_xor_si128(_mm_or_si128(x,bitwise_not(y)),z) #define f4(x,y,z) _mm_or_si128(_mm_and_si128(x,z),_mm_andnot_si128(z,y)) -#define f5(x,y,z) _mm_xor_si128(x,_mm_or_si128(y,not(z))) +#define f5(x,y,z) _mm_xor_si128(x,_mm_or_si128(y,bitwise_not(z))) #else @@ -61,7 +61,6 @@ namespace ripemd160sse { #endif - #define add3(x0, x1, x2 ) _mm_add_epi32(_mm_add_epi32(x0, x1), x2) #define add4(x0, x1, x2, x3) _mm_add_epi32(_mm_add_epi32(x0, x1), _mm_add_epi32(x2, x3)) @@ -300,11 +299,11 @@ namespace ripemd160sse { #ifdef WIN64 #define DEPACK(d,i) \ -((uint32_t *)d)[0] = s[0].m128i_u32[i]; \ -((uint32_t *)d)[1] = s[1].m128i_u32[i]; \ -((uint32_t *)d)[2] = s[2].m128i_u32[i]; \ -((uint32_t *)d)[3] = s[3].m128i_u32[i]; \ -((uint32_t *)d)[4] = s[4].m128i_u32[i]; + ((uint32_t *)d)[0] = _mm_extract_epi32(s[0], i); \ + ((uint32_t *)d)[1] = _mm_extract_epi32(s[1], i); \ + ((uint32_t *)d)[2] = _mm_extract_epi32(s[2], i); \ + ((uint32_t *)d)[3] = _mm_extract_epi32(s[3], i); \ + ((uint32_t *)d)[4] = _mm_extract_epi32(s[4], i); #else diff --git a/hash/sha256.cpp b/hash/sha256.cpp index e514e27..1d682f1 100644 --- a/hash/sha256.cpp +++ b/hash/sha256.cpp @@ -436,9 +436,12 @@ void sha256(unsigned char *input, size_t length, unsigned char *digest) { } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-const-variable" const uint8_t sizedesc_32[8] = { 0,0,0,0,0,0,1,0 }; const uint8_t sizedesc_33[8] = { 0,0,0,0,0,0,1,8 }; const uint8_t sizedesc_65[8] = { 0,0,0,0,0,0,2,8 }; +#pragma GCC diagnostic pop void sha256_33(unsigned char *input, unsigned char *digest) { @@ -496,13 +499,14 @@ void sha256_checksum(uint8_t *input, int length, uint8_t *checksum) { } std::string sha256_hex(unsigned char *digest) { + char buf[2 * 32 + 1]; + buf[2 * 32] = '\0'; - char buf[2*32+1]; - buf[2*32] = 0; - for (int i = 0; i < 32; i++) - sprintf(buf+i*2,"%02x",digest[i]); - return std::string(buf); + for (int i = 0; i < 32; i++) { + snprintf(buf + i * 2, sizeof(buf) - i * 2, "%02x", digest[i]); + } + return std::string(buf); } bool sha256_file(const char* file_name, uint8_t* checksum) { diff --git a/hash/sha256_sse.cpp b/hash/sha256_sse.cpp index 8e0f6cc..7c00b37 100644 --- a/hash/sha256_sse.cpp +++ b/hash/sha256_sse.cpp @@ -24,7 +24,7 @@ namespace _sha256sse { -#ifdef WIN64 +#ifdef _MSC_VER static const __declspec(align(16)) uint32_t _init[] = { #else static const uint32_t _init[] __attribute__ ((aligned (16))) = { @@ -568,10 +568,10 @@ void sha256sse_checksum(uint32_t *i0, uint32_t *i1, uint32_t *i2, uint32_t *i3, *((uint32_t *)d2) = __builtin_bswap32(s32[1]); *((uint32_t *)d3) = __builtin_bswap32(s32[0]); #else - *((uint32_t *)d0) = _byteswap_ulong(s[0].m128i_u32[3]); - *((uint32_t *)d1) = _byteswap_ulong(s[0].m128i_u32[2]); - *((uint32_t *)d2) = _byteswap_ulong(s[0].m128i_u32[1]); - *((uint32_t *)d3) = _byteswap_ulong(s[0].m128i_u32[0]); + *((uint32_t *)d0) = _byteswap_ulong(_mm_extract_epi32(s[0], 3)); + *((uint32_t *)d1) = _byteswap_ulong(_mm_extract_epi32(s[0], 2)); + *((uint32_t *)d2) = _byteswap_ulong(_mm_extract_epi32(s[0], 1)); + *((uint32_t *)d3) = _byteswap_ulong(_mm_extract_epi32(s[0], 0)); #endif } diff --git a/keyhunt.cpp b/keyhunt.cpp index a9a66e1..28fd860 100644 --- a/keyhunt.cpp +++ b/keyhunt.cpp @@ -11,6 +11,7 @@ email: albertobsd@gmail.com #include #include #include +#include #include "base58/libbase58.h" #include "rmd160/rmd160.h" #include "oldbloom/oldbloom.h" @@ -92,8 +93,14 @@ struct bPload { uint32_t finished; }; -#if defined(_WIN64) && !defined(__CYGWIN__) -#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop)) +#if defined(_WIN64) && !defined(__CYGWIN__) && defined(_MSC_VER) + +#define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop)) +#else + +#define PACK(__Declaration__) __Declaration__ __attribute__((__packed__)) +#endif + PACK(struct publickey { uint8_t parity; @@ -103,16 +110,6 @@ PACK(struct publickey uint64_t data64[4]; } X; }); -#else -struct __attribute__((__packed__)) publickey { - uint8_t parity; - union { - uint8_t data8[32]; - uint32_t data32[8]; - uint64_t data64[4]; - } X; -}; -#endif const char *Ccoinbuffer_default = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; @@ -437,17 +434,17 @@ int main(int argc, char **argv) { struct bPload *bPload_temp_ptr; size_t rsize; -#if defined(_WIN64) && !defined(__CYGWIN__) - DWORD s; - write_keys = CreateMutex(NULL, FALSE, NULL); - write_random = CreateMutex(NULL, FALSE, NULL); - bsgs_thread = CreateMutex(NULL, FALSE, NULL); -#else - pthread_mutex_init(&write_keys,NULL); - pthread_mutex_init(&write_random,NULL); - pthread_mutex_init(&bsgs_thread,NULL); - int s; -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + DWORD s; + write_keys = CreateMutex(NULL, FALSE, NULL); + write_random = CreateMutex(NULL, FALSE, NULL); + bsgs_thread = CreateMutex(NULL, FALSE, NULL); + #else + pthread_mutex_init(&write_keys,NULL); + pthread_mutex_init(&write_random,NULL); + pthread_mutex_init(&bsgs_thread,NULL); + int s; + #endif srand(time(NULL)); @@ -458,12 +455,18 @@ int main(int argc, char **argv) { ONE.SetInt32(1); BSGS_GROUP_SIZE.SetInt32(CPU_GRP_SIZE); -#if defined(_WIN64) && !defined(__CYGWIN__) - //Any windows secure random source goes here - rseed(clock() + time(NULL) + rand()); -#else - unsigned long rseedvalue; - int bytes_read = getrandom(&rseedvalue, sizeof(unsigned long), GRND_NONBLOCK); + #if defined(_WIN64) && !defined(__CYGWIN__) + //Any windows secure random source goes here + rseed(clock() + time(NULL) + rand()); + #else + unsigned long rseedvalue; + #if defined(__unix__) || defined(__unix) + int bytes_read = getrandom(&rseedvalue, sizeof(unsigned long), GRND_NONBLOCK); + #else + + arc4random_buf(&rseedvalue, sizeof(unsigned long)); + int bytes_read = sizeof(unsigned long); + #endif if(bytes_read > 0) { rseed(rseedvalue); /* @@ -472,15 +475,15 @@ int main(int argc, char **argv) { */ } else { - /* - what year is?? - WTF linux without RNG ? - */ - fprintf(stderr,"[E] Error getrandom() ?\n"); - exit(EXIT_FAILURE); - rseed(clock() + time(NULL) + rand()*rand()); - } -#endif + /* + what year is?? + WTF linux without RNG ? + */ + fprintf(stderr,"[E] Error getrandom() ?\n"); + exit(EXIT_FAILURE); + rseed(clock() + time(NULL) + rand()*rand()); + } + #endif @@ -567,7 +570,7 @@ int main(int argc, char **argv) { } } else { - fprintf(stderr,"[E] Invalid Minikey length %li : %s\n",strlen(optarg),optarg); + fprintf(stderr, "[E] Invalid Minikey length %zu : %s\n", strlen(optarg), optarg); exit(EXIT_FAILURE); } @@ -958,7 +961,6 @@ int main(int argc, char **argv) { writeFileIfNeeded(fileName); } } - if(FLAGMODE == MODE_BSGS ) { printf("[+] Opening file %s\n",fileName); fd = fopen(fileName,"rb"); @@ -1034,6 +1036,7 @@ int main(int argc, char **argv) { } } fclose(fd); + bsgs_point_number = N; if(bsgs_point_number > 0) { printf("[+] Added %u points from file\n",bsgs_point_number); @@ -1076,8 +1079,8 @@ int main(int argc, char **argv) { } BSGS_AUX.Set(&BSGS_M); - BSGS_AUX.Mod(&BSGS_GROUP_SIZE); - + BSGS_AUX.Mod(&BSGS_GROUP_SIZE); + if(!BSGS_AUX.IsZero()){ //If M is not divisible by BSGS_GROUP_SIZE (1024) hextemp = BSGS_GROUP_SIZE.GetBase10(); fprintf(stderr,"[E] M value is not divisible by %s\n",hextemp); @@ -1117,14 +1120,6 @@ int main(int argc, char **argv) { fprintf(stderr,"[E] the given range is small\n"); exit(EXIT_FAILURE); } - - /* - M 2199023255552 - 109951162777.6 - M2 109951162778 - 5497558138.9 - M3 5497558139 - */ BSGS_M.Mult((uint64_t)KFACTOR); BSGS_AUX.SetInt32(32); @@ -1211,30 +1206,28 @@ int main(int argc, char **argv) { else { itemsbloom3 = 1000; } - + printf("[+] Bloom filter for %" PRIu64 " elements ",bsgs_m); bloom_bP = (struct bloom*)calloc(256,sizeof(struct bloom)); checkpointer((void *)bloom_bP,__FILE__,"calloc","bloom_bP" ,__LINE__ -1 ); bloom_bP_checksums = (struct checksumsha256*)calloc(256,sizeof(struct checksumsha256)); checkpointer((void *)bloom_bP_checksums,__FILE__,"calloc","bloom_bP_checksums" ,__LINE__ -1 ); -#if defined(_WIN64) && !defined(__CYGWIN__) - bloom_bP_mutex = (HANDLE*) calloc(256,sizeof(HANDLE)); - -#else - bloom_bP_mutex = (pthread_mutex_t*) calloc(256,sizeof(pthread_mutex_t)); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + HANDLE* bloom_bP_mutex = (HANDLE*) calloc(256, sizeof(HANDLE)); + #else + bloom_bP_mutex = (pthread_mutex_t*) calloc(256,sizeof(pthread_mutex_t)); + #endif checkpointer((void *)bloom_bP_mutex,__FILE__,"calloc","bloom_bP_mutex" ,__LINE__ -1 ); - fflush(stdout); bloom_bP_totalbytes = 0; for(i=0; i< 256; i++) { -#if defined(_WIN64) && !defined(__CYGWIN__) - bloom_bP_mutex[i] = CreateMutex(NULL, FALSE, NULL); -#else - pthread_mutex_init(&bloom_bP_mutex[i],NULL); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + bloom_bP_mutex[i] = CreateMutex(NULL, FALSE, NULL); + #else + pthread_mutex_init(&bloom_bP_mutex[i],NULL); + #endif if(bloom_init2(&bloom_bP[i],itemsbloom,0.000001) == 1){ fprintf(stderr,"[E] error bloom_init _ [%" PRIu64 "]\n",i); exit(EXIT_FAILURE); @@ -1247,11 +1240,12 @@ int main(int argc, char **argv) { printf("[+] Bloom filter for %" PRIu64 " elements ",bsgs_m2); -#if defined(_WIN64) && !defined(__CYGWIN__) - bloom_bPx2nd_mutex = (HANDLE*) calloc(256,sizeof(HANDLE)); -#else - bloom_bPx2nd_mutex = (pthread_mutex_t*) calloc(256,sizeof(pthread_mutex_t)); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + HANDLE* bloom_bPx2nd_mutex = (HANDLE*) calloc(256, sizeof(HANDLE)); + #else + bloom_bPx2nd_mutex = (pthread_mutex_t*) calloc(256,sizeof(pthread_mutex_t)); + #endif + checkpointer((void *)bloom_bPx2nd_mutex,__FILE__,"calloc","bloom_bPx2nd_mutex" ,__LINE__ -1 ); bloom_bPx2nd = (struct bloom*)calloc(256,sizeof(struct bloom)); checkpointer((void *)bloom_bPx2nd,__FILE__,"calloc","bloom_bPx2nd" ,__LINE__ -1 ); @@ -1259,11 +1253,11 @@ int main(int argc, char **argv) { checkpointer((void *)bloom_bPx2nd_checksums,__FILE__,"calloc","bloom_bPx2nd_checksums" ,__LINE__ -1 ); bloom_bP2_totalbytes = 0; for(i=0; i< 256; i++) { -#if defined(_WIN64) && !defined(__CYGWIN__) - bloom_bPx2nd_mutex[i] = CreateMutex(NULL, FALSE, NULL); -#else - pthread_mutex_init(&bloom_bPx2nd_mutex[i],NULL); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + bloom_bPx2nd_mutex[i] = CreateMutex(NULL, FALSE, NULL); + #else + pthread_mutex_init(&bloom_bPx2nd_mutex[i],NULL); + #endif if(bloom_init2(&bloom_bPx2nd[i],itemsbloom2,0.000001) == 1){ fprintf(stderr,"[E] error bloom_init _ [%" PRIu64 "]\n",i); exit(EXIT_FAILURE); @@ -1272,15 +1266,16 @@ int main(int argc, char **argv) { //if(FLAGDEBUG) bloom_print(&bloom_bPx2nd[i]); } printf(": %.2f MB\n",(float)((float)(uint64_t)bloom_bP2_totalbytes/(float)(uint64_t)1048576)); - -#if defined(_WIN64) && !defined(__CYGWIN__) - bloom_bPx3rd_mutex = (HANDLE*) calloc(256,sizeof(HANDLE)); -#else - bloom_bPx3rd_mutex = (pthread_mutex_t*) calloc(256,sizeof(pthread_mutex_t)); -#endif - checkpointer((void *)bloom_bPx3rd_mutex,__FILE__,"calloc","bloom_bPx3rd_mutex" ,__LINE__ -1 ); - bloom_bPx3rd = (struct bloom*)calloc(256,sizeof(struct bloom)); + #if defined(_WIN64) && !defined(__CYGWIN__) + bloom_bPx3rd_mutex.resize(256, nullptr); + checkpointer(static_cast(bloom_bPx3rd_mutex.data()), __FILE__, "calloc", "bloom_bPx3rd_mutex", __LINE__ - 1); + #else + bloom_bPx3rd_mutex = (pthread_mutex_t*) calloc(256,sizeof(pthread_mutex_t)); + checkpointer(static_cast(bloom_bPx3rd_mutex), __FILE__, "calloc", "bloom_bPx3rd_mutex", __LINE__ - 1); + #endif + + bloom_bPx3rd = (struct bloom*)calloc(256, sizeof(struct bloom)); checkpointer((void *)bloom_bPx3rd,__FILE__,"calloc","bloom_bPx3rd" ,__LINE__ -1 ); bloom_bPx3rd_checksums = (struct checksumsha256*) calloc(256,sizeof(struct checksumsha256)); checkpointer((void *)bloom_bPx3rd_checksums,__FILE__,"calloc","bloom_bPx3rd_checksums" ,__LINE__ -1 ); @@ -1288,11 +1283,11 @@ int main(int argc, char **argv) { printf("[+] Bloom filter for %" PRIu64 " elements ",bsgs_m3); bloom_bP3_totalbytes = 0; for(i=0; i< 256; i++) { -#if defined(_WIN64) && !defined(__CYGWIN__) + #if defined(_WIN64) && !defined(__CYGWIN__) bloom_bPx3rd_mutex[i] = CreateMutex(NULL, FALSE, NULL); -#else + #else pthread_mutex_init(&bloom_bPx3rd_mutex[i],NULL); -#endif + #endif if(bloom_init2(&bloom_bPx3rd[i],itemsbloom3,0.000001) == 1){ fprintf(stderr,"[E] error bloom_init [%" PRIu64 "]\n",i); exit(EXIT_FAILURE); @@ -1301,10 +1296,6 @@ int main(int argc, char **argv) { //if(FLAGDEBUG) bloom_print(&bloom_bPx3rd[i]); } printf(": %.2f MB\n",(float)((float)(uint64_t)bloom_bP3_totalbytes/(float)(uint64_t)1048576)); - //if(FLAGDEBUG) printf("[D] bloom_bP3_totalbytes : %" PRIu64 "\n",bloom_bP3_totalbytes); - - - BSGS_MP = secp->ComputePublicKey(&BSGS_M); BSGS_MP_double = secp->ComputePublicKey(&BSGS_M_double); @@ -1636,17 +1627,17 @@ int main(int argc, char **argv) { THREADCYCLES++; } - printf("\r[+] processing %lu/%lu bP points : %i%%\r",FINISHED_ITEMS,bsgs_m,(int) (((double)FINISHED_ITEMS/(double)bsgs_m)*100)); + printf("\r[+] processing %" PRIu64 "/%" PRIu64 " bP points : %i%%\r", FINISHED_ITEMS, bsgs_m, (int) (((double)FINISHED_ITEMS/(double)bsgs_m)*100)); fflush(stdout); -#if defined(_WIN64) && !defined(__CYGWIN__) - tid = (HANDLE*)calloc(NTHREADS, sizeof(HANDLE)); - checkpointer((void *)tid,__FILE__,"calloc","tid" ,__LINE__ -1 ); - bPload_mutex = (HANDLE*) calloc(NTHREADS,sizeof(HANDLE)); -#else - tid = (pthread_t *) calloc(NTHREADS,sizeof(pthread_t)); - bPload_mutex = (pthread_mutex_t*) calloc(NTHREADS,sizeof(pthread_mutex_t)); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + tid = (HANDLE*)calloc(NTHREADS, sizeof(HANDLE)); + checkpointer((void *)tid,__FILE__,"calloc","tid" ,__LINE__ -1 ); + bPload_mutex = (HANDLE*) calloc(NTHREADS,sizeof(HANDLE)); + #else + tid = (pthread_t *) calloc(NTHREADS,sizeof(pthread_t)); + bPload_mutex = (pthread_mutex_t*) calloc(NTHREADS,sizeof(pthread_mutex_t)); + #endif checkpointer((void *)bPload_mutex,__FILE__,"calloc","bPload_mutex" ,__LINE__ -1 ); bPload_temp_ptr = (struct bPload*) calloc(NTHREADS,sizeof(struct bPload)); checkpointer((void *)bPload_temp_ptr,__FILE__,"calloc","bPload_temp_ptr" ,__LINE__ -1 ); @@ -1656,11 +1647,11 @@ int main(int argc, char **argv) { memset(bPload_threads_available,1,NTHREADS); for(j = 0; j < NTHREADS; j++) { -#if defined(_WIN64) && !defined(__CYGWIN__) - bPload_mutex[j] = CreateMutex(NULL, FALSE, NULL); -#else - pthread_mutex_init(&bPload_mutex[j],NULL); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + bPload_mutex[j] = CreateMutex(NULL, FALSE, NULL); + #else + pthread_mutex_init(&bPload_mutex[j],NULL); + #endif } do { @@ -1680,34 +1671,34 @@ int main(int argc, char **argv) { bPload_temp_ptr[j].workload = THREADBPWORKLOAD + PERTHREAD_R; salir = 1; } -#if defined(_WIN64) && !defined(__CYGWIN__) - tid[j] = CreateThread(NULL, 0, thread_bPload_2blooms, (void*) &bPload_temp_ptr[j], 0, &s); -#else - s = pthread_create(&tid[j],NULL,thread_bPload_2blooms,(void*) &bPload_temp_ptr[j]); - pthread_detach(tid[j]); -#endif - BASE+=THREADBPWORKLOAD; - THREADCOUNTER++; + #if defined(_WIN64) && !defined(__CYGWIN__) + tid[j] = CreateThread(NULL, 0, thread_bPload_2blooms, (void*) &bPload_temp_ptr[j], 0, &s); + #else + s = pthread_create(&tid[j],NULL,thread_bPload_2blooms,(void*) &bPload_temp_ptr[j]); + pthread_detach(tid[j]); + #endif + BASE+=THREADBPWORKLOAD; + THREADCOUNTER++; } } if(OLDFINISHED_ITEMS != FINISHED_ITEMS) { - printf("\r[+] processing %lu/%lu bP points : %i%%\r",FINISHED_ITEMS,bsgs_m2,(int) (((double)FINISHED_ITEMS/(double)bsgs_m2)*100)); + printf("\r[+] processing %" PRIu64 "/%" PRIu64 " bP points : %i%%\r", FINISHED_ITEMS, bsgs_m2, (int) (((double)FINISHED_ITEMS / (double)bsgs_m2) * 100)); fflush(stdout); OLDFINISHED_ITEMS = FINISHED_ITEMS; } for(j = 0 ; j < NTHREADS ; j++) { -#if defined(_WIN64) && !defined(__CYGWIN__) - WaitForSingleObject(bPload_mutex[j], INFINITE); - finished = bPload_temp_ptr[j].finished; - ReleaseMutex(bPload_mutex[j]); -#else - pthread_mutex_lock(&bPload_mutex[j]); - finished = bPload_temp_ptr[j].finished; - pthread_mutex_unlock(&bPload_mutex[j]); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + WaitForSingleObject(bPload_mutex[j], INFINITE); + finished = bPload_temp_ptr[j].finished; + ReleaseMutex(bPload_mutex[j]); + #else + pthread_mutex_lock(&bPload_mutex[j]); + finished = bPload_temp_ptr[j].finished; + pthread_mutex_unlock(&bPload_mutex[j]); + #endif if(finished) { bPload_temp_ptr[j].finished = 0; bPload_threads_available[j] = 1; @@ -1716,7 +1707,7 @@ int main(int argc, char **argv) { } } }while(FINISHED_THREADS_COUNTER < THREADCYCLES); - printf("\r[+] processing %lu/%lu bP points : 100%% \n",bsgs_m2,bsgs_m2); + printf("\r[+] processing %" PRIu64 "/%" PRIu64 " bP points : 100%% \n", bsgs_m2, bsgs_m2); free(tid); free(bPload_mutex); @@ -1747,16 +1738,16 @@ int main(int argc, char **argv) { //if(FLAGDEBUG) printf("[D] PERTHREAD_R: %lu\n",PERTHREAD_R); } - printf("\r[+] processing %lu/%lu bP points : %i%%\r",FINISHED_ITEMS,bsgs_m,(int) (((double)FINISHED_ITEMS/(double)bsgs_m)*100)); + printf("\r[+] processing %" PRIu64 "/%" PRIu64 " bP points : %i%%\r", FINISHED_ITEMS, bsgs_m, (int) (((double)FINISHED_ITEMS / (double)bsgs_m) * 100)); fflush(stdout); -#if defined(_WIN64) && !defined(__CYGWIN__) - tid = (HANDLE*)calloc(NTHREADS, sizeof(HANDLE)); - bPload_mutex = (HANDLE*) calloc(NTHREADS,sizeof(HANDLE)); -#else - tid = (pthread_t *) calloc(NTHREADS,sizeof(pthread_t)); - bPload_mutex = (pthread_mutex_t*) calloc(NTHREADS,sizeof(pthread_mutex_t)); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + tid = (HANDLE*)calloc(NTHREADS, sizeof(HANDLE)); + bPload_mutex = (HANDLE*) calloc(NTHREADS,sizeof(HANDLE)); + #else + tid = (pthread_t *) calloc(NTHREADS,sizeof(pthread_t)); + bPload_mutex = (pthread_mutex_t*) calloc(NTHREADS,sizeof(pthread_mutex_t)); + #endif checkpointer((void *)tid,__FILE__,"calloc","tid" ,__LINE__ -1 ); checkpointer((void *)bPload_mutex,__FILE__,"calloc","bPload_mutex" ,__LINE__ -1 ); @@ -1769,11 +1760,12 @@ int main(int argc, char **argv) { memset(bPload_threads_available,1,NTHREADS); for(j = 0; j < NTHREADS; j++) { -#if defined(_WIN64) && !defined(__CYGWIN__) - bPload_mutex = CreateMutex(NULL, FALSE, NULL); -#else - pthread_mutex_init(&bPload_mutex[j],NULL); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + bPload_mutex = (HANDLE*) malloc(sizeof(HANDLE)); + bPload_mutex[0] = CreateMutex(NULL, FALSE, NULL); + #else + pthread_mutex_init(&bPload_mutex[j],NULL); + #endif } do { @@ -1795,33 +1787,32 @@ int main(int argc, char **argv) { //if(FLAGDEBUG) printf("[D] Salir OK\n"); } //if(FLAGDEBUG) printf("[I] %lu to %lu\n",bPload_temp_ptr[i].from,bPload_temp_ptr[i].to); -#if defined(_WIN64) && !defined(__CYGWIN__) + #if defined(_WIN64) && !defined(__CYGWIN__) tid[j] = CreateThread(NULL, 0, thread_bPload, (void*) &bPload_temp_ptr[j], 0, &s); -#else + #else s = pthread_create(&tid[j],NULL,thread_bPload,(void*) &bPload_temp_ptr[j]); pthread_detach(tid[j]); -#endif + #endif BASE+=THREADBPWORKLOAD; THREADCOUNTER++; } } if(OLDFINISHED_ITEMS != FINISHED_ITEMS) { - printf("\r[+] processing %lu/%lu bP points : %i%%\r",FINISHED_ITEMS,bsgs_m,(int) (((double)FINISHED_ITEMS/(double)bsgs_m)*100)); + printf("\r[+] processing %" PRIu64 "/%" PRIu64 " bP points : %i%%\r", FINISHED_ITEMS, bsgs_m, (int) (((double)FINISHED_ITEMS / (double)bsgs_m) * 100)); fflush(stdout); OLDFINISHED_ITEMS = FINISHED_ITEMS; } for(j = 0 ; j < NTHREADS ; j++) { - -#if defined(_WIN64) && !defined(__CYGWIN__) - WaitForSingleObject(bPload_mutex[j], INFINITE); - finished = bPload_temp_ptr[j].finished; - ReleaseMutex(bPload_mutex[j]); -#else - pthread_mutex_lock(&bPload_mutex[j]); - finished = bPload_temp_ptr[j].finished; - pthread_mutex_unlock(&bPload_mutex[j]); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + WaitForSingleObject(bPload_mutex[j], INFINITE); + finished = bPload_temp_ptr[j].finished; + ReleaseMutex(bPload_mutex[j]); + #else + pthread_mutex_lock(&bPload_mutex[j]); + finished = bPload_temp_ptr[j].finished; + pthread_mutex_unlock(&bPload_mutex[j]); + #endif if(finished) { bPload_temp_ptr[j].finished = 0; bPload_threads_available[j] = 1; @@ -1831,7 +1822,7 @@ int main(int argc, char **argv) { } }while(FINISHED_THREADS_COUNTER < THREADCYCLES); - printf("\r[+] processing %lu/%lu bP points : 100%% \n",bsgs_m,bsgs_m); + printf("\r[+] processing %" PRIu64 "/%" PRIu64 " bP points : 100%% \n", bsgs_m, bsgs_m); free(tid); free(bPload_mutex); @@ -1839,38 +1830,38 @@ int main(int argc, char **argv) { free(bPload_threads_available); } } - - if(!FLAGREADEDFILE1 || !FLAGREADEDFILE2 || !FLAGREADEDFILE4) { + + if(!FLAGREADEDFILE1 || !FLAGREADEDFILE2 || !FLAGREADEDFILE4) { printf("[+] Making checkums .. "); fflush(stdout); } - if(!FLAGREADEDFILE1) { + if(!FLAGREADEDFILE1) { for(i = 0; i < 256 ; i++) { sha256((uint8_t*)bloom_bP[i].bf, bloom_bP[i].bytes,(uint8_t*) bloom_bP_checksums[i].data); memcpy(bloom_bP_checksums[i].backup,bloom_bP_checksums[i].data,32); } printf("."); } - if(!FLAGREADEDFILE2) { + if(!FLAGREADEDFILE2) { for(i = 0; i < 256 ; i++) { sha256((uint8_t*)bloom_bPx2nd[i].bf, bloom_bPx2nd[i].bytes,(uint8_t*) bloom_bPx2nd_checksums[i].data); memcpy(bloom_bPx2nd_checksums[i].backup,bloom_bPx2nd_checksums[i].data,32); } printf("."); } - if(!FLAGREADEDFILE4) { + if(!FLAGREADEDFILE4) { for(i = 0; i < 256 ; i++) { sha256((uint8_t*)bloom_bPx3rd[i].bf, bloom_bPx3rd[i].bytes,(uint8_t*) bloom_bPx3rd_checksums[i].data); memcpy(bloom_bPx3rd_checksums[i].backup,bloom_bPx3rd_checksums[i].data,32); } printf("."); } - if(!FLAGREADEDFILE1 || !FLAGREADEDFILE2 || !FLAGREADEDFILE4) { + if(!FLAGREADEDFILE1 || !FLAGREADEDFILE2 || !FLAGREADEDFILE4) { printf(" done\n"); fflush(stdout); } - if(!FLAGREADEDFILE3) { - printf("[+] Sorting %lu elements... ",bsgs_m3); + if(!FLAGREADEDFILE3) { + printf("[+] Sorting %" PRIu64 " elements... ", bsgs_m3); fflush(stdout); bsgs_sort(bPtable,bsgs_m3); sha256((uint8_t*)bPtable, bytes,(uint8_t*) checksum); @@ -1878,7 +1869,7 @@ int main(int argc, char **argv) { printf("Done!\n"); fflush(stdout); } - if(FLAGSAVEREADFILE || FLAGUPDATEFILE1 ) { + if(FLAGSAVEREADFILE || FLAGUPDATEFILE1 ) { if(!FLAGREADEDFILE1 || FLAGUPDATEFILE1) { snprintf(buffer_bloom_file,1024,"keyhunt_bsgs_4_%" PRIu64 ".blm",bsgs_m); @@ -2024,20 +2015,19 @@ int main(int argc, char **argv) { } } - i = 0; steps = (uint64_t *) calloc(NTHREADS,sizeof(uint64_t)); checkpointer((void *)steps,__FILE__,"calloc","steps" ,__LINE__ -1 ); ends = (unsigned int *) calloc(NTHREADS,sizeof(int)); checkpointer((void *)ends,__FILE__,"calloc","ends" ,__LINE__ -1 ); -#if defined(_WIN64) && !defined(__CYGWIN__) - tid = (HANDLE*)calloc(NTHREADS, sizeof(HANDLE)); -#else - tid = (pthread_t *) calloc(NTHREADS,sizeof(pthread_t)); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + tid = (HANDLE*)calloc(NTHREADS, sizeof(HANDLE)); + #else + tid = (pthread_t *) calloc(NTHREADS,sizeof(pthread_t)); + #endif checkpointer((void *)tid,__FILE__,"calloc","tid" ,__LINE__ -1 ); - + for(j= 0;j < NTHREADS; j++) { tt = (tothread*) malloc(sizeof(struct tothread)); checkpointer((void *)tt,__FILE__,"malloc","tt" ,__LINE__ -1 ); @@ -2045,101 +2035,110 @@ int main(int argc, char **argv) { steps[j] = 0; s = 0; switch(FLAGBSGSMODE) { -#if defined(_WIN64) && !defined(__CYGWIN__) - case 0: - tid[j] = CreateThread(NULL, 0, thread_process_bsgs, (void*)tt, 0, &s); + #if defined(_WIN64) && !defined(__CYGWIN__) + case 0: + tid[j] = CreateThread(NULL, 0, thread_process_bsgs, (void*)tt, 0, &s); + break; + case 1: + tid[j] = CreateThread(NULL, 0, thread_process_bsgs_backward, (void*)tt, 0, &s); + break; + case 2: + tid[j] = CreateThread(NULL, 0, thread_process_bsgs_both, (void*)tt, 0, &s); + break; + case 3: + tid[j] = CreateThread(NULL, 0, thread_process_bsgs_random, (void*)tt, 0, &s); + break; + case 4: + tid[j] = CreateThread(NULL, 0, thread_process_bsgs_dance, (void*)tt, 0, &s); + break; + #else + case 0: + s = pthread_create(&tid[j],NULL,thread_process_bsgs,(void *)tt); break; - case 1: - tid[j] = CreateThread(NULL, 0, thread_process_bsgs_backward, (void*)tt, 0, &s); + case 1: + s = pthread_create(&tid[j],NULL,thread_process_bsgs_backward,(void *)tt); break; - case 2: - tid[j] = CreateThread(NULL, 0, thread_process_bsgs_both, (void*)tt, 0, &s); + case 2: + s = pthread_create(&tid[j],NULL,thread_process_bsgs_both,(void *)tt); break; - case 3: - tid[j] = CreateThread(NULL, 0, thread_process_bsgs_random, (void*)tt, 0, &s); + case 3: + s = pthread_create(&tid[j],NULL,thread_process_bsgs_random,(void *)tt); break; - case 4: - tid[j] = CreateThread(NULL, 0, thread_process_bsgs_dance, (void*)tt, 0, &s); + case 4: + s = pthread_create(&tid[j],NULL,thread_process_bsgs_dance,(void *)tt); break; - } -#else - case 0: - s = pthread_create(&tid[j],NULL,thread_process_bsgs,(void *)tt); - break; - case 1: - s = pthread_create(&tid[j],NULL,thread_process_bsgs_backward,(void *)tt); - break; - case 2: - s = pthread_create(&tid[j],NULL,thread_process_bsgs_both,(void *)tt); - break; - case 3: - s = pthread_create(&tid[j],NULL,thread_process_bsgs_random,(void *)tt); - break; - case 4: - s = pthread_create(&tid[j],NULL,thread_process_bsgs_dance,(void *)tt); - break; -#endif - } -#if defined(_WIN64) && !defined(__CYGWIN__) - if (tid[j] == NULL) { -#else - if(s != 0) { -#endif - fprintf(stderr,"[E] thread thread_process\n"); - exit(EXIT_FAILURE); - } + #endif + } + #if defined(_WIN64) && !defined(__CYGWIN__) + if (tid[j] == NULL) { + #else + if(s != 0) { + #endif + fprintf(stderr,"[E] thread thread_process\n"); + exit(EXIT_FAILURE); + } } free(aux); + } + if(FLAGMODE != MODE_BSGS) { steps = (uint64_t *) calloc(NTHREADS,sizeof(uint64_t)); checkpointer((void *)steps,__FILE__,"calloc","steps" ,__LINE__ -1 ); ends = (unsigned int *) calloc(NTHREADS,sizeof(int)); checkpointer((void *)ends,__FILE__,"calloc","ends" ,__LINE__ -1 ); -#if defined(_WIN64) && !defined(__CYGWIN__) - tid = (HANDLE*)calloc(NTHREADS, sizeof(HANDLE)); -#else - tid = (pthread_t *) calloc(NTHREADS,sizeof(pthread_t)); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + tid = (HANDLE*)calloc(NTHREADS, sizeof(HANDLE)); + #else + tid = (pthread_t *) calloc(NTHREADS,sizeof(pthread_t)); + #endif checkpointer((void *)tid,__FILE__,"calloc","tid" ,__LINE__ -1 ); - for(j= 0;j < NTHREADS; j++) { + for (j = 0; j < NTHREADS; j++) { tt = (tothread*) malloc(sizeof(struct tothread)); - checkpointer((void *)tt,__FILE__,"malloc","tt" ,__LINE__ -1 ); + checkpointer((void *)tt, __FILE__, "malloc", "tt", __LINE__ - 1); tt->nt = j; steps[j] = 0; s = 0; - switch(FLAGMODE) { -#if defined(_WIN64) && !defined(__CYGWIN__) - case MODE_ADDRESS: - case MODE_XPOINT: - case MODE_RMD160: - tid[j] = CreateThread(NULL, 0, thread_process, (void*)tt, 0, &s); - break; - case MODE_MINIKEYS: - tid[j] = CreateThread(NULL, 0, thread_process_minikeys, (void*)tt, 0, &s); - break; - case MODE_VANITY: - tid[j] = CreateThread(NULL, 0, thread_process_vanity, (void*)tt, 0, &s); - break; -#else - case MODE_ADDRESS: - case MODE_XPOINT: - case MODE_RMD160: - s = pthread_create(&tid[j],NULL,thread_process,(void *)tt); - break; - case MODE_MINIKEYS: - s = pthread_create(&tid[j],NULL,thread_process_minikeys,(void *)tt); - break; - case MODE_VANITY: - s = pthread_create(&tid[j],NULL,thread_process_vanity,(void *)tt); - break; -#endif - } - if(s != 0) { - fprintf(stderr,"[E] pthread_create thread_process\n"); - exit(EXIT_FAILURE); + switch (FLAGMODE) { + #if defined(_WIN64) && !defined(__CYGWIN__) + case MODE_ADDRESS: + case MODE_XPOINT: + case MODE_RMD160: + tid[j] = CreateThread(NULL, 0, thread_process, (void*)tt, 0, &s); + break; + case MODE_MINIKEYS: + tid[j] = CreateThread(NULL, 0, thread_process_minikeys, (void*)tt, 0, &s); + break; + case MODE_VANITY: + tid[j] = CreateThread(NULL, 0, thread_process_vanity, (void*)tt, 0, &s); + break; + #else + case MODE_ADDRESS: + case MODE_XPOINT: + case MODE_RMD160: + s = pthread_create(&tid[j], NULL, thread_process, (void*)tt); + break; + case MODE_MINIKEYS: + s = pthread_create(&tid[j], NULL, thread_process_minikeys, (void*)tt); + break; + case MODE_VANITY: + s = pthread_create(&tid[j], NULL, thread_process_vanity, (void*)tt); + break; + #endif } + #if defined(_WIN64) && !defined(__CYGWIN__) + if (tid[j] == NULL) { + fprintf(stderr, "[E] CreateThread failed with error code %lu\n", GetLastError()); + exit(EXIT_FAILURE); + } + #else + if (s != 0) { + fprintf(stderr, "[E] pthread_create thread_process\n"); + exit(EXIT_FAILURE); + } + #endif } + } for(j =0; j < 7; j++) { @@ -2186,11 +2185,11 @@ int main(int argc, char **argv) { } } -#ifdef _WIN64 - WaitForSingleObject(bsgs_thread, INFINITE); -#else - pthread_mutex_lock(&bsgs_thread); -#endif + #ifdef _WIN64 + WaitForSingleObject(bsgs_thread, INFINITE); + #else + pthread_mutex_lock(&bsgs_thread); + #endif pretotal.Set(&total); pretotal.Div(&seconds); str_seconds = seconds.GetBase10(); @@ -2200,10 +2199,10 @@ int main(int argc, char **argv) { if(pretotal.IsLower(&int_limits[0])) { if(FLAGMATRIX) { - sprintf(buffer,"[+] Total %s keys in %s seconds: %s keys/s\n",str_total,str_seconds,str_pretotal); + snprintf(buffer, sizeof(buffer), "[+] Total %s keys in %s seconds: %s keys/s\n", str_total, str_seconds, str_pretotal); } else { - sprintf(buffer,"\r[+] Total %s keys in %s seconds: %s keys/s\r",str_total,str_seconds,str_pretotal); + snprintf(buffer, sizeof(buffer), "\r[+] Total %s keys in %s seconds: %s keys/s\r", str_total, str_seconds, str_pretotal); } } else { @@ -2221,15 +2220,13 @@ int main(int argc, char **argv) { div_pretotal.Set(&pretotal); div_pretotal.Div(&int_limits[salir ? i : i-1]); str_divpretotal = div_pretotal.GetBase10(); - if(FLAGMATRIX) { - sprintf(buffer,"[+] Total %s keys in %s seconds: ~%s %s (%s keys/s)\n",str_total,str_seconds,str_divpretotal,str_limits_prefixs[salir ? i : i-1],str_pretotal); - } - else { - if(THREADOUTPUT == 1) { - sprintf(buffer,"\r[+] Total %s keys in %s seconds: ~%s %s (%s keys/s)\r",str_total,str_seconds,str_divpretotal,str_limits_prefixs[salir ? i : i-1],str_pretotal); - } - else { - sprintf(buffer,"\r[+] Total %s keys in %s seconds: ~%s %s (%s keys/s)\r",str_total,str_seconds,str_divpretotal,str_limits_prefixs[salir ? i : i-1],str_pretotal); + if (FLAGMATRIX) { + snprintf(buffer, sizeof(buffer), "[+] Total %s keys in %s seconds: ~%s %s (%s keys/s)\n", str_total, str_seconds, str_divpretotal, str_limits_prefixs[salir ? i : i-1], str_pretotal); + } else { + if (THREADOUTPUT == 1) { + snprintf(buffer, sizeof(buffer), "\r[+] Total %s keys in %s seconds: ~%s %s (%s keys/s)\r", str_total, str_seconds, str_divpretotal, str_limits_prefixs[salir ? i : i-1], str_pretotal); + } else { + snprintf(buffer, sizeof(buffer), "\r[+] Total %s keys in %s seconds: ~%s %s (%s keys/s)\r", str_total, str_seconds, str_divpretotal, str_limits_prefixs[salir ? i : i-1], str_pretotal); } } free(str_divpretotal); @@ -2238,11 +2235,11 @@ int main(int argc, char **argv) { printf("%s",buffer); fflush(stdout); THREADOUTPUT = 0; -#ifdef _WIN64 - ReleaseMutex(bsgs_thread); -#else - pthread_mutex_unlock(&bsgs_thread); -#endif + #ifdef _WIN64 + ReleaseMutex(bsgs_thread); + #else + pthread_mutex_unlock(&bsgs_thread); + #endif free(str_seconds); free(str_pretotal); @@ -2251,11 +2248,11 @@ int main(int argc, char **argv) { } }while(continue_flag); printf("\nEnd\n"); -#ifdef _WIN64 - CloseHandle(write_keys); - CloseHandle(write_random); - CloseHandle(bsgs_thread); -#endif + #ifdef _WIN64 + CloseHandle(write_keys); + CloseHandle(write_random); + CloseHandle(bsgs_thread); + #endif } void pubkeytopubaddress_dst(char *pkey,int length,char *dst) { @@ -2335,9 +2332,9 @@ int searchbinary(struct address_value *buffer,char *data,int64_t array_length) { } #if defined(_WIN64) && !defined(__CYGWIN__) -DWORD WINAPI thread_process_minikeys(LPVOID vargp) { + DWORD WINAPI thread_process_minikeys(LPVOID vargp) { #else -void *thread_process_minikeys(void *vargp) { + void *thread_process_minikeys(void *vargp) { #endif FILE *keys; Point publickey[4]; @@ -2373,24 +2370,24 @@ void *thread_process_minikeys(void *vargp) { } else { if(FLAGBASEMINIKEY) { -#if defined(_WIN64) && !defined(__CYGWIN__) - WaitForSingleObject(write_random, INFINITE); - memcpy(buffer_b58,raw_baseminikey,21); - increment_minikey_N(raw_baseminikey); - ReleaseMutex(write_random); -#else - pthread_mutex_lock(&write_random); - memcpy(buffer_b58,raw_baseminikey,21); - increment_minikey_N(raw_baseminikey); - pthread_mutex_unlock(&write_random); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + WaitForSingleObject(write_random, INFINITE); + memcpy(buffer_b58,raw_baseminikey,21); + increment_minikey_N(raw_baseminikey); + ReleaseMutex(write_random); + #else + pthread_mutex_lock(&write_random); + memcpy(buffer_b58,raw_baseminikey,21); + increment_minikey_N(raw_baseminikey); + pthread_mutex_unlock(&write_random); + #endif } else { -#if defined(_WIN64) && !defined(__CYGWIN__) - WaitForSingleObject(write_random, INFINITE); -#else - pthread_mutex_lock(&write_random); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + WaitForSingleObject(write_random, INFINITE); + #else + pthread_mutex_lock(&write_random); + #endif if(raw_baseminikey == NULL){ raw_baseminikey = (char *) malloc(22); checkpointer((void *)raw_baseminikey,__FILE__,"malloc","raw_baseminikey" ,__LINE__ -1 ); @@ -2406,12 +2403,11 @@ void *thread_process_minikeys(void *vargp) { memcpy(buffer_b58,raw_baseminikey,21); increment_minikey_N(raw_baseminikey); } -#if defined(_WIN64) && !defined(__CYGWIN__) - ReleaseMutex(write_random); -#else - pthread_mutex_unlock(&write_random); -#endif - + #if defined(_WIN64) && !defined(__CYGWIN__) + ReleaseMutex(write_random); + #else + pthread_mutex_unlock(&write_random); + #endif } } set_minikey(minikey2check+1,buffer_b58,21); @@ -2471,11 +2467,11 @@ void *thread_process_minikeys(void *vargp) { /* hit */ hextemp = key_mpz[k].GetBase16(); secp->GetPublicKeyHex(false,publickey[k],public_key_uncompressed_hex); -#if defined(_WIN64) && !defined(__CYGWIN__) - WaitForSingleObject(write_keys, INFINITE); -#else - pthread_mutex_lock(&write_keys); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + WaitForSingleObject(write_keys, INFINITE); + #else + pthread_mutex_lock(&write_keys); + #endif keys = fopen("KEYFOUNDKEYFOUND.txt","a+"); rmd160toaddress_dst(publickeyhashrmd160_uncompress[k],address[k]); @@ -2485,11 +2481,11 @@ void *thread_process_minikeys(void *vargp) { fclose(keys); } printf("\nHIT!! Private Key: %s\npubkey: %s\nminikey: %s\naddress: %s\n",hextemp,public_key_uncompressed_hex,minikeys[k],address[k]); -#if defined(_WIN64) && !defined(__CYGWIN__) - ReleaseMutex(write_keys); -#else - pthread_mutex_unlock(&write_keys); -#endif + #if defined(_WIN64) && !defined(__CYGWIN__) + ReleaseMutex(write_keys); + #else + pthread_mutex_unlock(&write_keys); + #endif free(hextemp); } @@ -2501,7 +2497,11 @@ void *thread_process_minikeys(void *vargp) { }while(count < N_SEQUENTIAL_MAX && continue_flag); } }while(continue_flag); - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } @@ -3095,7 +3095,11 @@ void *thread_process(void *vargp) { } } while(continue_flag); ends[thread_number] = 1; - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } @@ -3532,7 +3536,11 @@ void *thread_process_vanity(void *vargp) { } } while(continue_flag); ends[thread_number] = 1; - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } void _swap(struct address_value *a,struct address_value *b) { @@ -4005,7 +4013,11 @@ pn.y.ModAdd(&GSn[i].y); steps[thread_number]+=2; }while(1); ends[thread_number] = 1; - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } #if defined(_WIN64) && !defined(__CYGWIN__) @@ -4260,7 +4272,11 @@ pn.y.ModAdd(&GSn[i].y); steps[thread_number]+=2; }while(1); ends[thread_number] = 1; - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } @@ -4552,7 +4568,7 @@ void *thread_bPload(void *vargp) { #if defined(_WIN64) && !defined(__CYGWIN__) WaitForSingleObject(bloom_bP_mutex[bloom_bP_index], INFINITE); bloom_add(&bloom_bP[bloom_bP_index], rawvalue ,BSGS_BUFFERXPOINTLENGTH); - ReleaseMutex(bloom_bP_mutex[bloom_bP_index); + ReleaseMutex(bloom_bP_mutex[bloom_bP_index]); #else pthread_mutex_lock(&bloom_bP_mutex[bloom_bP_index]); bloom_add(&bloom_bP[bloom_bP_index], rawvalue ,BSGS_BUFFERXPOINTLENGTH); @@ -4588,7 +4604,11 @@ void *thread_bPload(void *vargp) { pthread_mutex_unlock(&bPload_mutex[threadid]); pthread_exit(NULL); #endif - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } #if defined(_WIN64) && !defined(__CYGWIN__) @@ -4760,7 +4780,11 @@ void *thread_bPload_2blooms(void *vargp) { pthread_mutex_unlock(&bPload_mutex[threadid]); pthread_exit(NULL); #endif - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } /* This function perform the KECCAK Opetation*/ @@ -5063,7 +5087,11 @@ pn.y.ModAdd(&GSn[i].y); steps[thread_number]+=2; }while(1); ends[thread_number] = 1; - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } #if defined(_WIN64) && !defined(__CYGWIN__) @@ -5320,7 +5348,11 @@ pn.y.ModAdd(&GSn[i].y); steps[thread_number]+=2; }while(1); ends[thread_number] = 1; - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } #if defined(_WIN64) && !defined(__CYGWIN__) @@ -5605,7 +5637,11 @@ void *thread_process_bsgs_both(void *vargp) { steps[thread_number]+=2; }while(1); ends[thread_number] = 1; - return NULL; + #if defined(_WIN64) && !defined(__CYGWIN__) + return 0; + #else + return NULL; + #endif } @@ -6532,7 +6568,7 @@ bool forceReadFileXPoint(char *fileName) { } break; default: - fprintf(stderr,"[E] Omiting line unknow length size %li: %s\n",lenaux,aux); + fprintf(stderr, "[E] Omiting line unknow length size %zu: %s\n", lenaux, aux); break; } } @@ -6592,7 +6628,7 @@ void writeFileIfNeeded(const char *fileName) { snprintf(fileBloomName,30,"data_%s.dat",hexPrefix); fileDescriptor = fopen(fileBloomName,"wb"); dataSize = N * (sizeof(struct address_value)); - printf("[D] size data %li\n",dataSize); + printf("[D] size data %" PRIu64 "\n", dataSize); if(fileDescriptor != NULL) { printf("[+] Writing file %s ",fileBloomName); diff --git a/rmd160/rmd160.h b/rmd160/rmd160.h index 9ba7804..d301b6d 100644 --- a/rmd160/rmd160.h +++ b/rmd160/rmd160.h @@ -1,5 +1,4 @@ -/* RMD160.H - header file for RMD160.C - */ +/* RMD160.H - header file for RMD160.C */ #ifndef _RMD160_H_ #define _RMD160_H_ @@ -21,18 +20,15 @@ /* RIPEMD160 context. */ typedef struct RMD160Context { - uint32_t key[RIPEMD160_BLOCKWORDS]; - uint32_t iv[RIPEMD160_HASHWORDS]; - uint32_t bytesHi, bytesLo; + uint32_t key[RIPEMD160_BLOCKWORDS]; + uint32_t iv[RIPEMD160_HASHWORDS]; + uint32_t bytesHi, bytesLo; } RMD160_CTX; #define RIPEMD160Context RMD160Context -#ifdef _WIN64 -#else -#include - -__BEGIN_DECLS +#ifdef __cplusplus +extern "C" { #endif void RMD160Init(RMD160_CTX *); @@ -40,11 +36,10 @@ void RMD160Update(RMD160_CTX *, const unsigned char *, unsigned int); void RMD160Final(unsigned char [RMD160_HASHBYTES], RMD160_CTX *); char * RMD160End(RMD160_CTX *, char *); char * RMD160File(const char *, char *); -void RMD160Data(const unsigned char *, unsigned int, char *); -#ifdef _WIN64 -#else -__END_DECLS +void RMD160Data(const unsigned char *, unsigned int, char *); +#ifdef __cplusplus +} #endif #endif /* _RMD160_H_ */ diff --git a/secp256k1/Int.cpp b/secp256k1/Int.cpp index 3fca105..1956f84 100644 --- a/secp256k1/Int.cpp +++ b/secp256k1/Int.cpp @@ -334,23 +334,29 @@ void Int::SetQWord(int n, uint64_t b) { bits64[n] = b; } +inline unsigned char subborrow(unsigned char c, uint64_t x, uint64_t y, uint64_t* result) { +#if defined(__APPLE__) + return __builtin_ia32_subborrow_u64(c, x, y, result); +#else + return _subborrow_u64(c, x, y, result); +#endif +} + // ------------------------------------------------ void Int::Sub(Int *a) { - - unsigned char c = 0; - c = _subborrow_u64(c, bits64[0], a->bits64[0], bits64 +0); - c = _subborrow_u64(c, bits64[1], a->bits64[1], bits64 +1); - c = _subborrow_u64(c, bits64[2], a->bits64[2], bits64 +2); - c = _subborrow_u64(c, bits64[3], a->bits64[3], bits64 +3); - c = _subborrow_u64(c, bits64[4], a->bits64[4], bits64 +4); + unsigned char c = 0; + c = subborrow(c, bits64[0], a->bits64[0], bits64 + 0); + c = subborrow(c, bits64[1], a->bits64[1], bits64 + 1); + c = subborrow(c, bits64[2], a->bits64[2], bits64 + 2); + c = subborrow(c, bits64[3], a->bits64[3], bits64 + 3); + c = subborrow(c, bits64[4], a->bits64[4], bits64 + 4); #if NB64BLOCK > 5 - c = _subborrow_u64(c, bits64[5], a->bits64[5], bits64 +5); - c = _subborrow_u64(c, bits64[6], a->bits64[6], bits64 +6); - c = _subborrow_u64(c, bits64[7], a->bits64[7], bits64 +7); - c = _subborrow_u64(c, bits64[8], a->bits64[8], bits64 +8); + c = subborrow(c, bits64[5], a->bits64[5], bits64 + 5); + c = subborrow(c, bits64[6], a->bits64[6], bits64 + 6); + c = subborrow(c, bits64[7], a->bits64[7], bits64 + 7); + c = subborrow(c, bits64[8], a->bits64[8], bits64 + 8); #endif - } // ------------------------------------------------ @@ -358,16 +364,16 @@ void Int::Sub(Int *a) { void Int::Sub(Int *a,Int *b) { unsigned char c = 0; - c = _subborrow_u64(c, a->bits64[0], b->bits64[0], bits64 + 0); - c = _subborrow_u64(c, a->bits64[1], b->bits64[1], bits64 + 1); - c = _subborrow_u64(c, a->bits64[2], b->bits64[2], bits64 + 2); - c = _subborrow_u64(c, a->bits64[3], b->bits64[3], bits64 + 3); - c = _subborrow_u64(c, a->bits64[4], b->bits64[4], bits64 + 4); + c = subborrow(c, a->bits64[0], b->bits64[0], bits64 + 0); + c = subborrow(c, a->bits64[1], b->bits64[1], bits64 + 1); + c = subborrow(c, a->bits64[2], b->bits64[2], bits64 + 2); + c = subborrow(c, a->bits64[3], b->bits64[3], bits64 + 3); + c = subborrow(c, a->bits64[4], b->bits64[4], bits64 + 4); #if NB64BLOCK > 5 - c = _subborrow_u64(c, a->bits64[5], b->bits64[5], bits64 + 5); - c = _subborrow_u64(c, a->bits64[6], b->bits64[6], bits64 + 6); - c = _subborrow_u64(c, a->bits64[7], b->bits64[7], bits64 + 7); - c = _subborrow_u64(c, a->bits64[8], b->bits64[8], bits64 + 8); + c = subborrow(c, a->bits64[5], b->bits64[5], bits64 + 5); + c = subborrow(c, a->bits64[6], b->bits64[6], bits64 + 6); + c = subborrow(c, a->bits64[7], b->bits64[7], bits64 + 7); + c = subborrow(c, a->bits64[8], b->bits64[8], bits64 + 8); #endif } @@ -375,16 +381,16 @@ void Int::Sub(Int *a,Int *b) { void Int::Sub(uint64_t a) { unsigned char c = 0; - c = _subborrow_u64(c, bits64[0], a, bits64 + 0); - c = _subborrow_u64(c, bits64[1], 0, bits64 + 1); - c = _subborrow_u64(c, bits64[2], 0, bits64 + 2); - c = _subborrow_u64(c, bits64[3], 0, bits64 + 3); - c = _subborrow_u64(c, bits64[4], 0, bits64 + 4); + c = subborrow(c, bits64[0], a, bits64 + 0); + c = subborrow(c, bits64[1], 0, bits64 + 1); + c = subborrow(c, bits64[2], 0, bits64 + 2); + c = subborrow(c, bits64[3], 0, bits64 + 3); + c = subborrow(c, bits64[4], 0, bits64 + 4); #if NB64BLOCK > 5 - c = _subborrow_u64(c, bits64[5], 0, bits64 + 5); - c = _subborrow_u64(c, bits64[6], 0, bits64 + 6); - c = _subborrow_u64(c, bits64[7], 0, bits64 + 7); - c = _subborrow_u64(c, bits64[8], 0, bits64 + 8); + c = subborrow(c, bits64[5], 0, bits64 + 5); + c = subborrow(c, bits64[6], 0, bits64 + 6); + c = subborrow(c, bits64[7], 0, bits64 + 7); + c = subborrow(c, bits64[8], 0, bits64 + 8); #endif } @@ -392,16 +398,16 @@ void Int::Sub(uint64_t a) { void Int::SubOne() { unsigned char c = 0; - c = _subborrow_u64(c, bits64[0], 1, bits64 + 0); - c = _subborrow_u64(c, bits64[1], 0, bits64 + 1); - c = _subborrow_u64(c, bits64[2], 0, bits64 + 2); - c = _subborrow_u64(c, bits64[3], 0, bits64 + 3); - c = _subborrow_u64(c, bits64[4], 0, bits64 + 4); + c = subborrow(c, bits64[0], 1, bits64 + 0); + c = subborrow(c, bits64[1], 0, bits64 + 1); + c = subborrow(c, bits64[2], 0, bits64 + 2); + c = subborrow(c, bits64[3], 0, bits64 + 3); + c = subborrow(c, bits64[4], 0, bits64 + 4); #if NB64BLOCK > 5 - c = _subborrow_u64(c, bits64[5], 0, bits64 + 5); - c = _subborrow_u64(c, bits64[6], 0, bits64 + 6); - c = _subborrow_u64(c, bits64[7], 0, bits64 + 7); - c = _subborrow_u64(c, bits64[8], 0, bits64 + 8); + c = subborrow(c, bits64[5], 0, bits64 + 5); + c = subborrow(c, bits64[6], 0, bits64 + 6); + c = subborrow(c, bits64[7], 0, bits64 + 7); + c = subborrow(c, bits64[8], 0, bits64 + 8); #endif } @@ -444,16 +450,16 @@ bool Int::IsOdd() { void Int::Neg() { volatile unsigned char c=0; - c = _subborrow_u64(c, 0, bits64[0], bits64 + 0); - c = _subborrow_u64(c, 0, bits64[1], bits64 + 1); - c = _subborrow_u64(c, 0, bits64[2], bits64 + 2); - c = _subborrow_u64(c, 0, bits64[3], bits64 + 3); - c = _subborrow_u64(c, 0, bits64[4], bits64 + 4); + c = subborrow(c, 0, bits64[0], bits64 + 0); + c = subborrow(c, 0, bits64[1], bits64 + 1); + c = subborrow(c, 0, bits64[2], bits64 + 2); + c = subborrow(c, 0, bits64[3], bits64 + 3); + c = subborrow(c, 0, bits64[4], bits64 + 4); #if NB64BLOCK > 5 - c = _subborrow_u64(c, 0, bits64[5], bits64 + 5); - c = _subborrow_u64(c, 0, bits64[6], bits64 + 6); - c = _subborrow_u64(c, 0, bits64[7], bits64 + 7); - c = _subborrow_u64(c, 0, bits64[8], bits64 + 8); + c = subborrow(c, 0, bits64[5], bits64 + 5); + c = subborrow(c, 0, bits64[6], bits64 + 6); + c = subborrow(c, 0, bits64[7], bits64 + 7); + c = subborrow(c, 0, bits64[8], bits64 + 8); #endif } @@ -959,7 +965,7 @@ char* Int::GetBlockStr() { char bStr[256]; tmp[0] = 0; for (int i = NB32BLOCK-3; i>=0 ; i--) { - sprintf(bStr, "%08X", bits[i]); + snprintf(bStr, sizeof(bStr), "%08X", bits[i]); strcat(tmp, bStr); if(i!=0) strcat(tmp, " "); } @@ -976,12 +982,12 @@ char * Int::GetC64Str(int nbDigit) { for (int i = 0; i< nbDigit; i++) { if (bits64[i] != 0) { #ifdef _WIN64 - sprintf(bStr, "0x%016I64XULL", bits64[i]); + sprintf(bStr, "0x%016llXULL", bits64[i]); #else - sprintf(bStr, "0x%" PRIx64 "ULL", bits64[i]); + snprintf(bStr, sizeof(bStr), "0x%" PRIx64 "ULL", bits64[i]); #endif } else { - sprintf(bStr, "0ULL"); + snprintf(bStr, sizeof(bStr), "0ULL"); } strcat(tmp, bStr); if (i != nbDigit -1) strcat(tmp, ","); diff --git a/secp256k1/IntMod.cpp b/secp256k1/IntMod.cpp index 3946874..2b337ac 100644 --- a/secp256k1/IntMod.cpp +++ b/secp256k1/IntMod.cpp @@ -853,17 +853,22 @@ void Int::MontgomeryMult(Int *a, Int *b) { void Int::ModMulK1(Int *a, Int *b) { #ifndef _WIN64 -#if (__GNUC__ > 7) || (__GNUC__ == 7 && (__GNUC_MINOR__ > 2)) + +#ifdef __clang__ unsigned char c; #else - #warning "GCC lass than 7.3 detected, upgrade gcc to get best perfromance" - volatile unsigned char c; + + #if (__GNUC__ > 7) || (__GNUC__ == 7 && (__GNUC_MINOR__ > 2)) + unsigned char c; + #else + #warning "GCC less than 7.3 detected, upgrade gcc to get best performance" + volatile unsigned char c; + #endif #endif #else unsigned char c; #endif - uint64_t ah, al; uint64_t t[5]; uint64_t r512[8]; @@ -915,16 +920,23 @@ void Int::ModMulK1(Int *a, Int *b) { void Int::ModMulK1(Int *a) { #ifndef _WIN64 -#if (__GNUC__ > 7) || (__GNUC__ == 7 && (__GNUC_MINOR__ > 2)) + +#ifdef __clang__ unsigned char c; #else - #warning "GCC lass than 7.3 detected, upgrade gcc to get best perfromance" - volatile unsigned char c; + + #if (__GNUC__ > 7) || (__GNUC__ == 7 && (__GNUC_MINOR__ > 2)) + unsigned char c; + #else + #warning "GCC less than 7.3 detected, upgrade gcc to get best performance" + volatile unsigned char c; + #endif #endif #else unsigned char c; #endif + uint64_t ah, al; uint64_t t[5]; uint64_t r512[8]; @@ -975,16 +987,23 @@ void Int::ModMulK1(Int *a) { void Int::ModSquareK1(Int *a) { #ifndef _WIN64 -#if (__GNUC__ > 7) || (__GNUC__ == 7 && (__GNUC_MINOR__ > 2)) + +#ifdef __clang__ unsigned char c; #else - #warning "GCC lass than 7.3 detected, upgrade gcc to get best perfromance" - volatile unsigned char c; + + #if (__GNUC__ > 7) || (__GNUC__ == 7 && (__GNUC_MINOR__ > 2)) + unsigned char c; + #else + #warning "GCC less than 7.3 detected, upgrade gcc to get best performance" + volatile unsigned char c; + #endif #endif #else unsigned char c; #endif + uint64_t r512[8]; uint64_t u10, u11; uint64_t t1; diff --git a/secp256k1/Random.cpp b/secp256k1/Random.cpp index 03aca3a..fb8e0d8 100644 --- a/secp256k1/Random.cpp +++ b/secp256k1/Random.cpp @@ -17,6 +17,8 @@ #include "Random.h" +#include // Necessário para O_RDONLY +#include // Necessário para read() e open() #if defined(_WIN64) && !defined(__CYGWIN__) #else @@ -66,9 +68,9 @@ void rk_seed(unsigned long seed, rk_state *state) #define UPPER_MASK 0x80000000UL #define LOWER_MASK 0x7fffffffUL -#ifdef _WIN64 +#ifdef _MSC_VER // Disable "unary minus operator applied to unsigned type, result still unsigned" warning. -#pragma warning(disable : 4146) + #pragma warning(disable : 4146) #endif /* Slightly optimised reference implementation of the Mersenne Twister */ @@ -127,7 +129,11 @@ unsigned long rndl() { #else unsigned long rndl() { unsigned long r; - int bytes_read = getrandom(&r, sizeof(unsigned long), GRND_NONBLOCK ); + #if defined(__unix__) || defined(__unix) + int bytes_read = getrandom(&r, sizeof(unsigned long), GRND_NONBLOCK); + #else + int bytes_read = read(open("/dev/urandom", O_RDONLY), &r, sizeof(unsigned long)); + #endif if (bytes_read > 0) { return r; } diff --git a/secp256k1/SECP256K1.cpp b/secp256k1/SECP256K1.cpp index 46f918d..d17ec5f 100644 --- a/secp256k1/SECP256K1.cpp +++ b/secp256k1/SECP256K1.cpp @@ -585,7 +585,7 @@ 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) { -#ifdef WIN64 +#ifdef _MSC_VER __declspec(align(16)) unsigned char sh0[64]; __declspec(align(16)) unsigned char sh1[64]; __declspec(align(16)) unsigned char sh2[64]; @@ -747,7 +747,7 @@ 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) { -#ifdef WIN64 +#ifdef _MSC_VER __declspec(align(16)) unsigned char sh0[64]; __declspec(align(16)) unsigned char sh1[64]; __declspec(align(16)) unsigned char sh2[64]; diff --git a/sha3/keccak.c b/sha3/keccak.c index d680577..25368f6 100644 --- a/sha3/keccak.c +++ b/sha3/keccak.c @@ -32,15 +32,16 @@ #define secret /* can't use in variable-time operations, should zero */ -#define FOR5(X, STMT) do \ -{ \ - (X) = 0; (STMT); \ - (X) = 1; (STMT); \ - (X) = 2; (STMT); \ - (X) = 3; (STMT); \ - (X) = 4; (STMT); \ +#define FOR5(X, STMT) do \ +{ \ + (X) = 0; (STMT); \ + (X) = 1; (STMT); \ + (X) = 2; (STMT); \ + (X) = 3; (STMT); \ + (X) = 4; (STMT); \ } while (0) + static inline secret uint64_t rol64(secret uint64_t v, unsigned c) { @@ -55,21 +56,22 @@ keccakf1600_theta(secret uint64_t A[25]) unsigned y; C0 = C1 = C2 = C3 = C4 = 0; +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" - FOR5(y, { - C0 ^= A[0 + 5*y]; - C1 ^= A[1 + 5*y]; - C2 ^= A[2 + 5*y]; - C3 ^= A[3 + 5*y]; - C4 ^= A[4 + 5*y]; - }); - FOR5(y, { - A[0 + 5*y] ^= C4 ^ rol64(C1, 1); - A[1 + 5*y] ^= C0 ^ rol64(C2, 1); - A[2 + 5*y] ^= C1 ^ rol64(C3, 1); - A[3 + 5*y] ^= C2 ^ rol64(C4, 1); - A[4 + 5*y] ^= C3 ^ rol64(C0, 1); - }); + for (y = 0; y < 5; ++y) { + C0 ^= A[0 + 5 * y]; + C1 ^= A[1 + 5 * y]; + C2 ^= A[2 + 5 * y]; + C3 ^= A[3 + 5 * y]; + C4 ^= A[4 + 5 * y]; + } + for (y = 0; y < 5; ++y) { + A[0 + 5 * y] ^= C4 ^ rol64(C1, 1); + A[1 + 5 * y] ^= C0 ^ rol64(C2, 1); + A[2 + 5 * y] ^= C1 ^ rol64(C3, 1); + A[3 + 5 * y] ^= C2 ^ rol64(C4, 1); + A[4 + 5 * y] ^= C3 ^ rol64(C0, 1); + } #pragma GCC diagnostic pop } @@ -115,19 +117,22 @@ keccakf1600_chi(secret uint64_t A[25]) secret uint64_t B0, B1, B2, B3, B4; unsigned y; +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" - FOR5(y, { - B0 = A[0 + 5*y]; - B1 = A[1 + 5*y]; - B2 = A[2 + 5*y]; - B3 = A[3 + 5*y]; - B4 = A[4 + 5*y]; - A[0 + 5*y] ^= ~B1 & B2; - A[1 + 5*y] ^= ~B2 & B3; - A[2 + 5*y] ^= ~B3 & B4; - A[3 + 5*y] ^= ~B4 & B0; - A[4 + 5*y] ^= ~B0 & B1; - }); + for (y = 0; y < 5; ++y) { + B0 = A[0 + 5 * y]; + B1 = A[1 + 5 * y]; + B2 = A[2 + 5 * y]; + B3 = A[3 + 5 * y]; + B4 = A[4 + 5 * y]; + + A[0 + 5 * y] ^= ~B1 & B2; + A[1 + 5 * y] ^= ~B2 & B3; + A[2 + 5 * y] ^= ~B3 & B4; + A[3 + 5 * y] ^= ~B4 & B0; + A[4 + 5 * y] ^= ~B0 & B1; + } + #pragma GCC diagnostic pop } diff --git a/sha3/sha3.h b/sha3/sha3.h index 8118d27..ed0f28d 100644 --- a/sha3/sha3.h +++ b/sha3/sha3.h @@ -23,13 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - -#ifndef SHA3_H -#define SHA3_H +#ifndef SHA3_H +#define SHA3_H #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct sha3 { uint64_t A[25]; unsigned nb; /* number of bytes remaining to fill buffer */ @@ -47,42 +50,46 @@ typedef struct { struct sha3 C256; } SHAKE256_CTX; #define SHA3_384_DIGEST_LENGTH 48 #define SHA3_512_DIGEST_LENGTH 64 -void SHA3_224_Init(SHA3_224_CTX *); -void SHA3_224_Update(SHA3_224_CTX *, const uint8_t *, size_t); -void SHA3_224_Final(uint8_t[SHA3_224_DIGEST_LENGTH], SHA3_224_CTX *); +void SHA3_224_Init(SHA3_224_CTX *); +void SHA3_224_Update(SHA3_224_CTX *, const uint8_t *, size_t); +void SHA3_224_Final(uint8_t[SHA3_224_DIGEST_LENGTH], SHA3_224_CTX *); -void SHA3_256_Init(SHA3_256_CTX *); -void SHA3_256_Update(SHA3_256_CTX *, const uint8_t *, size_t); -void SHA3_256_Final(uint8_t[SHA3_256_DIGEST_LENGTH], SHA3_256_CTX *); +void SHA3_256_Init(SHA3_256_CTX *); +void SHA3_256_Update(SHA3_256_CTX *, const uint8_t *, size_t); +void SHA3_256_Final(uint8_t[SHA3_256_DIGEST_LENGTH], SHA3_256_CTX *); -void SHA3_384_Init(SHA3_384_CTX *); -void SHA3_384_Update(SHA3_384_CTX *, const uint8_t *, size_t); -void SHA3_384_Final(uint8_t[SHA3_384_DIGEST_LENGTH], SHA3_384_CTX *); +void SHA3_384_Init(SHA3_384_CTX *); +void SHA3_384_Update(SHA3_384_CTX *, const uint8_t *, size_t); +void SHA3_384_Final(uint8_t[SHA3_384_DIGEST_LENGTH], SHA3_384_CTX *); -void SHA3_512_Init(SHA3_512_CTX *); -void SHA3_512_Update(SHA3_512_CTX *, const uint8_t *, size_t); -void SHA3_512_Final(uint8_t[SHA3_512_DIGEST_LENGTH], SHA3_512_CTX *); +void SHA3_512_Init(SHA3_512_CTX *); +void SHA3_512_Update(SHA3_512_CTX *, const uint8_t *, size_t); +void SHA3_512_Final(uint8_t[SHA3_512_DIGEST_LENGTH], SHA3_512_CTX *); -void SHAKE128_Init(SHAKE128_CTX *); -void SHAKE128_Update(SHAKE128_CTX *, const uint8_t *, size_t); -void SHAKE128_Final(uint8_t *, size_t, SHAKE128_CTX *); +void SHAKE128_Init(SHAKE128_CTX *); +void SHAKE128_Update(SHAKE128_CTX *, const uint8_t *, size_t); +void SHAKE128_Final(uint8_t *, size_t, SHAKE128_CTX *); -void SHAKE256_Init(SHAKE256_CTX *); -void SHAKE256_Update(SHAKE256_CTX *, const uint8_t *, size_t); -void SHAKE256_Final(uint8_t *, size_t, SHAKE256_CTX *); +void SHAKE256_Init(SHAKE256_CTX *); +void SHAKE256_Update(SHAKE256_CTX *, const uint8_t *, size_t); +void SHAKE256_Final(uint8_t *, size_t, SHAKE256_CTX *); #define KECCAK_256_Init SHA3_256_Init #define KECCAK_256_Update SHA3_256_Update -void KECCAK_256_Final(uint8_t[SHA3_256_DIGEST_LENGTH], SHA3_256_CTX *); +void KECCAK_256_Final(uint8_t[SHA3_256_DIGEST_LENGTH], SHA3_256_CTX *); #define KECCAK_384_Init SHA3_384_Init #define KECCAK_384_Update SHA3_384_Update -void KECCAK_384_Final(uint8_t[SHA3_384_DIGEST_LENGTH], SHA3_384_CTX *); +void KECCAK_384_Final(uint8_t[SHA3_384_DIGEST_LENGTH], SHA3_384_CTX *); #define KECCAK_512_Init SHA3_512_Init #define KECCAK_512_Update SHA3_512_Update -void KECCAK_512_Final(uint8_t[SHA3_512_DIGEST_LENGTH], SHA3_512_CTX *); +void KECCAK_512_Final(uint8_t[SHA3_512_DIGEST_LENGTH], SHA3_512_CTX *); + +int SHA3_Selftest(void); -int SHA3_Selftest(void); +#ifdef __cplusplus +} +#endif #endif /* SHA3_H */ diff --git a/util.c b/util.c index 0c46cd4..6280449 100644 --- a/util.c +++ b/util.c @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include "util.h" @@ -101,22 +101,24 @@ char *tohex(char *ptr,int length){ buffer = (char *) malloc((length * 2)+1); for (int i = 0; i Date: Thu, 10 Oct 2024 21:53:33 -0300 Subject: [PATCH 2/2] Update README.md --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3feeeed..2986d5f 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,59 @@ Please read the CHANGELOG.md to see the new changes # Download and build +- Beta Multiplaforma build + +- MAC OS System + +Please install on your system + +- Git +- Brew +- XCode-Select +- GNU components +- OpenSSL +- GMP + +To install this components + + +- Brew + +``` +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +``` + +- Git + +``` +brew install git +``` + +- XCode + +``` +xcode-select --install +``` + +- GNU Components + +``` +brew install make automake gcc + +``` + +- Openssl + +``` +brew install openssl +``` + +- GMP + +``` +brew install gmp +``` + This program was made in a linux environment. if you are windows user i strongly recommend to use WSL enviroment on Windows. it is available in the Microsoft store @@ -91,12 +144,19 @@ don't forget change to the keyhunt directory (But i'm not here to teach you linu cd keyhunt ``` -First compile: +First compile(Linux && Mac OS): ``` make ``` +Windows(Compiled by WSL +): + +``` +make windows +``` + if you have problems compiling the `main` version you can compile the `legacy` version ```