aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2018-07-12 21:05:12 +0000
committerFranklin Wei <me@fwei.tk>2018-07-12 21:05:12 +0000
commit82e04dce129ee618f11c7c0afc2efd88a3e3dea5 (patch)
treead3acddb6a73ec2bbf72507e1e7c278dc518ad34
parent00e5cc796efc779288f7418eb7f7211e2b1023a7 (diff)
downloadcsaa-82e04dce129ee618f11c7c0afc2efd88a3e3dea5.zip
csaa-82e04dce129ee618f11c7c0afc2efd88a3e3dea5.tar.gz
csaa-82e04dce129ee618f11c7c0afc2efd88a3e3dea5.tar.bz2
csaa-82e04dce129ee618f11c7c0afc2efd88a3e3dea5.tar.xz
Make caller allocate memory in call to merkle_update()
Hopefully this is slightly faster... should probably profile.
-rw-r--r--iomt.c18
-rw-r--r--iomt.h2
-rw-r--r--service_provider.c4
3 files changed, 11 insertions, 13 deletions
diff --git a/iomt.c b/iomt.c
index 73e073a..292d64c 100644
--- a/iomt.c
+++ b/iomt.c
@@ -252,16 +252,14 @@ void restore_nodes(struct iomt *tree, const uint64_t *indices, const hash_t *val
}
/* Update mt_nodes to reflect a change to a leaf node's
- * value. Optionally, if old_dep is not NULL, *old_dep will be made to
- * point to an array of length mt_logleaves that contains the old node
- * values (whose indices are returned by bintree_ancestors()). NOTE:
- * this function will NOT set the corresponding IOMT leaf; use
- * iomt_update_leaf_full for that. */
-void merkle_update(struct iomt *tree, uint64_t leafidx, hash_t newval, hash_t **old_dep)
+ * value. Optionally, if old_dep is not NULL, old_dep[] will be filled
+ * with array of length mt_logleaves that contains the old node values
+ * (whose indices can be found with bintree_ancestors()).
+ *
+ * NOTE: this function will NOT set the corresponding IOMT leaf; use
+ * iomt_update_leaf_* for that. */
+void merkle_update(struct iomt *tree, uint64_t leafidx, hash_t newval, hash_t *old_dep)
{
- if(old_dep)
- *old_dep = calloc(tree->mt_logleaves, sizeof(hash_t));
-
uint64_t idx = ((uint64_t)1 << tree->mt_logleaves) - 1 + leafidx;
if(!tree->in_memory)
@@ -280,7 +278,7 @@ void merkle_update(struct iomt *tree, uint64_t leafidx, hash_t newval, hash_t **
/* TODO: optimize */
/* save old value */
if(old_dep)
- (*old_dep)[i] = iomt_getnode(tree, idx);
+ old_dep[i] = iomt_getnode(tree, idx);
iomt_setnode(tree, idx, parent);
}
diff --git a/iomt.h b/iomt.h
index 723ce6c..5a060a2 100644
--- a/iomt.h
+++ b/iomt.h
@@ -67,7 +67,7 @@ hash_t *merkle_complement(const struct iomt *tree, uint64_t leafidx, int **order
/* This function is prefixed merkle_ because it does not know about
* any IOMT-specific properties (though it is still passed an iomt
* struct) */
-void merkle_update(struct iomt *tree, uint64_t leafidx, hash_t newval, hash_t **old_dep);
+void merkle_update(struct iomt *tree, uint64_t leafidx, hash_t newval, hash_t *old_dep);
struct iomt *iomt_new(int logleaves);
struct iomt *iomt_new_from_db(void *db,
diff --git a/service_provider.c b/service_provider.c
index cd3174e..63ba783 100644
--- a/service_provider.c
+++ b/service_provider.c
@@ -110,8 +110,8 @@ struct tm_cert cert_eq(struct service_provider *sp,
&nu1_hmac);
/* We now update the ancestors of the encloser node. */
- hash_t *old_depvalues;
- merkle_update(sp->iomt, encloser_leafidx, h_encmod, &old_depvalues);
+ hash_t *old_depvalues = malloc(sizeof(hash_t) * sp->iomt->mt_logleaves);
+ merkle_update(sp->iomt, encloser_leafidx, h_encmod, old_depvalues);
int *ins_orders;
hash_t *ins_comp = merkle_complement(sp->iomt, placeholder_leafidx, &ins_orders);