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

Merge branch 'maint' into develop

This commit is contained in:
Henrik Hautakoski 2020-02-05 19:33:49 +01:00
commit fd0e893660
12 changed files with 41 additions and 25 deletions

View file

@ -18,7 +18,7 @@ set (PROGRAM_EXE ${CMAKE_PROJECT_NAME})
set (PROGRAM_SOURCE
src/string.cpp
src/ec.cpp
src/ec/openssl.cpp
src/base58.cpp
src/checksum.cpp
src/WIF.cpp

View file

@ -27,16 +27,19 @@
#include "checksum.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) {
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());
// Checksum
check = checksum_sha256d(buf, 33);
memcpy(buf + 33, check.data(), check.size());
check = checksum_sha256d(buf, 1 + EC_PRIVKEY_SIZE);
memcpy(buf + 1 + EC_PRIVKEY_SIZE, check.data(), check.size());
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) {
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 + 33, check.data(), check.size());
memcpy(buf + EC_PUBKEY_SIZE, check.data(), check.size());
return "EOS" + base58_encode(buf, buf + sizeof(buf));
}

View file

@ -25,7 +25,7 @@
#define WIF_H
#include <string>
#include "ec.h"
#include "ec/types.h"
std::string wif_priv_encode(ec_privkey_t priv);

View file

@ -22,7 +22,7 @@
* SOFTWARE.
*/
#include <chrono>
#include "ec.h"
#include "ec/generate.h"
#include "benchmark.h"
using std::chrono::steady_clock;

View file

@ -27,7 +27,9 @@
#include <cstddef>
#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);

View file

@ -21,10 +21,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef TYPES_H
#define TYPES_H
#ifndef EC_GENERATE_H
#define EC_GENERATE_H
#define EC_PRIVKEY_SIZE 32
#define EC_PUBKEY_SIZE 33 /* Compressed: 32 bytes + 1 prefix */
#include "types.h"
#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 */

View file

@ -24,7 +24,7 @@
#include <openssl/ec.h>
#include <openssl/bn.h>
#include <openssl/hmac.h>
#include "ec.h"
#include "generate.h"
static int ec_generate_pair(unsigned char *priv, unsigned char *pub) {

View file

@ -21,11 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef EC_H
#define EC_H
#ifndef EC_TYPES_H
#define EC_TYPES_H
#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_PUBKEY_SIZE> ec_pubkey_t;
@ -35,6 +43,4 @@ struct ec_keypair {
ec_pubkey_t pub;
};
int ec_generate_key(struct ec_keypair *pair);
#endif /* EC_H */
#endif /* EC_TYPES_H */

View file

@ -22,7 +22,7 @@
* SOFTWARE.
*/
#include <string>
#include "ec.h"
#include "ec/generate.h"
#include "key_search_helpers.h"
#include "key_search.h"

View file

@ -25,7 +25,7 @@
#define KEY_SEARCH_HELPERS_H
#include "string.h"
#include "ec.h"
#include "ec/types.h"
struct key_result {
size_t pos; // position where the word was found.

View file

@ -25,7 +25,7 @@
#include <thread>
#include <mutex>
#include <vector>
#include "ec.h"
#include "ec/generate.h"
#include "key_search_helpers.h"
#include "key_search.h"

View file

@ -28,7 +28,7 @@
#include <cstring>
#include "string.h"
#include "WIF.h"
#include "ec.h"
#include "ec/generate.h"
#include "key_search.h"
#include "benchmark.h"