aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--crypto.c30
-rw-r--r--crypto.h10
-rw-r--r--iomt.c84
-rw-r--r--iomt.h10
-rw-r--r--service_provider.c55
-rwxr-xr-xtestall.sh2
-rwxr-xr-xtestdummy.sh9
8 files changed, 100 insertions, 102 deletions
diff --git a/Makefile b/Makefile
index 7eb9497..775b152 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
all: client server dummy_client dummy_server
-CFLAGS = -g -Wall -Wformat-overflow=0 -O0 -lsqlite3
+CFLAGS = -g -Wall -Wformat-overflow=0 -O0 -lsqlite3 -ftrapv
sqlinit.c: sqlinit.txt
xxd -i $^ | sed 's/\([0-9a-f]\)$$/\0, 0x00/' > $@
diff --git a/crypto.c b/crypto.c
index 0b626ba..e51b502 100644
--- a/crypto.c
+++ b/crypto.c
@@ -118,12 +118,12 @@ hash_t merkle_compute(hash_t node, const hash_t *comp, const int *orders, size_t
/* Given a node's index, return the index of the parent in an array
* representation of a binary tree. */
-int bintree_parent(int idx)
+uint64_t bintree_parent(uint64_t idx)
{
return (idx - ((idx & 1) ? 1 : 2)) / 2;
}
-int bintree_sibling(int idx)
+uint64_t bintree_sibling(uint64_t idx)
{
return idx + ((idx & 1) ? 1 : -1);
}
@@ -139,14 +139,14 @@ int bintree_sibling(int idx)
* function will additionally allocate an array of `logleaves' *
* sizeof(int) with each element representing whether each
* complementary node is a left or right child. */
-int *bintree_complement(int leafidx, int logleaves, int **orders)
+uint64_t *bintree_complement(uint64_t leafidx, int logleaves, int **orders)
{
- int *comp = calloc(logleaves, sizeof(int));
+ uint64_t *comp = calloc(logleaves, sizeof(uint64_t));
if(orders)
*orders = calloc(logleaves, sizeof(int));
/* true index of leaf */
- int idx = (1 << logleaves) - 1 + leafidx;
+ uint64_t idx = (1 << logleaves) - 1 + leafidx;
/* progress up the tree */
for(int i = 0; i < logleaves; ++i)
@@ -165,11 +165,11 @@ int *bintree_complement(int leafidx, int logleaves, int **orders)
return comp;
}
-int *bintree_ancestors(int leafidx, int logleaves)
+uint64_t *bintree_ancestors(uint64_t leafidx, int logleaves)
{
- int *dep = calloc(logleaves, sizeof(int));
+ uint64_t *dep = calloc(logleaves, sizeof(uint64_t));
- int idx = (1 << logleaves) - 1 + leafidx;
+ uint64_t idx = (1 << logleaves) - 1 + leafidx;
for(int i = 0; i < logleaves; ++i)
{
idx = bintree_parent(idx);
@@ -180,7 +180,7 @@ int *bintree_ancestors(int leafidx, int logleaves)
}
/* Shim to get only the orders */
-int *bintree_complement_ordersonly(int leafidx, int logleaves)
+int *bintree_complement_ordersonly(uint64_t leafidx, int logleaves)
{
int *orders;
free(bintree_complement(leafidx, logleaves, &orders));
@@ -474,16 +474,16 @@ void crypto_test(void)
{
#if 1
int *orders;
- int *comp = bintree_complement(6, 4, &orders);
- int correct[] = { 22, 9, 3, 2 };
+ uint64_t *comp = bintree_complement(6, 4, &orders);
+ uint64_t correct[] = { 22, 9, 3, 2 };
int correct_orders[] = { 1, 0, 0, 1 };
- check("Complement calculation", !memcmp(comp, correct, 4 * sizeof(int)) && !memcmp(orders, correct_orders, 4 * sizeof(int)));
+ check("Complement calculation", !memcmp(comp, correct, 4 * sizeof(uint64_t)) && !memcmp(orders, correct_orders, 4 * sizeof(int)));
free(orders);
free(comp);
- int *dep = bintree_ancestors(6, 4);
- int correct_dep[] = { 10, 4, 1, 0 };
- check("Dependency calculation", !memcmp(dep, correct_dep, 4 * sizeof(int)));
+ uint64_t *dep = bintree_ancestors(6, 4);
+ uint64_t correct_dep[] = { 10, 4, 1, 0 };
+ check("Dependency calculation", !memcmp(dep, correct_dep, 4 * sizeof(uint64_t)));
free(dep);
{
diff --git a/crypto.h b/crypto.h
index 7e9d0ed..ed45730 100644
--- a/crypto.h
+++ b/crypto.h
@@ -41,15 +41,15 @@ hash_t merkle_parent(hash_t u, hash_t v, int order);
* function will additionally allocate an array of `logleaves' *
* sizeof(int) with each element representing whether each
* complementary node is a left or right child. */
-int *bintree_complement(int leafidx, int logleaves, int **orders);
-int *bintree_complement_ordersonly(int leafidx, int logleaves);
+uint64_t *bintree_complement(uint64_t leafidx, int logleaves, int **orders);
+int *bintree_complement_ordersonly(uint64_t leafidx, int logleaves);
/* Return an array of indices of tree nodes that are dependent on a
* given leaf node. Will be ordered from nearest relative to root. */
-int *bintree_ancestors(int leafidx, int logleaves);
+uint64_t *bintree_ancestors(uint64_t leafidx, int logleaves);
-int bintree_parent(int idx);
-int bintree_sibling(int idx);
+uint64_t bintree_parent(uint64_t idx);
+uint64_t bintree_sibling(uint64_t idx);
uint64_t hash_to_u64(hash_t h);
hash_t u64_to_hash(uint64_t n);
diff --git a/iomt.c b/iomt.c
index c632faf..9fe48e4 100644
--- a/iomt.c
+++ b/iomt.c
@@ -28,7 +28,7 @@ static void reset_and_bind(const struct iomt *tree, sqlite3_stmt *st)
}
/* internal nodes only */
-hash_t iomt_getnode(const struct iomt *tree, int idx)
+hash_t iomt_getnode(const struct iomt *tree, uint64_t idx)
{
if(tree->in_memory)
return tree->mem.mt_nodes[idx];
@@ -38,7 +38,7 @@ hash_t iomt_getnode(const struct iomt *tree, int idx)
reset_and_bind(tree, st);
- sqlite3_bind_int(st, 3, idx);
+ sqlite3_bind_int64(st, 3, idx);
int rc = sqlite3_step(st);
if(rc == SQLITE_ROW)
@@ -55,7 +55,7 @@ hash_t iomt_getnode(const struct iomt *tree, int idx)
}
}
-void iomt_setnode(const struct iomt *tree, int idx, hash_t val)
+void iomt_setnode(const struct iomt *tree, uint64_t idx, hash_t val)
{
if(tree->in_memory)
tree->mem.mt_nodes[idx] = val;
@@ -70,7 +70,7 @@ void iomt_setnode(const struct iomt *tree, int idx, hash_t val)
sqlite3_bind_blob(st, 3, &val, sizeof(val), SQLITE_TRANSIENT);
- sqlite3_bind_int(st, 4, idx);
+ sqlite3_bind_int64(st, 4, idx);
int rc = sqlite3_step(st);
@@ -82,7 +82,7 @@ void iomt_setnode(const struct iomt *tree, int idx, hash_t val)
st = tree->db.insertnode;
reset_and_bind(tree, st);
- sqlite3_bind_int(st, 3, idx);
+ sqlite3_bind_int64(st, 3, idx);
sqlite3_bind_blob(st, 4, &val, sizeof(val), SQLITE_TRANSIENT);
if(sqlite3_step(st) != SQLITE_DONE)
@@ -106,15 +106,15 @@ struct iomt_node iomt_getleaf(const struct iomt *tree, uint64_t leafidx)
sqlite3_stmt *st = tree->db.getleaf;
reset_and_bind(tree, st);
- sqlite3_bind_int(st, 3, leafidx);
+ sqlite3_bind_int64(st, 3, leafidx);
int rc = sqlite3_step(st);
if(rc == SQLITE_ROW)
{
struct iomt_node ret;
- ret.idx = sqlite3_column_int(st, 0);
- ret.next_idx = sqlite3_column_int(st, 1);
+ ret.idx = sqlite3_column_int64(st, 0);
+ ret.next_idx = sqlite3_column_int64(st, 1);
memcpy(&ret.val, sqlite3_column_blob(st, 2), sizeof(ret.val));
return ret;
@@ -141,11 +141,11 @@ void iomt_setleaf(struct iomt *tree, uint64_t leafidx, struct iomt_node val)
sqlite3_stmt *st = tree->db.updateleaf;
reset_and_bind(tree, st);
- sqlite3_bind_int(st, 3, val.idx);
- sqlite3_bind_int(st, 4, val.next_idx);
+ sqlite3_bind_int64(st, 3, val.idx);
+ sqlite3_bind_int64(st, 4, val.next_idx);
sqlite3_bind_blob(st, 5, &val.val, sizeof(val.val), SQLITE_TRANSIENT);
- sqlite3_bind_int(st, 6, leafidx);
+ sqlite3_bind_int64(st, 6, leafidx);
int rc = sqlite3_step(st);
@@ -157,9 +157,9 @@ void iomt_setleaf(struct iomt *tree, uint64_t leafidx, struct iomt_node val)
st = tree->db.insertleaf;
reset_and_bind(tree, st);
- sqlite3_bind_int(st, 3, leafidx);
- sqlite3_bind_int(st, 4, val.idx);
- sqlite3_bind_int(st, 5, val.next_idx);
+ sqlite3_bind_int64(st, 3, leafidx);
+ sqlite3_bind_int64(st, 4, val.idx);
+ sqlite3_bind_int64(st, 5, val.next_idx);
sqlite3_bind_blob(st, 6, &val.val, sizeof(val.val), SQLITE_TRANSIENT);
if(sqlite3_step(st) != SQLITE_DONE)
@@ -172,9 +172,9 @@ void iomt_setleaf(struct iomt *tree, uint64_t leafidx, struct iomt_node val)
}
}
-hash_t *merkle_complement(const struct iomt *tree, int leafidx, int **orders)
+hash_t *merkle_complement(const struct iomt *tree, uint64_t leafidx, int **orders)
{
- int *compidx = bintree_complement(leafidx, tree->mt_logleaves, orders);
+ uint64_t *compidx = bintree_complement(leafidx, tree->mt_logleaves, orders);
hash_t *comp = lookup_nodes(tree, compidx, tree->mt_logleaves);
free(compidx);
return comp;
@@ -187,7 +187,7 @@ hash_t *merkle_complement(const struct iomt *tree, int leafidx, int **orders)
* be called once, namely when the service provider is created. */
void iomt_fill(struct iomt *tree)
{
- for(int i = 0; i < tree->mt_leafcount; ++i)
+ for(uint64_t i = 0; i < tree->mt_leafcount; ++i)
{
uint64_t mt_idx = (1 << tree->mt_logleaves) - 1 + i;
iomt_setnode(tree, mt_idx, hash_node(iomt_getleaf(tree, i)));
@@ -197,7 +197,7 @@ void iomt_fill(struct iomt *tree)
for(int i = tree->mt_logleaves - 1; i >= 0; --i)
{
uint64_t baseidx = (1 << i) - 1;
- for(int j = 0; j < (1 << i); ++j)
+ for(uint64_t j = 0; j < (1 << i); ++j)
{
uint64_t mt_idx = baseidx + j;
iomt_setnode(tree, mt_idx, merkle_parent(iomt_getnode(tree, 2 * mt_idx + 1),
@@ -215,7 +215,7 @@ void iomt_fill(struct iomt *tree)
* to modify each function to take the array of all nodes in the tree
* in addition to the complement indices, but this function will serve
* as a shim in the meantime. */
-hash_t *lookup_nodes(const struct iomt *tree, const int *indices, int n)
+hash_t *lookup_nodes(const struct iomt *tree, const uint64_t *indices, int n)
{
hash_t *ret = calloc(n, sizeof(hash_t));
for(int i = 0; i < n; ++i)
@@ -223,7 +223,7 @@ hash_t *lookup_nodes(const struct iomt *tree, const int *indices, int n)
return ret;
}
-void restore_nodes(struct iomt *tree, const int *indices, const hash_t *values, int n)
+void restore_nodes(struct iomt *tree, const uint64_t *indices, const hash_t *values, int n)
{
for(int i = 0; i < n; ++i)
iomt_setnode(tree, indices[i], values[i]);
@@ -273,7 +273,7 @@ struct iomt_node iomt_find_leaf(const struct iomt *tree, uint64_t idx, uint64_t
{
if(tree->in_memory)
{
- for(int i = 0; i < tree->mt_leafcount; ++i)
+ for(uint64_t i = 0; i < tree->mt_leafcount; ++i)
if(idx == iomt_getleaf(tree, i).idx)
{
if(leafidx)
@@ -287,15 +287,15 @@ struct iomt_node iomt_find_leaf(const struct iomt *tree, uint64_t idx, uint64_t
sqlite3_stmt *st = tree->db.findleaf;
reset_and_bind(tree, st);
- sqlite3_bind_int(st, 3, idx);
+ sqlite3_bind_int64(st, 3, idx);
if(sqlite3_step(st) == SQLITE_ROW)
{
if(leafidx)
- *leafidx = sqlite3_column_int(st, 0);
+ *leafidx = sqlite3_column_int64(st, 0);
struct iomt_node ret;
ret.idx = idx;
- ret.next_idx = sqlite3_column_int(st, 1);
+ ret.next_idx = sqlite3_column_int64(st, 1);
memcpy(&ret.val, sqlite3_column_blob(st, 2), sizeof(ret.val));
return ret;
@@ -308,7 +308,7 @@ struct iomt_node iomt_find_encloser(const struct iomt *tree, uint64_t idx, uint6
{
if(tree->in_memory)
{
- for(int i = 0; i < tree->mt_leafcount; ++i)
+ for(uint64_t i = 0; i < tree->mt_leafcount; ++i)
if(encloses(iomt_getleaf(tree, i).idx, iomt_getleaf(tree, i).next_idx, idx))
{
if(leafidx)
@@ -322,15 +322,15 @@ struct iomt_node iomt_find_encloser(const struct iomt *tree, uint64_t idx, uint6
sqlite3_stmt *st = tree->db.findencloser;
reset_and_bind(tree, st);
- sqlite3_bind_int(st, 3, idx);
+ sqlite3_bind_int64(st, 3, idx);
if(sqlite3_step(st) == SQLITE_ROW)
{
if(leafidx)
- *leafidx = sqlite3_column_int(st, 0);
+ *leafidx = sqlite3_column_int64(st, 0);
struct iomt_node ret;
- ret.idx = sqlite3_column_int(st, 1);
- ret.next_idx = sqlite3_column_int(st, 2);
+ ret.idx = sqlite3_column_int64(st, 1);
+ ret.next_idx = sqlite3_column_int64(st, 2);
memcpy(&ret.val, sqlite3_column_blob(st, 3), sizeof(ret.val));
return ret;
@@ -343,7 +343,7 @@ struct iomt_node iomt_find_leaf_or_encloser(const struct iomt *tree, uint64_t id
{
if(tree->in_memory)
{
- for(int i = 0; i < tree->mt_leafcount; ++i)
+ for(uint64_t i = 0; i < tree->mt_leafcount; ++i)
{
if(iomt_getleaf(tree, i).idx == idx ||
encloses(iomt_getleaf(tree, i).idx, iomt_getleaf(tree, i).next_idx, idx))
@@ -360,15 +360,15 @@ struct iomt_node iomt_find_leaf_or_encloser(const struct iomt *tree, uint64_t id
sqlite3_stmt *st = tree->db.findleaf_or_encloser;
reset_and_bind(tree, st);
- sqlite3_bind_int(st, 3, idx);
+ sqlite3_bind_int64(st, 3, idx);
if(sqlite3_step(st) == SQLITE_ROW)
{
if(leafidx)
- *leafidx = sqlite3_column_int(st, 0);
+ *leafidx = sqlite3_column_int64(st, 0);
struct iomt_node ret;
- ret.idx = sqlite3_column_int(st, 1);
- ret.next_idx = sqlite3_column_int(st, 2);
+ ret.idx = sqlite3_column_int64(st, 1);
+ ret.next_idx = sqlite3_column_int64(st, 2);
memcpy(&ret.val, sqlite3_column_blob(st, 3), sizeof(ret.val));
return ret;
@@ -438,7 +438,7 @@ struct iomt *iomt_new(int logleaves)
tree->in_memory = true;
- tree->mt_leafcount = 1 << logleaves;
+ tree->mt_leafcount = 1UL << logleaves;
tree->mt_logleaves = logleaves;
tree->mem.mt_leaves = calloc(tree->mt_leafcount, sizeof(struct iomt_node));
@@ -500,7 +500,7 @@ struct iomt *iomt_new_from_db(void *db,
tree->in_memory = false;
- tree->mt_leafcount = 1 << logleaves;
+ tree->mt_leafcount = 1UL << logleaves;
tree->mt_logleaves = logleaves;
tree->db.db = db;
@@ -584,10 +584,10 @@ struct iomt *iomt_dup_in_db(void *db,
oldtree->mt_logleaves);
/* copy nodes, leaves (we do not recalculate the tree) */
- for(int i = 0; i < newtree->mt_leafcount; ++i)
+ for(uint64_t i = 0; i < newtree->mt_leafcount; ++i)
iomt_setleaf(newtree, i, iomt_getleaf(oldtree, i));
- for(int i = 0; i < 2 * newtree->mt_leafcount - 1; ++i)
+ for(uint64_t i = 0; i < 2 * newtree->mt_leafcount - 1; ++i)
iomt_setnode(newtree, i, iomt_getnode(oldtree, i));
return newtree;
@@ -616,10 +616,10 @@ struct iomt *iomt_dup(const struct iomt *oldtree)
else
{
/* copy nodes, leaves (we do not recalculate the tree) */
- for(int i = 0; i < newtree->mt_leafcount; ++i)
+ for(uint64_t i = 0; i < newtree->mt_leafcount; ++i)
iomt_setleaf(newtree, i, iomt_getleaf(oldtree, i));
- for(int i = 0; i < 2 * newtree->mt_leafcount - 1; ++i)
+ for(uint64_t i = 0; i < 2 * newtree->mt_leafcount - 1; ++i)
iomt_setnode(newtree, i, iomt_getnode(oldtree, i));
}
@@ -659,7 +659,7 @@ void iomt_serialize(const struct iomt *tree,
write_fn(userdata, tree->mem.mt_leaves, sizeof(struct iomt_node) * tree->mt_leafcount);
else
{
- for(int i = 0; i < tree->mt_leafcount; ++i)
+ for(uint64_t i = 0; i < tree->mt_leafcount; ++i)
{
struct iomt_node node = iomt_getleaf(tree, i);
write_fn(userdata, &node, sizeof(node));
@@ -769,7 +769,7 @@ void iomt_dump(const struct iomt *tree)
{
if(tree)
{
- for(int i = 0; i < tree->mt_leafcount; ++i)
+ for(uint64_t i = 0; i < tree->mt_leafcount; ++i)
{
struct iomt_node node = iomt_getleaf(tree, i);
printf("(%lu, %s, %lu)%s",
diff --git a/iomt.h b/iomt.h
index 060a582..7a00cb4 100644
--- a/iomt.h
+++ b/iomt.h
@@ -55,10 +55,10 @@ struct iomt {
hash_t hash_node(struct iomt_node node);
-hash_t *lookup_nodes(const struct iomt *tree, const int *indices, int n);
-void restore_nodes(struct iomt *tree, const int *indices, const hash_t *values, int n);
+hash_t *lookup_nodes(const struct iomt *tree, const uint64_t *indices, int n);
+void restore_nodes(struct iomt *tree, const uint64_t *indices, const hash_t *values, int n);
-hash_t *merkle_complement(const struct iomt *tree, int leafidx, int **orders);
+hash_t *merkle_complement(const struct iomt *tree, uint64_t leafidx, int **orders);
/* This function is prefixed merkle_ because it does not know about
* any IOMT-specific properties (though it is still passed an iomt
@@ -110,8 +110,8 @@ void iomt_dump(const struct iomt *tree);
hash_t iomt_getroot(const struct iomt *tree);
-hash_t iomt_getnode(const struct iomt *tree, int idx);
-void iomt_setnode(const struct iomt *tree, int idx, hash_t val);
+hash_t iomt_getnode(const struct iomt *tree, uint64_t idx);
+void iomt_setnode(const struct iomt *tree, uint64_t idx, hash_t val);
struct iomt_node iomt_getleaf(const struct iomt *tree, uint64_t leafidx);
diff --git a/service_provider.c b/service_provider.c
index fa940bf..1b68a25 100644
--- a/service_provider.c
+++ b/service_provider.c
@@ -125,7 +125,7 @@ struct tm_cert cert_eq(struct service_provider *sp,
&nu2_hmac);
/* restore the tree */
- int *dep_indices = bintree_ancestors(encloser_leafidx, sp->iomt->mt_logleaves);
+ uint64_t *dep_indices = bintree_ancestors(encloser_leafidx, sp->iomt->mt_logleaves);
restore_nodes(sp->iomt, dep_indices, old_depvalues, sp->iomt->mt_logleaves);
free(dep_indices);
@@ -141,18 +141,18 @@ struct tm_cert cert_eq(struct service_provider *sp,
/* write to file data_dir/file_idx/version */
void write_contents(const struct service_provider *sp,
- int file_idx, int version,
+ uint64_t file_idx, uint64_t version,
const void *data, size_t len)
{
mkdir(sp->data_dir, 0755);
char dirname[MAX_PATH];
- snprintf(dirname, sizeof(dirname), "%s/%d", sp->data_dir, file_idx);
+ snprintf(dirname, sizeof(dirname), "%s/%lu", sp->data_dir, file_idx);
mkdir(dirname, 0755);
char filename[MAX_PATH];
- snprintf(filename, sizeof(filename), "%s/%d/%d", sp->data_dir, file_idx, version);
+ snprintf(filename, sizeof(filename), "%s/%lu/%lu", sp->data_dir, file_idx, version);
FILE *f = fopen(filename, "w");
@@ -172,11 +172,11 @@ size_t file_len(FILE *f)
}
void *read_contents(const struct service_provider *sp,
- int file_idx, int version,
+ uint64_t file_idx, uint64_t version,
size_t *len)
{
char filename[MAX_PATH];
- snprintf(filename, sizeof(filename), "%s/%d/%d", sp->data_dir, file_idx, version);
+ snprintf(filename, sizeof(filename), "%s/%lu/%lu", sp->data_dir, file_idx, version);
FILE *f = fopen(filename, "r");
@@ -254,6 +254,9 @@ struct service_provider *sp_new(const void *key, size_t keylen,
bool overwrite_db)
{
assert(logleaves > 0);
+ if(logleaves >= 63)
+ warn("logleaves value too large, will likely fail");
+
struct service_provider *sp = calloc(1, sizeof(*sp));
bool iomt_init = true;
@@ -346,16 +349,16 @@ static struct file_record *lookup_record(struct service_provider *sp, uint64_t i
sqlite3_stmt *st;
sqlite3_prepare_v2(handle, sql, -1, &st, 0);
- sqlite3_bind_int(st, 1, idx);
+ sqlite3_bind_int64(st, 1, idx);
int rc = sqlite3_step(st);
if(rc == SQLITE_ROW)
{
struct file_record *rec = calloc(1, sizeof(struct file_record));
- rec->idx = sqlite3_column_int(st, 0);
- rec->version = sqlite3_column_int(st, 1);
- rec->counter = sqlite3_column_int(st, 2);
+ rec->idx = sqlite3_column_int64(st, 0);
+ rec->version = sqlite3_column_int64(st, 1);
+ rec->counter = sqlite3_column_int64(st, 2);
memcpy(&rec->fr_cert, sqlite3_column_blob(st, 3), sizeof(rec->fr_cert));
memcpy(&rec->fr_hmac, sqlite3_column_blob(st, 4), sizeof(rec->fr_hmac));
@@ -385,9 +388,9 @@ static void insert_record(struct service_provider *sp, const struct file_record
const char *sql = "INSERT INTO FileRecords VALUES ( ?1, ?2, ?3, ?4, ?5, ?6 );";
sqlite3_stmt *st;
sqlite3_prepare_v2(handle, sql, -1, &st, 0);
- sqlite3_bind_int(st, 1, rec->idx);
- sqlite3_bind_int(st, 2, rec->version);
- sqlite3_bind_int(st, 3, rec->counter);
+ sqlite3_bind_int64(st, 1, rec->idx);
+ sqlite3_bind_int64(st, 2, rec->version);
+ sqlite3_bind_int64(st, 3, rec->counter);
sqlite3_bind_blob(st, 4, &rec->fr_cert, sizeof(rec->fr_cert), SQLITE_TRANSIENT);
sqlite3_bind_blob(st, 5, &rec->fr_hmac, sizeof(rec->fr_hmac), SQLITE_TRANSIENT);
sqlite3_bind_int(st, 6, rec->acl->mt_logleaves);
@@ -410,13 +413,13 @@ static void update_record(struct service_provider *sp,
sqlite3_stmt *st;
sqlite3_prepare_v2(handle, sql, -1, &st, 0);
- sqlite3_bind_int(st, 1, rec->idx);
- sqlite3_bind_int(st, 2, rec->version);
- sqlite3_bind_int(st, 3, rec->counter);
+ sqlite3_bind_int64(st, 1, rec->idx);
+ sqlite3_bind_int64(st, 2, rec->version);
+ sqlite3_bind_int64(st, 3, rec->counter);
sqlite3_bind_blob(st, 4, &rec->fr_cert, sizeof(rec->fr_cert), SQLITE_TRANSIENT);
sqlite3_bind_blob(st, 5, &rec->fr_hmac, sizeof(rec->fr_hmac), SQLITE_TRANSIENT);
sqlite3_bind_int(st, 6, rec->acl->mt_logleaves);
- sqlite3_bind_int(st, 7, rec->idx);
+ sqlite3_bind_int64(st, 7, rec->idx);
assert(sqlite3_step(st) == SQLITE_DONE);
@@ -432,8 +435,8 @@ static void insert_version(struct service_provider *sp,
const char *sql = "INSERT INTO Versions VALUES ( ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8 );";
sqlite3_stmt *st;
sqlite3_prepare_v2(handle, sql, -1, &st, 0);
- sqlite3_bind_int(st, 1, rec->idx);
- sqlite3_bind_int(st, 2, ver->version);
+ sqlite3_bind_int64(st, 1, rec->idx);
+ sqlite3_bind_int64(st, 2, ver->version);
sqlite3_bind_blob(st, 3, &ver->kf, sizeof(ver->kf), SQLITE_TRANSIENT);
sqlite3_bind_blob(st, 4, &ver->encrypted_secret, sizeof(ver->encrypted_secret), SQLITE_TRANSIENT);
sqlite3_bind_blob(st, 5, &ver->vr_cert, sizeof(ver->vr_cert), SQLITE_TRANSIENT);
@@ -452,7 +455,7 @@ static void insert_version(struct service_provider *sp,
sqlite3_finalize(st);
}
-static int count_versions(struct service_provider *sp,
+static uint64_t count_versions(struct service_provider *sp,
uint64_t file_idx)
{
sqlite3 *handle = sp->db;
@@ -462,12 +465,12 @@ static int count_versions(struct service_provider *sp,
sqlite3_stmt *st;
sqlite3_prepare_v2(handle, sql, -1, &st, 0);
- sqlite3_bind_int(st, 1, file_idx);
+ sqlite3_bind_int64(st, 1, file_idx);
assert(sqlite3_step(st) == SQLITE_ROW);
/* praying it works */
- return sqlite3_column_int(st, 0);
+ return sqlite3_column_int64(st, 0);
}
static struct file_version *lookup_version(struct service_provider *sp,
@@ -484,15 +487,15 @@ static struct file_version *lookup_version(struct service_provider *sp,
sqlite3_stmt *st;
sqlite3_prepare_v2(handle, sql, -1, &st, 0);
- sqlite3_bind_int(st, 1, file_idx);
- sqlite3_bind_int(st, 2, version);
+ sqlite3_bind_int64(st, 1, file_idx);
+ sqlite3_bind_int64(st, 2, version);
int rc = sqlite3_step(st);
if(rc == SQLITE_ROW)
{
struct file_version *ver = calloc(1, sizeof(struct file_version));
- ver->version = sqlite3_column_int(st, 1);
+ ver->version = sqlite3_column_int64(st, 1);
memcpy(&ver->kf, sqlite3_column_blob(st, 2), sizeof(ver->kf));
memcpy(&ver->encrypted_secret, sqlite3_column_blob(st, 3), sizeof(ver->encrypted_secret));
memcpy(&ver->vr_cert, sqlite3_column_blob(st, 4), sizeof(ver->vr_cert));
@@ -680,7 +683,7 @@ static uint64_t find_empty_slot(struct service_provider *sp)
if(rc == SQLITE_ROW)
{
- return sqlite3_column_int(st, 0);
+ return sqlite3_column_int64(st, 0);
}
return (uint64_t) -1;
diff --git a/testall.sh b/testall.sh
index 42df4f5..122b980 100755
--- a/testall.sh
+++ b/testall.sh
@@ -7,7 +7,7 @@ fi
echo "Initializing..."
./server $1 csaa.db --overwrite > /dev/null &
pid=$!
-sleep 5
+sleep 2
time ./testcreate.sh ./client
time ./testmodify.sh ./client
time ./testretrieve.sh ./client
diff --git a/testdummy.sh b/testdummy.sh
index 1d3bf97..e8c4222 100755
--- a/testdummy.sh
+++ b/testdummy.sh
@@ -1,15 +1,10 @@
#!/bin/bash
-if [[ $# -ne 1 ]]
-then
- echo "Usage: "$0" LOGLEAVES"
- exit 1
-fi
echo "Initializing..."
rm csaa.db
sqlite3 csaa.db < sqlinit.txt
-./dummy_server $1 csaa.db > /dev/null &
+./dummy_server 10 csaa.db > /dev/null &
pid=$!
-sleep 5
+sleep 1
time ./testcreate.sh ./dummy_client
time ./testmodify.sh ./dummy_client
time ./testretrieve.sh ./dummy_client