From 079729bab895133957181dd9e4c11ca33ced508d Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 6 Jan 2016 14:43:03 +0300 Subject: [PATCH] EncLess -> Encless for convenience Signed-off-by: Sergey Matveev --- src/govpn/cmd/govpn-client/main.go | 2 +- src/govpn/cmd/govpn-client/tcp.go | 2 +- src/govpn/cmd/govpn-server/conf.go | 4 +- src/govpn/cmd/govpn-server/tcp.go | 2 +- src/govpn/conf.go | 2 +- src/govpn/encless.go | 10 ++--- src/govpn/encless_test.go | 16 ++++---- src/govpn/handshake.go | 60 +++++++++++++++--------------- src/govpn/handshake_test.go | 4 +- src/govpn/peer.go | 20 +++++----- src/govpn/peer_test.go | 8 ++-- 11 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/govpn/cmd/govpn-client/main.go b/src/govpn/cmd/govpn-client/main.go index 630547d..7c4514e 100644 --- a/src/govpn/cmd/govpn-client/main.go +++ b/src/govpn/cmd/govpn-client/main.go @@ -85,7 +85,7 @@ func main() { Timeout: time.Second * time.Duration(timeout), Noise: *noisy, CPR: *cpr, - EncLess: *encless, + Encless: *encless, Verifier: verifier, DSAPriv: priv, } diff --git a/src/govpn/cmd/govpn-client/tcp.go b/src/govpn/cmd/govpn-client/tcp.go index 88ddeeb..7f2af60 100644 --- a/src/govpn/cmd/govpn-client/tcp.go +++ b/src/govpn/cmd/govpn-client/tcp.go @@ -43,7 +43,7 @@ func startTCP(timeouted, rehandshaking, termination chan struct{}) { func handleTCP(conn *net.TCPConn, timeouted, rehandshaking, termination chan struct{}) { hs := govpn.HandshakeStart(*remoteAddr, conn, conf) - buf := make([]byte, 2*(govpn.EncLessEnlargeSize+*mtu)+*mtu) + buf := make([]byte, 2*(govpn.EnclessEnlargeSize+*mtu)+*mtu) var n int var err error var prev int diff --git a/src/govpn/cmd/govpn-server/conf.go b/src/govpn/cmd/govpn-server/conf.go index 809c56d..cd74669 100644 --- a/src/govpn/cmd/govpn-server/conf.go +++ b/src/govpn/cmd/govpn-server/conf.go @@ -53,7 +53,7 @@ func confRead() map[govpn.PeerId]*govpn.PeerConf { if err != nil { log.Fatalln("Unable to decode the key:", err.Error(), pc.VerifierRaw) } - if pc.EncLess { + if pc.Encless { pc.Noise = true } if pc.MTU == 0 { @@ -69,7 +69,7 @@ func confRead() map[govpn.PeerId]*govpn.PeerConf { Down: pc.Down, Noise: pc.Noise, CPR: pc.CPR, - EncLess: pc.EncLess, + Encless: pc.Encless, } if pc.TimeoutInt <= 0 { pc.TimeoutInt = govpn.TimeoutDefault diff --git a/src/govpn/cmd/govpn-server/tcp.go b/src/govpn/cmd/govpn-server/tcp.go index c0e7f16..e3458cb 100644 --- a/src/govpn/cmd/govpn-server/tcp.go +++ b/src/govpn/cmd/govpn-server/tcp.go @@ -51,7 +51,7 @@ func startTCP() { func handleTCP(conn net.Conn) { addr := conn.RemoteAddr().String() - buf := make([]byte, govpn.EncLessEnlargeSize+2*govpn.MTUMax) + buf := make([]byte, govpn.EnclessEnlargeSize+2*govpn.MTUMax) var n int var err error var prev int diff --git a/src/govpn/conf.go b/src/govpn/conf.go index 2d3937d..4cb2f15 100644 --- a/src/govpn/conf.go +++ b/src/govpn/conf.go @@ -35,7 +35,7 @@ type PeerConf struct { Timeout time.Duration `json:"-"` Noise bool `json:"noise"` CPR int `json:"cpr"` - EncLess bool `json:"encless"` + Encless bool `json:"encless"` VerifierRaw string `json:"verifier"` // This is passphrase verifier diff --git a/src/govpn/encless.go b/src/govpn/encless.go index c25c8d7..21162b7 100644 --- a/src/govpn/encless.go +++ b/src/govpn/encless.go @@ -24,16 +24,16 @@ import ( ) const ( - EncLessEnlargeSize = aont.HSize + aont.RSize*cnw.EnlargeFactor + EnclessEnlargeSize = aont.HSize + aont.RSize*cnw.EnlargeFactor ) // Confidentiality preserving (but encryptionless) encoding. // // It uses Chaffing-and-Winnowing technology (it is neither // encryption nor steganography) over All-Or-Nothing-Transformed data. -// nonce is 64-bit nonce. Output data will be EncLessEnlargeSize larger. +// nonce is 64-bit nonce. Output data will be EnclessEnlargeSize larger. // It also consumes 64-bits of entropy. -func EncLessEncode(authKey *[32]byte, nonce, in []byte) ([]byte, error) { +func EnclessEncode(authKey *[32]byte, nonce, in []byte) ([]byte, error) { r := new([aont.RSize]byte) var err error if _, err = Rand.Read(r[:]); err != nil { @@ -51,8 +51,8 @@ func EncLessEncode(authKey *[32]byte, nonce, in []byte) ([]byte, error) { return out, nil } -// Decode EncLessEncode-ed data. -func EncLessDecode(authKey *[32]byte, nonce, in []byte) ([]byte, error) { +// Decode EnclessEncode-ed data. +func EnclessDecode(authKey *[32]byte, nonce, in []byte) ([]byte, error) { var err error winnowed, err := cnw.Winnow( authKey, nonce, in[:aont.RSize*cnw.EnlargeFactor], diff --git a/src/govpn/encless_test.go b/src/govpn/encless_test.go index 89d6d59..20b0df6 100644 --- a/src/govpn/encless_test.go +++ b/src/govpn/encless_test.go @@ -34,15 +34,15 @@ func init() { rand.Read(testKey[:]) } -func TestEncLessSymmetric(t *testing.T) { +func TestEnclessSymmetric(t *testing.T) { nonce := make([]byte, 8) f := func(pktNum uint64, in []byte) bool { binary.BigEndian.PutUint64(nonce, pktNum) - encoded, err := EncLessEncode(testKey, nonce, in) + encoded, err := EnclessEncode(testKey, nonce, in) if err != nil { return false } - decoded, err := EncLessDecode(testKey, nonce, encoded) + decoded, err := EnclessDecode(testKey, nonce, encoded) if err != nil { return false } @@ -53,25 +53,25 @@ func TestEncLessSymmetric(t *testing.T) { } } -func BenchmarkEncLessEncode(b *testing.B) { +func BenchmarkEnclessEncode(b *testing.B) { nonce := make([]byte, 8) data := make([]byte, 128) rand.Read(nonce) rand.Read(data) b.ResetTimer() for i := 0; i < b.N; i++ { - EncLessEncode(testKey, nonce, data) + EnclessEncode(testKey, nonce, data) } } -func BenchmarkEncLessDecode(b *testing.B) { +func BenchmarkEnclessDecode(b *testing.B) { nonce := make([]byte, 8) data := make([]byte, 128) rand.Read(nonce) rand.Read(data) - encoded, _ := EncLessEncode(testKey, nonce, data) + encoded, _ := EnclessEncode(testKey, nonce, data) b.ResetTimer() for i := 0; i < b.N; i++ { - EncLessDecode(testKey, nonce, encoded) + EnclessDecode(testKey, nonce, encoded) } } diff --git a/src/govpn/handshake.go b/src/govpn/handshake.go index fb0c649..8c76967 100644 --- a/src/govpn/handshake.go +++ b/src/govpn/handshake.go @@ -166,9 +166,9 @@ func HandshakeStart(addr string, conn io.Writer, conf *PeerConf) *Handshake { enc = make([]byte, 32) } copy(enc, dhPubRepr[:]) - if conf.EncLess { + if conf.Encless { var err error - enc, err = EncLessEncode(state.dsaPubH, state.rNonce[:], enc) + enc, err = EnclessEncode(state.dsaPubH, state.rNonce[:], enc) if err != err { panic(err) } @@ -188,15 +188,15 @@ func HandshakeStart(addr string, conn io.Writer, conf *PeerConf) *Handshake { // authenticated Peer is ready, then return nil. func (h *Handshake) Server(data []byte) *Peer { // R + ENC(H(DSAPub), R, El(CDHPub)) + IDtag - if h.rNonce == nil && ((!h.Conf.EncLess && len(data) >= 48) || - (h.Conf.EncLess && len(data) == EncLessEnlargeSize+h.Conf.MTU)) { + if h.rNonce == nil && ((!h.Conf.Encless && len(data) >= 48) || + (h.Conf.Encless && len(data) == EnclessEnlargeSize+h.Conf.MTU)) { h.rNonce = new([RSize]byte) copy(h.rNonce[:], data[:RSize]) // Decrypt remote public key cDHRepr := new([32]byte) - if h.Conf.EncLess { - out, err := EncLessDecode( + if h.Conf.Encless { + out, err := EnclessDecode( h.dsaPubH, h.rNonce[:], data[RSize:len(data)-xtea.BlockSize], @@ -226,10 +226,10 @@ func (h *Handshake) Server(data []byte) *Peer { var encPub []byte var err error - if h.Conf.EncLess { + if h.Conf.Encless { encPub = make([]byte, h.Conf.MTU) copy(encPub, dhPubRepr[:]) - encPub, err = EncLessEncode(h.dsaPubH, h.rNonceNext(1), encPub) + encPub, err = EnclessEncode(h.dsaPubH, h.rNonceNext(1), encPub) if err != nil { panic(err) } @@ -248,16 +248,16 @@ func (h *Handshake) Server(data []byte) *Peer { log.Fatalln("Error reading random for S:", err) } var encRs []byte - if h.Conf.Noise && !h.Conf.EncLess { + if h.Conf.Noise && !h.Conf.Encless { encRs = make([]byte, h.Conf.MTU-len(encPub)-xtea.BlockSize) - } else if h.Conf.EncLess { + } else if h.Conf.Encless { encRs = make([]byte, h.Conf.MTU-xtea.BlockSize) } else { encRs = make([]byte, RSize+SSize) } copy(encRs, append(h.rServer[:], h.sServer[:]...)) - if h.Conf.EncLess { - encRs, err = EncLessEncode(h.key, h.rNonce[:], encRs) + if h.Conf.Encless { + encRs, err = EnclessEncode(h.key, h.rNonce[:], encRs) if err != nil { panic(err) } @@ -270,12 +270,12 @@ func (h *Handshake) Server(data []byte) *Peer { h.LastPing = time.Now() } else // ENC(K, R+1, RS + RC + SC + Sign(DSAPriv, K)) + IDtag - if h.rClient == nil && ((!h.Conf.EncLess && len(data) >= 120) || - (h.Conf.EncLess && len(data) == EncLessEnlargeSize+h.Conf.MTU)) { + if h.rClient == nil && ((!h.Conf.Encless && len(data) >= 120) || + (h.Conf.Encless && len(data) == EnclessEnlargeSize+h.Conf.MTU)) { var dec []byte var err error - if h.Conf.EncLess { - dec, err = EncLessDecode( + if h.Conf.Encless { + dec, err = EnclessDecode( h.key, h.rNonceNext(1), data[:len(data)-xtea.BlockSize], @@ -313,8 +313,8 @@ func (h *Handshake) Server(data []byte) *Peer { enc = make([]byte, RSize) } copy(enc, dec[RSize:RSize+RSize]) - if h.Conf.EncLess { - enc, err = EncLessEncode(h.key, h.rNonceNext(2), enc) + if h.Conf.Encless { + enc, err = EnclessEncode(h.key, h.rNonceNext(2), enc) if err != nil { panic(err) } @@ -346,14 +346,14 @@ func (h *Handshake) Server(data []byte) *Peer { func (h *Handshake) Client(data []byte) *Peer { // ENC(H(DSAPub), R+1, El(SDHPub)) + ENC(K, R, RS + SS) + IDtag if h.rServer == nil && h.key == nil && - ((!h.Conf.EncLess && len(data) >= 80) || - (h.Conf.EncLess && len(data) == 2*(EncLessEnlargeSize+h.Conf.MTU))) { + ((!h.Conf.Encless && len(data) >= 80) || + (h.Conf.Encless && len(data) == 2*(EnclessEnlargeSize+h.Conf.MTU))) { // Decrypt remote public key sDHRepr := new([32]byte) var tmp []byte var err error - if h.Conf.EncLess { - tmp, err = EncLessDecode( + if h.Conf.Encless { + tmp, err = EnclessDecode( h.dsaPubH, h.rNonceNext(1), data[:len(data)/2], @@ -380,8 +380,8 @@ func (h *Handshake) Client(data []byte) *Peer { // Decrypt Rs h.rServer = new([RSize]byte) h.sServer = new([SSize]byte) - if h.Conf.EncLess { - tmp, err = EncLessDecode( + if h.Conf.Encless { + tmp, err = EnclessDecode( h.key, h.rNonce[:], data[len(data)/2:len(data)-xtea.BlockSize], @@ -425,8 +425,8 @@ func (h *Handshake) Client(data []byte) *Peer { copy(enc[RSize:], h.rClient[:]) copy(enc[RSize+RSize:], h.sClient[:]) copy(enc[RSize+RSize+SSize:], sign[:]) - if h.Conf.EncLess { - enc, err = EncLessEncode(h.key, h.rNonceNext(1), enc) + if h.Conf.Encless { + enc, err = EnclessEncode(h.key, h.rNonceNext(1), enc) if err != nil { panic(err) } @@ -439,13 +439,13 @@ func (h *Handshake) Client(data []byte) *Peer { h.LastPing = time.Now() } else // ENC(K, R+2, RC) + IDtag - if h.key != nil && ((!h.Conf.EncLess && len(data) >= 16) || - (h.Conf.EncLess && len(data) == EncLessEnlargeSize+h.Conf.MTU)) { + if h.key != nil && ((!h.Conf.Encless && len(data) >= 16) || + (h.Conf.Encless && len(data) == EnclessEnlargeSize+h.Conf.MTU)) { var err error // Decrypt rClient var dec []byte - if h.Conf.EncLess { - dec, err = EncLessDecode( + if h.Conf.Encless { + dec, err = EnclessDecode( h.key, h.rNonceNext(2), data[:len(data)-xtea.BlockSize], diff --git a/src/govpn/handshake_test.go b/src/govpn/handshake_test.go index 02c592b..228f58b 100644 --- a/src/govpn/handshake_test.go +++ b/src/govpn/handshake_test.go @@ -62,7 +62,7 @@ func TestHandshakeEnclessSymmetric(t *testing.T) { v := VerifierNew(DefaultM, DefaultT, DefaultP, &peerId) conf.Verifier = v conf.DSAPriv = v.PasswordApply("does not matter") - conf.EncLess = true + conf.Encless = true conf.Noise = true hsS := NewHandshake("server", Dummy{&ciphertext}, conf) hsC := HandshakeStart("client", Dummy{&ciphertext}, conf) @@ -74,6 +74,6 @@ func TestHandshakeEnclessSymmetric(t *testing.T) { if hsC.Client(ciphertext) == nil { t.Fail() } - conf.EncLess = false + conf.Encless = false conf.Noise = false } diff --git a/src/govpn/peer.go b/src/govpn/peer.go index f4e04b0..2907662 100644 --- a/src/govpn/peer.go +++ b/src/govpn/peer.go @@ -72,7 +72,7 @@ type Peer struct { NoiseEnable bool CPR int CPRCycle time.Duration `json:"-"` - EncLess bool + Encless bool MTU int // Cryptography related @@ -166,8 +166,8 @@ func newPeer(isClient bool, addr string, conn io.Writer, conf *PeerConf, key *[S } bufSize := S20BS + 2*conf.MTU - if conf.EncLess { - bufSize += EncLessEnlargeSize + if conf.Encless { + bufSize += EnclessEnlargeSize noiseEnable = true } peer := Peer{ @@ -178,7 +178,7 @@ func newPeer(isClient bool, addr string, conn io.Writer, conf *PeerConf, key *[S NoiseEnable: noiseEnable, CPR: conf.CPR, CPRCycle: cprCycle, - EncLess: conf.EncLess, + Encless: conf.Encless, MTU: conf.MTU, Key: key, @@ -238,9 +238,9 @@ func (p *Peer) EthProcess(data []byte) { p.BytesPayloadOut += int64(len(data)) } - if p.NoiseEnable && !p.EncLess { + if p.NoiseEnable && !p.Encless { p.frameT = p.bufT[S20BS : S20BS+p.MTU-TagSize] - } else if p.EncLess { + } else if p.Encless { p.frameT = p.bufT[S20BS : S20BS+p.MTU] } else { p.frameT = p.bufT[S20BS : S20BS+len(data)+1+NonceSize] @@ -252,9 +252,9 @@ func (p *Peer) EthProcess(data []byte) { p.frameT[len(p.frameT)-NonceSize:], ) var out []byte - if p.EncLess { + if p.Encless { var err error - out, err = EncLessEncode( + out, err = EnclessEncode( p.Key, p.frameT[len(p.frameT)-NonceSize:], p.frameT[:len(p.frameT)-NonceSize], @@ -296,9 +296,9 @@ func (p *Peer) PktProcess(data []byte, tap io.Writer, reorderable bool) bool { } var out []byte p.BusyR.Lock() - if p.EncLess { + if p.Encless { var err error - out, err = EncLessDecode( + out, err = EnclessDecode( p.Key, data[len(data)-NonceSize:], data[:len(data)-NonceSize], diff --git a/src/govpn/peer_test.go b/src/govpn/peer_test.go index 09a0465..c0200e3 100644 --- a/src/govpn/peer_test.go +++ b/src/govpn/peer_test.go @@ -86,11 +86,11 @@ func TestTransportSymmetricNoise(t *testing.T) { peer.NoiseEnable = true } -func TestTransportSymmetricEncLess(t *testing.T) { +func TestTransportSymmetricEncless(t *testing.T) { peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte)) - peer.EncLess = true + peer.Encless = true peer.NoiseEnable = true - peerd.EncLess = true + peerd.Encless = true peerd.NoiseEnable = true f := func(payload []byte) bool { if len(payload) == 0 { @@ -103,7 +103,7 @@ func TestTransportSymmetricEncLess(t *testing.T) { t.Error(err) } peer.NoiseEnable = false - peer.EncLess = false + peer.Encless = false } func BenchmarkEnc(b *testing.B) { -- 2.44.0