MaxPathSize = 1<<8 - 1
NNCPBundlePrefix = "NNCP"
+
+ PktSizeOverhead = 8 + poly1305.TagSize
)
var (
BadMagic error = errors.New("Unknown magic number")
BadPktType error = errors.New("Unknown packet type")
- PktOverhead int64
- PktEncOverhead int64
- PktSizeOverhead int64 = 8 + poly1305.TagSize
+ PktOverhead int64
+ PktEncOverhead int64
)
type Pkt struct {
Type PktType
Nice uint8
PathLen uint8
- Path *[MaxPathSize]byte
+ Path [MaxPathSize]byte
}
type PktTbs struct {
Nice uint8
Sender *NodeId
Recipient *NodeId
- ExchPub *[32]byte
+ ExchPub [32]byte
}
type PktEnc struct {
Nice uint8
Sender *NodeId
Recipient *NodeId
- ExchPub *[32]byte
- Sign *[ed25519.SignatureSize]byte
+ ExchPub [32]byte
+ Sign [ed25519.SignatureSize]byte
}
func init() {
- pkt := Pkt{
- Type: PktTypeFile,
- Path: new([MaxPathSize]byte),
- }
+ pkt := Pkt{Type: PktTypeFile}
var buf bytes.Buffer
n, err := xdr.Marshal(&buf, pkt)
if err != nil {
}
pktEnc := PktEnc{
Magic: MagicNNCPEv4,
- Nice: 123,
Sender: dummyId,
Recipient: dummyId,
- ExchPub: new([32]byte),
- Sign: new([ed25519.SignatureSize]byte),
}
n, err = xdr.Marshal(&buf, pktEnc)
if err != nil {
Type: typ,
Nice: nice,
PathLen: uint8(len(path)),
- Path: new([MaxPathSize]byte),
}
copy(pkt.Path[:], path)
return &pkt, nil
Nice: nice,
Sender: our.Id,
Recipient: their.Id,
- ExchPub: pubEph,
+ ExchPub: *pubEph,
}
var tbsBuf bytes.Buffer
if _, err = xdr.Marshal(&tbsBuf, &tbs); err != nil {
Nice: nice,
Sender: our.Id,
Recipient: their.Id,
- ExchPub: pubEph,
- Sign: signature,
+ ExchPub: *pubEph,
+ Sign: *signature,
}
if _, err = xdr.Marshal(out, &pktEnc); err != nil {
return err
return their, 0, errors.New("Invalid signature")
}
sharedKey := new([32]byte)
- curve25519.ScalarMult(sharedKey, our.ExchPrv, pktEnc.ExchPub)
+ curve25519.ScalarMult(sharedKey, our.ExchPrv, &pktEnc.ExchPub)
kdf, err := blake2b.NewXOF(KDFXOFSize, sharedKey[:])
if err != nil {
return their, 0, err