diff options
-rw-r--r-- | runtime/librsgt.c | 14 | ||||
-rw-r--r-- | runtime/librsgt_read.c | 20 |
2 files changed, 26 insertions, 8 deletions
diff --git a/runtime/librsgt.c b/runtime/librsgt.c index f00c894d..aa74f09d 100644 --- a/runtime/librsgt.c +++ b/runtime/librsgt.c @@ -218,15 +218,14 @@ tlvFlush(gtctx ctx) } void -tlvWriteRecHash(gtctx ctx, GTDataHash *r) +tlvWriteHash(gtctx ctx, uint16_t tlvtype, GTDataHash *r) { unsigned tlvlen; tlvlen = 1 + r->digest_length; - tlv16Write(ctx, 0x00, 0x0900, tlvlen); + tlv16Write(ctx, 0x00, tlvtype, tlvlen); tlvbufAddOctet(ctx, hashIdentifier(ctx->hashAlg)); tlvbufAddOctetString(ctx, r->digest, r->digest_length); -dbgprintf("DDDD: tlvWriteRecHash: tlvlen %u, digest_len %u\n", tlvlen, r->digest_length); } void @@ -281,7 +280,7 @@ readStateFile(gtctx ctx) if(read(fd, &sf, sizeof(sf)) != sizeof(sf)) goto err; if(strncmp(sf.hdr, "GTSTAT10", 8)) goto err; - ctx->lenBlkStrtHash = hashOutputLengthOctets(sf.lenHash); + ctx->lenBlkStrtHash = sf.lenHash; ctx->blkStrtHash = calloc(1, ctx->lenBlkStrtHash); if((rr=read(fd, ctx->blkStrtHash, ctx->lenBlkStrtHash)) != ctx->lenBlkStrtHash) { @@ -534,9 +533,11 @@ sigblkAddRecord(gtctx ctx, const uchar *rec, const size_t len) hash_m(ctx, &m); hash_r(ctx, &r, rec, len); if(ctx->bKeepRecordHashes) - tlvWriteRecHash(ctx, r); + tlvWriteHash(ctx, 0x0900, r); hash_node(ctx, &x, m, r, 1); /* hash leaf */ /* persists x here if Merkle tree needs to be persisted! */ + if(ctx->bKeepTreeHashes) + tlvWriteHash(ctx, 0x0901, x); /* add x to the forest as new leaf, update roots list */ t = x; for(j = 0 ; j < ctx->nRoots ; ++j) { @@ -549,6 +550,9 @@ sigblkAddRecord(gtctx ctx, const uchar *rec, const size_t len) /* hash interim node */ hash_node(ctx, &t, ctx->roots_hash[j], t, j+2); ctx->roots_valid[j] = 0; + // TODO: check if this is correct location (paper!) + if(ctx->bKeepTreeHashes) + tlvWriteHash(ctx, 0x0901, t); } } if(t != NULL) { diff --git a/runtime/librsgt_read.c b/runtime/librsgt_read.c index a1c59509..be78580d 100644 --- a/runtime/librsgt_read.c +++ b/runtime/librsgt_read.c @@ -237,7 +237,7 @@ done: return r; } static int -rsgt_tlvrdREC_HASH(FILE *fp, imprint_t **imprint, uint16_t tlvlen) +rsgt_tlvrdIMPRINT(FILE *fp, imprint_t **imprint, uint16_t tlvlen) { int r = 1; imprint_t *imp; @@ -293,7 +293,11 @@ rsgt_tlvrd(FILE *fp, uint16_t *tlvtype, uint16_t *tlvlen, void *obj) if((r = rsgt_tlvrdTL(fp, tlvtype, tlvlen)) != 0) goto done; switch(*tlvtype) { case 0x0900: - r = rsgt_tlvrdREC_HASH(fp, obj, *tlvlen); + r = rsgt_tlvrdIMPRINT(fp, obj, *tlvlen); + if(r != 0) goto done; + break; + case 0x0901: + r = rsgt_tlvrdIMPRINT(fp, obj, *tlvlen); if(r != 0) goto done; break; case 0x0902: @@ -345,7 +349,14 @@ rsgt_printIMPRINT(FILE *fp, char *name, imprint_t *imp, uint8_t verbose) static void rsgt_printREC_HASH(FILE *fp, imprint_t *imp, uint8_t verbose) { - rsgt_printIMPRINT(fp, "[0x0900]Record Signature Record: ", + rsgt_printIMPRINT(fp, "[0x0900]Record hash................: ", + imp, verbose); +} + +static void +rsgt_printINT_HASH(FILE *fp, imprint_t *imp, uint8_t verbose) +{ + rsgt_printIMPRINT(fp, "[0x0901]Intermediate aggregate hash: ", imp, verbose); } @@ -396,6 +407,9 @@ rsgt_tlvprint(FILE *fp, uint16_t tlvtype, void *obj, uint8_t verbose) case 0x0900: rsgt_printREC_HASH(fp, obj, verbose); break; + case 0x0901: + rsgt_printINT_HASH(fp, obj, verbose); + break; case 0x0902: rsgt_printBLOCK_SIG(fp, obj, verbose); break; |