Got cipher StreamReader/Writer in w/o yet using them.

This commit is contained in:
Russ Magee 2018-01-08 23:26:24 -08:00
parent 9885067a48
commit b28ca552bd
2 changed files with 13 additions and 7 deletions

View file

@ -41,7 +41,7 @@ const (
/* Support functionality to set up encryption after a channel has /* Support functionality to set up encryption after a channel has
been negotiated via hkexnet.go been negotiated via hkexnet.go
*/ */
func (hd Conn) getReadStream(keymat *big.Int, flags uint32, r io.Reader) (ret io.Reader) { func (hc Conn) getStreamReader(keymat *big.Int, flags uint32, r io.Reader) (ret *cipher.StreamReader) {
var key []byte var key []byte
var block cipher.Block var block cipher.Block
var err error var err error
@ -78,7 +78,7 @@ func (hd Conn) getReadStream(keymat *big.Int, flags uint32, r io.Reader) (ret io
return return
} }
func (hd Conn) getWriteStream(keymat *big.Int, flags uint32, w io.Writer) (ret io.Writer) { func (hc Conn) getStreamWriter(keymat *big.Int, flags uint32, w io.Writer) (ret *cipher.StreamWriter) {
var key []byte var key []byte
var block cipher.Block var block cipher.Block
var err error var err error

View file

@ -22,6 +22,7 @@ package herradurakex
// 'net.Dial', 'net.Listen' etc. with 'hkex.Dial', 'hkex.Listen' and so // 'net.Dial', 'net.Listen' etc. with 'hkex.Dial', 'hkex.Listen' and so
// forth. // forth.
import ( import (
"crypto/cipher"
"fmt" "fmt"
"math/big" "math/big"
"net" "net"
@ -32,6 +33,8 @@ import (
type Conn struct { type Conn struct {
c net.Conn // which also implements io.Reader, io.Writer, ... c net.Conn // which also implements io.Reader, io.Writer, ...
h *HerraduraKEx h *HerraduraKEx
r *cipher.StreamReader
w *cipher.StreamWriter
} }
// Dial as net.Dial(), but with implicit HKEx PeerD read on connect // Dial as net.Dial(), but with implicit HKEx PeerD read on connect
@ -40,9 +43,8 @@ func Dial(protocol string, ipport string) (hc *Conn, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
hc = &Conn{c, New(0, 0)} hc = &Conn{c, New(0, 0), nil, nil}
// KEx
fmt.Fprintf(c, "0x%s\n", hc.h.d.Text(16)) fmt.Fprintf(c, "0x%s\n", hc.h.d.Text(16))
d := big.NewInt(0) d := big.NewInt(0)
@ -55,6 +57,9 @@ func Dial(protocol string, ipport string) (hc *Conn, err error) {
fmt.Printf("**(c)** peerD:%s\n", hc.h.PeerD.Text(16)) fmt.Printf("**(c)** peerD:%s\n", hc.h.PeerD.Text(16))
hc.h.FA() hc.h.FA()
fmt.Printf("**(c)** FA:%s\n", hc.h.fa) fmt.Printf("**(c)** FA:%s\n", hc.h.fa)
hc.r = hc.getStreamReader(hc.h.fa, 0x0, hc.c)
hc.w = hc.getStreamWriter(hc.h.fa, 0x0, hc.c)
return return
} }
@ -90,9 +95,9 @@ func (hl *HKExListener) Accept() (hc Conn, err error) {
fmt.Println("[Accepted]") fmt.Println("[Accepted]")
if err != nil { if err != nil {
return Conn{nil, nil}, err return Conn{nil, nil, nil, nil}, err
} }
hc = Conn{c, New(0, 0)} hc = Conn{c, New(0, 0), nil, nil}
d := big.NewInt(0) d := big.NewInt(0)
_, err = fmt.Fscanln(c, d) _, err = fmt.Fscanln(c, d)
@ -106,9 +111,10 @@ func (hl *HKExListener) Accept() (hc Conn, err error) {
hc.h.FA() hc.h.FA()
fmt.Printf("**(s)** FA:%s\n", hc.h.fa) fmt.Printf("**(s)** FA:%s\n", hc.h.fa)
// KEx
fmt.Fprintf(c, "0x%s\n", hc.h.d.Text(16)) fmt.Fprintf(c, "0x%s\n", hc.h.d.Text(16))
hc.r = hc.getStreamReader(hc.h.fa, 0x0, hc.c)
hc.w = hc.getStreamWriter(hc.h.fa, 0x0, hc.c)
return return
} }