Skip to content

Commit 2e73fcf

Browse files
Fix staticcheck warnings
Signed-off-by: Alexander Yastrebov <yastrebov.alex@gmail.com>
1 parent f333402 commit 2e73fcf

File tree

7 files changed

+28
-29
lines changed

7 files changed

+28
-29
lines changed

conn/bind_std_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func Test_coalesceMessages(t *testing.T) {
4242
{
4343
name: "one message no coalesce",
4444
buffs: [][]byte{
45-
make([]byte, 1, 1),
45+
make([]byte, 1),
4646
},
4747
wantLens: []int{1},
4848
wantGSO: []int{0},
@@ -51,7 +51,7 @@ func Test_coalesceMessages(t *testing.T) {
5151
name: "two messages equal len coalesce",
5252
buffs: [][]byte{
5353
make([]byte, 1, 2),
54-
make([]byte, 1, 1),
54+
make([]byte, 1),
5555
},
5656
wantLens: []int{2},
5757
wantGSO: []int{1},
@@ -60,7 +60,7 @@ func Test_coalesceMessages(t *testing.T) {
6060
name: "two messages unequal len coalesce",
6161
buffs: [][]byte{
6262
make([]byte, 2, 3),
63-
make([]byte, 1, 1),
63+
make([]byte, 1),
6464
},
6565
wantLens: []int{3},
6666
wantGSO: []int{2},
@@ -69,8 +69,8 @@ func Test_coalesceMessages(t *testing.T) {
6969
name: "three messages second unequal len coalesce",
7070
buffs: [][]byte{
7171
make([]byte, 2, 3),
72-
make([]byte, 1, 1),
73-
make([]byte, 2, 2),
72+
make([]byte, 1),
73+
make([]byte, 2),
7474
},
7575
wantLens: []int{3, 2},
7676
wantGSO: []int{2, 0},
@@ -79,8 +79,8 @@ func Test_coalesceMessages(t *testing.T) {
7979
name: "three messages limited cap coalesce",
8080
buffs: [][]byte{
8181
make([]byte, 2, 4),
82-
make([]byte, 2, 2),
83-
make([]byte, 2, 2),
82+
make([]byte, 2),
83+
make([]byte, 2),
8484
},
8585
wantLens: []int{4, 2},
8686
wantGSO: []int{2, 0},

device/device_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ package device
77

88
import (
99
"bytes"
10+
"crypto/rand"
1011
"encoding/hex"
1112
"fmt"
1213
"io"
13-
"math/rand"
14+
mrand "math/rand/v2"
1415
"net/netip"
1516
"os"
1617
"runtime"
@@ -224,11 +225,11 @@ func TestUpDown(t *testing.T) {
224225
if err := d.Up(); err != nil {
225226
t.Errorf("failed up bring up device: %v", err)
226227
}
227-
time.Sleep(time.Duration(rand.Intn(int(time.Nanosecond * (0x10000 - 1)))))
228+
time.Sleep(mrand.N(time.Nanosecond * (0x10000 - 1)))
228229
if err := d.Down(); err != nil {
229230
t.Errorf("failed to bring down device: %v", err)
230231
}
231-
time.Sleep(time.Duration(rand.Intn(int(time.Nanosecond * (0x10000 - 1)))))
232+
time.Sleep(mrand.N(time.Nanosecond * (0x10000 - 1)))
232233
}
233234
}(pair[i].dev)
234235
}

device/endpoint_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package device
77

88
import (
9-
"math/rand"
9+
"crypto/rand"
1010
"net/netip"
1111
)
1212

device/noise-helpers.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ func (sk *NoisePrivateKey) publicKey() (pk NoisePublicKey) {
9898
var errInvalidPublicKey = errors.New("invalid public key")
9999

100100
func (sk *NoisePrivateKey) sharedSecret(pk NoisePublicKey) (ss [NoisePublicKeySize]byte, err error) {
101-
apk := (*[NoisePublicKeySize]byte)(&pk)
102-
ask := (*[NoisePrivateKeySize]byte)(sk)
103-
curve25519.ScalarMult(&ss, ask, apk)
104-
if isZero(ss[:]) {
101+
p, err := curve25519.X25519(sk[:], pk[:])
102+
if err != nil {
105103
return ss, errInvalidPublicKey
106104
}
105+
copy(ss[:], p)
107106
return ss, nil
108107
}

device/noise-protocol.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"golang.org/x/crypto/blake2s"
1616
"golang.org/x/crypto/chacha20poly1305"
17-
"golang.org/x/crypto/poly1305"
1817

1918
"golang.zx2c4.com/wireguard/tai64n"
2019
)
@@ -61,13 +60,13 @@ const (
6160
)
6261

6362
const (
64-
MessageInitiationSize = 148 // size of handshake initiation message
65-
MessageResponseSize = 92 // size of response message
66-
MessageCookieReplySize = 64 // size of cookie reply message
67-
MessageTransportHeaderSize = 16 // size of data preceding content in transport message
68-
MessageTransportSize = MessageTransportHeaderSize + poly1305.TagSize // size of empty transport
69-
MessageKeepaliveSize = MessageTransportSize // size of keepalive
70-
MessageHandshakeSize = MessageInitiationSize // size of largest handshake related message
63+
MessageInitiationSize = 148 // size of handshake initiation message
64+
MessageResponseSize = 92 // size of response message
65+
MessageCookieReplySize = 64 // size of cookie reply message
66+
MessageTransportHeaderSize = 16 // size of data preceding content in transport message
67+
MessageTransportSize = MessageTransportHeaderSize + chacha20poly1305.Overhead // size of empty transport
68+
MessageKeepaliveSize = MessageTransportSize // size of keepalive
69+
MessageHandshakeSize = MessageInitiationSize // size of largest handshake related message
7170
)
7271

7372
const (
@@ -86,8 +85,8 @@ type MessageInitiation struct {
8685
Type uint32
8786
Sender uint32
8887
Ephemeral NoisePublicKey
89-
Static [NoisePublicKeySize + poly1305.TagSize]byte
90-
Timestamp [tai64n.TimestampSize + poly1305.TagSize]byte
88+
Static [NoisePublicKeySize + chacha20poly1305.Overhead]byte
89+
Timestamp [tai64n.TimestampSize + chacha20poly1305.Overhead]byte
9190
MAC1 [blake2s.Size128]byte
9291
MAC2 [blake2s.Size128]byte
9392
}
@@ -97,7 +96,7 @@ type MessageResponse struct {
9796
Sender uint32
9897
Receiver uint32
9998
Ephemeral NoisePublicKey
100-
Empty [poly1305.TagSize]byte
99+
Empty [chacha20poly1305.Overhead]byte
101100
MAC1 [blake2s.Size128]byte
102101
MAC2 [blake2s.Size128]byte
103102
}
@@ -113,7 +112,7 @@ type MessageCookieReply struct {
113112
Type uint32
114113
Receiver uint32
115114
Nonce [chacha20poly1305.NonceSizeX]byte
116-
Cookie [blake2s.Size128 + poly1305.TagSize]byte
115+
Cookie [blake2s.Size128 + chacha20poly1305.Overhead]byte
117116
}
118117

119118
var errMessageLengthMismatch = errors.New("message length mismatch")

device/receive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (device *Device) RoutineReceiveIncoming(maxBatchSize int, recv conn.Receive
113113
return
114114
}
115115
device.log.Verbosef("Failed to receive %s packet: %v", recvName, err)
116-
if neterr, ok := err.(net.Error); ok && !neterr.Temporary() {
116+
if neterr, ok := err.(net.Error); ok && !neterr.Timeout() {
117117
return
118118
}
119119
if deathSpiral < 10 {

tun/tun_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
8787
if name != "utun" {
8888
_, err := fmt.Sscanf(name, "utun%d", &ifIndex)
8989
if err != nil || ifIndex < 0 {
90-
return nil, fmt.Errorf("Interface name must be utun[0-9]*")
90+
return nil, fmt.Errorf("interface name must be utun[0-9]*")
9191
}
9292
}
9393

0 commit comments

Comments
 (0)