diff options
author | Franklin Wei <me@fwei.tk> | 2018-05-28 21:15:42 -0400 |
---|---|---|
committer | Franklin Wei <me@fwei.tk> | 2018-05-28 21:15:42 -0400 |
commit | d367850a94d75d7b39f596d6bcd1dd8b8e463dd7 (patch) | |
tree | ad0053b1454041e6f0dc70aa4a9989da4019f12c | |
parent | b24eba453c4d2acaac96d81adf23d2f22585404b (diff) | |
download | csaa-d367850a94d75d7b39f596d6bcd1dd8b8e463dd7.zip csaa-d367850a94d75d7b39f596d6bcd1dd8b8e463dd7.tar.gz csaa-d367850a94d75d7b39f596d6bcd1dd8b8e463dd7.tar.bz2 csaa-d367850a94d75d7b39f596d6bcd1dd8b8e463dd7.tar.xz |
add RV, RU certificate generation
-rw-r--r-- | service_provider.h | 2 | ||||
-rw-r--r-- | trusted_module.c | 82 | ||||
-rw-r--r-- | trusted_module.h | 34 |
3 files changed, 111 insertions, 7 deletions
diff --git a/service_provider.h b/service_provider.h index a0b9bd9..b1910a0 100644 --- a/service_provider.h +++ b/service_provider.h @@ -8,7 +8,7 @@ struct iomt_node { int idx, next_idx; /* idx cannot be zero */ - hash_t value; /* all zero indicates placeholder */ + hash_t val; /* all zero indicates placeholder */ }; struct service_provider; diff --git a/trusted_module.c b/trusted_module.c index 7a79a8f..2fbc926 100644 --- a/trusted_module.c +++ b/trusted_module.c @@ -235,7 +235,7 @@ struct tm_cert tm_cert_equiv(struct trusted_module *tm, struct iomt_node ins; ins.idx = a; ins.next_idx = encloser->next_idx; - memset(ins.value.hash, 0, sizeof(ins.value.hash)); + memset(ins.val.hash, 0, sizeof(ins.val.hash)); hash_t viprime = hash_node(&ins); @@ -260,10 +260,16 @@ struct tm_cert tm_cert_equiv(struct trusted_module *tm, } /* nu must be of the form [x,y,x,y] to indicate that x is a child of y */ +/* also, if b > 0 and nonexist != NULL, this function will generate a + * certificate indicating that no node with index b exists with root + * y*/ struct tm_cert tm_cert_record_verify(struct trusted_module *tm, const struct tm_cert *nu, hash_t hmac, const struct iomt_node *node, - hash_t *hmac_out) + hash_t *hmac_out, + int b, + struct tm_cert *nonexist, + hash_t *hmac_nonexist) { if(!nu) return cert_null; @@ -274,15 +280,85 @@ struct tm_cert tm_cert_record_verify(struct trusted_module *tm, if(!hash_equals(nu->nu.orig_node, node_h)) return cert_null; + /* issue a certificate verifying that no node with index b exists as a child of y */ + if(b > 0 && nonexist && hmac_nonexist) + { + if(encloses(node->idx, node->next_idx, b)) + { + memset(nonexist, 0, sizeof(*nonexist)); + nonexist->type = RV; + nonexist->rv.idx = b; + + /* not needed */ + //memset(nonexist->rv.val, 0, sizeof(nonexist->rv.val)); + + nonexist->rv.root = nu->nu.orig_root; + + *hmac_nonexist = cert_sign(tm, nonexist); + } + else + *nonexist = cert_null; + } + + /* verify that this node is a child of y */ + struct tm_cert cert; + + memset(&cert, 0, sizeof(cert)); + + cert.type = RV; + cert.rv.root = nu->nu.orig_root; + cert.rv.idx = node->idx; + cert.rv.val = node->val; + + *hmac_out = cert_sign(tm, &cert); + return cert; +} + +struct tm_cert tm_cert_record_update(struct trusted_module *tm, + const struct tm_cert *nu, hash_t nu_hmac, + const struct iomt_node *node, + hash_t new_val, + hash_t *hmac_out) +{ + if(!nu) + return cert_null; + if(nu->type != NU) + return cert_null; + if(!cert_verify(tm, nu, nu_hmac)) + return cert_null; + + hash_t orig_h = hash_node(node); + struct iomt_node new_node = *node; + new_node.val = new_val; + + hash_t new_h = hash_node(&new_node); + + if(!hash_equals(nu->nu.orig_node, orig_h) || !hash_equals(nu->nu.new_node, new_h)) + return cert_null; + + struct tm_cert cert; + memset(&cert, 0, sizeof(cert)); + + cert.type = RU; + cert.ru.idx = node->idx; + cert.ru.orig_val = node->val; + cert.ru.new_val = new_val; + cert.ru.orig_root = nu->nu.orig_root; + cert.ru.new_root = nu->nu.new_root; + + *hmac_out = cert_sign(tm, &cert); + return cert; } + + +/* self-test */ void check(int condition) { printf(condition ? "PASS\n" : "FAIL\n"); } -/* self-test */ void tm_test(void) { /* test merkle tree with zeros */ diff --git a/trusted_module.h b/trusted_module.h index 0799132..d1cf2ce 100644 --- a/trusted_module.h +++ b/trusted_module.h @@ -16,16 +16,20 @@ struct tm_cert { struct { /* new_root has an additional placeholder */ hash_t orig_root, new_root; - char zero[2 * 32]; } eq; /* equivalence */ struct { /* proof that there is a node with given idx,val that is a * child of root; if val=0, proof that there is no such * node */ + hash_t root; int idx; hash_t val; - hash_t root; - } rv; /* record verify */ + } rv; /* record verify */ + struct { + int idx; + hash_t orig_val, new_val; + hash_t orig_root, new_root; + } ru; /* record update */ }; }; @@ -54,3 +58,27 @@ struct tm_cert tm_cert_equiv(struct trusted_module *tm, const struct tm_cert *nu_ins, hash_t hmac_ins, const struct iomt_node *encloser, int a, hash_t *hmac_out); + +/* nu must be of the form [x,y,x,y] to indicate that x is a child of y */ +/* also, if b > 0 and nonexist != NULL, this function will generate a + * certificate indicating that no node with index b exists with root + * y*/ +struct tm_cert tm_cert_record_verify(struct trusted_module *tm, + const struct tm_cert *nu, hash_t hmac, + const struct iomt_node *node, + hash_t *hmac_out, + int b, + struct tm_cert *nonexist, + hash_t *hmac_nonexist); + +struct tm_cert tm_cert_record_update(struct trusted_module *tm, + const struct tm_cert *nu, hash_t nu_hmac, + const struct iomt_node *node, + hash_t new_val, + hash_t *hmac_out); + +/* transformation procedures (return true on success) */ + +/* change internal IOMT root to equivalent root */ +bool tm_set_equiv_root(struct trusted_module *tm, + const struct tm_cert *cert_eq, hash_t hmac); |