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:
parent
6a721c4634
commit
2a2360bd7d
5 changed files with 46 additions and 5 deletions
|
|
@ -40,7 +40,7 @@ set( LIB_NAME ${PROJECT_NAME} )
|
|||
|
||||
set( LIB_SOURCE
|
||||
src/base58.cpp
|
||||
src/types.cpp
|
||||
src/ec.cpp
|
||||
src/WIF.cpp
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#define LIBEOSIO_WIF_H
|
||||
|
||||
#include <string>
|
||||
#include <libeosio/types.hpp>
|
||||
#include <libeosio/ec.hpp>
|
||||
|
||||
namespace libeosio {
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include <libeosio/types.hpp>
|
||||
#include <libeosio/ec.hpp>
|
||||
|
||||
std::ostream& _hex(std::ostream& os, const unsigned char *b, std::size_t sz) {
|
||||
os << "[ " << std::hex;
|
||||
Loading…
Add table
Add a link
Reference in a new issue