began sleep_tree.c , sleep_tree_entry_t added to sleep.h
This commit is contained in:
59
inc/sleep.h
59
inc/sleep.h
@@ -16,18 +16,71 @@ content.tree*/
|
||||
// test
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SLEEP_HEADER_SIZE 32u
|
||||
|
||||
// TODO MAGIC_BITFIELD, MAGIC_SIG, MAGIC_TREE
|
||||
|
||||
#define SLEEP_ALGO_BLAKE2B "BLAKE2b"
|
||||
#define SLEEP_ALGO_ED25519 "Ed25519"
|
||||
|
||||
typedef struct sleep_header {
|
||||
#define SLEEP_TREE_ENTRY_SIZE 40u
|
||||
#define SLEEP_SIG_ENTRY_SIZE 64u
|
||||
#define SLEEP_BITFIELD_ENTRY_SIZE 3328u
|
||||
|
||||
enum sleep_hash_type {
|
||||
SLEEP_HASH_LEAF = 0,
|
||||
SLEEP_HASH_PARENT = 1,
|
||||
SLEEP_HASH_ROOT = 2
|
||||
};
|
||||
|
||||
// Wire
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__MUSL__)
|
||||
#define SLEEP_PACKED __attribute__((packed))
|
||||
#else
|
||||
#define SLEEP_PACKED
|
||||
#pragma pack(push,1) // pragma deez
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct SLEEP_PACKED sleep_header {
|
||||
uint32_t magic_be;
|
||||
uint8_t version;
|
||||
uint16_t entry_size_be;
|
||||
uint8_t algo_len;
|
||||
char algo[24];
|
||||
} sleep_header_t;
|
||||
// TODO assert must be 32 bytes
|
||||
|
||||
// 32 byte hash + 8 byte BE len
|
||||
typedef struct SLEEP_PACKED sleep_tree_entry {
|
||||
uint8_t hash[32];
|
||||
uint64_t length_be;
|
||||
} sleep_tree_entry_t;
|
||||
// TODO assert
|
||||
|
||||
// 64 bytes
|
||||
typedef struct SLEEP_PACKED sleep_sig_entry {
|
||||
uint8_t sig[64];
|
||||
} sleep_sig_entry_t;
|
||||
// TODO assert
|
||||
|
||||
// 3328 bytes: tree[2048] + data[1024] + index[256]
|
||||
typedef struct SLEEP_PACKED sleep_bitfield_entry {
|
||||
uint8_t tree[2048];
|
||||
uint8_t data[1024];
|
||||
uint8_t index[256];
|
||||
} sleep_bitfield_entry_t;
|
||||
// TODO DOTO ODOT assert it
|
||||
|
||||
#if !defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
// TODO BE INT into and out of buffers **
|
||||
|
||||
// crypto helpers
|
||||
#ifdef SLEEP_SALT
|
||||
@@ -44,5 +97,7 @@ int sleep_compute_discovery_key(const uint8_t pubkey[32], uint8_t out32[32]);
|
||||
|
||||
// function decs
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* SLEEP_H */
|
||||
|
||||
Reference in New Issue
Block a user