Don't use modules
Feel free to revert this if you have a strong feeling about it. But so far as I can see, it adds a lot of complexity for basically no upsides.
This commit is contained in:
		
							parent
							
								
									77285c99aa
								
							
						
					
					
						commit
						bffe99aead
					
				
					 9 changed files with 20 additions and 23 deletions
				
			
		|  | @ -3,7 +3,6 @@ package main | ||||||
| import ( | import ( | ||||||
| 	"crypto/hmac" | 	"crypto/hmac" | ||||||
| 	"crypto/rand" | 	"crypto/rand" | ||||||
| 	"git.zx2c4.com/wireguard-go/internal/xchacha20poly1305" |  | ||||||
| 	"golang.org/x/crypto/blake2s" | 	"golang.org/x/crypto/blake2s" | ||||||
| 	"golang.org/x/crypto/chacha20poly1305" | 	"golang.org/x/crypto/chacha20poly1305" | ||||||
| 	"sync" | 	"sync" | ||||||
|  | @ -158,7 +157,7 @@ func (st *CookieChecker) CreateReply( | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	xchacha20poly1305.Encrypt( | 	XChaCha20Poly1305Encrypt( | ||||||
| 		reply.Cookie[:0], | 		reply.Cookie[:0], | ||||||
| 		&reply.Nonce, | 		&reply.Nonce, | ||||||
| 		cookie[:], | 		cookie[:], | ||||||
|  | @ -202,7 +201,7 @@ func (st *CookieGenerator) ConsumeReply(msg *MessageCookieReply) bool { | ||||||
| 
 | 
 | ||||||
| 	var cookie [blake2s.Size128]byte | 	var cookie [blake2s.Size128]byte | ||||||
| 
 | 
 | ||||||
| 	_, err := xchacha20poly1305.Decrypt( | 	_, err := XChaCha20Poly1305Decrypt( | ||||||
| 		cookie[:0], | 		cookie[:0], | ||||||
| 		&msg.Nonce, | 		&msg.Nonce, | ||||||
| 		msg.Cookie[:], | 		msg.Cookie[:], | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"git.zx2c4.com/wireguard-go/internal/ratelimiter" |  | ||||||
| 	"runtime" | 	"runtime" | ||||||
| 	"sync" | 	"sync" | ||||||
| 	"sync/atomic" | 	"sync/atomic" | ||||||
|  | @ -51,7 +50,7 @@ type Device struct { | ||||||
| 
 | 
 | ||||||
| 	rate struct { | 	rate struct { | ||||||
| 		underLoadUntil atomic.Value | 		underLoadUntil atomic.Value | ||||||
| 		limiter        ratelimiter.Ratelimiter | 		limiter        Ratelimiter | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pool struct { | 	pool struct { | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"git.zx2c4.com/wireguard-go/internal/tai64n" |  | ||||||
| 	"golang.org/x/crypto/blake2s" | 	"golang.org/x/crypto/blake2s" | ||||||
| 	"golang.org/x/crypto/chacha20poly1305" | 	"golang.org/x/crypto/chacha20poly1305" | ||||||
| 	"golang.org/x/crypto/poly1305" | 	"golang.org/x/crypto/poly1305" | ||||||
|  | @ -59,7 +58,7 @@ type MessageInitiation struct { | ||||||
| 	Sender    uint32 | 	Sender    uint32 | ||||||
| 	Ephemeral NoisePublicKey | 	Ephemeral NoisePublicKey | ||||||
| 	Static    [NoisePublicKeySize + poly1305.TagSize]byte | 	Static    [NoisePublicKeySize + poly1305.TagSize]byte | ||||||
| 	Timestamp [tai64n.TimestampSize + poly1305.TagSize]byte | 	Timestamp [TimestampSize + poly1305.TagSize]byte | ||||||
| 	MAC1      [blake2s.Size128]byte | 	MAC1      [blake2s.Size128]byte | ||||||
| 	MAC2      [blake2s.Size128]byte | 	MAC2      [blake2s.Size128]byte | ||||||
| } | } | ||||||
|  | @ -100,7 +99,7 @@ type Handshake struct { | ||||||
| 	remoteStatic              NoisePublicKey           // long term key
 | 	remoteStatic              NoisePublicKey           // long term key
 | ||||||
| 	remoteEphemeral           NoisePublicKey           // ephemeral public key
 | 	remoteEphemeral           NoisePublicKey           // ephemeral public key
 | ||||||
| 	precomputedStaticStatic   [NoisePublicKeySize]byte // precomputed shared secret
 | 	precomputedStaticStatic   [NoisePublicKeySize]byte // precomputed shared secret
 | ||||||
| 	lastTimestamp             tai64n.Timestamp | 	lastTimestamp             Timestamp | ||||||
| 	lastInitiationConsumption time.Time | 	lastInitiationConsumption time.Time | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -207,7 +206,7 @@ func (device *Device) CreateMessageInitiation(peer *Peer) (*MessageInitiation, e | ||||||
| 
 | 
 | ||||||
| 	// encrypt timestamp
 | 	// encrypt timestamp
 | ||||||
| 
 | 
 | ||||||
| 	timestamp := tai64n.Now() | 	timestamp := TimestampNow() | ||||||
| 	func() { | 	func() { | ||||||
| 		var key [chacha20poly1305.KeySize]byte | 		var key [chacha20poly1305.KeySize]byte | ||||||
| 		KDF2( | 		KDF2( | ||||||
|  | @ -272,7 +271,7 @@ func (device *Device) ConsumeMessageInitiation(msg *MessageInitiation) *Peer { | ||||||
| 
 | 
 | ||||||
| 	// verify identity
 | 	// verify identity
 | ||||||
| 
 | 
 | ||||||
| 	var timestamp tai64n.Timestamp | 	var timestamp Timestamp | ||||||
| 	var key [chacha20poly1305.KeySize]byte | 	var key [chacha20poly1305.KeySize]byte | ||||||
| 
 | 
 | ||||||
| 	handshake.mutex.RLock() | 	handshake.mutex.RLock() | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package ratelimiter | package main | ||||||
| 
 | 
 | ||||||
| /* Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */ | /* Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */ | ||||||
| 
 | 
 | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package ratelimiter | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"net" | 	"net" | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package tai64n | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"bytes" | 	"bytes" | ||||||
|  | @ -11,7 +11,7 @@ const base = uint64(4611686018427387914) | ||||||
| 
 | 
 | ||||||
| type Timestamp [TimestampSize]byte | type Timestamp [TimestampSize]byte | ||||||
| 
 | 
 | ||||||
| func Now() Timestamp { | func TimestampNow() Timestamp { | ||||||
| 	var tai64n Timestamp | 	var tai64n Timestamp | ||||||
| 	now := time.Now() | 	now := time.Now() | ||||||
| 	secs := base + uint64(now.Unix()) | 	secs := base + uint64(now.Unix()) | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package tai64n | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"testing" | 	"testing" | ||||||
|  | @ -9,10 +9,10 @@ import ( | ||||||
|  * as used by WireGuard. |  * as used by WireGuard. | ||||||
|  */ |  */ | ||||||
| func TestMonotonic(t *testing.T) { | func TestMonotonic(t *testing.T) { | ||||||
| 	old := Now() | 	old := TimestampNow() | ||||||
| 	for i := 0; i < 10000; i++ { | 	for i := 0; i < 10000; i++ { | ||||||
| 		time.Sleep(time.Nanosecond) | 		time.Sleep(time.Nanosecond) | ||||||
| 		next := Now() | 		next := TimestampNow() | ||||||
| 		if !next.After(old) { | 		if !next.After(old) { | ||||||
| 			t.Error("TAI64N, not monotonically increasing on nano-second scale") | 			t.Error("TAI64N, not monotonically increasing on nano-second scale") | ||||||
| 		} | 		} | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| // Use of this source code is governed by a license that can be
 | // Use of this source code is governed by a license that can be
 | ||||||
| // found in the LICENSE file.
 | // found in the LICENSE file.
 | ||||||
| 
 | 
 | ||||||
| package xchacha20poly1305 | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"encoding/binary" | 	"encoding/binary" | ||||||
|  | @ -138,7 +138,7 @@ func hChaCha20(out *[32]byte, nonce []byte, key *[32]byte) { | ||||||
| 	binary.LittleEndian.PutUint32(out[28:], v15) | 	binary.LittleEndian.PutUint32(out[28:], v15) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func Encrypt( | func XChaCha20Poly1305Encrypt( | ||||||
| 	dst []byte, | 	dst []byte, | ||||||
| 	nonceFull *[24]byte, | 	nonceFull *[24]byte, | ||||||
| 	plaintext []byte, | 	plaintext []byte, | ||||||
|  | @ -153,7 +153,7 @@ func Encrypt( | ||||||
| 	return aead.Seal(dst, nonce[:], plaintext, additionalData) | 	return aead.Seal(dst, nonce[:], plaintext, additionalData) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func Decrypt( | func XChaCha20Poly1305Decrypt( | ||||||
| 	dst []byte, | 	dst []byte, | ||||||
| 	nonceFull *[24]byte, | 	nonceFull *[24]byte, | ||||||
| 	plaintext []byte, | 	plaintext []byte, | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| package xchacha20poly1305 | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"encoding/hex" | 	"encoding/hex" | ||||||
|  | @ -60,7 +60,7 @@ func TestXChaCha20(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 			// test encryption
 | 			// test encryption
 | ||||||
| 
 | 
 | ||||||
| 			ct := Encrypt( | 			ct := XChaCha20Poly1305Encrypt( | ||||||
| 				nil, | 				nil, | ||||||
| 				&nonceArray, | 				&nonceArray, | ||||||
| 				pt, | 				pt, | ||||||
|  | @ -74,7 +74,7 @@ func TestXChaCha20(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 			// test decryption
 | 			// test decryption
 | ||||||
| 
 | 
 | ||||||
| 			ptp, err := Decrypt( | 			ptp, err := XChaCha20Poly1305Decrypt( | ||||||
| 				nil, | 				nil, | ||||||
| 				&nonceArray, | 				&nonceArray, | ||||||
| 				ct, | 				ct, | ||||||
		Loading…
	
		Reference in a new issue