Esempio n. 1
0
func (s *ShannonStream) FinishSend() (err error) {
	count := 4
	mac := make([]byte, count)
	C.shn_finish(&s.sendCipher,
		(*C.uchar)(unsafe.Pointer(&mac[0])),
		C.int(count))

	s.sendNonce += 1
	nonce := make([]uint8, 4)
	binary.BigEndian.PutUint32(nonce, s.sendNonce)
	C.shn_nonce(&s.sendCipher,
		(*C.uchar)(unsafe.Pointer(&nonce[0])),
		C.int(len(nonce)))

	_, err = s.writer.Write(mac)
	return
}
Esempio n. 2
0
func (s *ShannonStream) finishRecv() {
	count := 4

	mac := make([]byte, count)
	io.ReadFull(s.reader, mac)

	mac2 := make([]byte, count)
	C.shn_finish(&s.recvCipher,
		(*C.uchar)(unsafe.Pointer(&mac2[0])),
		C.int(count))

	if !bytes.Equal(mac, mac2) {
		//log.Fatal("received mac doesn't match")
		log.Println("received mac doesn't match")
	}

	s.recvNonce += 1
	nonce := make([]uint8, 4)
	binary.BigEndian.PutUint32(nonce, s.recvNonce)
	C.shn_nonce(&s.recvCipher,
		(*C.uchar)(unsafe.Pointer(&nonce[0])),
		C.int(len(nonce)))
}