Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save received preimages in a shachain. #25

Merged
merged 2 commits into from
Jun 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion daemon/packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,6 @@ Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt)
* SHA256 hash of `revocation_preimage` matches the previous commitment
* transaction, and MUST fail if it does not.
*/
/* FIXME: Save preimage in shachain too. */
if (!check_preimage(r->revocation_preimage, &ci->revocation_hash))
return pkt_err(peer, "complete preimage incorrect");

Expand All @@ -819,6 +818,9 @@ Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt)

proto_to_sha256(r->revocation_preimage, ci->revocation_preimage);

// save revocation preimages in shachain
shachain_add_hash(&peer->their_preimages, 0xFFFFFFFFFFFFFFFFL - ci->commit_num, ci->revocation_preimage);

/* Save next revocation hash. */
proto_to_sha256(r->next_revocation_hash,
&peer->remote.next_revocation_hash);
Expand Down
4 changes: 4 additions & 0 deletions daemon/peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "netaddr.h"
#include "state.h"
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/crypto/shachain/shachain.h>
#include <ccan/list/list.h>
#include <ccan/time/time.h>

Expand Down Expand Up @@ -214,6 +215,9 @@ struct peer {

/* Stuff we have in common. */
struct peer_visible_state local, remote;

/* this is where we will store their revocation preimages*/
struct shachain their_preimages;
};

void setup_listeners(struct lightningd_state *dstate, unsigned int portnum);
Expand Down
5 changes: 4 additions & 1 deletion daemon/secrets.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ void peer_secrets_init(struct peer *peer)
if (RAND_bytes(peer->secrets->revocation_seed.u.u8,
sizeof(peer->secrets->revocation_seed.u.u8)) != 1)
fatal("Could not get random bytes for revocation seed");

shachain_init(&peer->their_preimages);
}

void peer_get_revocation_preimage(const struct peer *peer, u64 index,
struct sha256 *preimage)
{
shachain_from_seed(&peer->secrets->revocation_seed, index, preimage);
// generate hashes in reverse order, otherwise the first hash gives away everything
shachain_from_seed(&peer->secrets->revocation_seed, 0xFFFFFFFFFFFFFFFFL - index, preimage);
}

void peer_get_revocation_hash(const struct peer *peer, u64 index,
Expand Down