MCEL: Merkle-Chaining Event Ledger 1.0.0.0a (A1)
A post-quantum secure block-chain ledger system
merkle.h File Reference

MCEL merkle support header. More...

#include "mcelcommon.h"
#include "domain.h"

Go to the source code of this file.

Macros

#define MCEL_MERKLE_HASH_SIZE   32U
 The Merkle hash element size in bytes.
#define MCEL_MERKLE_NODE_SIZE   (MCEL_MERKLE_HASH_SIZE * 2U)
 The Merkle internal node input size in bytes (left hash plus right hash).
#define MCEL_MERKLE_PROOF_HASHES_MAX   32U
 The maximum number of sibling hashes in a MCEL Merkle membership proof.

Functions

MCEL_EXPORT_API size_t mcel_merkle_consistency_proof_size (size_t oldcount, size_t newcount)
 Get the required buffer size for a MCEL Merkle consistency proof.
MCEL_EXPORT_API size_t mcel_merkle_proof_size (size_t count)
 Get the required buffer size for a MCEL Merkle membership proof.
MCEL_EXPORT_API bool mcel_merkle_prove_member (uint8_t *proof, size_t prooflen, const uint8_t *leaves, size_t count, size_t index)
 Generate a MCEL Merkle membership proof for a leaf index.
MCEL_EXPORT_API bool mcel_merkle_member_verify (const uint8_t *root, const uint8_t *leaf, const uint8_t *proof, size_t prooflen, size_t count, size_t index)
 Verify a MCEL Merkle membership proof for a leaf hash.
MCEL_EXPORT_API bool mcel_merkle_root (uint8_t *root, const uint8_t *leaves, size_t count)
 Compute the MCEL Merkle root from an ordered list of leaf hashes.
MCEL_EXPORT_API bool mcel_merkle_root_hash (uint8_t *output, mcel_domain_types domain)
 Compute the MCEL Merkle root hash.
MCEL_EXPORT_API bool mcel_merkle_node_hash (uint8_t *output, const uint8_t *left, const uint8_t *right)
 Compute the MCEL Merkle node hash.

Detailed Description

MCEL merkle support header.

Macro Definition Documentation

◆ MCEL_MERKLE_PROOF_HASHES_MAX

#define MCEL_MERKLE_PROOF_HASHES_MAX   32U

The maximum number of sibling hashes in a MCEL Merkle membership proof.

This bound supports up to 2^MCEL_MERKLE_PROOF_HASHES_MAX leaves.

Function Documentation

◆ mcel_merkle_consistency_proof_size()

MCEL_EXPORT_API size_t mcel_merkle_consistency_proof_size ( size_t oldcount,
size_t newcount )

Get the required buffer size for a MCEL Merkle consistency proof.

Parameters
oldcountThe leaf count of the older tree.
newcountThe leaf count of the newer tree.
Returns
The required proof size in bytes or 0 on error.

◆ mcel_merkle_member_verify()

MCEL_EXPORT_API bool mcel_merkle_member_verify ( const uint8_t * root,
const uint8_t * leaf,
const uint8_t * proof,
size_t prooflen,
size_t count,
size_t index )

Verify a MCEL Merkle membership proof for a leaf hash.

Parameters
rootA pointer to the Merkle root array of size MCEL_BLOCK_HASH_SIZE.
leaf[const] A pointer to the leaf hash array of size MCEL_BLOCK_HASH_SIZE.
proof[const] A pointer to the proof buffer containing sibling hashes.
prooflenThe length of the proof buffer in bytes.
countThe number of leaves in the tree.
indexThe leaf index being proven (0..count-1).
Returns
Returns true if the proof is valid.

◆ mcel_merkle_node_hash()

MCEL_EXPORT_API bool mcel_merkle_node_hash ( uint8_t * output,
const uint8_t * left,
const uint8_t * right )

Compute the MCEL Merkle node hash.

Parameters
outputA pointer to the output node hash array of size MCEL_BLOCK_HASH_SIZE.
leftA pointer to left node hash MCEL_BLOCK_HASH_SIZE.
rightA pointer to right node hash MCEL_BLOCK_HASH_SIZE.
Returns
Returns true if the Merkle root was computed successfully.

◆ mcel_merkle_proof_size()

MCEL_EXPORT_API size_t mcel_merkle_proof_size ( size_t count)

Get the required buffer size for a MCEL Merkle membership proof.

Parameters
countThe number of leaves in the tree.
Returns
The required proof size in bytes, or 0 on error.

◆ mcel_merkle_prove_member()

MCEL_EXPORT_API bool mcel_merkle_prove_member ( uint8_t * proof,
size_t prooflen,
const uint8_t * leaves,
size_t count,
size_t index )

Generate a MCEL Merkle membership proof for a leaf index.

Parameters
proofA pointer to the output proof buffer.
prooflenThe length of the output proof buffer in bytes.
leaves[const] A pointer to the leaf hash array (count * MCEL_BLOCK_HASH_SIZE).
countThe number of leaves in the array.
indexThe leaf index to prove (0..count-1).
Returns
Returns true if the proof was generated successfully.

◆ mcel_merkle_root()

MCEL_EXPORT_API bool mcel_merkle_root ( uint8_t * root,
const uint8_t * leaves,
size_t count )

Compute the MCEL Merkle root from an ordered list of leaf hashes.

Parameters
rootA pointer to the output root hash array of size MCEL_BLOCK_HASH_SIZE.
leaves[const] A pointer to an array of leaf hashes, each of size MCEL_BLOCK_HASH_SIZE.
countThe number of leaves in the array.
Returns
Returns true if the Merkle root was computed successfully.

◆ mcel_merkle_root_hash()

MCEL_EXPORT_API bool mcel_merkle_root_hash ( uint8_t * output,
mcel_domain_types domain )

Compute the MCEL Merkle root hash.

Parameters
outputA pointer to the output root hash array of size MCEL_BLOCK_HASH_SIZE.
domainThe MCEL domain identifier.
Returns
Returns true if the Merkle root was computed successfully.