Move replay into subpackage
This commit is contained in:
parent
0a63188afa
commit
5a2228a5c9
@ -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
|
||||
|
7
misc.go
7
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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user