1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-06-18 04:00:03 +02:00

move some of the headers that should be included in the library to "include/eoskeygen" folder.

This commit is contained in:
Henrik Hautakoski 2020-03-19 08:11:58 +01:00
parent 6bf611f7d0
commit 8035e3233c
23 changed files with 35 additions and 33 deletions

View file

@ -0,0 +1,72 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EOSIOKEYGEN_CORE_DICTIONARY_H
#define EOSIOKEYGEN_CORE_DICTIONARY_H
#include <vector>
#include <string>
#include <map>
#include <set>
namespace eoskeygen {
class Dictionary
{
public :
// Map that contains position and length for substrings.
//
// key = position in the search string.
// value = length of the word from this position.
typedef std::map< size_t, size_t > search_result_t;
public :
// Load words from file.
bool loadFromFile(const std::string& filename);
// Add a word
void add(const std::string& word);
// Add words from another dictionary.
void add(const Dictionary& dictionary);
void clear();
// Returns true if word exists in the dictionary.
bool contains(const std::string& word) const;
// Searches the subject for words defined in the dictionary.
// Returns a search_result_t with the words found in subject.
// See search_result_t for more details.
search_result_t search(const std::string& subject) const;
protected :
// Words in the dictionary.
std::set<std::string> m_words;
};
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_CORE_DICTIONARY_H */

View file

@ -0,0 +1,52 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EOSIOKEYGEN_CORE_STRING_H
#define EOSIOKEYGEN_CORE_STRING_H
#include <vector>
#include <string>
namespace eoskeygen {
typedef std::vector<std::string> strlist_t;
strlist_t strsplitwords(const std::string& str, const std::string& delim = ",");
strlist_t strsplit(const std::string& str, const std::string& delim);
std::string strjoin(const strlist_t& list, const std::string& delim);
std::string& strtolower(std::string& str);
std::string& rtrim(std::string& str);
std::string& ltrim(std::string& str);
std::string& trim(std::string& str);
strlist_t& base58_strip(strlist_t& list);
strlist_t l33twords(std::string str);
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_CORE_STRING_H */

View file

@ -0,0 +1,40 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EOSIOKEYGEN_CRYPTO_WIF_H
#define EOSIOKEYGEN_CRYPTO_WIF_H
#include <string>
#include <eoskeygen/crypto/types.h>
namespace eoskeygen {
std::string wif_priv_encode(ec_privkey_t priv);
std::string wif_pub_encode(ec_pubkey_t pub);
void wif_print_key(const struct ec_keypair *key);
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_CRYPTO_WIF_H */

View file

@ -0,0 +1,46 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EOSIOKEYGEN_CRYPTO_BASE58_H
#define EOSIOKEYGEN_CRYPTO_BASE58_H
#include <string>
#include <vector>
namespace eoskeygen {
std::string base58_encode(const std::string& str);
std::string base58_encode(const std::vector<unsigned char>& vch);
std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend);
bool is_base58(char ch);
// Returns std::string::npos if the string contains only base58 characters
// Otherwise the position of the first non base58 character is returned.
size_t is_base58(const std::string& str);
std::string& base58_strip(std::string& str);
} //namespace eoskeygen
#endif /* EOSIOKEYGEN_CRYPTO_BASE58_H */

View file

@ -0,0 +1,54 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EOSIOKEYGEN_CRYPTO_EOS_CHECKSUM_H
#define EOSIOKEYGEN_CRYPTO_EOS_CHECKSUM_H
#include <cstddef>
#include <cstring>
#include <array>
#include <eoskeygen/crypto/hash.h>
namespace eoskeygen {
#define CHECKSUM_SIZE 4
typedef std::array<unsigned char, CHECKSUM_SIZE> checksum_t;
template <typename T, T* (*F)(const unsigned char *, std::size_t, T*)>
inline checksum_t checksum(const unsigned char* data, std::size_t len) {
checksum_t crc;
T hash;
F(data, len, &hash);
std::memcpy(crc.data(), &hash, crc.size());
return crc;
}
#define checksum_sha256 checksum<sha256_t, sha256>
#define checksum_sha256d checksum<sha256_t, sha256d>
#define checksum_ripemd160 checksum<ripemd160_t, ripemd160>
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_CHECKSUM_H */

View file

@ -0,0 +1,39 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EOSIOKEYGEN_CRYPTO_EC_H
#define EOSIOKEYGEN_CRYPTO_EC_H
#include <eoskeygen/crypto/types.h>
namespace eoskeygen {
/**
* Generates a keypair using the secp256k1 curve.
* public key is in compressed format.
*/
int ec_generate_key(struct ec_keypair *pair);
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_CRYPTO_EC_H */

View file

@ -0,0 +1,41 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EOSIOKEYGEN_CRYPTO_HASH_H
#define EOSIOKEYGEN_CRYPTO_HASH_H
#include <cstddef>
#include <eoskeygen/crypto/types.h>
namespace eoskeygen {
sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out);
// sha256 double.
sha256_t* sha256d(const unsigned char *data, std::size_t len, sha256_t* out);
ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out);
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_CRYPTO_HASH_H */

View file

@ -0,0 +1,55 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EOSIOKEYGEN_CRYPTO_TYPES_H
#define EOSIOKEYGEN_CRYPTO_TYPES_H
#include <array>
namespace eoskeygen {
#define EC_PRIVKEY_SIZE 32
/*
* Compressed format!
* z||x, where byte z specifies which (of the 2) solutions of the quadratic equation y is.
* Each cordinate is 32 bytes.
*/
#define EC_PUBKEY_SIZE (32 + 1)
typedef std::array<unsigned char, EC_PRIVKEY_SIZE> ec_privkey_t;
typedef std::array<unsigned char, EC_PUBKEY_SIZE> ec_pubkey_t;
struct ec_keypair {
ec_privkey_t secret;
ec_pubkey_t pub;
};
// Hashes.
typedef struct { unsigned char data[20]; } ripemd160_t;
typedef struct { unsigned char data[32]; } sha256_t;
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_CRYPTO_TYPES_H */

View file

@ -0,0 +1,82 @@
/**
* MIT License
*
* Copyright (c) 2019-2020 EOS Sw/eden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EOSIOKEYGEN_KEY_SEARCH_H
#define EOSIOKEYGEN_KEY_SEARCH_H
#include <eoskeygen/core/dictionary.h>
#include <eoskeygen/core/string.h>
namespace eoskeygen {
class KeySearch
{
public :
// Add a word to search for.
void addWord(const std::string& str);
// Add a list of words to search for.
void addList(const strlist_t& list);
void addDictionary(const Dictionary& dictionary);
// get the list of words to search for.
const strlist_t& getList();
// Clears the search list.
void clear();
#ifdef HAVE_THREADS
// Set the number of threads to use while searching.
void setThreadCount(size_t num);
#endif /* HAVE_THREADS */
// Perform a search.
void find(size_t num_results);
protected :
#ifdef HAVE_THREADS
void _thr_proc();
void _search_mt(size_t n);
#endif /* HAVE_THREADS */
void _search_linear(size_t n);
protected :
// List of words to search for.
strlist_t m_words;
// Dictionary to use when we find a search result.
Dictionary m_dict;
#ifdef HAVE_THREADS
// Number of threads to use.
size_t m_threads;
#endif /* HAVE_THREADS */
};
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_KEY_SEARCH_H */