optimized

This commit is contained in:
fluttershy 2025-03-01 04:57:59 +05:00
parent 256fa1f35c
commit 0573038c3d
2 changed files with 16 additions and 83 deletions

View File

@ -3,6 +3,6 @@ project(yggminer)
file(GLOB ${PROJECT_NAME}SOURCES *.cpp)
file(GLOB ${PROJECT_NAME}HEADERS *.h)
add_executable(${PROJECT_NAME} sources/main.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -O3 -pipe -Wall -Wextra -flto=full")
set(CMAKE_CXX_FLAGS_RELEASE "-march=native -O3 -ffast-math -ftree-vectorize -fdelete-null-pointer-checks -fno-exceptions -fno-rtti -finline-functions -pthread -fomit-frame-pointer -pipe -Wall -Wextra -flto=full")
target_link_libraries(${PROJECT_NAME} pthread)
target_link_libraries(${PROJECT_NAME} sodium)
target_link_libraries(${PROJECT_NAME} sodium)

View File

@ -11,7 +11,6 @@
#include <regex>
#include <arpa/inet.h>
#include <immintrin.h>
int countsize = 0;
using Key = std::array<unsigned char, 32>;
using Address = std::array<unsigned char, 16>;
struct KeysBox {
@ -20,16 +19,9 @@ struct KeysBox {
};
struct option {
unsigned int proc = 0;
int mode = 1; // режим майнинга
bool log = true; // логгирование
int high = 20; // начальная высота при майнинге: dec(20) == hex(14)
bool letsup = true; // повышение высоты при нахождении
bool mesh = false; // отображение meshname-доменов
bool fullkeys = true; // отображение секретного ключа в консоли в полном формате
std::string str = "aaaa";
bool log = true;
int high = 20;
std::string outputfile;
int sbt_size = 7;
bool sbt_alarm = false;
};
static option conf;
int parameters(option& conf, std::string arg) {
@ -42,75 +34,26 @@ int parameters(option& conf, std::string arg) {
if (ss.fail()) return 1;
return 0;
}
if (arg.find("--pattern") != npos || arg.find("-p") != npos) {
ss >> conf.str;
if (ss.fail()) return 1;
return 0;
}
if (arg.find("--altitude") != npos || arg.find("-a") != npos) {
ss >> std::hex >> conf.high;
if (ss.fail()) return 1;
return 0;
}
}
else if (arg == "--ip" || arg == "-i") conf.mode = 0;
else if (arg == "--ip-high" || arg == "-ih") conf.mode = 2;
else if (arg == "--regexp" || arg == "-r") conf.mode = 3;
else if (arg == "--regexp-high" || arg == "-rh") conf.mode = 4;
else if (arg == "--mesh" || arg == "-m") conf.mode = 5;
else if (arg == "--mesh-regexp" || arg == "-mr") conf.mode = 6;
else if (arg == "--brute-force" || arg == "-b") conf.mode = 7;
else if (arg == "--increase-none" || arg == "-in") conf.letsup = false;
else if (arg == "--logging-none" || arg == "-ln") conf.log = false;
else if (arg == "--display-mesh" || arg == "-dm") conf.mesh = true;
else if (arg == "--full-pk" || arg == "-fp") conf.fullkeys = true;
else if (arg == "--threads" || arg == "-t") return 777;
else if (arg == "--pattern" || arg == "-p") return 777;
if (arg == "--threads" || arg == "-t") return 777;
else if (arg == "--altitude" || arg == "-a") return 777;
return 0;
}
void displayConfig() {
unsigned short processor_count = std::thread::hardware_concurrency();
if (conf.proc == 0 || conf.proc > static_cast<unsigned int>(processor_count))
if (conf.proc == 0 || conf.proc > static_cast<unsigned int>(processor_count)) {
conf.proc = static_cast<unsigned int>(processor_count);
countsize = 80000 * conf.proc;
std::cout << " Threads: " << conf.proc << ", ";
if (conf.mode == 0)
std::cout << "IPv6 pattern (" << conf.str << "), ";
else if (conf.mode == 1) {
std::cout << "high addresses (2" << std::setw(2) << std::setfill('0') <<
std::hex << conf.high << std::dec;
(conf.letsup != 0) ? std::cout << "++), " : std::cout << "+), ";
} else if (conf.mode == 2) {
std::cout << "by pattern (" << conf.str << ") & high (2" <<
std::setw(2) << std::setfill('0') << std::hex << conf.high << std::dec;
(conf.letsup != 0) ? std::cout << "++), " : std::cout << "+), ";
} else if (conf.mode == 3)
std::cout << "IPv6 regexp (" << conf.str << "), ";
else if (conf.mode == 4) {
std::cout << "IPv6 regexp (" << conf.str << ") & high (2" <<
std::setw(2) << std::setfill('0') << std::hex << conf.high << std::dec;
(conf.letsup != 0) ? std::cout << "++), " : std::cout << "+), ";
} else if (conf.mode == 5)
std::cout << "meshname pattern (" << conf.str << "), ";
else if (conf.mode == 6)
std::cout << "meshname regexp (" << conf.str << "), ";
else if (conf.mode == 7)
std::cout << "subnet brute force (" << conf.str << "/" << (conf.sbt_size + 1) * 8 << "), ";
if (conf.log)
std::cout << "logging to text file.";
else
std::cout << "console log only.";
if ((conf.mode == 5 || conf.mode == 6) && conf.mesh == 0)
conf.mesh = 1;
std::cout << std::endl << std::endl;
}
std::cout << " Threads: " << conf.proc << ", " << "high addresses (2" << std::setw(2) << std::setfill('0') << std::hex << conf.high << "+)" << std::dec << std::endl;
}
KeysBox getKeyPair() {
KeysBox getKeyPair() noexcept {
KeysBox keys;
unsigned char sk[64];
crypto_sign_ed25519_keypair(keys.PublicKey.data(), sk);
memcpy(keys.PrivateKey.data(), sk, 32);
crypto_sign_ed25519_keypair(keys.PublicKey.data(), keys.PrivateKey.data());
return keys;
}
std::string getAddress(const Address& rawAddr) {
@ -120,20 +63,21 @@ std::string getAddress(const Address& rawAddr) {
}
inline std::string keyToString(const Key& key) {
std::string result;
result.reserve(64);
for (int i = 0; i < 32; ++i) {
result.push_back("0123456789abcdef"[key.data()[i] >> 4]);
result.push_back("0123456789abcdef"[key.data()[i] & 0x0F]);
}
return result;
}
inline Key bitwiseInverse(const Key& key) {
inline Key bitwiseInverse(const Key& key) noexcept {
Key inverted;
std::transform(key.begin(), key.end(), inverted.begin(), [](unsigned char byte) {
return static_cast<unsigned char>(~byte);
});
return inverted;
}
int getOnes(const Key& value) {
int getOnes(const Key&& value) noexcept {
int leadOnes = 0;
for (int i = 0; i < 17; ++i) {
if (value[i] == 0xFF) {
@ -150,31 +94,20 @@ int getOnes(const Key& value) {
}
return leadOnes;
}
void printKeys(int ones, const KeysBox& keys) {
char buffer[256];
int len = snprintf(buffer, sizeof(buffer), "\nAddr:\t2%x\nPK:\t%s\nSK:\t%s\n", ones, keyToString(keys.PublicKey).c_str(), keyToString(keys.PrivateKey).c_str());
if (len > 0 && len < static_cast<int>(sizeof(buffer))) {
printf("%s", buffer);
} else {
fprintf(stderr, "Buffer overflow or error in snprintf\n");
}
}
void miner_thread() {
KeysBox keys;
Key inv;
int ones;
while (1) {
keys = getKeyPair();
inv = bitwiseInverse(keys.PublicKey);
if ((ones = getOnes(inv)) > conf.high) {
if ((ones = getOnes(bitwiseInverse(keys.PublicKey))) > conf.high) {
conf.high = ones;
printKeys(ones, keys);
printf("\nAddr:\t2%x\nPK:\t%s\nSK:\t%s\n", ones, keyToString(keys.PublicKey).c_str(), keyToString(keys.PrivateKey).c_str());
}
}
}
void startThreads() {
std::vector<std::thread> threads;
for (unsigned int i = 0; i < std::thread::hardware_concurrency(); ++i) {
for (unsigned int i = 0; i < conf.proc; i++) {
threads.emplace_back(miner_thread);
}
for (auto& thread : threads) {