mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-07-03 11:53:41 +02:00
Merge branch 'maint' into develop
This commit is contained in:
commit
fd0e893660
12 changed files with 41 additions and 25 deletions
|
|
@ -18,7 +18,7 @@ set (PROGRAM_EXE ${CMAKE_PROJECT_NAME})
|
||||||
|
|
||||||
set (PROGRAM_SOURCE
|
set (PROGRAM_SOURCE
|
||||||
src/string.cpp
|
src/string.cpp
|
||||||
src/ec.cpp
|
src/ec/openssl.cpp
|
||||||
src/base58.cpp
|
src/base58.cpp
|
||||||
src/checksum.cpp
|
src/checksum.cpp
|
||||||
src/WIF.cpp
|
src/WIF.cpp
|
||||||
|
|
|
||||||
13
src/WIF.cpp
13
src/WIF.cpp
|
|
@ -27,16 +27,19 @@
|
||||||
#include "checksum.h"
|
#include "checksum.h"
|
||||||
#include "WIF.h"
|
#include "WIF.h"
|
||||||
|
|
||||||
|
#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) {
|
||||||
|
|
||||||
checksum_t check;
|
checksum_t check;
|
||||||
unsigned char buf[37] = { 0x80 };
|
// 1 byte extra for prefix.
|
||||||
|
unsigned char buf[1 + EC_PRIVKEY_SIZE + CHECKSUM_SIZE] = { PRIV_KEY_PREFIX };
|
||||||
|
|
||||||
memcpy(buf + 1, priv.data(), priv.size());
|
memcpy(buf + 1, priv.data(), priv.size());
|
||||||
|
|
||||||
// Checksum
|
// Checksum
|
||||||
check = checksum_sha256d(buf, 33);
|
check = checksum_sha256d(buf, 1 + EC_PRIVKEY_SIZE);
|
||||||
memcpy(buf + 33, check.data(), check.size());
|
memcpy(buf + 1 + EC_PRIVKEY_SIZE, check.data(), check.size());
|
||||||
|
|
||||||
return base58_encode(buf, buf + sizeof(buf));
|
return base58_encode(buf, buf + sizeof(buf));
|
||||||
}
|
}
|
||||||
|
|
@ -44,10 +47,10 @@ 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) {
|
||||||
|
|
||||||
checksum_t check = checksum_ripemd160(pub.data(), pub.size());
|
checksum_t check = checksum_ripemd160(pub.data(), pub.size());
|
||||||
unsigned char buf[37];
|
unsigned char buf[EC_PUBKEY_SIZE + CHECKSUM_SIZE];
|
||||||
|
|
||||||
memcpy(buf, pub.data(), pub.size());
|
memcpy(buf, pub.data(), pub.size());
|
||||||
memcpy(buf + 33, check.data(), check.size());
|
memcpy(buf + EC_PUBKEY_SIZE, check.data(), check.size());
|
||||||
|
|
||||||
return "EOS" + base58_encode(buf, buf + sizeof(buf));
|
return "EOS" + base58_encode(buf, buf + sizeof(buf));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
#define WIF_H
|
#define WIF_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "ec.h"
|
#include "ec/types.h"
|
||||||
|
|
||||||
std::string wif_priv_encode(ec_privkey_t priv);
|
std::string wif_priv_encode(ec_privkey_t priv);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include "ec.h"
|
#include "ec/generate.h"
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
|
|
||||||
using std::chrono::steady_clock;
|
using std::chrono::steady_clock;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,9 @@
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
typedef std::array<unsigned char, 4> checksum_t;
|
#define CHECKSUM_SIZE 4
|
||||||
|
|
||||||
|
typedef std::array<unsigned char, CHECKSUM_SIZE> checksum_t;
|
||||||
|
|
||||||
checksum_t checksum_sha256d(const unsigned char *data, std::size_t len);
|
checksum_t checksum_sha256d(const unsigned char *data, std::size_t len);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,15 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef TYPES_H
|
#ifndef EC_GENERATE_H
|
||||||
#define TYPES_H
|
#define EC_GENERATE_H
|
||||||
|
|
||||||
#define EC_PRIVKEY_SIZE 32
|
#include "types.h"
|
||||||
#define EC_PUBKEY_SIZE 33 /* Compressed: 32 bytes + 1 prefix */
|
|
||||||
|
|
||||||
#endif /* TYPES_H */
|
/**
|
||||||
|
* Generates a keypair using the secp256k1 curve.
|
||||||
|
* public key is in compressed format.
|
||||||
|
*/
|
||||||
|
int ec_generate_key(struct ec_keypair *pair);
|
||||||
|
|
||||||
|
#endif /* EC_GENERATE_H */
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
#include <openssl/ec.h>
|
#include <openssl/ec.h>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
#include <openssl/hmac.h>
|
#include <openssl/hmac.h>
|
||||||
#include "ec.h"
|
#include "generate.h"
|
||||||
|
|
||||||
static int ec_generate_pair(unsigned char *priv, unsigned char *pub) {
|
static int ec_generate_pair(unsigned char *priv, unsigned char *pub) {
|
||||||
|
|
||||||
|
|
@ -21,11 +21,19 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef EC_H
|
#ifndef EC_TYPES_H
|
||||||
#define EC_H
|
#define EC_TYPES_H
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "types.h"
|
|
||||||
|
#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_PRIVKEY_SIZE> ec_privkey_t;
|
||||||
typedef std::array<unsigned char, EC_PUBKEY_SIZE> ec_pubkey_t;
|
typedef std::array<unsigned char, EC_PUBKEY_SIZE> ec_pubkey_t;
|
||||||
|
|
@ -35,6 +43,4 @@ struct ec_keypair {
|
||||||
ec_pubkey_t pub;
|
ec_pubkey_t pub;
|
||||||
};
|
};
|
||||||
|
|
||||||
int ec_generate_key(struct ec_keypair *pair);
|
#endif /* EC_TYPES_H */
|
||||||
|
|
||||||
#endif /* EC_H */
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "ec.h"
|
#include "ec/generate.h"
|
||||||
#include "key_search_helpers.h"
|
#include "key_search_helpers.h"
|
||||||
#include "key_search.h"
|
#include "key_search.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
#define KEY_SEARCH_HELPERS_H
|
#define KEY_SEARCH_HELPERS_H
|
||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "ec.h"
|
#include "ec/types.h"
|
||||||
|
|
||||||
struct key_result {
|
struct key_result {
|
||||||
size_t pos; // position where the word was found.
|
size_t pos; // position where the word was found.
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ec.h"
|
#include "ec/generate.h"
|
||||||
#include "key_search_helpers.h"
|
#include "key_search_helpers.h"
|
||||||
#include "key_search.h"
|
#include "key_search.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "WIF.h"
|
#include "WIF.h"
|
||||||
#include "ec.h"
|
#include "ec/generate.h"
|
||||||
#include "key_search.h"
|
#include "key_search.h"
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue