mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-07-04 12:03:41 +02:00
Adding "eoskeygen" namespace.
This commit is contained in:
parent
20a47d11b5
commit
0e9d23086f
22 changed files with 95 additions and 11 deletions
|
|
@ -27,6 +27,8 @@
|
||||||
#include "checksum.h"
|
#include "checksum.h"
|
||||||
#include "WIF.h"
|
#include "WIF.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
#define PRIV_KEY_PREFIX 0x80 /* 0x80 for "Bitcoin mainnet". Always used by EOS. */
|
#define PRIV_KEY_PREFIX 0x80 /* 0x80 for "Bitcoin mainnet". Always used by EOS. */
|
||||||
|
|
||||||
std::string wif_priv_encode(ec_privkey_t priv) {
|
std::string wif_priv_encode(ec_privkey_t priv) {
|
||||||
|
|
@ -60,3 +62,5 @@ void wif_print_key(const struct ec_keypair *key) {
|
||||||
std::cout << "Public: " << wif_pub_encode(key->pub) << std::endl;
|
std::cout << "Public: " << wif_pub_encode(key->pub) << std::endl;
|
||||||
std::cout << "Private: " << wif_priv_encode(key->secret) << std::endl;
|
std::cout << "Private: " << wif_priv_encode(key->secret) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,14 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "ec/types.h"
|
#include "ec/types.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
std::string wif_priv_encode(ec_privkey_t priv);
|
std::string wif_priv_encode(ec_privkey_t priv);
|
||||||
|
|
||||||
std::string wif_pub_encode(ec_pubkey_t pub);
|
std::string wif_pub_encode(ec_pubkey_t pub);
|
||||||
|
|
||||||
void wif_print_key(const struct ec_keypair *key);
|
void wif_print_key(const struct ec_keypair *key);
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
||||||
#endif /* WIF_H */
|
#endif /* WIF_H */
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include "base58.h"
|
#include "base58.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
static const char charmap[59] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
static const char charmap[59] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||||
|
|
||||||
std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend) {
|
std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend) {
|
||||||
|
|
@ -80,3 +82,5 @@ std::string base58_encode(const std::vector<unsigned char>& vch) {
|
||||||
|
|
||||||
return base58_encode(vch.data(), vch.data() + vch.size());
|
return base58_encode(vch.data(), vch.data() + vch.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,12 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
std::string base58_encode(const std::string& str);
|
std::string base58_encode(const std::string& str);
|
||||||
std::string base58_encode(const std::vector<unsigned char>& vch);
|
std::string base58_encode(const std::vector<unsigned char>& vch);
|
||||||
std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend);
|
std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend);
|
||||||
|
|
||||||
|
} //namespace eoskeygen
|
||||||
|
|
||||||
#endif /* BASE58_H */
|
#endif /* BASE58_H */
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ using std::chrono::steady_clock;
|
||||||
using std::chrono::duration;
|
using std::chrono::duration;
|
||||||
using std::chrono::time_point;
|
using std::chrono::time_point;
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
void benchmark(size_t num_keys, struct benchmark_result* res) {
|
void benchmark(size_t num_keys, struct benchmark_result* res) {
|
||||||
|
|
||||||
time_point<steady_clock> start;
|
time_point<steady_clock> start;
|
||||||
|
|
@ -48,3 +50,5 @@ void benchmark(size_t num_keys, struct benchmark_result* res) {
|
||||||
res->sec = duration<float>(steady_clock::now() - start).count();
|
res->sec = duration<float>(steady_clock::now() - start).count();
|
||||||
res->kps = static_cast<float>(num_keys) / res->sec;
|
res->kps = static_cast<float>(num_keys) / res->sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
struct benchmark_result {
|
struct benchmark_result {
|
||||||
float sec; // elapsed seconds.
|
float sec; // elapsed seconds.
|
||||||
float kps; // keys per second.
|
float kps; // keys per second.
|
||||||
|
|
@ -33,4 +35,6 @@ struct benchmark_result {
|
||||||
|
|
||||||
void benchmark(size_t num_keys, struct benchmark_result* res);
|
void benchmark(size_t num_keys, struct benchmark_result* res);
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
||||||
#endif /* BENCHMARK_H */
|
#endif /* BENCHMARK_H */
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "checksum.h"
|
#include "checksum.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
inline void sha256d(const unsigned char *data, std::size_t len, unsigned char *out) {
|
inline void sha256d(const unsigned char *data, std::size_t len, unsigned char *out) {
|
||||||
SHA256(data, len, out);
|
SHA256(data, len, out);
|
||||||
SHA256(out, 32, out);
|
SHA256(out, 32, out);
|
||||||
|
|
@ -46,3 +48,5 @@ inline void sha256d(const unsigned char *data, std::size_t len, unsigned char *o
|
||||||
|
|
||||||
checksum_impl(sha256d, sha256d)
|
checksum_impl(sha256d, sha256d)
|
||||||
checksum_impl(ripemd160, RIPEMD160)
|
checksum_impl(ripemd160, RIPEMD160)
|
||||||
|
|
||||||
|
} // namespace eosio-keygen
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
#define CHECKSUM_SIZE 4
|
#define CHECKSUM_SIZE 4
|
||||||
|
|
||||||
typedef std::array<unsigned char, CHECKSUM_SIZE> checksum_t;
|
typedef std::array<unsigned char, CHECKSUM_SIZE> checksum_t;
|
||||||
|
|
@ -35,4 +37,6 @@ checksum_t checksum_sha256d(const unsigned char *data, std::size_t len);
|
||||||
|
|
||||||
checksum_t checksum_ripemd160(const unsigned char *data, std::size_t len);
|
checksum_t checksum_ripemd160(const unsigned char *data, std::size_t len);
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
||||||
#endif /* CHECKSUM_H */
|
#endif /* CHECKSUM_H */
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
namespace console {
|
namespace console {
|
||||||
|
|
||||||
// enum for all supported colors.
|
// enum for all supported colors.
|
||||||
|
|
@ -80,4 +82,6 @@ namespace console {
|
||||||
|
|
||||||
} // namespace console
|
} // namespace console
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
||||||
#endif /* CONSOLE_H */
|
#endif /* CONSOLE_H */
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
namespace console {
|
namespace console {
|
||||||
|
|
||||||
std::ostream& reset(std::ostream& os) {
|
std::ostream& reset(std::ostream& os) {
|
||||||
|
|
@ -69,3 +71,5 @@ std::ostream& operator<<(std::ostream& os, const fg& obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace console
|
} // namespace console
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
// WinAPI colors
|
// WinAPI colors
|
||||||
#define FG_BLACK 0
|
#define FG_BLACK 0
|
||||||
#define FG_BLUE FOREGROUND_BLUE
|
#define FG_BLUE FOREGROUND_BLUE
|
||||||
|
|
@ -88,3 +90,5 @@ std::ostream& operator<<(std::ostream& os, const fg& obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace console
|
} // namespace console
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,14 @@
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a keypair using the secp256k1 curve.
|
* Generates a keypair using the secp256k1 curve.
|
||||||
* public key is in compressed format.
|
* public key is in compressed format.
|
||||||
*/
|
*/
|
||||||
int ec_generate_key(struct ec_keypair *pair);
|
int ec_generate_key(struct ec_keypair *pair);
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
||||||
#endif /* EC_GENERATE_H */
|
#endif /* EC_GENERATE_H */
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
#include <openssl/hmac.h>
|
#include <openssl/hmac.h>
|
||||||
#include "generate.h"
|
#include "generate.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
static int ec_generate_pair(unsigned char *priv, unsigned char *pub) {
|
static int ec_generate_pair(unsigned char *priv, unsigned char *pub) {
|
||||||
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
@ -69,3 +71,5 @@ int ec_generate_key(struct ec_keypair *pair) {
|
||||||
|
|
||||||
return ec_generate_pair(pair->secret.data(), pair->pub.data());
|
return ec_generate_pair(pair->secret.data(), pair->pub.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
#define EC_PRIVKEY_SIZE 32
|
#define EC_PRIVKEY_SIZE 32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -43,4 +45,6 @@ struct ec_keypair {
|
||||||
ec_pubkey_t pub;
|
ec_pubkey_t pub;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
||||||
#endif /* EC_TYPES_H */
|
#endif /* EC_TYPES_H */
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
#include "key_search_helpers.h"
|
#include "key_search_helpers.h"
|
||||||
#include "key_search.h"
|
#include "key_search.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
void KeySearch::addWord(const std::string& str)
|
void KeySearch::addWord(const std::string& str)
|
||||||
{
|
{
|
||||||
std::string tmp = str;
|
std::string tmp = str;
|
||||||
|
|
@ -78,3 +80,5 @@ void KeySearch::find(size_t num_results) {
|
||||||
|
|
||||||
_search_linear(num_results);
|
_search_linear(num_results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
class KeySearch
|
class KeySearch
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
@ -67,4 +69,6 @@ protected :
|
||||||
#endif /* HAVE_THREADS */
|
#endif /* HAVE_THREADS */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
||||||
#endif /* KEY_SEARCH_H */
|
#endif /* KEY_SEARCH_H */
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "key_search_helpers.h"
|
#include "key_search_helpers.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
void key_search_result(const struct ec_keypair* key, const struct key_result* result) {
|
void key_search_result(const struct ec_keypair* key, const struct key_result* result) {
|
||||||
|
|
||||||
std::string pub = wif_pub_encode(key->pub);
|
std::string pub = wif_pub_encode(key->pub);
|
||||||
|
|
@ -59,3 +61,5 @@ bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list,
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "ec/types.h"
|
#include "ec/types.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
struct key_result {
|
struct key_result {
|
||||||
size_t pos; // position where the word was found.
|
size_t pos; // position where the word was found.
|
||||||
size_t len; // the length of the word.
|
size_t len; // the length of the word.
|
||||||
|
|
@ -38,4 +40,6 @@ void key_search_result(const struct ec_keypair* key, const struct key_result* re
|
||||||
// returns true if a word was found (stored in <result>), false otherwise.
|
// returns true if a word was found (stored in <result>), false otherwise.
|
||||||
bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, struct key_result *result);
|
bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, struct key_result *result);
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
||||||
#endif /* KEY_SEARCH_HELPERS_H */
|
#endif /* KEY_SEARCH_HELPERS_H */
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@
|
||||||
#include "key_search_helpers.h"
|
#include "key_search_helpers.h"
|
||||||
#include "key_search.h"
|
#include "key_search.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
// Max keys to search for,
|
// Max keys to search for,
|
||||||
std::size_t g_max;
|
std::size_t g_max;
|
||||||
|
|
||||||
|
|
@ -95,3 +97,5 @@ void KeySearch::_search_mt(size_t n)
|
||||||
t[i].join();
|
t[i].join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
22
src/main.cpp
22
src/main.cpp
|
|
@ -39,13 +39,13 @@ bool option_l33t = false;
|
||||||
int option_num_threads = std::thread::hardware_concurrency();
|
int option_num_threads = std::thread::hardware_concurrency();
|
||||||
#endif /* HAVE_THREADS */
|
#endif /* HAVE_THREADS */
|
||||||
|
|
||||||
void cmd_search(const strlist_t& words, int count) {
|
void cmd_search(const eoskeygen::strlist_t& words, int count) {
|
||||||
|
|
||||||
KeySearch ks;
|
eoskeygen::KeySearch ks;
|
||||||
|
|
||||||
if (option_l33t) {
|
if (option_l33t) {
|
||||||
for(std::size_t i = 0; i < words.size(); i++) {
|
for(std::size_t i = 0; i < words.size(); i++) {
|
||||||
ks.addList(l33twords(words[i]));
|
ks.addList(eoskeygen::l33twords(words[i]));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ks.addList(words);
|
ks.addList(words);
|
||||||
|
|
@ -56,7 +56,7 @@ void cmd_search(const strlist_t& words, int count) {
|
||||||
#endif /* HAVE_THREADS */
|
#endif /* HAVE_THREADS */
|
||||||
|
|
||||||
std::cout << "Searching for " << count
|
std::cout << "Searching for " << count
|
||||||
<< " keys containing: " << strjoin(ks.getList(), ",")
|
<< " keys containing: " << eoskeygen::strjoin(ks.getList(), ",")
|
||||||
#ifdef HAVE_THREADS
|
#ifdef HAVE_THREADS
|
||||||
<< ", Using: " << option_num_threads << " threads"
|
<< ", Using: " << option_num_threads << " threads"
|
||||||
#endif /* HAVE_THREADS */
|
#endif /* HAVE_THREADS */
|
||||||
|
|
@ -106,12 +106,12 @@ void usage(const char *name) {
|
||||||
|
|
||||||
void cmd_benchmark(size_t num_keys) {
|
void cmd_benchmark(size_t num_keys) {
|
||||||
|
|
||||||
struct benchmark_result res;
|
struct eoskeygen::benchmark_result res;
|
||||||
|
|
||||||
std::cout << "Benchmark: Generating "
|
std::cout << "Benchmark: Generating "
|
||||||
<< num_keys << " keys" << std::endl;
|
<< num_keys << " keys" << std::endl;
|
||||||
|
|
||||||
benchmark(num_keys, &res);
|
eoskeygen::benchmark(num_keys, &res);
|
||||||
|
|
||||||
std::cout << "Result: Took " << res.sec << " seconds, "
|
std::cout << "Result: Took " << res.sec << " seconds, "
|
||||||
<< res.kps << " keys per second." << std::endl;
|
<< res.kps << " keys per second." << std::endl;
|
||||||
|
|
@ -125,9 +125,9 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
// No args, just print a key.
|
// No args, just print a key.
|
||||||
if (argc <= 1) {
|
if (argc <= 1) {
|
||||||
struct ec_keypair pair;
|
struct eoskeygen::ec_keypair pair;
|
||||||
ec_generate_key(&pair);
|
eoskeygen::ec_generate_key(&pair);
|
||||||
wif_print_key(&pair);
|
eoskeygen::wif_print_key(&pair);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,7 +139,7 @@ int main(int argc, char **argv) {
|
||||||
if (!strcmp(argv[p], "search")) {
|
if (!strcmp(argv[p], "search")) {
|
||||||
|
|
||||||
int count = 10;
|
int count = 10;
|
||||||
strlist_t words;
|
eoskeygen::strlist_t words;
|
||||||
|
|
||||||
while(p++ < argc - 1) {
|
while(p++ < argc - 1) {
|
||||||
if (!strcmp(argv[p], "--l33t")) {
|
if (!strcmp(argv[p], "--l33t")) {
|
||||||
|
|
@ -167,7 +167,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
// wordlist and count
|
// wordlist and count
|
||||||
else if (words.size() < 1) {
|
else if (words.size() < 1) {
|
||||||
words = strsplitwords(std::string(argv[p]));
|
words = eoskeygen::strsplitwords(std::string(argv[p]));
|
||||||
|
|
||||||
if (p + 1 < argc) {
|
if (p + 1 < argc) {
|
||||||
count = atoi(argv[++p]);
|
count = atoi(argv[++p]);
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
strlist_t strsplitwords(const std::string& str, const std::string& delim) {
|
strlist_t strsplitwords(const std::string& str, const std::string& delim) {
|
||||||
|
|
||||||
strlist_t words = strsplit(str, delim);
|
strlist_t words = strsplit(str, delim);
|
||||||
|
|
@ -156,3 +158,5 @@ strlist_t l33twords(std::string str) {
|
||||||
_l33t(list, str, 0);
|
_l33t(list, str, 0);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace eoskeygen {
|
||||||
|
|
||||||
typedef std::vector<std::string> strlist_t;
|
typedef std::vector<std::string> strlist_t;
|
||||||
|
|
||||||
strlist_t strsplitwords(const std::string& str, const std::string& delim = ",");
|
strlist_t strsplitwords(const std::string& str, const std::string& delim = ",");
|
||||||
|
|
@ -46,4 +48,6 @@ strlist_t& base58_strip(strlist_t& list);
|
||||||
|
|
||||||
strlist_t l33twords(std::string str);
|
strlist_t l33twords(std::string str);
|
||||||
|
|
||||||
|
} // namespace eoskeygen
|
||||||
|
|
||||||
#endif /* STRING_H */
|
#endif /* STRING_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue