Ejemplo n.º 1
0
func (ic *incoming) Init(session *Session) {
	ic.session = session
	ic.handshake = &session.handshake
	ic.state = stateHandshakeNoKey
	ic.stateChan = session.stateChan
	ic.cipher.SetRandomKey()
	ic.handshakeReassembly = buf.BeginReassembly(prim.PublicBinaryLen)
	ic.frameReassembly = buf.BeginReassembly(session.MTU + frameOverhead)

	nbufs := 3
	ic.frontGrams = make(chan []byte, nbufs)
	ic.frontBufs = make(chan []byte, nbufs)
	for i := 0; i < nbufs; i++ {
		ic.frontBufs <- make([]byte, 0, session.MTU)
	}
	ic.frontHeldBuf = nil
	ic.frontHeldTail = nil
}
Ejemplo n.º 2
0
func (og *outgoing) Init(session *Session, initialData []byte) {
	og.session = session
	og.handshake = &session.handshake
	og.state = stateHandshakeNoKey
	og.stateChan = session.stateChan
	og.cipher.SetRandomKey()
	og.queued = buf.BeginReassembly(prim.PublicBinaryLen + 2*prim.AuthLen + session.MTU + frameOverhead)
	og.queued.CopyIn(initialData)

	nbufs := 3
	og.frontGrams = make(chan []byte, nbufs)
	og.frontBufs = make(chan []byte, nbufs)
	for i := 0; i < nbufs; i++ {
		og.frontBufs <- make([]byte, 0, session.MTU)
	}
}
Ejemplo n.º 3
0
func (ic *incoming) receivedEphemeralKey() {
	log.Debug("<-  received ephemeral key")
	ic.handshake.completeWith(ic.handshakeReassembly.Data())

	inKeys := &ic.handshake.in
	ic.cipher.SetKey(inKeys.cipherKey)
	ic.mac.SetKey(inKeys.authKey)
	ic.mac.Reset(0)
	ic.macPosition = 0
	ic.confirm = inKeys.confirm
	log.Debug("<-  expect confirmation starting with %x", ic.confirm[:2])
	inKeys.Clear()

	ic.handshakeReassembly = buf.BeginReassembly(prim.AuthLen)
	ic.state = stateHandshakeKey
	ic.stateChan <- ic.state
}