aboutsummaryrefslogtreecommitdiff
path: root/crypto.c
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2018-06-25 15:32:23 -0400
committerFranklin Wei <me@fwei.tk>2018-06-25 15:32:23 -0400
commit42aa4d804e7e8f42745e32d23080f0b895dddb32 (patch)
tree426e74b942244cb487f58f00ab6c1e5a1990c21f /crypto.c
parent51674fc424435b49e7538448276e1af509669e04 (diff)
downloadcsaa-42aa4d804e7e8f42745e32d23080f0b895dddb32.zip
csaa-42aa4d804e7e8f42745e32d23080f0b895dddb32.tar.gz
csaa-42aa4d804e7e8f42745e32d23080f0b895dddb32.tar.bz2
csaa-42aa4d804e7e8f42745e32d23080f0b895dddb32.tar.xz
Limit direct access to IOMT structure
Preparation for moving to database backend instead of storing everything in memory.
Diffstat (limited to 'crypto.c')
-rw-r--r--crypto.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/crypto.c b/crypto.c
index d14e52e..ae744ae 100644
--- a/crypto.c
+++ b/crypto.c
@@ -277,30 +277,52 @@ void merkle_update(struct iomt *tree, uint64_t leafidx, hash_t newval, hash_t **
}
}
+hash_t iomt_getroot(const struct iomt *tree)
+{
+ return tree->mt_nodes[0];
+}
+
+struct iomt_node *iomt_get_leaf_by_idx(const struct iomt *tree, uint64_t leafidx)
+{
+ return tree->mt_leaves + leafidx;
+}
+
/* find a node with given idx */
-struct iomt_node *iomt_find_leaf(const struct iomt *tree, uint64_t idx)
+struct iomt_node *iomt_find_leaf(const struct iomt *tree, uint64_t idx, uint64_t *leafidx)
{
for(int i = 0; i < tree->mt_leafcount; ++i)
if(idx == tree->mt_leaves[i].idx)
+ {
+ if(leafidx)
+ *leafidx = i;
return tree->mt_leaves + i;
+ }
return NULL;
}
-struct iomt_node *iomt_find_encloser(const struct iomt *tree, uint64_t idx)
+struct iomt_node *iomt_find_encloser(const struct iomt *tree, uint64_t idx, uint64_t *leafidx)
{
for(int i = 0; i < tree->mt_leafcount; ++i)
if(encloses(tree->mt_leaves[i].idx, tree->mt_leaves[i].next_idx, idx))
+ {
+ if(leafidx)
+ *leafidx = i;
return tree->mt_leaves + i;
+ }
return NULL;
}
-struct iomt_node *iomt_find_leaf_or_encloser(const struct iomt *tree, uint64_t idx)
+struct iomt_node *iomt_find_leaf_or_encloser(const struct iomt *tree, uint64_t idx, uint64_t *leafidx)
{
for(int i = 0; i < tree->mt_leafcount; ++i)
{
if(tree->mt_leaves[i].idx == idx ||
encloses(tree->mt_leaves[i].idx, tree->mt_leaves[i].next_idx, idx))
+ {
+ if(leafidx)
+ *leafidx = i;
return tree->mt_leaves + i;
+ }
}
return NULL;
}
@@ -308,10 +330,11 @@ struct iomt_node *iomt_find_leaf_or_encloser(const struct iomt *tree, uint64_t i
void iomt_update(struct iomt *tree, uint64_t idx, hash_t newval)
{
/* update the leaf first, then use merkle_update */
- struct iomt_node *leaf = iomt_find_leaf(tree, idx);
+ uint64_t leafidx;
+ struct iomt_node *leaf = iomt_find_leaf(tree, idx, &leafidx);
leaf->val = newval;
- merkle_update(tree, leaf - tree->mt_leaves, hash_node(leaf), NULL);
+ merkle_update(tree, leafidx, hash_node(leaf), NULL);
}
void iomt_update_leaf_full(struct iomt *tree, uint64_t leafidx,