packet_helper.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package packet
  2. import (
  3. "golang.org/x/crypto/blake2s"
  4. "golang.org/x/crypto/chacha20poly1305"
  5. "golang.zx2c4.com/wireguard/tai64n"
  6. "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
  7. )
  8. const poly1305TagSize = 16
  9. var (
  10. InitialChainKey [blake2s.Size]byte
  11. InitialHash [blake2s.Size]byte
  12. ZeroNonce [chacha20poly1305.NonceSize]byte
  13. )
  14. func init() {
  15. InitialChainKey = blake2s.Sum256([]byte(NoiseConstruction))
  16. mixHash(&InitialHash, &InitialChainKey, []byte(WGIdentifier))
  17. }
  18. type MessageInitiation struct {
  19. Type MessageType
  20. Sender uint32
  21. Ephemeral NoisePublicKey
  22. Static [NoisePublicKeySize + poly1305TagSize]byte
  23. Timestamp [tai64n.TimestampSize + poly1305TagSize]byte
  24. MAC1 [blake2s.Size128]byte
  25. MAC2 [blake2s.Size128]byte
  26. }
  27. type MetricMessage struct {
  28. Type MessageType
  29. ID uint32
  30. Sender wgtypes.Key
  31. Reciever wgtypes.Key
  32. TimeStamp int64
  33. }
  34. type ProxyMessage struct {
  35. Type MessageType
  36. Sender [16]byte
  37. Reciever [16]byte
  38. }
  39. type ProxyUpdateMessage struct {
  40. Type MessageType
  41. Action ProxyActionType
  42. Sender wgtypes.Key
  43. Reciever wgtypes.Key
  44. ListenPort uint32
  45. }