1
0
Fork 0
mirror of https://github.com/eosswedenorg/libantelope synced 2026-06-16 03:34:56 +02:00

Split include/libeosio/types.hpp into ec.hpp and hash.hpp

This commit is contained in:
Henrik Hautakoski 2023-03-11 09:48:12 +01:00
parent 6a721c4634
commit 2a2360bd7d
5 changed files with 46 additions and 5 deletions

View file

@ -25,7 +25,7 @@
#define LIBEOSIO_WIF_H
#include <string>
#include <libeosio/types.hpp>
#include <libeosio/ec.hpp>
namespace libeosio {

View file

@ -24,10 +24,39 @@
#ifndef LIBEOSIO_EC_H
#define LIBEOSIO_EC_H
#include <libeosio/types.hpp>
#include <libeosio/hash.hpp>
#include <iostream>
#include <array>
namespace libeosio {
/**
* Elliptic curve private key size (in bytes)
*/
#define EC_PRIVKEY_SIZE 32
/**
* Elliptic curve public key size (in bytes)
*
* 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)
/**
* Elliptic curve priv/pub key datastructures.
*/
typedef std::array<unsigned char, EC_PRIVKEY_SIZE> ec_privkey_t;
typedef std::array<unsigned char, EC_PUBKEY_SIZE> ec_pubkey_t;
/**
* Elliptic curve keypair (public + private)
*/
struct ec_keypair {
ec_privkey_t secret;
ec_pubkey_t pub;
};
/**
* Generates a keypair using the secp256k1 curve.
* public key is in compressed format.
@ -36,4 +65,11 @@ int ec_generate_key(struct ec_keypair *pair);
} // namespace libeosio
// Stream operators
std::ostream& operator<<(std::ostream& os, const libeosio::ec_privkey_t& pk);
std::ostream& operator<<(std::ostream& os, const libeosio::ec_pubkey_t& pk);
#endif /* LIBEOSIO_EC_H */

View file

@ -25,10 +25,15 @@
#define LIBEOSIO_HASH_H
#include <cstdint>
#include <libeosio/types.hpp>
namespace libeosio {
/**
* Hashes
*/
typedef struct { unsigned char data[20]; } ripemd160_t;
typedef struct { unsigned char data[32]; } sha256_t;
/**
* sha256 hashing function.
* Hashes the content in `data` up to `len` bytes. The result is stored in `out`.