public class ListMerkleTreeNodeSource extends java.lang.Object implements MerkleTreeNodeSource
MerkleTreeNodeSource over an in-memory list of entry hashes, computing each
requested node from the entries beneath it (RFC 9162 Section 2.1.1) and keeping it.
This is what the List<byte[]> overloads of the MerkleTreePrimitives
generators use, and it suits the tree sizes a test, a prototype or a
standalone-certificate subtree handles in memory. Every full-subtree node computed is
cached, so the first proof over a tree of n entries costs O(n) hashes
and each proof after it O(log^2 n) lookups: a CA issuing a certificate for
every entry of a checkpoint should construct one instance and pass it to the
MerkleTreeNodeSource overloads, rather than call the List overloads,
which build a fresh instance per call and so pay the O(n) every time. The
cache holds one hash per internal node, about 50 bytes per entry.
The list is read in place, not copied, and may grow by appending after construction - the nodes of an append-only tree never change - but an entry already in the list must not be replaced, as nodes above it have been kept. Instances are safe to share between threads.
A production log should implement MerkleTreeNodeSource over its own
storage instead - or extend this class and override getFullSubtreeHash(long, long) to
serve stored nodes, falling back to super for the rest.
| Constructor and Description |
|---|
ListMerkleTreeNodeSource(java.util.List<byte[]> entryHashes,
MerkleTreeHash hash) |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
getFullSubtreeHash(long start,
long end)
Returns
MTH(D[start:end]) computed from the entry hashes. |
long |
size() |
public ListMerkleTreeNodeSource(java.util.List<byte[]> entryHashes,
MerkleTreeHash hash)
entryHashes - hashes of the tree's entries, entry i at position i
(each MTH({entry}), i.e. MerkleTreeHash.hashLeaf(byte[]));
read in place, and may only grow by appending from now onhash - the Merkle tree hash implementationpublic long size()
public byte[] getFullSubtreeHash(long start,
long end)
MTH(D[start:end]) computed from the entry hashes. Any range
covered by the list is accepted, not only full subtrees; the empty range
hashes to HASH("").getFullSubtreeHash in interface MerkleTreeNodeSourcestart - subtree start index (inclusive), a multiple of end - startend - subtree end index (exclusive); end - start is a power of twoend == start + 1 this is the entry hash
MTH({entry}), i.e. MerkleTreeHash.hashLeaf(byte[]) of the entryjava.lang.IllegalArgumentException - if the range is invalid or not covered by the list