mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-07 16:14:26 +01:00
lightningd/derive_basepoints.h: one place for 2^48 shachain constant.
Suggested-by: Christian Decker <decker.christian@gmail.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -655,7 +655,7 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
|
||||
* generated by the protocol in [BOLT #3]
|
||||
*/
|
||||
if (!shachain_add_hash(&peer->their_shachain,
|
||||
281474976710655ULL - peer->commit_index[REMOTE],
|
||||
shachain_index(peer->commit_index[REMOTE]),
|
||||
&old_commit_secret)) {
|
||||
peer_failed(io_conn_fd(peer->peer_conn),
|
||||
&peer->pcs.cs,
|
||||
|
||||
@@ -40,11 +40,7 @@ bool derive_basepoints(const struct privkey *seed,
|
||||
*/
|
||||
*shaseed = keys.shaseed;
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
* the first secret used MUST be index 281474976710655, and then the
|
||||
* index decremented. */
|
||||
shachain_from_seed(shaseed, 281474976710655ULL - per_commit_index,
|
||||
shachain_from_seed(shaseed, shachain_index(per_commit_index),
|
||||
&per_commit_secret);
|
||||
|
||||
/* BOLT #3:
|
||||
@@ -71,14 +67,13 @@ bool next_per_commit_point(const struct sha256 *shaseed,
|
||||
|
||||
/* Get old secret. */
|
||||
if (per_commit_index > 0)
|
||||
shachain_from_seed(shaseed, 281474976710655ULL
|
||||
- (per_commit_index - 1),
|
||||
shachain_from_seed(shaseed, shachain_index(per_commit_index - 1),
|
||||
old_commit_secret);
|
||||
else
|
||||
assert(old_commit_secret == NULL);
|
||||
|
||||
/* Derive new per-commitment-point. */
|
||||
shachain_from_seed(shaseed, 281474976710655ULL - (per_commit_index + 1),
|
||||
shachain_from_seed(shaseed, shachain_index(per_commit_index + 1),
|
||||
&per_commit_secret);
|
||||
|
||||
/* BOLT #3:
|
||||
|
||||
@@ -33,4 +33,14 @@ bool next_per_commit_point(const struct sha256 *shaseed,
|
||||
struct pubkey *per_commit_point,
|
||||
u64 per_commit_index);
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
* the first secret used MUST be index 281474976710655, and then the index
|
||||
* decremented.
|
||||
*/
|
||||
static inline u64 shachain_index(u64 per_commit_index)
|
||||
{
|
||||
assert(per_commit_index < (1ULL << 48));
|
||||
return 281474976710655ULL - per_commit_index;
|
||||
}
|
||||
#endif /* LIGHTNING_LIGHTNINGD_DERIVE_BASEPOINTS_H */
|
||||
|
||||
Reference in New Issue
Block a user