diff options
Diffstat (limited to 'device/noise-protocol.go')
-rw-r--r-- | device/noise-protocol.go | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/device/noise-protocol.go b/device/noise-protocol.go index 3ce7839..03b872b 100644 --- a/device/noise-protocol.go +++ b/device/noise-protocol.go @@ -15,7 +15,6 @@ import ( "golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/poly1305" "golang.zx2c4.com/wireguard/tai64n" - "golang.zx2c4.com/wireguard/wgcfg" ) type handshakeState int @@ -85,8 +84,8 @@ const ( type MessageInitiation struct { Type uint32 Sender uint32 - Ephemeral wgcfg.Key - Static [wgcfg.KeySize + poly1305.TagSize]byte + Ephemeral NoisePublicKey + Static [NoisePublicKeySize + poly1305.TagSize]byte Timestamp [tai64n.TimestampSize + poly1305.TagSize]byte MAC1 [blake2s.Size128]byte MAC2 [blake2s.Size128]byte @@ -96,7 +95,7 @@ type MessageResponse struct { Type uint32 Sender uint32 Receiver uint32 - Ephemeral wgcfg.Key + Ephemeral NoisePublicKey Empty [poly1305.TagSize]byte MAC1 [blake2s.Size128]byte MAC2 [blake2s.Size128]byte @@ -119,15 +118,15 @@ type MessageCookieReply struct { type Handshake struct { state handshakeState mutex sync.RWMutex - hash [blake2s.Size]byte // hash value - chainKey [blake2s.Size]byte // chain key - presharedKey wgcfg.SymmetricKey // psk - localEphemeral wgcfg.PrivateKey // ephemeral secret key - localIndex uint32 // used to clear hash-table - remoteIndex uint32 // index for sending - remoteStatic wgcfg.Key // long term key - remoteEphemeral wgcfg.Key // ephemeral public key - precomputedStaticStatic [wgcfg.KeySize]byte // precomputed shared secret + hash [blake2s.Size]byte // hash value + chainKey [blake2s.Size]byte // chain key + presharedKey NoiseSymmetricKey // psk + localEphemeral NoisePrivateKey // ephemeral secret key + localIndex uint32 // used to clear hash-table + remoteIndex uint32 // index for sending + remoteStatic NoisePublicKey // long term key + remoteEphemeral NoisePublicKey // ephemeral public key + precomputedStaticStatic [NoisePublicKeySize]byte // precomputed shared secret lastTimestamp tai64n.Timestamp lastInitiationConsumption time.Time lastSentHandshake time.Time @@ -189,7 +188,7 @@ func (device *Device) CreateMessageInitiation(peer *Peer) (*MessageInitiation, e var err error handshake.hash = InitialHash handshake.chainKey = InitialChainKey - handshake.localEphemeral, err = wgcfg.NewPrivateKey() + handshake.localEphemeral, err = newPrivateKey() if err != nil { return nil, err } @@ -198,14 +197,14 @@ func (device *Device) CreateMessageInitiation(peer *Peer) (*MessageInitiation, e msg := MessageInitiation{ Type: MessageInitiationType, - Ephemeral: handshake.localEphemeral.Public(), + Ephemeral: handshake.localEphemeral.publicKey(), } handshake.mixKey(msg.Ephemeral[:]) handshake.mixHash(msg.Ephemeral[:]) // encrypt static key - ss := handshake.localEphemeral.SharedSecret(handshake.remoteStatic) + ss := handshake.localEphemeral.sharedSecret(handshake.remoteStatic) if isZero(ss[:]) { return nil, errZeroECDHResult } @@ -266,9 +265,9 @@ func (device *Device) ConsumeMessageInitiation(msg *MessageInitiation) *Peer { // decrypt static key var err error - var peerPK wgcfg.Key + var peerPK NoisePublicKey var key [chacha20poly1305.KeySize]byte - ss := device.staticIdentity.privateKey.SharedSecret(msg.Ephemeral) + ss := device.staticIdentity.privateKey.sharedSecret(msg.Ephemeral) if isZero(ss[:]) { return nil } @@ -377,18 +376,18 @@ func (device *Device) CreateMessageResponse(peer *Peer) (*MessageResponse, error // create ephemeral key - handshake.localEphemeral, err = wgcfg.NewPrivateKey() + handshake.localEphemeral, err = newPrivateKey() if err != nil { return nil, err } - msg.Ephemeral = handshake.localEphemeral.Public() + msg.Ephemeral = handshake.localEphemeral.publicKey() handshake.mixHash(msg.Ephemeral[:]) handshake.mixKey(msg.Ephemeral[:]) func() { - ss := handshake.localEphemeral.SharedSecret(handshake.remoteEphemeral) + ss := handshake.localEphemeral.sharedSecret(handshake.remoteEphemeral) handshake.mixKey(ss[:]) - ss = handshake.localEphemeral.SharedSecret(handshake.remoteStatic) + ss = handshake.localEphemeral.sharedSecret(handshake.remoteStatic) handshake.mixKey(ss[:]) }() @@ -458,13 +457,13 @@ func (device *Device) ConsumeMessageResponse(msg *MessageResponse) *Peer { mixKey(&chainKey, &handshake.chainKey, msg.Ephemeral[:]) func() { - ss := handshake.localEphemeral.SharedSecret(msg.Ephemeral) + ss := handshake.localEphemeral.sharedSecret(msg.Ephemeral) mixKey(&chainKey, &chainKey, ss[:]) setZero(ss[:]) }() func() { - ss := device.staticIdentity.privateKey.SharedSecret(msg.Ephemeral) + ss := device.staticIdentity.privateKey.sharedSecret(msg.Ephemeral) mixKey(&chainKey, &chainKey, ss[:]) setZero(ss[:]) }() |