mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-28 09:27:29 +02:00
Adding comments for MixHeader, create New method
This commit is contained in:
25
sphinx.go
25
sphinx.go
@@ -61,16 +61,25 @@ type SharedSecret [sharedSecretSize]byte
|
|||||||
var zeroNode [securityParameter]byte
|
var zeroNode [securityParameter]byte
|
||||||
var nullDest byte
|
var nullDest byte
|
||||||
|
|
||||||
// MixHeader...
|
// MixHeader is the onion wrapped hop-to-hop routing information neccessary to
|
||||||
|
// propagate a message through the mix-net without intermediate nodes having
|
||||||
|
// knowledge of their position within the route, the source, the destination,
|
||||||
|
// and finally the identities of the past/future nodes in the route. At each hop
|
||||||
|
// the ephemeral key is used by the node to perform ECDH between itself and the
|
||||||
|
// source node. This derived secret key is used to check the MAC of the entire mix
|
||||||
|
// header, decrypt the next set of routing information, and re-randomize the
|
||||||
|
// ephemeral key for the next node in the path. This per-hop re-randomization
|
||||||
|
// allows us to only propgate a single group element through the onion route.
|
||||||
|
// TODO(roasbeef): serialize/deserialize methods..
|
||||||
type MixHeader struct {
|
type MixHeader struct {
|
||||||
DHKey *btcec.PublicKey
|
EphemeralKey *btcec.PublicKey
|
||||||
RoutingInfo [routingInfoSize]byte
|
RoutingInfo [routingInfoSize]byte
|
||||||
HeaderMAC [securityParameter]byte
|
HeaderMAC [securityParameter]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateSphinxHeader...
|
// GenerateSphinxHeader...
|
||||||
// TODO(roasbeef): or pass in identifiers as payment path? have map from id -> pubkey
|
// TODO(roasbeef): or pass in identifiers as payment path? have map from id -> pubkey
|
||||||
func GenerateSphinxHeader(dest []byte, identifier [securityParameter]byte,
|
func NewMixHeader(dest []byte, identifier [securityParameter]byte,
|
||||||
paymentPath []*btcec.PublicKey) (*MixHeader, [][sharedSecretSize]byte, error) {
|
paymentPath []*btcec.PublicKey) (*MixHeader, [][sharedSecretSize]byte, error) {
|
||||||
// Each hop performs ECDH with our ephemeral key pair to arrive at a
|
// Each hop performs ECDH with our ephemeral key pair to arrive at a
|
||||||
// shared secret. Additionally, each hop randomizes the group element
|
// shared secret. Additionally, each hop randomizes the group element
|
||||||
@@ -171,9 +180,9 @@ func GenerateSphinxHeader(dest []byte, identifier [securityParameter]byte,
|
|||||||
var r [routingInfoSize]byte
|
var r [routingInfoSize]byte
|
||||||
copy(r[:], mixHeader)
|
copy(r[:], mixHeader)
|
||||||
header := &MixHeader{
|
header := &MixHeader{
|
||||||
DHKey: hopEphemeralPubKeys[0],
|
EphemeralKey: hopEphemeralPubKeys[0],
|
||||||
RoutingInfo: r,
|
RoutingInfo: r,
|
||||||
HeaderMAC: headerMac,
|
HeaderMAC: headerMac,
|
||||||
}
|
}
|
||||||
|
|
||||||
return header, hopSharedSecrets, nil
|
return header, hopSharedSecrets, nil
|
||||||
|
Reference in New Issue
Block a user