diff options
author | Linus Nordberg <linus@nordberg.se> | 2014-09-18 13:00:44 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2014-09-18 13:00:44 +0200 |
commit | e84b362eb7f5dbdea44c811534521f89707f66b4 (patch) | |
tree | 727fd71a302b79ec43fc13b4c31cda2e0186fd53 /src/plop.erl | |
parent | a34637a8162aa0cbd8835513bc143e051dd1e503 (diff) |
Add field 'mtlhash' to the database, for get-proof-by-hash.
Also, in db:
Add field 'mtlhash' to record 'plop'. Rename 'hash' -> 'entryhash'.
Add leaf_hash(), calculating a leaf hash from data.
Fix a bug where print_tree() print half a byte of the hashes.
Rename tree_hash() -> root().
Closes CATLFISH-3.
Diffstat (limited to 'src/plop.erl')
-rw-r--r-- | src/plop.erl | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/plop.erl b/src/plop.erl index 81d3cc9..92ada3a 100644 --- a/src/plop.erl +++ b/src/plop.erl @@ -151,9 +151,9 @@ handle_call({consistency, {First, Second}}, _From, Plop) -> {reply, ht:consistency(First - 1, Second - 1), Plop}; handle_call({inclusion, {Hash, TreeSize}}, _From, Plop) -> - {Index, Proof} = case db:find(Hash) of + {Index, Proof} = case db:find(mtlhash, Hash) of [] -> []; - {plop, I, _Hash, _MTL, _SPT} -> + {plop, I, _EntryHash, _MTLHash, _MTL, _SPT} -> {I, ht:path(I, TreeSize - 1)} end, {reply, {Index, Proof}, Plop}; @@ -175,13 +175,14 @@ do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry}, Privkey, LogID) -> DB_hash = crypto:hash(sha256, serialise(PlopEntry)), - Record = db:find(DB_hash), + Record = db:find(entryhash, DB_hash), case Record of - #plop{index = _I, mtl = #mtl{entry = E}, spt = SPT} -> - %%io:format("Found entry: index=~p~n", [I]), - %% Database consistency checking. FIXME: Remove. + #plop{index = _I, mtl = MTL, spt = SPT} -> + %% Costly database consistency checking. FIXME: Remove. + E = MTL#mtl.entry, Record = Record#plop{ - hash = DB_hash, + entryhash = DB_hash, + mtlhash = ht:leaf_hash(serialise(MTL)), mtl = #mtl{entry = #timestamped_entry{ timestamp = E#timestamped_entry.timestamp, @@ -190,13 +191,14 @@ do_add(TimestampedEntry = #timestamped_entry{entry = PlopEntry}, [] -> NewSPT = spt(LogID, Privkey, TimestampedEntry), MTL = #mtl{entry = TimestampedEntry}, - %%io:format("Creating new entry: index=~p~n", [ht:size()]), + MTLtext = serialise(MTL), DB_data = #plop{index = ht:size(), - hash = DB_hash, + entryhash = DB_hash, + mtlhash = ht:leaf_hash(MTLtext), mtl = MTL, spt = NewSPT}, {atomic, ok} = db:add(DB_data), - {ht:add(serialise(MTL)), NewSPT}; + {ht:add(MTLtext), NewSPT}; Err -> {error, Err} end. @@ -230,7 +232,7 @@ sth(PrivKey, []) -> sth(PrivKey, #sth_signed{version = Version, timestamp = Timestamp_in}) -> Timestamp = timestamp(Timestamp_in), Treesize = ht:size(), - Roothash = ht:tree_hash(), + Roothash = ht:root(), BinToSign = serialise(#sth_signed{ version = Version, signature_type = tree_hash, |