update comments, tests forthcoming

This commit is contained in:
Olaoluwa Osuntokun
2015-10-22 12:15:14 -07:00
parent e75d0c4f6a
commit 2edf9209f6

View File

@@ -78,8 +78,11 @@ type MixHeader struct {
HeaderMAC [securityParameter]byte HeaderMAC [securityParameter]byte
} }
// GenerateSphinxHeader... // NewMixHeader creates a new mix header which is capable of obliviously
// TODO(roasbeef): or pass in identifiers as payment path? have map from id -> pubkey // routing a message through the mix-net path outline by 'paymentPath'
// to a final node indicated by 'identifier' housing a message addressed to
// 'dest'. This function returns the created mix header along with a derived
// shared secret for each node in the path.
func NewMixHeader(dest LightningAddress, identifier [securityParameter]byte, func NewMixHeader(dest LightningAddress, 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
@@ -151,8 +154,9 @@ func NewMixHeader(dest LightningAddress, identifier [securityParameter]byte,
xor(mixHeader, mixHeader, streamBytes[:(2*(numMaxHops-numHops)+3)*securityParameter]) xor(mixHeader, mixHeader, streamBytes[:(2*(numMaxHops-numHops)+3)*securityParameter])
mixHeader = append(mixHeader, filler...) mixHeader = append(mixHeader, filler...)
// Calculate a MAC over the encrypted mix header for the last hop, using // Calculate a MAC over the encrypted mix header for the last hop
// the same shared secret key as used for encryption above. // (including the filler bytes), using the same shared secret key as
// used for encryption above.
headerMac := calcMac(generateKey("mu", hopSharedSecrets[numHops-1]), mixHeader) headerMac := calcMac(generateKey("mu", hopSharedSecrets[numHops-1]), mixHeader)
// Now we compute the routing information for each hop, along with a // Now we compute the routing information for each hop, along with a
@@ -302,8 +306,8 @@ func generateKey(keyType string, sharedKey [sharedSecretSize]byte) [securityPara
return key return key
} }
// generateRandBytes... // generateHeaderPadding...
// generates // TODO(roasbeef): comments...
func generateCipherStream(key [securityParameter]byte, numBytes uint) []byte { func generateCipherStream(key [securityParameter]byte, numBytes uint) []byte {
block, _ := aes.NewCipher(key[:]) block, _ := aes.NewCipher(key[:])
@@ -362,23 +366,23 @@ type processMsgAction struct {
// SphinxNode... // SphinxNode...
type SphinxNode struct { type SphinxNode struct {
identifier [securityParameter]byte nodeID [securityParameter]byte
// TODO(roasbeef): swap out with btcutil.AddressLightningKey // TODO(roasbeef): swap out with btcutil.AddressLightningKey maybe?
name []byte nodeAddr []byte
lnKey *btcec.PrivateKey lnKey *btcec.PrivateKey
seenSecrets map[[securityParameter]byte]struct{} seenSecrets map[[sharedSecretSize]byte]struct{}
} }
// NewSphinxNode... // NewSphinxNode...
func NewSphinxNode(nodeID [securityParameter]byte, nodeAddr LightningAddress, nodeKey *btcec.PrivateKey) *SphinxNode { func NewSphinxNode(nodeID [securityParameter]byte, nodeAddr LightningAddress, nodeKey *btcec.PrivateKey) *SphinxNode {
return &SphinxNode{ return &SphinxNode{
identifier: nodeID, nodeID: nodeID,
name: nodeAddr, nodeAddr: nodeAddr,
lnKey: nodeKey, lnKey: nodeKey,
// TODO(roasbeef): replace instead with bloom filter? // TODO(roasbeef): replace instead with bloom filter?
// * https://moderncrypto.org/mail-archive/messaging/2015/001911.html // * https://moderncrypto.org/mail-archive/messaging/2015/001911.html
seenSecrets: make(map[[securityParameter]byte]struct{}), seenSecrets: make(map[[sharedSecretSize]byte]struct{}),
} }
} }