aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--device/keypair.go2
-rw-r--r--device/noise-protocol.go2
-rw-r--r--replay/replay.go12
-rw-r--r--replay/replay_test.go18
4 files changed, 17 insertions, 17 deletions
diff --git a/device/keypair.go b/device/keypair.go
index 2f2f222..254e696 100644
--- a/device/keypair.go
+++ b/device/keypair.go
@@ -26,7 +26,7 @@ type Keypair struct {
sendNonce uint64
send cipher.AEAD
receive cipher.AEAD
- replayFilter replay.ReplayFilter
+ replayFilter replay.Filter
isInitiator bool
created time.Time
localIndex uint32
diff --git a/device/noise-protocol.go b/device/noise-protocol.go
index be92b4b..1dc854f 100644
--- a/device/noise-protocol.go
+++ b/device/noise-protocol.go
@@ -567,7 +567,7 @@ func (peer *Peer) BeginSymmetricSession() error {
keypair.created = time.Now()
keypair.sendNonce = 0
- keypair.replayFilter.Init()
+ keypair.replayFilter.Reset()
keypair.isInitiator = isInitiator
keypair.localIndex = peer.handshake.localIndex
keypair.remoteIndex = peer.handshake.remoteIndex
diff --git a/replay/replay.go b/replay/replay.go
index 8685712..5b2de41 100644
--- a/replay/replay.go
+++ b/replay/replay.go
@@ -17,24 +17,24 @@ const (
bitMask = blockBits - 1
)
-// A ReplayFilter rejects replayed messages by checking if message counter value is
+// A Filter rejects replayed messages by checking if message counter value is
// within a sliding window of previously received messages.
-// The zero value for ReplayFilter is an empty filter ready to use.
+// The zero value for Filter is an empty filter ready to use.
// Filters are unsafe for concurrent use.
-type ReplayFilter struct {
+type Filter struct {
last uint64
ring [ringBlocks]block
}
-// Init resets the filter to empty state.
-func (f *ReplayFilter) Init() {
+// Reset resets the filter to empty state.
+func (f *Filter) Reset() {
f.last = 0
f.ring[0] = 0
}
// ValidateCounter checks if the counter should be accepted.
// Overlimit counters (>= limit) are always rejected.
-func (f *ReplayFilter) ValidateCounter(counter uint64, limit uint64) bool {
+func (f *Filter) ValidateCounter(counter uint64, limit uint64) bool {
if counter >= limit {
return false
}
diff --git a/replay/replay_test.go b/replay/replay_test.go
index 5af66ff..fcffd20 100644
--- a/replay/replay_test.go
+++ b/replay/replay_test.go
@@ -14,10 +14,10 @@ import (
*
*/
-const RejectAfterMessages = (1 << 64) - (1 << 4) - 1
+const RejectAfterMessages = 1<<64 - 1<<13 - 1
func TestReplay(t *testing.T) {
- var filter ReplayFilter
+ var filter Filter
const T_LIM = windowSize + 1
@@ -29,7 +29,7 @@ func TestReplay(t *testing.T) {
}
}
- filter.Init()
+ filter.Reset()
T(0, true) /* 1 */
T(1, true) /* 2 */
@@ -67,7 +67,7 @@ func TestReplay(t *testing.T) {
T(0, false) /* 34 */
t.Log("Bulk test 1")
- filter.Init()
+ filter.Reset()
testNumber = 0
for i := uint64(1); i <= windowSize; i++ {
T(i, true)
@@ -76,7 +76,7 @@ func TestReplay(t *testing.T) {
T(0, false)
t.Log("Bulk test 2")
- filter.Init()
+ filter.Reset()
testNumber = 0
for i := uint64(2); i <= windowSize+1; i++ {
T(i, true)
@@ -85,14 +85,14 @@ func TestReplay(t *testing.T) {
T(0, false)
t.Log("Bulk test 3")
- filter.Init()
+ filter.Reset()
testNumber = 0
for i := uint64(windowSize + 1); i > 0; i-- {
T(i, true)
}
t.Log("Bulk test 4")
- filter.Init()
+ filter.Reset()
testNumber = 0
for i := uint64(windowSize + 2); i > 1; i-- {
T(i, true)
@@ -100,7 +100,7 @@ func TestReplay(t *testing.T) {
T(0, false)
t.Log("Bulk test 5")
- filter.Init()
+ filter.Reset()
testNumber = 0
for i := uint64(windowSize); i > 0; i-- {
T(i, true)
@@ -109,7 +109,7 @@ func TestReplay(t *testing.T) {
T(0, false)
t.Log("Bulk test 6")
- filter.Init()
+ filter.Reset()
testNumber = 0
for i := uint64(windowSize); i > 0; i-- {
T(i, true)