Class MerkleTreePrimitives
java.lang.Object
org.bouncycastle.cert.plants.MerkleTreePrimitives
Merkle Tree primitives for Merkle Tree Certificates (PLANTS).
Implements subtree inclusion proofs, consistency proofs, and interval covering.
All algorithms are expressed against the MerkleTreeHash operator,
which the caller supplies; there are no direct org.bouncycastle.crypto.*
or java.security.* dependencies in this class.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSimple container for a subtree interval (start inclusive, end exclusive). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]evaluateSubtreeInclusionProof(long index, long start, long end, byte[] entryHash, List<byte[]> proof, MerkleTreeHash hash) Evaluates a subtree inclusion proof, returning the expected subtree hash.static List<long[]> findCoveringSubtrees(long start, long end) Finds the minimal set of subtrees that efficiently cover the interval [start, end).static booleanisValidSubtree(long start, long end) Checks whether[start, end)is a valid subtree interval per Section 4.1: 0 <= start < end, and start is a multiple of BIT_CEIL(end - start).static booleanverifySubtreeConsistencyProof(long start, long end, long n, byte[] subtreeHash, byte[] rootHash, List<byte[]> proof, MerkleTreeHash hash) Verifies a subtree consistency proof.static booleanverifySubtreeInclusionProof(long index, long start, long end, byte[] entryHash, byte[] subtreeHash, List<byte[]> proof, MerkleTreeHash hash) Verifies a subtree inclusion proof by comparing the evaluated hash with the given subtree hash.
-
Constructor Details
-
MerkleTreePrimitives
public MerkleTreePrimitives()
-
-
Method Details
-
evaluateSubtreeInclusionProof
public static byte[] evaluateSubtreeInclusionProof(long index, long start, long end, byte[] entryHash, List<byte[]> proof, MerkleTreeHash hash) throws InvalidProofException Evaluates a subtree inclusion proof, returning the expected subtree hash.- Parameters:
index- absolute index of the entry in the logstart- subtree start index (inclusive)end- subtree end index (exclusive)entryHash- hash of the entry (MTH({entry}))proof- list of node hashes forming the inclusion proofhash- the Merkle tree hash implementation- Returns:
- the expected subtree hash
- Throws:
InvalidProofException- if the proof is malformed or cannot be evaluated- See Also:
-
verifySubtreeInclusionProof
public static boolean verifySubtreeInclusionProof(long index, long start, long end, byte[] entryHash, byte[] subtreeHash, List<byte[]> proof, MerkleTreeHash hash) Verifies a subtree inclusion proof by comparing the evaluated hash with the given subtree hash.- Parameters:
index- absolute index of the entrystart- subtree startend- subtree endentryHash- hash of the entrysubtreeHash- claimed subtree hashproof- inclusion proofhash- hash implementation- Returns:
- true if the proof is valid, false otherwise
-
verifySubtreeConsistencyProof
public static boolean verifySubtreeConsistencyProof(long start, long end, long n, byte[] subtreeHash, byte[] rootHash, List<byte[]> proof, MerkleTreeHash hash) Verifies a subtree consistency proof.- Parameters:
start- subtree start indexend- subtree end index (exclusive)n- full tree size (number of entries)subtreeHash- hash of the subtree (MTH(D[start:end]))rootHash- hash of the full tree (MTH(D[0:n]))proof- list of node hashes forming the consistency proofhash- hash implementation- Returns:
- true if the proof is valid, false otherwise
- See Also:
-
isValidSubtree
public static boolean isValidSubtree(long start, long end) Checks whether[start, end)is a valid subtree interval per Section 4.1: 0 <= start < end, and start is a multiple of BIT_CEIL(end - start).- Parameters:
start- subtree start (inclusive)end- subtree end (exclusive)- Returns:
- true if the interval describes a valid subtree
-
findCoveringSubtrees
Finds the minimal set of subtrees that efficiently cover the interval [start, end). Returns a list of one or two (start, end) pairs.- Parameters:
start- start index of the interval (inclusive)end- end index of the interval (exclusive)- Returns:
- list of one or two subtrees covering the interval (as long arrays of length 2)
- See Also:
-