Commit fc3a9f3b authored by David Wong's avatar David Wong Committed by Jonathan Rudenberg

Removed the XR pattern and added the initiator check in WriteMessage and...

Removed the XR pattern and added the initiator check in WriteMessage and ReadMessage according to spec (#22)

* removed the XR pattern and added the initiator check in WriteMessage and ReadMessage according to spec

* removed extra space I shouldn't have added

* fixed vectors

* re-generated via vectorgen
parent c49e9fa1
......@@ -13,7 +13,7 @@ var HandshakeKN = HandshakePattern{
InitiatorPreMessages: []MessagePattern{MessagePatternS},
Messages: [][]MessagePattern{
{MessagePatternE},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHES},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHSE},
},
}
......@@ -32,7 +32,7 @@ var HandshakeKK = HandshakePattern{
ResponderPreMessages: []MessagePattern{MessagePatternS},
Messages: [][]MessagePattern{
{MessagePatternE, MessagePatternDHES, MessagePatternDHSS},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHES},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHSE},
},
}
......@@ -40,7 +40,7 @@ var HandshakeNX = HandshakePattern{
Name: "NX",
Messages: [][]MessagePattern{
{MessagePatternE},
{MessagePatternE, MessagePatternDHEE, MessagePatternS, MessagePatternDHSE},
{MessagePatternE, MessagePatternDHEE, MessagePatternS, MessagePatternDHES},
},
}
......@@ -49,7 +49,7 @@ var HandshakeKX = HandshakePattern{
InitiatorPreMessages: []MessagePattern{MessagePatternS},
Messages: [][]MessagePattern{
{MessagePatternE},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHES, MessagePatternS, MessagePatternDHSE},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHSE, MessagePatternS, MessagePatternDHES},
},
}
......@@ -66,7 +66,7 @@ var HandshakeIN = HandshakePattern{
Name: "IN",
Messages: [][]MessagePattern{
{MessagePatternE, MessagePatternS},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHES},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHSE},
},
}
......@@ -85,7 +85,7 @@ var HandshakeIK = HandshakePattern{
ResponderPreMessages: []MessagePattern{MessagePatternS},
Messages: [][]MessagePattern{
{MessagePatternE, MessagePatternDHES, MessagePatternS, MessagePatternDHSS},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHES},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHSE},
},
}
......@@ -93,17 +93,7 @@ var HandshakeXX = HandshakePattern{
Name: "XX",
Messages: [][]MessagePattern{
{MessagePatternE},
{MessagePatternE, MessagePatternDHEE, MessagePatternS, MessagePatternDHSE},
{MessagePatternS, MessagePatternDHSE},
},
}
var HandshakeXR = HandshakePattern{
Name: "XR",
Messages: [][]MessagePattern{
{MessagePatternE},
{MessagePatternE, MessagePatternDHEE},
{MessagePatternS, MessagePatternDHSE},
{MessagePatternE, MessagePatternDHEE, MessagePatternS, MessagePatternDHES},
{MessagePatternS, MessagePatternDHSE},
},
}
......@@ -112,7 +102,7 @@ var HandshakeIX = HandshakePattern{
Name: "IX",
Messages: [][]MessagePattern{
{MessagePatternE, MessagePatternS},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHES, MessagePatternS, MessagePatternDHSE},
{MessagePatternE, MessagePatternDHEE, MessagePatternDHSE, MessagePatternS, MessagePatternDHES},
},
}
......
......@@ -211,6 +211,7 @@ type HandshakeState struct {
psk []byte // preshared key, maybe zero length
messagePatterns [][]MessagePattern
shouldWrite bool
initiator bool
msgIdx int
rng io.Reader
}
......@@ -269,6 +270,7 @@ func NewHandshakeState(c Config) *HandshakeState {
psk: c.PresharedKey,
messagePatterns: c.Pattern.Messages,
shouldWrite: c.Initiator,
initiator: c.Initiator,
rng: c.Random,
}
if hs.rng == nil {
......@@ -355,9 +357,17 @@ func (s *HandshakeState) WriteMessage(out, payload []byte) ([]byte, *CipherState
case MessagePatternDHEE:
s.ss.MixKey(s.ss.cs.DH(s.e.Private, s.re))
case MessagePatternDHES:
s.ss.MixKey(s.ss.cs.DH(s.e.Private, s.rs))
if s.initiator {
s.ss.MixKey(s.ss.cs.DH(s.e.Private, s.rs))
} else {
s.ss.MixKey(s.ss.cs.DH(s.s.Private, s.re))
}
case MessagePatternDHSE:
s.ss.MixKey(s.ss.cs.DH(s.s.Private, s.re))
if s.initiator {
s.ss.MixKey(s.ss.cs.DH(s.s.Private, s.re))
} else {
s.ss.MixKey(s.ss.cs.DH(s.e.Private, s.rs))
}
case MessagePatternDHSS:
s.ss.MixKey(s.ss.cs.DH(s.s.Private, s.rs))
case MessagePatternPSK:
......@@ -430,9 +440,17 @@ func (s *HandshakeState) ReadMessage(out, message []byte) ([]byte, *CipherState,
case MessagePatternDHEE:
s.ss.MixKey(s.ss.cs.DH(s.e.Private, s.re))
case MessagePatternDHES:
s.ss.MixKey(s.ss.cs.DH(s.s.Private, s.re))
if s.initiator {
s.ss.MixKey(s.ss.cs.DH(s.e.Private, s.rs))
} else {
s.ss.MixKey(s.ss.cs.DH(s.s.Private, s.re))
}
case MessagePatternDHSE:
s.ss.MixKey(s.ss.cs.DH(s.e.Private, s.rs))
if s.initiator {
s.ss.MixKey(s.ss.cs.DH(s.s.Private, s.re))
} else {
s.ss.MixKey(s.ss.cs.DH(s.e.Private, s.rs))
}
case MessagePatternDHSS:
s.ss.MixKey(s.ss.cs.DH(s.s.Private, s.rs))
case MessagePatternPSK:
......
......@@ -56,7 +56,6 @@ func init() {
HandshakeXK,
HandshakeIK,
HandshakeXX,
HandshakeXR,
HandshakeIX,
HandshakeN,
HandshakeK,
......
......@@ -29,7 +29,6 @@ func main() {
HandshakeN,
HandshakeK,
HandshakeX,
HandshakeXR,
} {
for _, prologue := range []bool{false, true} {
for _, payloads := range []bool{false, true} {
......@@ -79,12 +78,12 @@ func writeHandshake(out io.Writer, cs CipherSuite, h HandshakePattern, pskPlacem
ephR := cs.GenerateKeypair(hexReader(key2))
configI := Config{
CipherSuite: cs,
Random: hexReader(key3),
Pattern: h,
Initiator: true,
Prologue: prologue,
PresharedKey: psk,
CipherSuite: cs,
Random: hexReader(key3),
Pattern: h,
Initiator: true,
Prologue: prologue,
PresharedKey: psk,
PresharedKeyPlacement: pskPlacement,
}
configR := configI
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment