Пример #1
0
func setKey(ctx *C.shn_ctx, key []uint8) {
	C.shn_key(ctx,
		(*C.uchar)(unsafe.Pointer(&key[0])),
		C.int(len(key)))

	nonce := make([]byte, 4)
	binary.BigEndian.PutUint32(nonce, 0)
	C.shn_nonce(ctx,
		(*C.uchar)(unsafe.Pointer(&nonce[0])),
		C.int(len(nonce)))
}
Пример #2
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
}
Пример #3
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)))
}