summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-23 02:32:02 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-23 03:58:27 +0200
commit5a2228a5c910ada948677f1dd3fcc59f74e5cb20 (patch)
treebafb31cbcc18221e2299f8fef21d9c2f4471f706
parent0a63188afab1dd49380f916963307f9b2efdcac1 (diff)
Move replay into subpackage
-rw-r--r--keypair.go3
-rw-r--r--misc.go7
-rw-r--r--receive.go2
-rw-r--r--replay/replay.go (renamed from replay.go)15
-rw-r--r--replay/replay_test.go (renamed from replay_test.go)6
5 files changed, 17 insertions, 16 deletions
diff --git a/keypair.go b/keypair.go
index be7600b..face310 100644
--- a/keypair.go
+++ b/keypair.go
@@ -7,6 +7,7 @@
package main
import (
+ "./replay"
"crypto/cipher"
"sync"
"time"
@@ -23,7 +24,7 @@ type Keypair struct {
sendNonce uint64
send cipher.AEAD
receive cipher.AEAD
- replayFilter ReplayFilter
+ replayFilter replay.ReplayFilter
isInitiator bool
created time.Time
localIndex uint32
diff --git a/misc.go b/misc.go
index af61718..ede94f9 100644
--- a/misc.go
+++ b/misc.go
@@ -47,10 +47,3 @@ func min(a, b uint) uint {
}
return a
}
-
-func minUint64(a uint64, b uint64) uint64 {
- if a > b {
- return b
- }
- return a
-}
diff --git a/receive.go b/receive.go
index 3d9710c..707b056 100644
--- a/receive.go
+++ b/receive.go
@@ -544,7 +544,7 @@ func (peer *Peer) RoutineSequentialReceiver() {
// check for replay
- if !elem.keypair.replayFilter.ValidateCounter(elem.counter) {
+ if !elem.keypair.replayFilter.ValidateCounter(elem.counter, RejectAfterMessages) {
continue
}
diff --git a/replay.go b/replay/replay.go
index 2d9c6e1..993ff58 100644
--- a/replay.go
+++ b/replay/replay.go
@@ -4,9 +4,7 @@
* Copyright (C) 2017-2018 Mathias N. Hall-Andersen <mathias@hall-andersen.dk>.
*/
-package main
-
-/* Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */
+package replay
/* Implementation of RFC6479
* https://tools.ietf.org/html/rfc6479
@@ -32,6 +30,13 @@ const (
BacktrackWords = CounterBitsTotal / _WordSize
)
+func minUint64(a uint64, b uint64) uint64 {
+ if a > b {
+ return b
+ }
+ return a
+}
+
type ReplayFilter struct {
counter uint64
backtrack [BacktrackWords]uintptr
@@ -42,8 +47,8 @@ func (filter *ReplayFilter) Init() {
filter.backtrack[0] = 0
}
-func (filter *ReplayFilter) ValidateCounter(counter uint64) bool {
- if counter >= RejectAfterMessages {
+func (filter *ReplayFilter) ValidateCounter(counter uint64, limit uint64) bool {
+ if counter >= limit {
return false
}
diff --git a/replay_test.go b/replay/replay_test.go
index 8b2e57d..da39498 100644
--- a/replay_test.go
+++ b/replay/replay_test.go
@@ -4,7 +4,7 @@
* Copyright (C) 2017-2018 Mathias N. Hall-Andersen <mathias@hall-andersen.dk>.
*/
-package main
+package replay
import (
"testing"
@@ -15,6 +15,8 @@ import (
*
*/
+const RejectAfterMessages = (1 << 64) - (1 << 4) - 1
+
func TestReplay(t *testing.T) {
var filter ReplayFilter
@@ -23,7 +25,7 @@ func TestReplay(t *testing.T) {
testNumber := 0
T := func(n uint64, v bool) {
testNumber++
- if filter.ValidateCounter(n) != v {
+ if filter.ValidateCounter(n, RejectAfterMessages) != v {
t.Fatal("Test", testNumber, "failed", n, v)
}
}