Commit 52cb934d authored by Reinaldo de Souza Jr's avatar Reinaldo de Souza Jr
Browse files

This is how it was before transitioning to a new DAKE

parent 0936f0d3
......@@ -86,27 +86,62 @@ func (e *Entity) receive(m Msg) {
}
}
func (e *Entity) transitionDAKE() bool {
return e.rid > 0
}
func (e *Entity) sendP1() Msg {
e.our_dh_priv, e.our_dh_pub, _ = c.GenerateKeys()
if e.transitionDAKE() {
fmt.Println("Sending a P1 to transition to a new DAKE")
}
toSend := Msg{P1, e.name, -1, -1, e.our_dh_pub, nil}
fmt.Printf("%s \tsending: %v\n", e.name, toSend)
return toSend
}
func (e *Entity) receiveP1(m Msg) {
e.their_dh = m.dh
e.rid = e.rid + 1
if bytes.Compare(e.our_dh_priv[:], NULLSEC[:]) == 1 {
secret := c.ComputeSecret(e.our_dh_priv, e.their_dh)
e.derive(secret[:])
if e.transitionDAKE() {
fmt.Println("Receiving a P1 to transition to a new DAKE")
}
}
func (e *Entity) sendP2() Msg {
e.our_dh_priv, e.our_dh_pub, _ = c.GenerateKeys()
secret := c.ComputeSecret(e.our_dh_priv, e.their_dh)
e.derive(secret[:])
e.j = 0 // she will ratchet when sending next
if e.transitionDAKE() {
fmt.Println("Sending a P2 to transition to a new DAKE")
}
toSend := Msg{P2, e.name, -1, -1, e.our_dh_pub, nil}
fmt.Printf("%s \tsending: %v\n", e.name, toSend)
return toSend
}
func (e *Entity) receiveP2(m Msg) {
e.their_dh = m.dh
e.rid = e.rid + 1
secret := c.ComputeSecret(e.our_dh_priv, e.their_dh)
e.derive(secret[:])
e.j = 1 // so he does not ratchet
if e.transitionDAKE() {
fmt.Println("Receiving a P2 to transition to a new DAKE")
}
}
func (e *Entity) receiveData(m Msg) {
ck := make([]byte, 64)
if m.rid == e.rid+1 {
fmt.Printf("%s \tFollow Ratcheting...\n", e.name)
e.rid = m.rid
e.their_dh = m.dh
secret := c.ComputeSecret(e.our_dh_priv, e.their_dh)
......@@ -165,33 +200,6 @@ func (e *Entity) query() Msg {
return toSend
}
func (e *Entity) sendP1() Msg {
e.our_dh_priv, e.our_dh_pub, _ = c.GenerateKeys()
e.j = 1
e.rid = e.rid + 1
if bytes.Compare(e.their_dh[:], NULLPUB[:]) == 1 {
secret := c.ComputeSecret(e.our_dh_priv, e.their_dh)
e.derive(secret[:])
}
toSend := Msg{P1, e.name, -1, -1, e.our_dh_pub, nil}
fmt.Printf("%s \tsending: %v\n", e.name, toSend)
return toSend
}
func (e *Entity) sendP2() Msg {
e.j = 0
e.rid = e.rid + 1
e.our_dh_priv, e.our_dh_pub, _ = c.GenerateKeys()
secret := c.ComputeSecret(e.our_dh_priv, e.their_dh)
e.derive(secret[:])
toSend := Msg{P2, e.name, -1, -1, e.our_dh_pub, nil}
fmt.Printf("%s \tsending: %v\n", e.name, toSend)
return toSend
}
func main() {
a, b := initialize()
b.receive(a.query())
......@@ -257,9 +265,9 @@ func main() {
func initialize() (alice, bob Entity) {
alice.name = "Alice"
alice.rid = -2
alice.rid = 0
bob.name = "Bob"
bob.rid = -2
bob.rid = 0
return alice, bob
}
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