-
Notifications
You must be signed in to change notification settings - Fork 0
Ozan/merkletree #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Ozan/merkletree #32
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
83d68a0
implements merkle tree implementation and insertion to it
onacitarhan17 877ba35
implements merkle tree authentication
onacitarhan17 e57e613
Merge branch 'master' into ozan/merkletree
onacitarhan17 b4cf75f
implements tests
onacitarhan17 2846da5
implements hash table for searching in merkle tree
onacitarhan17 99f469f
implements thread safety to merkle tree implementation
onacitarhan17 d5d5d14
fixes lint & spotbugs issues
onacitarhan17 1f8b40b
Merge branch 'master' into ozan/merkletree
onacitarhan17 29bb463
renames Merkle Tree creation function in MerkleTreeFixture.java
onacitarhan17 4bb13ff
Merge branch 'master' into ozan/merkletree
onacitarhan17 ff38dea
suppresses EI_EXPOSE_REP warnings in spotbugs
onacitarhan17 7c9f4d7
Merge remote-tracking branch 'origin/ozan/merkletree' into ozan/merkl…
onacitarhan17 f767ff8
suppresses warnings in spotbugs
onacitarhan17 df3b433
adds comments for unit tests
onacitarhan17 94cfe9b
handles exceptions on MerkleTree.java
onacitarhan17 d3b1343
changes how id of an entity is stored on the merkle tree, changed fro…
onacitarhan17 ccffc17
handles exceptions better for locks
onacitarhan17 cc555b4
changes get method in a way it gets the AuthenticatedEntity by id not…
onacitarhan17 8cdb9a2
improves thread safety check
onacitarhan17 205970f
improves exception handling1
onacitarhan17 d0f93ab
improves the hashing and how proofs are created in merkle tree
onacitarhan17 21cef64
applies revisions
thep2p a3b33b7
applies revisions
thep2p 9d20b36
applies revisions
thep2p d4a77a7
applies revisions
thep2p 8696b0f
fixes lint
thep2p df806a8
removes unnecessary setters
thep2p 8b5d912
removes unnecessary setters
thep2p bd1ad65
fixes a java doc
thep2p afee4e1
applies revisions
thep2p b4a394b
fixes lint
thep2p 2ad6832
applies revisions
thep2p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package modules.ads.merkletree; | ||
|
|
||
| import crypto.Sha3256Hasher; | ||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import model.Entity; | ||
| import model.crypto.Sha3256Hash; | ||
|
|
||
| /** | ||
| * A node in the Merkle tree. | ||
| */ | ||
| public class MerkleNode { | ||
| private static final Sha3256Hasher hasher = new Sha3256Hasher(); | ||
| private MerkleNode left; | ||
| private MerkleNode right; | ||
| private MerkleNode parent; | ||
| private boolean isLeft; | ||
| private Sha3256Hash hash; | ||
|
|
||
| /** | ||
| * Default constructor. | ||
| */ | ||
| public MerkleNode() { | ||
| this.left = null; | ||
| this.right = null; | ||
| this.parent = null; | ||
| this.isLeft = false; | ||
| this.hash = null; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor with entity and isLeft. | ||
| * | ||
| * @param e input entity | ||
| * @param isLeft boolean that specifies if the node is left child or not | ||
| */ | ||
| public MerkleNode(Entity e, boolean isLeft) { | ||
| this.left = null; | ||
| this.right = null; | ||
| this.parent = null; | ||
| this.isLeft = isLeft; | ||
| this.hash = hasher.computeHash(e.id()); | ||
| } | ||
|
|
||
| /** | ||
| * Constructor with hash of the entity. | ||
| * | ||
| * @param hash input hash of the entity corresponding to that node | ||
| */ | ||
| public MerkleNode(Sha3256Hash hash) { | ||
| this.left = null; | ||
| this.right = null; | ||
| this.parent = null; | ||
| this.isLeft = false; | ||
| this.hash = hash; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor of a parent node. | ||
| * | ||
| * @param hash input hash of the entity corresponding to that node | ||
| * @param left left child of the node | ||
| * @param right right child of the node | ||
| */ | ||
| @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "left and right are intentionally mutable externally") | ||
| public MerkleNode(Sha3256Hash hash, MerkleNode left, MerkleNode right) { | ||
| this.left = left; | ||
| this.right = right; | ||
| this.parent = null; | ||
| this.isLeft = false; | ||
| this.hash = hash; | ||
| } | ||
|
|
||
| @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "internal representation is intentionally returned") | ||
| public MerkleNode getLeft() { | ||
| return left; | ||
| } | ||
|
|
||
| @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "internal representation is intentionally returned") | ||
| public MerkleNode getRight() { | ||
| return right; | ||
| } | ||
|
|
||
| @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "internal representation is intentionally returned") | ||
| public MerkleNode getParent() { | ||
| return parent; | ||
| } | ||
|
|
||
| @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "parent is intentionally mutable externally") | ||
| public void setParent(MerkleNode parent) { | ||
| this.parent = parent; | ||
| } | ||
|
|
||
| public Sha3256Hash getHash() { | ||
| return hash; | ||
| } | ||
|
|
||
| public boolean isLeft() { | ||
| return isLeft; | ||
| } | ||
|
|
||
| public void setLeft(boolean isLeft) { | ||
| this.isLeft = isLeft; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the sibling of the node. | ||
| * | ||
| * @return the sibling of the node | ||
| */ | ||
| public MerkleNode getSibling() { | ||
| if (isLeft()) { | ||
| return parent.getRight(); | ||
| } else { | ||
| return parent.getLeft(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package modules.ads.merkletree; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Objects; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import model.crypto.Sha3256Hash; | ||
| import modules.ads.MembershipProof; | ||
|
|
||
| /** | ||
| * A proof of membership in a Merkle tree. | ||
| */ | ||
| public class MerkleProof implements MembershipProof { | ||
| private ArrayList<Sha3256Hash> path; | ||
| private final ArrayList<Boolean> isLeftNode; | ||
| private final Sha3256Hash root; | ||
|
|
||
| /** | ||
| * Constructs a proof from a list of hashes and a root. | ||
| * | ||
| * @param path the list of hashes | ||
| * @param root the root | ||
| * @param isLeftNode the list of isLeft Boolean values of the hashes | ||
| */ | ||
| public MerkleProof(ArrayList<Sha3256Hash> path, Sha3256Hash root, ArrayList<Boolean> isLeftNode) { | ||
| this.path = new ArrayList<>(path); | ||
| this.root = root; | ||
| this.isLeftNode = new ArrayList<>(isLeftNode); | ||
| } | ||
|
|
||
| @Override | ||
| public ArrayList<Sha3256Hash> getPath() { | ||
| return new ArrayList<>(path); | ||
| } | ||
|
|
||
| public void setPath(ArrayList<Sha3256Hash> path) { | ||
| this.path = new ArrayList<>(path); | ||
| } | ||
|
|
||
| @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "internal representation is intentionally returned") | ||
| public ArrayList<Boolean> getIsLeftNode() { | ||
| return isLeftNode; | ||
| } | ||
|
|
||
| public Sha3256Hash getRoot() { | ||
| return root; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| MerkleProof proof = (MerkleProof) o; | ||
| for (int i = 0; i < path.size(); i++) { | ||
| if (!Arrays.equals(path.get(i).getBytes(), proof.path.get(i).getBytes())) { | ||
| return false; | ||
| } | ||
| } | ||
| return root.equals(proof.root); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(path, root); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not always
h(b1||b2)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in d0f93ab