import (
"crypto/hmac"
"crypto/rand"
+ "git.zx2c4.com/wireguard-go/internal/xchacha20poly1305"
"golang.org/x/crypto/blake2s"
"golang.org/x/crypto/chacha20poly1305"
"sync"
return nil, err
}
- XChaCha20Poly1305Encrypt(
+ xchacha20poly1305.Encrypt(
reply.Cookie[:0],
&reply.Nonce,
cookie[:],
var cookie [blake2s.Size128]byte
- _, err := XChaCha20Poly1305Decrypt(
+ _, err := xchacha20poly1305.Decrypt(
cookie[:0],
&msg.Nonce,
msg.Cookie[:],
package main
import (
+ "git.zx2c4.com/wireguard-go/internal/ratelimiter"
"runtime"
"sync"
"sync/atomic"
rate struct {
underLoadUntil atomic.Value
- limiter Ratelimiter
+ limiter ratelimiter.Ratelimiter
}
pool struct {
-package main
+package ratelimiter
/* Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */
-package main
+package ratelimiter
import (
"net"
-package main
+package tai64n
import (
"bytes"
type Timestamp [TimestampSize]byte
-func TimestampNow() Timestamp {
+func Now() Timestamp {
var tai64n Timestamp
now := time.Now()
secs := base + uint64(now.Unix())
-package main
+package tai64n
import (
"testing"
* as used by WireGuard.
*/
func TestMonotonic(t *testing.T) {
- old := TimestampNow()
+ old := Now()
for i := 0; i < 10000; i++ {
time.Sleep(time.Nanosecond)
- next := TimestampNow()
+ next := Now()
if !next.After(old) {
t.Error("TAI64N, not monotonically increasing on nano-second scale")
}
// Use of this source code is governed by a license that can be
// found in the LICENSE file.
-package main
+package xchacha20poly1305
import (
"encoding/binary"
binary.LittleEndian.PutUint32(out[28:], v15)
}
-func XChaCha20Poly1305Encrypt(
+func Encrypt(
dst []byte,
nonceFull *[24]byte,
plaintext []byte,
return aead.Seal(dst, nonce[:], plaintext, additionalData)
}
-func XChaCha20Poly1305Decrypt(
+func Decrypt(
dst []byte,
nonceFull *[24]byte,
plaintext []byte,
-package main
+package xchacha20poly1305
import (
"encoding/hex"
// test encryption
- ct := XChaCha20Poly1305Encrypt(
+ ct := Encrypt(
nil,
&nonceArray,
pt,
// test decryption
- ptp, err := XChaCha20Poly1305Decrypt(
+ ptp, err := Decrypt(
nil,
&nonceArray,
ct,
import (
"errors"
+ "git.zx2c4.com/wireguard-go/internal/tai64n"
"golang.org/x/crypto/blake2s"
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/poly1305"
Sender uint32
Ephemeral NoisePublicKey
Static [NoisePublicKeySize + poly1305.TagSize]byte
- Timestamp [TimestampSize + poly1305.TagSize]byte
+ Timestamp [tai64n.TimestampSize + poly1305.TagSize]byte
MAC1 [blake2s.Size128]byte
MAC2 [blake2s.Size128]byte
}
remoteStatic NoisePublicKey // long term key
remoteEphemeral NoisePublicKey // ephemeral public key
precomputedStaticStatic [NoisePublicKeySize]byte // precomputed shared secret
- lastTimestamp Timestamp
+ lastTimestamp tai64n.Timestamp
lastInitiationConsumption time.Time
}
// encrypt timestamp
- timestamp := TimestampNow()
+ timestamp := tai64n.Now()
func() {
var key [chacha20poly1305.KeySize]byte
KDF2(
// verify identity
- var timestamp Timestamp
+ var timestamp tai64n.Timestamp
var key [chacha20poly1305.KeySize]byte
handshake.mutex.RLock()